class RecombeeApiClient::RecombeeClient

Client for sending requests to Recombee recommender system

Constants

BATCH_MAX_SIZE
USER_AGENT

Public Class Methods

new(account, token, options = {}) click to toggle source
  • account -> Name of your account at Recombee

  • token -> Secret token obtained from Recombee for signing requests

# File lib/recombee_api_client.rb, line 26
def initialize(account, token, options = {})
  @account = account
  @token = token
  @protocol = options[:protocol] || 'https'
  @base_uri = get_base_uri(options)
end

Public Instance Methods

send(request) click to toggle source
  • request -> ApiRequest to be sent to Recombee recommender

# File lib/recombee_api_client.rb, line 35
def send(request)

  return send_multipart_batch(request) if request.kind_of? Batch and request.requests.size > BATCH_MAX_SIZE

  timeout = request.timeout / 1000
  uri = process_request_uri(request)
  uri = sign_url(uri)
  protocol = request.ensure_https ? 'https' : @protocol.to_s
  uri = protocol + '://' + @base_uri + uri
  # puts uri
  begin
    case request.method
    when :put
      put(request, uri, timeout)
    when :get
      get(request, uri, timeout)
    when :post
      post(request, uri, timeout)
    when :delete
      delete(request, uri, timeout)
    end
  rescue Timeout::Error
    fail ApiTimeout.new(request)
  end
end