class RecombeeApiClient::RecombeeClient

Client for sending requests to Recombee recommender system

Constants

BATCH_MAX_SIZE
USER_AGENT

Public Class Methods

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

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

  • protocol -> Default protocol for sending requests. Possible values: 'http', 'https'.

# File lib/recombee_api_client.rb, line 27
def initialize(account, token, protocol = 'https', options = {})
  @account = account
  @token = token
  @protocol = protocol
  @base_uri = ENV['RAPI_URI'] if ENV.key? 'RAPI_URI'
  @base_uri||=  options[:base_uri]
  @base_uri||= 'rapi.recombee.com'
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 38
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
  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