Class: ImageBoss::Path
- Inherits:
-
Object
- Object
- ImageBoss::Path
- Defined in:
- lib/imageboss/path.rb
Constant Summary collapse
- SERVICE_URL =
'https://img.imageboss.me'.freeze
- OPERATIONS =
{ cover: { recipe: '/:source/:operation::mode/:widthx:height/:options/', required: [:width, :height] }, width: { recipe: '/:source/:operation/:width/:options/', required: [:width] }, height: { recipe: '/:source/:operation/:height/:options/', required: [:height]}, cdn: { recipe: '/:source/:operation/:options/', required: [] } }.freeze
Instance Method Summary collapse
-
#initialize(client_options, asset_path) ⇒ Path
constructor
A new instance of Path.
- #operation(name, options = {}) ⇒ Object
Constructor Details
#initialize(client_options, asset_path) ⇒ Path
Returns a new instance of Path.
18 19 20 21 22 23 24 |
# File 'lib/imageboss/path.rb', line 18 def initialize(, asset_path) @client_options = @service_url = [:service_url] || SERVICE_URL @source = [:source] @secret = [:secret] @asset_path = asset_path end |
Instance Method Details
#operation(name, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/imageboss/path.rb', line 26 def operation(name, = {}) return @asset_path unless @client_options[:enabled] @operation_name = name.to_sym @options = @extra_options = ([:options]) @operation = OPERATIONS[@operation_name] @required = @operation[:required] @required.each do |r| @options.fetch(r) end recipe = [ SERVICE_URL, @operation[:recipe].chomp('/'), @asset_path.gsub(/^\/?(.+)/, "\\1") ].join recipe_url = parse(recipe) recipe_path = parse(recipe).gsub(SERVICE_URL, '') @secret == false ? recipe_url : add_params(recipe_url, { bossToken: create_token(recipe_path) }) end |