Rails-based base tool engine integrates a variety of services
Add this line to your application's Gemfile:
- Copy repo to your rails project, like
engines/
- Add this to your gemfile
gem 'bean_utils', path: 'engines/bean_utils'
- Run
bundle install
- Run
rake bean_utils:install:migrations
generate migrations - Delete the migrations files that are not needed for this project
- Run
rake db:migrate
TBD...
TBD...
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.
- New a model inheritance
BeanUtils::ThirdPartyApplication
(STI), likeBeanUtils::GoogleApplication
- 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)
- Defining method like
api_config
, then you can use it where you want to use it. - 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)
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
Contribution directions go here.
The gem is available as open source under the terms of the MIT License.