Skip to content

Commit 6732701

Browse files
committed
Added SetValues base class
1 parent 06e4d08 commit 6732701

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
module RecombeeApiClient
2+
require_relative 'request'
3+
require_relative '../errors'
4+
5+
##
6+
#Set/update (some) property values of a given entity.
7+
#
8+
class SetValues < ApiRequest
9+
attr_reader :cascade_create, :values
10+
11+
##
12+
# * *Required arguments*
13+
# - +values+ -> The values for the individual properties.
14+
#
15+
#Example of body:
16+
#```
17+
# {
18+
# "product_description": "4K TV with 3D feature",
19+
# "categories": ["Electronics", "Televisions"],
20+
# "price_usd": 342,
21+
# "in_stock_from": "2016-11-16T08:00Z",
22+
# }
23+
#```
24+
#
25+
# * *Optional arguments (given as hash optional)*
26+
# - +cascadeCreate+ -> Sets whether the item should be created if not present in the database.
27+
#
28+
def initialize( values, optional = {})
29+
@values = values
30+
@cascade_create = optional['cascadeCreate']
31+
@optional = optional
32+
@optional.each do |par, _|
33+
fail UnknownOptionalParameter.new(par) unless ["cascadeCreate"].include? par
34+
end
35+
end
36+
37+
# HTTP method
38+
def method
39+
:post
40+
end
41+
42+
# Values of body parameters as a Hash
43+
def body_parameters
44+
result = Hash.new
45+
result = result.merge(@values)
46+
result['!cascadeCreate'] = true if @cascade_create
47+
result
48+
end
49+
50+
# Values of query parameters as a Hash.
51+
# name of parameter => value of the parameter
52+
def query_parameters
53+
Hash.new
54+
end
55+
end
56+
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 = '1.3'
2+
VERSION = '1.3.1'
33
end

0 commit comments

Comments
 (0)