Eezy Common
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file lib/eezy_common
. To experiment with that code, run bin/console
for an interactive prompt. All the gems which are created going ahead will be added here
Installation
Add this line to your application's Gemfile:
gem 'eezy_common'
And then execute:
$ bundle
Or install it yourself as:
$ gem install eezy_common
Configuration
Usage
EezyCommon.configure do |config|
config.some_config = 'foo-bar'
end
EezyCommon.configuration
EezyCommon.configuration.some_config
Available Configuration Options
EezyCommon.configuration.support_host
EezyCommon.configuration.support_api_key
EezyCommon.configuration.support_profile_path
EezyCommon.configuration.support_contact_us_path
Usage
Logging Configuration
require 'eezy_common/logging/config'
Rails.application.configure do
EezyCommon::Logging::Config.configure(config)
end
Demogorgon API Client
require 'eezy_common/api_clients/demogorgon'
url = ''
user = ''
password = ''
client = EezyCommon::ApiClients::Demogorgon.new(host: url, user: user, password: password, queue: 'optional_default_queue')
client.generate_preview(resource_hash, queue: 'optional_queue_name')
resource_hash = {
site: 'vecteezy',
foreign_id: 'resource_id',
original_file_url: 'url of the file',
webhook_url: 'Callback url',
need_watermark: true
}
client.generate_thumbnail(resource_hash, queue: 'optional_queue_name')
resource_hash = {
foreign_id: 'resource_id',
original_file_url: 'url of the file',
webhook_url: 'Callback url',
thumbnail_time: 3
}
Background Removal API Client
ref. https://ml.eezy.cloud/background-removal/docs
require 'eezy_common/background_removal/client'
url = ''
source_file = ''
client = EezyCommon::BackgroundRemoval::Client.new(url: url)
process_response = client.process(url: source_file)
process_response.success?
process_response.failed?
process_response.job_guid
status_response = client.status(job_guid: job_guid_from_process_response)
status_response.success?
status_response.failed?
status_response.mask
status_response.no_background
status_response.blur
Image API Client
ref. https://ml.eezy.cloud/image-api/docs
require 'eezy_common/image_api/client'
url = ''
prompt = ''
client = EezyCommon::ImageAPI::Client.new(url: url)
process_response = client.process(prompt: prompt)
process_response.success?
process_response.failed?
process_response.job_guid
status_response = client.status(job_guid: job_guid_from_process_response)
status_response.success?
status_response.failed?
status_response.model
status_response.seed
status_response.image_urls
Custom IRB Rails Console
- Create initializer to inject the custom console
Rails.application.console do
gem = Gem::Specification.find_by_name('eezy_common')
gem_root = gem.gem_dir
ARGV.push '-r', File.join(gem_root, 'lib', 'eezy_common', 'irb.rb')
end
- Add irb history file to .gitignore
.*-irb-history.txt
Metrics
require 'eezy_common/metrics'
EezyCommon.configure do |config|
config.metrics_host = 'www.example.com'
config.metrics_port = 1234
config.metrics_single_thread = false
config.metrics_buffer_flush_interval = 60
end
EezyCommon::Metrics.default_tags = %W[env:#{Rails.env} server:#{Socket.gethostname} app:#{Settings.app}]
EezyCommon::Metrics.increment('exceptions')
EezyCommon::Metrics.decrement('exceptions')
EezyCommon::Metrics.count('exceptions', 5)
EezyCommon::Metrics.gauge('queue_size', 15)
EezyCommon::Metrics.timing('operation.duration', 35)
EezyCommon::Metrics.count('tagged_value', 5, tags: ["another_tag:value", ...])
EezyCommon::Metrics.count("tagged_value.#{tag_value}", 5)
EezyCommon::Metrics.count("tagged_value.#{tag_value}", 6)
value = EezyCommon::Metrics.benchmark('expensive_operation.duration') do
perform_some_expensive_operation_and_return_value!
end
Exception Handler
SENTRY_ORG=eezy-mk
SENTRY_AUTH_TOKEN=TOKENGOESHERE
require 'eezy_common/exception_handler_railtie'
require 'eezy_common/exception_handler'
EezyCommon::ExceptionHandler.configure do |config|
config.app_dirs_pattern = /(bin|exe|app|config|lib|test|frontend)/.freeze
config.release = ENV['SENTRY_RELEASE'] if ENV['SENTRY_RELEASE']
end
def foo
puts 'Hello World'
rescue StandardError => e
EezyCommon::ExceptionHandler.handle(e)
EezyCommon::ExceptionHandler.handle(e,
logger: Logger.new(STDOUT),
report_metric: true,
track_error: true,
message: 'This is an example',
context: { foo: true, bar: false })
end
EezyCommon::ExceptionHandler.set_user({id: 12345})
class SkipException < StandardError
def skip_tracking?
true
end
end
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/eezy_common.