Skip to content

Commit 31255d7

Browse files
committed
Support endpoints for handling search synonyms
1 parent 01e40fc commit 31255d7

14 files changed

+350
-2
lines changed

lib/recombee_api_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class RecombeeClient
1818
include HTTParty
1919

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

2323
##
2424
# - +account+ -> Name of your account at Recombee
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#
2+
# This file is auto-generated, do not edit
3+
#
4+
5+
module RecombeeApiClient
6+
require_relative 'request'
7+
require_relative '../errors'
8+
9+
##
10+
#Adds a new synonym for the [Search items](https://docs.recombee.com/api.html#search-items).
11+
#
12+
#When the `term` is used in the search query, the `synonym` is also used for the full-text search.
13+
#Unless `oneWay=true`, it works also in the opposite way (`synonym` -> `term`).
14+
#
15+
#An example of a synonym can be `science fiction` for the term `sci-fi`.
16+
#
17+
class AddSearchSynonym < ApiRequest
18+
attr_reader :term, :synonym, :one_way
19+
attr_accessor :timeout
20+
attr_accessor :ensure_https
21+
22+
##
23+
# * *Required arguments*
24+
# - +term+ -> A word to which the `synonym` is specified.
25+
# - +synonym+ -> A word that should be considered equal to the `term` by the full-text search engine.
26+
#
27+
# * *Optional arguments (given as hash optional)*
28+
# - +oneWay+ -> If set to `true`, only `term` -> `synonym` is considered. If set to `false`, also `synonym` -> `term` works.
29+
#
30+
#Default: `false`.
31+
#
32+
#
33+
def initialize(term, synonym, optional = {})
34+
@term = term
35+
@synonym = synonym
36+
optional = normalize_optional(optional)
37+
@one_way = optional['oneWay']
38+
@optional = optional
39+
@timeout = 10000
40+
@ensure_https = false
41+
@optional.each do |par, _|
42+
fail UnknownOptionalParameter.new(par) unless ["oneWay"].include? par
43+
end
44+
end
45+
46+
# HTTP method
47+
def method
48+
:post
49+
end
50+
51+
# Values of body parameters as a Hash
52+
def body_parameters
53+
p = Hash.new
54+
p['term'] = @term
55+
p['synonym'] = @synonym
56+
p['oneWay'] = @optional['oneWay'] if @optional.include? 'oneWay'
57+
p
58+
end
59+
60+
# Values of query parameters as a Hash.
61+
# name of parameter => value of the parameter
62+
def query_parameters
63+
params = {}
64+
params
65+
end
66+
67+
# Relative path to the endpoint
68+
def path
69+
"/{databaseId}/synonyms/items/"
70+
end
71+
end
72+
end
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#
2+
# This file is auto-generated, do not edit
3+
#
4+
5+
module RecombeeApiClient
6+
require_relative 'request'
7+
require_relative '../errors'
8+
9+
##
10+
#Deletes all synonyms defined in the database.
11+
#
12+
class DeleteAllSearchSynonyms < ApiRequest
13+
14+
attr_accessor :timeout
15+
attr_accessor :ensure_https
16+
17+
##
18+
#
19+
def initialize()
20+
@timeout = 10000
21+
@ensure_https = false
22+
end
23+
24+
# HTTP method
25+
def method
26+
:delete
27+
end
28+
29+
# Values of body parameters as a Hash
30+
def body_parameters
31+
p = Hash.new
32+
p
33+
end
34+
35+
# Values of query parameters as a Hash.
36+
# name of parameter => value of the parameter
37+
def query_parameters
38+
params = {}
39+
params
40+
end
41+
42+
# Relative path to the endpoint
43+
def path
44+
"/{databaseId}/synonyms/items/"
45+
end
46+
end
47+
end
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# This file is auto-generated, do not edit
3+
#
4+
5+
module RecombeeApiClient
6+
require_relative 'request'
7+
require_relative '../errors'
8+
9+
##
10+
#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).
11+
#
12+
class DeleteSearchSynonym < ApiRequest
13+
attr_reader :id
14+
attr_accessor :timeout
15+
attr_accessor :ensure_https
16+
17+
##
18+
# * *Required arguments*
19+
# - +id+ -> ID of the synonym that should be deleted.
20+
#
21+
def initialize(id)
22+
@id = id
23+
@timeout = 10000
24+
@ensure_https = false
25+
end
26+
27+
# HTTP method
28+
def method
29+
:delete
30+
end
31+
32+
# Values of body parameters as a Hash
33+
def body_parameters
34+
p = Hash.new
35+
p
36+
end
37+
38+
# Values of query parameters as a Hash.
39+
# name of parameter => value of the parameter
40+
def query_parameters
41+
params = {}
42+
params
43+
end
44+
45+
# Relative path to the endpoint
46+
def path
47+
"/{databaseId}/synonyms/items/#{@id}"
48+
end
49+
end
50+
end
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#
2+
# This file is auto-generated, do not edit
3+
#
4+
5+
module RecombeeApiClient
6+
require_relative 'request'
7+
require_relative '../errors'
8+
9+
##
10+
#Gives the list of synonyms defined in the database.
11+
class ListSearchSynonyms < ApiRequest
12+
attr_reader :count, :offset
13+
attr_accessor :timeout
14+
attr_accessor :ensure_https
15+
16+
##
17+
#
18+
# * *Optional arguments (given as hash optional)*
19+
# - +count+ -> The number of synonyms to be listed.
20+
# - +offset+ -> Specifies the number of synonyms to skip (ordered by `term`).
21+
#
22+
def initialize(optional = {})
23+
optional = normalize_optional(optional)
24+
@count = optional['count']
25+
@offset = optional['offset']
26+
@optional = optional
27+
@timeout = 100000
28+
@ensure_https = false
29+
@optional.each do |par, _|
30+
fail UnknownOptionalParameter.new(par) unless ["count","offset"].include? par
31+
end
32+
end
33+
34+
# HTTP method
35+
def method
36+
:get
37+
end
38+
39+
# Values of body parameters as a Hash
40+
def body_parameters
41+
p = Hash.new
42+
p
43+
end
44+
45+
# Values of query parameters as a Hash.
46+
# name of parameter => value of the parameter
47+
def query_parameters
48+
params = {}
49+
params['count'] = @optional['count'] if @optional['count']
50+
params['offset'] = @optional['offset'] if @optional['offset']
51+
params
52+
end
53+
54+
# Relative path to the endpoint
55+
def path
56+
"/{databaseId}/synonyms/items/"
57+
end
58+
end
59+
end

lib/recombee_api_client/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module RecombeeApiClient
2-
VERSION = '3.1.0'
2+
VERSION = '3.2.0'
33
end

spec/api/add_search_synonym.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# This file is auto-generated, do not edit
3+
#
4+
5+
require 'spec_helper'
6+
require_relative 'set_environment'
7+
shared_examples 'add search synonym' do
8+
include_context 'set environment'
9+
10+
it 'adds search synonym' do
11+
req = described_class.new('sci-fi','science fiction',{'oneWay' => true})
12+
resp = @client.send(req)
13+
expect(resp['term']).to eq 'sci-fi'
14+
expect(resp['synonym']).to eq 'science fiction'
15+
req = described_class.new('sci-fi','science fiction',{'oneWay' => true})
16+
expect { @client.send(req) }.to raise_exception { |exception|
17+
expect(exception).to be_a(RecombeeApiClient::ResponseError)
18+
expect(exception.status_code).to eq 409
19+
}
20+
end
21+
22+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# This file is auto-generated, do not edit
3+
#
4+
5+
require 'spec_helper'
6+
require_relative "add_search_synonym"
7+
8+
describe RecombeeApiClient::AddSearchSynonym do
9+
it_behaves_like "add search synonym"
10+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# This file is auto-generated, do not edit
3+
#
4+
5+
require 'spec_helper'
6+
require_relative 'set_environment'
7+
shared_examples 'delete all search synonyms' do
8+
include_context 'set environment'
9+
10+
it 'deletes all search synonyms' do
11+
req = described_class.new()
12+
resp = @client.send(req)
13+
end
14+
15+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# This file is auto-generated, do not edit
3+
#
4+
5+
require 'spec_helper'
6+
require_relative "delete_all_search_synonyms"
7+
8+
describe RecombeeApiClient::DeleteAllSearchSynonyms do
9+
it_behaves_like "delete all search synonyms"
10+
end

0 commit comments

Comments
 (0)