Skip to content

Commit 457a6d2

Browse files
committed
Make the timestamp parameter optional for interaction additions - default is the current time
1 parent c9bf748 commit 457a6d2

File tree

13 files changed

+55
-48
lines changed

13 files changed

+55
-48
lines changed

lib/recombee_api_client/api/add_bookmark.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ class AddBookmark < ApiRequest
1717
# * *Required arguments*
1818
# - +user_id+ -> User who bookmarked the item
1919
# - +item_id+ -> Bookmarked item
20-
# - +timestamp+ -> Unix timestamp of the bookmark. If you don't have the timestamp value available, you may use some artificial value, such as 0. It is preferable, however, to provide the timestamp whenever possible as the user's preferences may evolve over time.
2120
#
2221
# * *Optional arguments (given as hash optional)*
22+
# - +timestamp+ -> UTC timestamp of the bookmark as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
2323
# - +cascadeCreate+ -> Sets whether the given user/item should be created if not present in the database.
2424
#
25-
def initialize(user_id, item_id, timestamp, optional = {})
25+
def initialize(user_id, item_id, optional = {})
2626
@user_id = user_id
2727
@item_id = item_id
28-
@timestamp = timestamp
28+
@timestamp = optional['timestamp']
2929
@cascade_create = optional['cascadeCreate']
3030
@optional = optional
3131
@timeout = 1000
3232
@optional.each do |par, _|
33-
fail UnknownOptionalParameter.new(par) unless ["cascadeCreate"].include? par
33+
fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate"].include? par
3434
end
3535
end
3636

@@ -44,7 +44,7 @@ def body_parameters
4444
p = Hash.new
4545
p['userId'] = @user_id
4646
p['itemId'] = @item_id
47-
p['timestamp'] = @timestamp
47+
p['timestamp'] = @optional['timestamp'] if @optional['timestamp']
4848
p['cascadeCreate'] = @optional['cascadeCreate'] if @optional['cascadeCreate']
4949
p
5050
end

lib/recombee_api_client/api/add_cart_addition.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ class AddCartAddition < ApiRequest
1717
# * *Required arguments*
1818
# - +user_id+ -> User who added the item to the cart
1919
# - +item_id+ -> Item added to the cart
20-
# - +timestamp+ -> Unix timestamp of the cart addition. If you don't have the timestamp value available, you may use some artificial value, such as 0. It is preferable, however, to provide the timestamp whenever possible as the user's preferences may evolve over time.
2120
#
2221
# * *Optional arguments (given as hash optional)*
22+
# - +timestamp+ -> UTC timestamp of the cart addition as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
2323
# - +cascadeCreate+ -> Sets whether the given user/item should be created if not present in the database.
2424
#
25-
def initialize(user_id, item_id, timestamp, optional = {})
25+
def initialize(user_id, item_id, optional = {})
2626
@user_id = user_id
2727
@item_id = item_id
28-
@timestamp = timestamp
28+
@timestamp = optional['timestamp']
2929
@cascade_create = optional['cascadeCreate']
3030
@optional = optional
3131
@timeout = 1000
3232
@optional.each do |par, _|
33-
fail UnknownOptionalParameter.new(par) unless ["cascadeCreate"].include? par
33+
fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate"].include? par
3434
end
3535
end
3636

@@ -44,7 +44,7 @@ def body_parameters
4444
p = Hash.new
4545
p['userId'] = @user_id
4646
p['itemId'] = @item_id
47-
p['timestamp'] = @timestamp
47+
p['timestamp'] = @optional['timestamp'] if @optional['timestamp']
4848
p['cascadeCreate'] = @optional['cascadeCreate'] if @optional['cascadeCreate']
4949
p
5050
end

lib/recombee_api_client/api/add_detail_view.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ class AddDetailView < ApiRequest
1717
# * *Required arguments*
1818
# - +user_id+ -> User who viewed the item
1919
# - +item_id+ -> Viewed item
20-
# - +timestamp+ -> Unix timestamp of the view. If you don't have the timestamp value available, you may use some artificial value, such as 0. It is preferable, however, to provide the timestamp whenever possible as the user's preferences may evolve over time.
2120
#
2221
# * *Optional arguments (given as hash optional)*
22+
# - +timestamp+ -> UTC timestamp of the view as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
2323
# - +duration+ -> Duration of the view
2424
# - +cascadeCreate+ -> Sets whether the given user/item should be created if not present in the database.
2525
#
26-
def initialize(user_id, item_id, timestamp, optional = {})
26+
def initialize(user_id, item_id, optional = {})
2727
@user_id = user_id
2828
@item_id = item_id
29-
@timestamp = timestamp
29+
@timestamp = optional['timestamp']
3030
@duration = optional['duration']
3131
@cascade_create = optional['cascadeCreate']
3232
@optional = optional
3333
@timeout = 1000
3434
@optional.each do |par, _|
35-
fail UnknownOptionalParameter.new(par) unless ["duration","cascadeCreate"].include? par
35+
fail UnknownOptionalParameter.new(par) unless ["timestamp","duration","cascadeCreate"].include? par
3636
end
3737
end
3838

@@ -46,7 +46,7 @@ def body_parameters
4646
p = Hash.new
4747
p['userId'] = @user_id
4848
p['itemId'] = @item_id
49-
p['timestamp'] = @timestamp
49+
p['timestamp'] = @optional['timestamp'] if @optional['timestamp']
5050
p['duration'] = @optional['duration'] if @optional['duration']
5151
p['cascadeCreate'] = @optional['cascadeCreate'] if @optional['cascadeCreate']
5252
p

lib/recombee_api_client/api/add_purchase.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ class AddPurchase < ApiRequest
1717
# * *Required arguments*
1818
# - +user_id+ -> User who purchased the item
1919
# - +item_id+ -> Purchased item
20-
# - +timestamp+ -> Unix timestamp of the purchase. If you don't have the timestamp value available, you may use some artificial value, such as 0. It is preferable, however, to provide the timestamp whenever possible as the user's preferences may evolve over time.
2120
#
2221
# * *Optional arguments (given as hash optional)*
22+
# - +timestamp+ -> UTC timestamp of the purchase as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
2323
# - +cascadeCreate+ -> Sets whether the given user/item should be created if not present in the database.
2424
#
25-
def initialize(user_id, item_id, timestamp, optional = {})
25+
def initialize(user_id, item_id, optional = {})
2626
@user_id = user_id
2727
@item_id = item_id
28-
@timestamp = timestamp
28+
@timestamp = optional['timestamp']
2929
@cascade_create = optional['cascadeCreate']
3030
@optional = optional
3131
@timeout = 1000
3232
@optional.each do |par, _|
33-
fail UnknownOptionalParameter.new(par) unless ["cascadeCreate"].include? par
33+
fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate"].include? par
3434
end
3535
end
3636

@@ -44,7 +44,7 @@ def body_parameters
4444
p = Hash.new
4545
p['userId'] = @user_id
4646
p['itemId'] = @item_id
47-
p['timestamp'] = @timestamp
47+
p['timestamp'] = @optional['timestamp'] if @optional['timestamp']
4848
p['cascadeCreate'] = @optional['cascadeCreate'] if @optional['cascadeCreate']
4949
p
5050
end

lib/recombee_api_client/api/add_rating.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ class AddRating < ApiRequest
1717
# * *Required arguments*
1818
# - +user_id+ -> User who submitted the rating
1919
# - +item_id+ -> Rated item
20-
# - +timestamp+ -> Unix timestamp of the rating. If you don't have the timestamp value available, you may use some artificial value, such as 0. It is preferable, however, to provide the timestamp whenever possible as the user's preferences may evolve over time.
2120
# - +rating+ -> Rating rescaled to interval [-1.0,1.0], where -1.0 means the worst rating possible, 0.0 means neutral, and 1.0 means absolutely positive rating. For example, in the case of 5-star evaluations, rating = (numStars-3)/2 formula may be used for the conversion.
2221
#
2322
# * *Optional arguments (given as hash optional)*
23+
# - +timestamp+ -> UTC timestamp of the rating as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
2424
# - +cascadeCreate+ -> Sets whether the given user/item should be created if not present in the database.
2525
#
26-
def initialize(user_id, item_id, timestamp, rating, optional = {})
26+
def initialize(user_id, item_id, rating, optional = {})
2727
@user_id = user_id
2828
@item_id = item_id
29-
@timestamp = timestamp
3029
@rating = rating
30+
@timestamp = optional['timestamp']
3131
@cascade_create = optional['cascadeCreate']
3232
@optional = optional
3333
@timeout = 1000
3434
@optional.each do |par, _|
35-
fail UnknownOptionalParameter.new(par) unless ["cascadeCreate"].include? par
35+
fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate"].include? par
3636
end
3737
end
3838

@@ -46,8 +46,8 @@ def body_parameters
4646
p = Hash.new
4747
p['userId'] = @user_id
4848
p['itemId'] = @item_id
49-
p['timestamp'] = @timestamp
5049
p['rating'] = @rating
50+
p['timestamp'] = @optional['timestamp'] if @optional['timestamp']
5151
p['cascadeCreate'] = @optional['cascadeCreate'] if @optional['cascadeCreate']
5252
p
5353
end

lib/recombee_api_client/api/batch.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ def request_to_batch_hash(req)
5454
'path' => path
5555
}
5656
params = req.query_parameters
57+
5758
if req.body_parameters
5859
params = params.merge(req.body_parameters)
5960
end
61+
6062
bh['params'] = params if params.size > 0
6163
bh
6264
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 = '0.1.0'
2+
VERSION = '1.1.0'
33
end

spec/api/add_interaction.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,46 @@
55
include_context 'set environment'
66

77
it 'does not fail with cascadeCreate' do
8-
req = described_class.new('u_id', 'i_id', 0, 'cascadeCreate' => true)
8+
req = described_class.new('u_id', 'i_id', 'cascadeCreate' => true)
99
expect { @client.send(req) }.not_to raise_exception
1010
end
1111

1212
it 'does not fail with existing item and user' do
13-
req = described_class.new('entity_id', 'entity_id', 0)
13+
req = described_class.new('entity_id', 'entity_id')
14+
expect { @client.send(req) }.not_to raise_exception
15+
end
16+
17+
it 'does not fail with valid timestamp' do
18+
req = described_class.new('entity_id', 'entity_id', 'timestamp' => '2013-10-29T09:38:41.341Z')
1419
expect { @client.send(req) }.not_to raise_exception
1520
end
1621

1722
it 'fails with nonexisting item id' do
18-
req = described_class.new('entity_id', 'i_id', 0)
23+
req = described_class.new('entity_id', 'i_id')
1924
expect { @client.send(req) }.to raise_exception { |exception|
2025
expect(exception).to be_a(RecombeeApiClient::ResponseError)
2126
expect(exception.status_code).to eq 404
2227
}
2328
end
2429

2530
it 'fails with nonexisting user id' do
26-
req = described_class.new('u_id', 'entity_id', 0)
31+
req = described_class.new('u_id', 'entity_id')
2732
expect { @client.send(req) }.to raise_exception { |exception|
2833
expect(exception).to be_a(RecombeeApiClient::ResponseError)
2934
expect(exception.status_code).to eq 404
3035
}
3136
end
3237

3338
it 'fails with invalid time' do
34-
req = described_class.new('entity_id', 'entity_id', -15)
39+
req = described_class.new('entity_id', 'entity_id', 'timestamp' => -15)
3540
expect { @client.send(req) }.to raise_exception { |exception|
3641
expect(exception).to be_a(RecombeeApiClient::ResponseError)
3742
expect(exception.status_code).to eq 400
3843
}
3944
end
4045

4146
it 'really stores interaction to the system' do
42-
req = described_class.new('u_id', 'i_id', 0, 'cascadeCreate' => true)
47+
req = described_class.new('u_id', 'i_id', {'cascadeCreate' => true, 'timestamp' => 5})
4348
expect { @client.send(req) }.not_to raise_exception
4449
expect { @client.send(req) }.to raise_exception { |exception|
4550
expect(exception).to be_a(RecombeeApiClient::ResponseError)

spec/api/add_rating_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,49 @@
55
include_context 'set environment'
66

77
it 'does not fail with cascadeCreate' do
8-
dv = described_class.new('u_id', 'i_id', 0, 1, 'cascadeCreate' => true)
8+
dv = described_class.new('u_id', 'i_id', 1, 'cascadeCreate' => true)
99
expect { @client.send(dv) }.not_to raise_exception
1010
end
1111

1212
it 'does not fail with existing item and user' do
13-
dv = described_class.new('entity_id', 'entity_id', 0, 0)
13+
dv = described_class.new('entity_id', 'entity_id', 0)
1414
expect { @client.send(dv) }.not_to raise_exception
1515
end
1616

1717
it 'fails with nonexisting item id' do
18-
dv = described_class.new('entity_id', 'i_id', 0, -1)
18+
dv = described_class.new('entity_id', 'i_id', -1)
1919
expect { @client.send(dv) }.to raise_exception { |exception|
2020
expect(exception).to be_a(RecombeeApiClient::ResponseError)
2121
expect(exception.status_code).to eq 404
2222
}
2323
end
2424

2525
it 'fails with nonexisting user id' do
26-
dv = described_class.new('u_id', 'entity_id', 0, 0.5)
26+
dv = described_class.new('u_id', 'entity_id', 0.5)
2727
expect { @client.send(dv) }.to raise_exception { |exception|
2828
expect(exception).to be_a(RecombeeApiClient::ResponseError)
2929
expect(exception.status_code).to eq 404
3030
}
3131
end
3232

3333
it 'fails with invalid time' do
34-
dv = described_class.new('entity_id', 'entity_id', -15, 0)
34+
dv = described_class.new('entity_id', 'entity_id', 0, 'timestamp' => -15)
3535
expect { @client.send(dv) }.to raise_exception { |exception|
3636
expect(exception).to be_a(RecombeeApiClient::ResponseError)
3737
expect(exception.status_code).to eq 400
3838
}
3939
end
4040

4141
it 'fails with invalid rating' do
42-
dv = described_class.new('entity_id', 'entity_id', 15, -2)
42+
dv = described_class.new('entity_id', 'entity_id', -2)
4343
expect { @client.send(dv) }.to raise_exception { |exception|
4444
expect(exception).to be_a(RecombeeApiClient::ResponseError)
4545
expect(exception.status_code).to eq 400
4646
}
4747
end
4848

4949
it 'really stores interaction to the system' do
50-
dv = described_class.new('u_id', 'i_id', 0, 0.3, 'cascadeCreate' => true)
50+
dv = described_class.new('u_id', 'i_id', 0.3, {'cascadeCreate' => true, 'timestamp' => 5})
5151
expect { @client.send(dv) }.not_to raise_exception
5252
expect { @client.send(dv) }.to raise_exception { |exception|
5353
expect(exception).to be_a(RecombeeApiClient::ResponseError)

spec/api/batch_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
ListItems.new('filter' => "'num' < 99"),
2323
DeleteItem.new('item1'),
2424
ListItems.new('filter' => "'num' >= 99"),
25-
AddCartAddition.new('user', 'item2', 0),
26-
AddCartAddition.new('user', 'item2', 0, 'cascadeCreate' => true)
25+
AddCartAddition.new('user', 'item2'),
26+
AddCartAddition.new('user', 'item2', 'cascadeCreate' => true)
2727
]
2828
repl = @client.send(Batch.new(reqs))
2929

0 commit comments

Comments
 (0)