class Scale

Constants

VALID_TASK_TYPES

Attributes

api_key[RW]
callback_auth_key[RW]
default_request_params[RW]
logging[RW]

Public Class Methods

new(api_key: nil, callback_auth_key: nil, default_request_params: {}, logging: false, callback_url: nil) click to toggle source
# File lib/scale.rb, line 39
def initialize(api_key: nil, callback_auth_key: nil, default_request_params: {}, logging: false, callback_url: nil)
  Scale.validate_api_key(api_key)

  self.api_key = api_key
  self.callback_auth_key = callback_auth_key
  self.default_request_params = default_request_params.merge(callback_url: callback_url)
  self.logging = logging
end
validate_api_key(api_key) click to toggle source
# File lib/scale.rb, line 33
def self.validate_api_key(api_key)
  if api_key.length < 5 || !(api_key.start_with?('live') || api_key.start_with?('test')) 
    raise Api::APIKeyInvalid
  end
end

Public Instance Methods

build_callback(params, callback_key: nil) { |callback| ... } click to toggle source
# File lib/scale.rb, line 68
def build_callback(params, callback_key: nil)
  callback = Api::Callback.new(params, callback_key: callback_key, client: client)
  
  if block_given?
    yield callback
  else 
    callback
  end
end
client() click to toggle source
# File lib/scale.rb, line 56
def client
  @client ||= Api.new(api_key, callback_auth_key, default_request_params, logging)
end
create_task(type, args = {}) click to toggle source
# File lib/scale.rb, line 64
def create_task(type, args = {})
  client.create_task(type, args)
end
live()
Alias for: live?
live?() click to toggle source
# File lib/scale.rb, line 48
def live?
  api_key.start_with?('live')
end
Also aliased as: live, live_mode?
live_mode?()
Alias for: live?
method_missing(methodId, *args, &block) click to toggle source
# File lib/scale.rb, line 17
def method_missing(methodId, *args, &block)
  str = methodId.id2name
  match = /^create_([a-z_]+)_task$/.match(str)
  if match
    taskType = match[1].gsub(/[^a-z]/, '')
    taskType = "annotation" if taskType == "imagerecognition"
    if VALID_TASK_TYPES.include?(taskType)
      create_task(match[1], *args)
    else
      raise ArgumentError.new("Method `#{methodId}` doesn't exist.")
    end
  else
    raise ArgumentError.new("Method `#{methodId}` doesn't exist.")
  end
end
tasks() click to toggle source
# File lib/scale.rb, line 60
def tasks
  @tasks ||= Scale::Api::Tasks.new(client)
end
test()
Alias for: test?
test?() click to toggle source
# File lib/scale.rb, line 52
def test?
  api_key.start_with?('test')
end
Also aliased as: test, test_mode?
test_mode?()
Alias for: test?