Skip to content

Commit

Permalink
Support endpoints for handling search synonyms
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraFiedler committed Feb 16, 2021
1 parent 01e40fc commit 31255d7
Show file tree
Hide file tree
Showing 14 changed files with 350 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/recombee_api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RecombeeClient
include HTTParty

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

##
# - +account+ -> Name of your account at Recombee
Expand Down
72 changes: 72 additions & 0 deletions lib/recombee_api_client/api/add_search_synonym.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#
# This file is auto-generated, do not edit
#

module RecombeeApiClient
require_relative 'request'
require_relative '../errors'

##
#Adds a new synonym for the [Search items](https://docs.recombee.com/api.html#search-items).
#
#When the `term` is used in the search query, the `synonym` is also used for the full-text search.
#Unless `oneWay=true`, it works also in the opposite way (`synonym` -> `term`).
#
#An example of a synonym can be `science fiction` for the term `sci-fi`.
#
class AddSearchSynonym < ApiRequest
attr_reader :term, :synonym, :one_way
attr_accessor :timeout
attr_accessor :ensure_https

##
# * *Required arguments*
# - +term+ -> A word to which the `synonym` is specified.
# - +synonym+ -> A word that should be considered equal to the `term` by the full-text search engine.
#
# * *Optional arguments (given as hash optional)*
# - +oneWay+ -> If set to `true`, only `term` -> `synonym` is considered. If set to `false`, also `synonym` -> `term` works.
#
#Default: `false`.
#
#
def initialize(term, synonym, optional = {})
@term = term
@synonym = synonym
optional = normalize_optional(optional)
@one_way = optional['oneWay']
@optional = optional
@timeout = 10000
@ensure_https = false
@optional.each do |par, _|
fail UnknownOptionalParameter.new(par) unless ["oneWay"].include? par
end
end

# HTTP method
def method
:post
end

# Values of body parameters as a Hash
def body_parameters
p = Hash.new
p['term'] = @term
p['synonym'] = @synonym
p['oneWay'] = @optional['oneWay'] if @optional.include? 'oneWay'
p
end

# Values of query parameters as a Hash.
# name of parameter => value of the parameter
def query_parameters
params = {}
params
end

# Relative path to the endpoint
def path
"/{databaseId}/synonyms/items/"
end
end
end
47 changes: 47 additions & 0 deletions lib/recombee_api_client/api/delete_all_search_synonyms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# This file is auto-generated, do not edit
#

module RecombeeApiClient
require_relative 'request'
require_relative '../errors'

##
#Deletes all synonyms defined in the database.
#
class DeleteAllSearchSynonyms < ApiRequest

attr_accessor :timeout
attr_accessor :ensure_https

##
#
def initialize()
@timeout = 10000
@ensure_https = false
end

# HTTP method
def method
:delete
end

# Values of body parameters as a Hash
def body_parameters
p = Hash.new
p
end

# Values of query parameters as a Hash.
# name of parameter => value of the parameter
def query_parameters
params = {}
params
end

# Relative path to the endpoint
def path
"/{databaseId}/synonyms/items/"
end
end
end
50 changes: 50 additions & 0 deletions lib/recombee_api_client/api/delete_search_synonym.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# This file is auto-generated, do not edit
#

module RecombeeApiClient
require_relative 'request'
require_relative '../errors'

##
#Deletes synonym of given `id` and this synonym is no longer taken into account in the [Search items](https://docs.recombee.com/api.html#search-items).
#
class DeleteSearchSynonym < ApiRequest
attr_reader :id
attr_accessor :timeout
attr_accessor :ensure_https

##
# * *Required arguments*
# - +id+ -> ID of the synonym that should be deleted.
#
def initialize(id)
@id = id
@timeout = 10000
@ensure_https = false
end

# HTTP method
def method
:delete
end

# Values of body parameters as a Hash
def body_parameters
p = Hash.new
p
end

# Values of query parameters as a Hash.
# name of parameter => value of the parameter
def query_parameters
params = {}
params
end

# Relative path to the endpoint
def path
"/{databaseId}/synonyms/items/#{@id}"
end
end
end
59 changes: 59 additions & 0 deletions lib/recombee_api_client/api/list_search_synonyms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#
# This file is auto-generated, do not edit
#

module RecombeeApiClient
require_relative 'request'
require_relative '../errors'

##
#Gives the list of synonyms defined in the database.
class ListSearchSynonyms < ApiRequest
attr_reader :count, :offset
attr_accessor :timeout
attr_accessor :ensure_https

##
#
# * *Optional arguments (given as hash optional)*
# - +count+ -> The number of synonyms to be listed.
# - +offset+ -> Specifies the number of synonyms to skip (ordered by `term`).
#
def initialize(optional = {})
optional = normalize_optional(optional)
@count = optional['count']
@offset = optional['offset']
@optional = optional
@timeout = 100000
@ensure_https = false
@optional.each do |par, _|
fail UnknownOptionalParameter.new(par) unless ["count","offset"].include? par
end
end

# HTTP method
def method
:get
end

# Values of body parameters as a Hash
def body_parameters
p = Hash.new
p
end

# Values of query parameters as a Hash.
# name of parameter => value of the parameter
def query_parameters
params = {}
params['count'] = @optional['count'] if @optional['count']
params['offset'] = @optional['offset'] if @optional['offset']
params
end

# Relative path to the endpoint
def path
"/{databaseId}/synonyms/items/"
end
end
end
2 changes: 1 addition & 1 deletion lib/recombee_api_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RecombeeApiClient
VERSION = '3.1.0'
VERSION = '3.2.0'
end
22 changes: 22 additions & 0 deletions spec/api/add_search_synonym.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# This file is auto-generated, do not edit
#

require 'spec_helper'
require_relative 'set_environment'
shared_examples 'add search synonym' do
include_context 'set environment'

it 'adds search synonym' do
req = described_class.new('sci-fi','science fiction',{'oneWay' => true})
resp = @client.send(req)
expect(resp['term']).to eq 'sci-fi'
expect(resp['synonym']).to eq 'science fiction'
req = described_class.new('sci-fi','science fiction',{'oneWay' => true})
expect { @client.send(req) }.to raise_exception { |exception|
expect(exception).to be_a(RecombeeApiClient::ResponseError)
expect(exception.status_code).to eq 409
}
end

end
10 changes: 10 additions & 0 deletions spec/api/add_search_synonym_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# This file is auto-generated, do not edit
#

require 'spec_helper'
require_relative "add_search_synonym"

describe RecombeeApiClient::AddSearchSynonym do
it_behaves_like "add search synonym"
end
15 changes: 15 additions & 0 deletions spec/api/delete_all_search_synonyms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# This file is auto-generated, do not edit
#

require 'spec_helper'
require_relative 'set_environment'
shared_examples 'delete all search synonyms' do
include_context 'set environment'

it 'deletes all search synonyms' do
req = described_class.new()
resp = @client.send(req)
end

end
10 changes: 10 additions & 0 deletions spec/api/delete_all_search_synonyms_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# This file is auto-generated, do not edit
#

require 'spec_helper'
require_relative "delete_all_search_synonyms"

describe RecombeeApiClient::DeleteAllSearchSynonyms do
it_behaves_like "delete all search synonyms"
end
22 changes: 22 additions & 0 deletions spec/api/delete_search_synonym.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# This file is auto-generated, do not edit
#

require 'spec_helper'
require_relative 'set_environment'
shared_examples 'delete search synonym' do
include_context 'set environment'

it 'deletes search synonym' do
req = AddSearchSynonym.new('sci-fi','science fiction')
resp = @client.send(req)
req = described_class.new(resp['id'])
resp = @client.send(req)
req = described_class.new('a968271b-d666-4dfb-8a30-f459e564ba7b')
expect { @client.send(req) }.to raise_exception { |exception|
expect(exception).to be_a(RecombeeApiClient::ResponseError)
expect(exception.status_code).to eq 404
}
end

end
10 changes: 10 additions & 0 deletions spec/api/delete_search_synonym_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# This file is auto-generated, do not edit
#

require 'spec_helper'
require_relative "delete_search_synonym"

describe RecombeeApiClient::DeleteSearchSynonym do
it_behaves_like "delete search synonym"
end
21 changes: 21 additions & 0 deletions spec/api/list_search_synonyms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# This file is auto-generated, do not edit
#

require 'spec_helper'
require_relative 'set_environment'
shared_examples 'list search synonyms' do
include_context 'set environment'

it 'lists search synonyms' do
req = AddSearchSynonym.new('sci-fi','science fiction')
resp = @client.send(req)
req = described_class.new()
resp = @client.send(req)
expect(resp['synonyms'].size).to eq 1
req = described_class.new({'count' => 10,'offset' => 1})
resp = @client.send(req)
expect(resp['synonyms'].size).to eq 0
end

end
10 changes: 10 additions & 0 deletions spec/api/list_search_synonyms_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# This file is auto-generated, do not edit
#

require 'spec_helper'
require_relative "list_search_synonyms"

describe RecombeeApiClient::ListSearchSynonyms do
it_behaves_like "list search synonyms"
end

0 comments on commit 31255d7

Please sign in to comment.