Skip to content

Commit e48f94c

Browse files
committed
Release: v6.3.0
- Added support for property roles and metadata
1 parent 0410a10 commit e48f94c

11 files changed

Lines changed: 204 additions & 31 deletions

lib/recombee_api_client.rb

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

2121
BATCH_MAX_SIZE = 10_000
22-
USER_AGENT = { 'User-Agent' => 'recombee-ruby-api-client/6.2.0' }
22+
USER_AGENT = { 'User-Agent' => 'recombee-ruby-api-client/6.3.0' }
2323

2424
##
2525
# - +account+ -> Name of your account at Recombee

lib/recombee_api_client/api/add_item_property.rb

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module RecombeeApiClient
1010
# Adding an item property is somewhat equivalent to adding a column to the table of items. The items may be characterized by various properties of different types.
1111
#
1212
class AddItemProperty < ApiRequest
13-
attr_reader :property_name, :type
13+
attr_reader :property_name, :type, :role, :metadata
1414
attr_accessor :timeout, :ensure_https
1515

1616
##
@@ -19,15 +19,15 @@ class AddItemProperty < ApiRequest
1919
#
2020
# - +type+ -> Value type of the item property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`, `image` or `imageList`.
2121
#
22-
# * `int`- Signed integer number.
22+
# * `int` - Signed integer number.
2323
#
2424
# * `double` - Floating point number. It uses 64-bit base-2 format (IEEE 754 standard).
2525
#
2626
# * `string` - UTF-8 string.
2727
#
2828
# * `boolean` - *true* / *false*
2929
#
30-
# * `timestamp` - Value representing date and time.
30+
# * `timestamp` - Value representing date and time. ISO8601-1 pattern (string) or UTC epoch time (number).
3131
#
3232
# * `set` - Set of strings.
3333
#
@@ -36,11 +36,23 @@ class AddItemProperty < ApiRequest
3636
# * `imageList` - List of URLs that refer to images.
3737
#
3838
#
39-
def initialize(property_name, type)
39+
# * *Optional arguments (given as hash optional)*
40+
# - +role+ -> [Role](https://docs.recombee.com/api/property_roles_metadata#roles) to assign to the property.
41+
#
42+
# - +metadata+ -> List of [metadata](https://docs.recombee.com/api/property_roles_metadata#metadata) entries to assign to the property.
43+
#
44+
def initialize(property_name, type, optional = {})
4045
@property_name = property_name
4146
@type = type
47+
optional = normalize_hash_to_camel_case(optional)
48+
@role = optional['role']
49+
@metadata = optional['metadata']
50+
@optional = optional
4251
@timeout = 100_000
4352
@ensure_https = false
53+
@optional.each do |par, _|
54+
raise UnknownOptionalParameter.new(par) unless %w[role metadata].include? par
55+
end
4456
end
4557

4658
# HTTP method
@@ -50,16 +62,18 @@ def method
5062

5163
# Values of body parameters as a Hash
5264
def body_parameters
53-
{}
65+
p = {}
66+
p['type'] = @type
67+
p['role'] = @optional['role'] if @optional.include? 'role'
68+
p['metadata'] = @optional['metadata'] if @optional.include? 'metadata'
69+
70+
p
5471
end
5572

5673
# Values of query parameters as a Hash.
5774
# name of parameter => value of the parameter
5875
def query_parameters
59-
params = {}
60-
params['type'] = @type
61-
62-
params
76+
{}
6377
end
6478

6579
# Relative path to the endpoint

lib/recombee_api_client/api/add_user_property.rb

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module RecombeeApiClient
1010
# Adding a user property is somewhat equivalent to adding a column to the table of users. The users may be characterized by various properties of different types.
1111
#
1212
class AddUserProperty < ApiRequest
13-
attr_reader :property_name, :type
13+
attr_reader :property_name, :type, :role, :metadata
1414
attr_accessor :timeout, :ensure_https
1515

1616
##
@@ -27,16 +27,28 @@ class AddUserProperty < ApiRequest
2727
#
2828
# * `boolean` - *true* / *false*
2929
#
30-
# * `timestamp` - Value representing date and time.
30+
# * `timestamp` - Value representing date and time. ISO8601-1 pattern (string) or UTC epoch time (number).
3131
#
3232
# * `set` - Set of strings.
3333
#
3434
#
35-
def initialize(property_name, type)
35+
# * *Optional arguments (given as hash optional)*
36+
# - +role+ -> [Role](https://docs.recombee.com/api/property_roles_metadata#roles) to assign to the property.
37+
#
38+
# - +metadata+ -> List of [metadata](https://docs.recombee.com/api/property_roles_metadata#metadata) entries to assign to the property.
39+
#
40+
def initialize(property_name, type, optional = {})
3641
@property_name = property_name
3742
@type = type
43+
optional = normalize_hash_to_camel_case(optional)
44+
@role = optional['role']
45+
@metadata = optional['metadata']
46+
@optional = optional
3847
@timeout = 100_000
3948
@ensure_https = false
49+
@optional.each do |par, _|
50+
raise UnknownOptionalParameter.new(par) unless %w[role metadata].include? par
51+
end
4052
end
4153

4254
# HTTP method
@@ -46,16 +58,18 @@ def method
4658

4759
# Values of body parameters as a Hash
4860
def body_parameters
49-
{}
61+
p = {}
62+
p['type'] = @type
63+
p['role'] = @optional['role'] if @optional.include? 'role'
64+
p['metadata'] = @optional['metadata'] if @optional.include? 'metadata'
65+
66+
p
5067
end
5168

5269
# Values of query parameters as a Hash.
5370
# name of parameter => value of the parameter
5471
def query_parameters
55-
params = {}
56-
params['type'] = @type
57-
58-
params
72+
{}
5973
end
6074

6175
# Relative path to the endpoint

lib/recombee_api_client/api/recommend_next_item_segments.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,24 @@ module RecombeeApiClient
77
require_relative '../errors'
88

99
##
10-
# Returns Item segments that shall be shown to a user as next recommendations when the user e.g. scrolls the page down (*infinite scroll*) or goes to the next page.
10+
# Returns [Item Segments](https://docs.recombee.com/segmentations) to be shown as the next recommendations when a user scrolls (e.g., within a carousel or feed of Item Segments such as brands, artists, topics, or categories).
11+
#
12+
# The request requires the `recommId` of a base recommendation request and the number of Segments to return (`count`).
1113
#
12-
# It accepts `recommId` of a base recommendation request (e.g., request from the first page) and the number of segments that shall be returned (`count`).
1314
# The base request can be one of:
1415
# - [Recommend Item Segments to Item](https://docs.recombee.com/api#recommend-item-segments-to-item)
1516
# - [Recommend Item Segments to User](https://docs.recombee.com/api#recommend-item-segments-to-user)
1617
# - [Recommend Item Segments to Item Segment](https://docs.recombee.com/api#recommend-item-segments-to-item-segment)
1718
# - [Search Item Segments](https://docs.recombee.com/api#search-item-segments)
1819
#
19-
# All the other parameters are inherited from the base request.
20+
# All other parameters are inherited from the base request associated with the provided `recommId`.
2021
#
21-
# *Recommend next Item segments* can be called many times for a single `recommId` and each call returns different (previously not recommended) segments.
22-
# The number of *Recommend next Item segments* calls performed so far is returned in the `numberNextRecommsCalls` field.
22+
# This endpoint can be called multiple times for a single `recommId`. Each call returns different Item Segments that have not been recommended in previous calls.
23+
# The number of calls made so far is returned in the `numberNextRecommsCalls` field.
2324
#
24-
# *Recommend next Item segments* can be requested up to 30 minutes after the base request or a previous *Recommend next Item segments* call.
25+
# Requests can be made up to 30 minutes after the base request or the most recent Recommend Next Item Segments call.
2526
#
26-
# For billing purposes, each call to *Recommend next Item segments* is counted as a separate recommendation request.
27+
# For billing purposes, each call to this endpoint is counted as a separate recommendation request.
2728
#
2829
class RecommendNextItemSegments < ApiRequest
2930
attr_reader :recomm_id, :count
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#
2+
# This file is auto-generated, do not edit
3+
#
4+
5+
require 'json'
6+
7+
module RecombeeApiClient
8+
require_relative 'input'
9+
require_relative '../errors'
10+
11+
##
12+
# Initializes PropertyMetadata input#
13+
class PropertyMetadata < Input
14+
attr_reader :name, :settings
15+
16+
##
17+
# * *Required arguments*
18+
# - +name+ -> Name of the [metadata](https://docs.recombee.com/api/property_roles_metadata#metadata) assigned to the property.
19+
#
20+
# * *Optional arguments (given as hash optional)*
21+
# - +settings+ -> Optional configuration for this metadata entry.
22+
#
23+
def initialize(name, optional = {})
24+
@name = name
25+
optional = normalize_hash_to_camel_case(optional)
26+
@settings = optional['settings']
27+
@optional = optional
28+
@optional.each do |par, _|
29+
raise UnknownOptionalParameter.new(par) unless ['settings'].include? par
30+
end
31+
end
32+
33+
# Return only JSON-serializable primitives.
34+
def as_json(_options = {})
35+
res = {}
36+
res['name'] = @name
37+
res['settings'] = @optional['settings'] if @optional['settings']
38+
39+
res
40+
end
41+
42+
def to_json(*args)
43+
as_json.to_json(*args)
44+
end
45+
end
46+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#
2+
# This file is auto-generated, do not edit
3+
#
4+
5+
require 'json'
6+
7+
module RecombeeApiClient
8+
require_relative 'input'
9+
require_relative '../errors'
10+
11+
##
12+
# Initializes PropertyRole input#
13+
class PropertyRole < Input
14+
attr_reader :name, :settings
15+
16+
##
17+
# * *Required arguments*
18+
# - +name+ -> Name of the [role](https://docs.recombee.com/api/property_roles_metadata#roles) assigned to the property.
19+
#
20+
# * *Optional arguments (given as hash optional)*
21+
# - +settings+ -> Optional configuration specific to the selected role.
22+
#
23+
def initialize(name, optional = {})
24+
@name = name
25+
optional = normalize_hash_to_camel_case(optional)
26+
@settings = optional['settings']
27+
@optional = optional
28+
@optional.each do |par, _|
29+
raise UnknownOptionalParameter.new(par) unless ['settings'].include? par
30+
end
31+
end
32+
33+
# Return only JSON-serializable primitives.
34+
def as_json(_options = {})
35+
res = {}
36+
res['name'] = @name
37+
res['settings'] = @optional['settings'] if @optional['settings']
38+
39+
res
40+
end
41+
42+
def to_json(*args)
43+
as_json.to_json(*args)
44+
end
45+
end
46+
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 = '6.2.0'
2+
VERSION = '6.3.0'
33
end

spec/api/add_item_property.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 item property' do
8+
include_context 'set environment'
9+
10+
it 'does not fail with valid name and type' do
11+
req = described_class.new('number', 'int')
12+
@client.send(req)
13+
req = described_class.new('str', 'string')
14+
@client.send(req)
15+
end
16+
17+
it 'fails with invalid type' do
18+
req = described_class.new('prop', 'integer')
19+
expect { @client.send(req) }.to(raise_exception do |exception|
20+
expect(exception).to be_a(RecombeeApiClient::ResponseError)
21+
expect(exception.status_code).to eq 400
22+
end)
23+
end
24+
25+
it 'really stores property to the system' do
26+
req = described_class.new('number2', 'int')
27+
@client.send(req)
28+
expect { @client.send(req) }.to(raise_exception do |exception|
29+
expect(exception).to be_a(RecombeeApiClient::ResponseError)
30+
expect(exception.status_code).to eq 409
31+
end)
32+
end
33+
34+
it 'does not fail with valid property role and metadata' do
35+
req = described_class.new('title', 'string', { 'role' => 'title' })
36+
@client.send(req)
37+
end
38+
39+
it 'fails with duplicate property role or invalid metadata' do
40+
req = described_class.new('str4', 'string', { 'role' => 'summary' })
41+
@client.send(req)
42+
expect { @client.send(req) }.to(raise_exception do |exception|
43+
expect(exception).to be_a(RecombeeApiClient::ResponseError)
44+
expect(exception.status_code).to eq 409
45+
end)
46+
req = described_class.new('str5', 'string', { 'role' => 'titl' })
47+
expect { @client.send(req) }.to(raise_exception do |exception|
48+
expect(exception).to be_a(RecombeeApiClient::ResponseError)
49+
expect(exception.status_code).to eq 404
50+
end)
51+
end
52+
end

spec/api/add_item_property_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#
44

55
require 'spec_helper'
6-
require_relative 'add_property'
6+
require_relative 'add_item_property'
77

88
describe RecombeeApiClient::AddItemProperty do
9-
it_behaves_like 'add property'
9+
it_behaves_like 'add item property'
1010
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
require 'spec_helper'
66
require_relative 'set_environment'
7-
shared_examples 'add property' do
7+
shared_examples 'add user property' do
88
include_context 'set environment'
99

1010
it 'does not fail with valid name and type' do

0 commit comments

Comments
 (0)