Class: RecombeeApiClient::RecombeeClient

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/recombee_api_client.rb

Overview

Client for sending requests to Recombee recommender system

Constant Summary collapse

BATCH_MAX_SIZE =
10000
USER_AGENT =
{'User-Agent' => 'recombee-ruby-api-client/5.1.0'}

Instance Method Summary collapse

Constructor Details

#initialize(account, token, options = {}) ⇒ RecombeeClient

  • account -> Name of your account at Recombee

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



26
27
28
29
30
31
# File 'lib/recombee_api_client.rb', line 26

def initialize(, token, options = {})
  @account = 
  @token = token
  @protocol = options[:protocol] || 'https'
  @base_uri = get_base_uri(options)
end

Instance Method Details

#send(request) ⇒ Object

  • request -> ApiRequest to be sent to Recombee recommender



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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