Skip to content

Rails-based base tool engine integrates a variety of services

License

Notifications You must be signed in to change notification settings

beansmile/bean_utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BeanUtils

Rails-based base tool engine integrates a variety of services

Installation

Add this line to your application's Gemfile:

  1. Copy repo to your rails project, like engines/
  2. Add this to your gemfile gem 'bean_utils', path: 'engines/bean_utils'
  3. Run bundle install
  4. Run rake bean_utils:install:migrations generate migrations
  5. Delete the migrations files that are not needed for this project
  6. Run rake db:migrate

Usage

Sms

TBD...

IdVerification

TBD...

Third-Party Application

Save third-party application data to database, make the operation and maintenance easier, you can update the data directly and add a restart step to the service if necessary.

  1. New a model inheritance BeanUtils::ThirdPartyApplication (STI), like BeanUtils::GoogleApplication
  2. Define the attributes in your application model
  • Normal attributes application_attrs :api_base_uri, this will generate these methods: api_base_uri=, api_base_uri
  • Secret attributes application_secret_attrs :api_key, :api_secret, this will generate these methods: api_key=, api_key(Encrypted), api_key_decryption(Decrypted)
  1. Defining method like api_config, then you can use it where you want to use it.
  2. Make your Admin-end of this module.

Example: using in your third-party request client.

# models/bean_utils/google_application.rb
def api_config
 {
   api_base_uri: api_base_uri,
   api_key: api_key_decryption,
   api_secret: api_secret_decryption,
 }
end
# lib/google/client.rb
module Google
  class Client
    include HTTParty

    class << self
      def config
        ::BeanUtils::GoogleApplication.first.api_config
      end
    end

    def http_post()
      post(path, body: body, headers: headers)
    end

    def headers
      { api_key: Google::Client.config.dig(:api_key) }
    end
  end
end

Google::Client.base_uri Google::Client.config.dig(:api_base_uri)

EmailDomains

Email domain whitelist and blocklist base on https://github.com/disposable-email-domains/disposable-email-domains.

# Check if the email is in the blocklisted domains
BeanUtils::EmailDomains.in_blocklist?("email@example.com") #=> return true or false

# Check if the email is in the whitelist domains
BeanUtils::EmailDomains.in_whitelist?("email@example.com") #=> return true or false

# Or you can directly read out the list to do other things
BeanUtils::EmailDomains.blocklist # return array of domain

BeanUtils::EmailDomains.whitelist # return array of domain

Contributing

Contribution directions go here.

License

The gem is available as open source under the terms of the MIT License.

About

Rails-based base tool engine integrates a variety of services

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published