Class: Algolia::Recommend::Client
- Inherits:
-
Object
- Object
- Algolia::Recommend::Client
- Includes:
- Helpers
- Defined in:
- lib/algolia/recommend_client.rb
Class Method Summary collapse
-
.create(app_id, api_key) ⇒ Object
Create a new client providing only app ID and API key.
-
.create_with_config(config) ⇒ Object
Create a new client providing only an Recommend::Config object.
Instance Method Summary collapse
-
#get_frequently_bought_together(requests, opts = {}) ⇒ Hash
Get frequently bought together items for the given requests.
-
#get_recommendations(requests, opts = {}) ⇒ Hash
Get recommendation for the given queries.
-
#get_related_products(requests, opts = {}) ⇒ Hash
Get related products for the given requests.
-
#initialize(recommend_config, opts = {}) ⇒ Client
constructor
Initializes the Recommend client.
Methods included from Helpers
#check_array, #check_object, #chunk, #deserialize_settings, #get_object_id, #get_option, #handle_params, #hash_includes_subset?, included, #json_to_hash, #path_encode, #symbolize_hash, #to_json, #to_query_string
Constructor Details
#initialize(recommend_config, opts = {}) ⇒ Client
Initializes the Recommend client
18 19 20 21 22 23 24 |
# File 'lib/algolia/recommend_client.rb', line 18 def initialize(recommend_config, opts = {}) @config = recommend_config adapter = opts[:adapter] || Defaults::ADAPTER logger = opts[:logger] || LoggerHelper.create requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter, logger) @transporter = Transport::Transport.new(@config, requester) end |
Class Method Details
.create(app_id, api_key) ⇒ Object
Create a new client providing only app ID and API key
33 34 35 36 |
# File 'lib/algolia/recommend_client.rb', line 33 def self.create(app_id, api_key) config = Recommend::Config.new(application_id: app_id, api_key: api_key) create_with_config(config) end |
.create_with_config(config) ⇒ Object
Create a new client providing only an Recommend::Config object
44 45 46 |
# File 'lib/algolia/recommend_client.rb', line 44 def self.create_with_config(config) new(config) end |
Instance Method Details
#get_frequently_bought_together(requests, opts = {}) ⇒ Hash
Get frequently bought together items for the given requests
85 86 87 88 89 90 |
# File 'lib/algolia/recommend_client.rb', line 85 def get_frequently_bought_together(requests, opts = {}) get_recommendations( set_request_models(symbolize_all(requests), Model::BOUGHT_TOGETHER), opts ) end |
#get_recommendations(requests, opts = {}) ⇒ Hash
Get recommendation for the given queries
55 56 57 58 59 60 61 62 |
# File 'lib/algolia/recommend_client.rb', line 55 def get_recommendations(requests, opts = {}) @transporter.write( :POST, '/1/indexes/*/recommendations', { requests: format_recommendation_requests(symbolize_all(requests)) }, opts ) end |
#get_related_products(requests, opts = {}) ⇒ Hash
Get related products for the given requests
71 72 73 74 75 76 |
# File 'lib/algolia/recommend_client.rb', line 71 def (requests, opts = {}) get_recommendations( set_request_models(symbolize_all(requests), Model::RELATED_PRODUCTS), opts ) end |