New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eezy_common

Package Overview
Maintainers
1
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eezy_common

  • 1.5.0
  • unpublished
  • Rubygems

Version published
Maintainers
1
Created
Source

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
# ./config/initializers/eezy_common.rb
EezyCommon.configure do |config|
  config.some_config = 'foo-bar'
end

# Usage
EezyCommon.configuration # => #<OpenStruct some_config="foo-bar">
EezyCommon.configuration.some_config #=> "foo-bar"
Available Configuration Options
EezyCommon.configuration.support_host # Host to support ticketing system
EezyCommon.configuration.support_api_key # API Key to support ticketing system
EezyCommon.configuration.support_profile_path # Path to profile api endpoint in support ticketing system
EezyCommon.configuration.support_contact_us_path # Path to contact us api endpoint in support ticketing system

Usage

Logging Configuration
# config/environments/production.rb
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')

# For Generating Preview
client.generate_preview(resource_hash, queue: 'optional_queue_name')

# queue provided here will override the default client queue
# define resource_hash in your app
# Example resource_hash:
resource_hash = {
  site: 'vecteezy',
  foreign_id: 'resource_id',
  original_file_url: 'url of the file',
  webhook_url: 'Callback url',
  need_watermark: true #boolean
}


# For getting thumbnail at particular time
client.generate_thumbnail(resource_hash, queue: 'optional_queue_name')
# queue provided here will override the default client queue
# define resource_hash in your app
# Example resource_hash:
resource_hash = {
  foreign_id: 'resource_id',
  original_file_url: 'url of the file',
  webhook_url: 'Callback url',
  thumbnail_time: 3 #At what time frame in seconds you want the thumbnail generated
}
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)

# Generate a job to remove a background
process_response = client.process(url: source_file)
process_response.success?
process_response.failed?
process_response.job_guid

# Poll job status
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
#etc...
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)

# Generate a job to generate an image
process_response = client.process(prompt: prompt)
process_response.success?
process_response.failed?
process_response.job_guid

# Poll job status
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
#etc...
Custom IRB Rails Console
  • Create initializer to inject the custom console
# ./app/config/initializers/irb.rb

# frozen_string_literal: true

Rails.application.console do
  gem = Gem::Specification.find_by_name('eezy_common') # rubocop:disable Rails/DynamicFindBy
  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
# ./config/initializers/eezy_common.rb
require 'eezy_common/metrics'

EezyCommon.configure do |config|
  config.metrics_host = 'www.example.com' # defaults to localhost
  config.metrics_port = 1234 # defaults to 8125
  config.metrics_single_thread = false # defaults to false. https://github.com/DataDog/dogstatsd-ruby#v5x-common-pitfalls
  config.metrics_buffer_flush_interval = 60 # defaults to 10. Set to nil to disable
end

EezyCommon::Metrics.default_tags = %W[env:#{Rails.env} server:#{Socket.gethostname} app:#{Settings.app}]

# Usage
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) # can be any number but conventionally in integer milliseconds

# metric key names can be generally [a-zA-Z0-9_-.] but InfluxDB will convert periods to underscores

# Providing extra tags
# BE CAREFUL, if the total cardinality of all tag values across all projects is too high, it can
# clog up influxDB. Good tag values are a known low cardinality, e.g. locale or content_type
EezyCommon::Metrics.count('tagged_value', 5, tags: ["another_tag:value", ...])

# If you're unsure, put your 'tag' in the metric name and then split in the dashboard
EezyCommon::Metrics.count("tagged_value.#{tag_value}", 5)
EezyCommon::Metrics.count("tagged_value.#{tag_value}", 6)

# Benchmark runs the (required) block, emits a timing() in milliseconds, and returns the block value
value = EezyCommon::Metrics.benchmark('expensive_operation.duration') do
  perform_some_expensive_operation_and_return_value!
end
Exception Handler
# Ensure sentry env vars are set somewhere
SENTRY_ORG=eezy-mk
SENTRY_AUTH_TOKEN=TOKENGOESHERE

# To enable sentry rails and sidekiq middlewares you need to load the railtie
# ./config/application.rb
require 'eezy_common/exception_handler_railtie'

# ./config/initializers/eezy_common.rb
require 'eezy_common/exception_handler'

EezyCommon::ExceptionHandler.configure do |config|
  # Set app level dirs
  config.app_dirs_pattern = /(bin|exe|app|config|lib|test|frontend)/.freeze

  # Set the current release to the one generated by deploy
  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

# Advanced Usages
EezyCommon::ExceptionHandler.set_user({id: 12345})

# Skip tracking at the exception instance level by defining a #skip_tracking? method
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.

FAQs

Package last updated on 08 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc