blomming_api 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/blomming_api/buy_endpoints.rb +35 -43
- data/lib/blomming_api/private_helpers.rb +22 -20
- data/lib/blomming_api/sell_endpoints.rb +24 -0
- data/lib/blomming_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e68d30d6391b0b83d63f68c253850bfa881211d
|
4
|
+
data.tar.gz: 52e45bf9d99bee1a8511ee83528873fe7f7d1d07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 436ddd6e358c4a8bb02668fc0b47f37d786a2d59689c23dd4887413a85869e2195fe6f01c48433f999b467022d02fa4ea9cec82ca53e1021c1292e1e8c10747b
|
7
|
+
data.tar.gz: ee03040cd62ffb1ae80f7320ed4e0031929a3d7a31b442352690f2a07a9d4b53c09121eb4d5e48dac6e1db63545877c0d508c875e752f3d4e5038ced4e697268
|
@@ -7,30 +7,49 @@ module BlommingApi
|
|
7
7
|
#
|
8
8
|
# CARTS
|
9
9
|
#
|
10
|
-
|
11
|
-
|
10
|
+
|
11
|
+
def carts_create(sku_id, params={})
|
12
|
+
url = api_url '/carts'
|
13
|
+
req = request_params({currency: @currency}.merge(params))
|
14
|
+
|
15
|
+
# with a hash sends parameters as a urlencoded form body
|
16
|
+
load = {:sku_id => sku_id, :multipart => true}
|
17
|
+
|
18
|
+
# debug
|
19
|
+
#puts req
|
20
|
+
#RestClient.log = 'stdout'
|
21
|
+
|
22
|
+
load_or_retry do
|
23
|
+
RestClient.post url, load, req
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def carts_add(*skus, cart_id, params)
|
28
|
+
url = api_url "/carts/#{cart_id}/add"
|
12
29
|
req = request_params({currency: @currency, locale: @locale}.merge(params))
|
13
|
-
|
30
|
+
|
31
|
+
# with a hash sends parameters as a urlencoded form body
|
32
|
+
load = {:skus => skus.join(','), :multipart => true}
|
14
33
|
|
15
34
|
load_or_retry do
|
16
|
-
# POST with raw JSON payloads ?
|
17
35
|
RestClient.put url, load, req
|
18
36
|
end
|
19
37
|
end
|
20
38
|
|
21
|
-
def
|
22
|
-
url = api_url
|
39
|
+
def carts_remove(*skus, cart_id, params)
|
40
|
+
url = api_url "/carts/#{cart_id}/remove"
|
23
41
|
req = request_params({currency: @currency, locale: @locale}.merge(params))
|
24
|
-
load = MultiJson.dump order
|
25
42
|
|
43
|
+
# with a hash sends parameters as a urlencoded form body
|
44
|
+
load = {:skus => skus.join(','), :multipart => true}
|
45
|
+
|
26
46
|
load_or_retry do
|
27
|
-
|
28
|
-
RestClient.post url, load, req
|
47
|
+
RestClient.put url, load, req
|
29
48
|
end
|
30
49
|
end
|
31
50
|
|
32
|
-
def carts_clear(params={})
|
33
|
-
url = api_url '/carts/clear'
|
51
|
+
def carts_clear(cart_id, params={})
|
52
|
+
url = api_url '/carts/#{cart_id}/clear'
|
34
53
|
req = request_params({currency: @currency, locale: @locale}.merge(params))
|
35
54
|
|
36
55
|
load_or_retry do
|
@@ -39,34 +58,16 @@ module BlommingApi
|
|
39
58
|
end
|
40
59
|
end
|
41
60
|
|
42
|
-
def
|
43
|
-
url = api_url '/carts/
|
44
|
-
req = request_params({
|
45
|
-
|
46
|
-
# debug
|
47
|
-
puts req
|
48
|
-
|
49
|
-
load_or_retry do
|
50
|
-
# with a hash sends parameters as a urlencoded form body
|
51
|
-
RestClient.post url, req #load,
|
52
|
-
end
|
53
|
-
end
|
54
|
-
=begin
|
55
|
-
def carts_create(sku_id, params={})
|
56
|
-
url = api_url '/carts/create'
|
57
|
-
req = request_params(params)
|
58
|
-
|
59
|
-
load = MultiJson.dump({sku_id: sku_id, currency: @currency})
|
60
|
-
|
61
|
-
# debug
|
62
|
-
puts load
|
61
|
+
def carts_checkout(order, params={})
|
62
|
+
url = api_url '/carts/checkout'
|
63
|
+
req = request_params({currency: @currency, locale: @locale}.merge(params))
|
64
|
+
load = MultiJson.dump order
|
63
65
|
|
64
66
|
load_or_retry do
|
67
|
+
# POST with raw JSON payloads ?
|
65
68
|
RestClient.post url, load, req
|
66
69
|
end
|
67
70
|
end
|
68
|
-
=end
|
69
|
-
|
70
71
|
|
71
72
|
def carts_place_paypal_order(paypal_order, params={})
|
72
73
|
url = api_url '/carts/place_paypal_order'
|
@@ -78,15 +79,6 @@ module BlommingApi
|
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
81
|
-
def carts_remove(skus, params={})
|
82
|
-
url = api_url '/carts/remove'
|
83
|
-
req = request_params({currency: @currency, locale: @locale}.merge(params))
|
84
|
-
load = MultiJson.dump skus
|
85
|
-
|
86
|
-
load_or_retry do
|
87
|
-
RestClient.put url, load, req
|
88
|
-
end
|
89
|
-
end
|
90
82
|
|
91
83
|
def carts_shipping_countries(params={})
|
92
84
|
url = api_url '/carts/shipping_countries'
|
@@ -35,7 +35,7 @@ module BlommingApi
|
|
35
35
|
# if @survive_on_fatal_error if false (default)
|
36
36
|
# process die with exit
|
37
37
|
# if @survive_on_fatal_error if true (must be specified in config file)
|
38
|
-
# load_or_retry return value: nil (no data
|
38
|
+
# load_or_retry return value: nil (no data available!).
|
39
39
|
#
|
40
40
|
# === arguments
|
41
41
|
#
|
@@ -63,23 +63,22 @@ module BlommingApi
|
|
63
63
|
authenticate_refresh e
|
64
64
|
retry
|
65
65
|
|
66
|
-
elsif
|
67
|
-
return fatal_error! e
|
68
|
-
|
69
|
-
elsif http_status_code_422? e
|
66
|
+
elsif http_status_code_4xx? e
|
70
67
|
return fatal_error! e
|
71
68
|
|
72
69
|
elsif http_status_code_5xx? e
|
73
|
-
|
70
|
+
server_error! e
|
71
|
+
retry
|
74
72
|
|
75
73
|
# any other exception
|
76
74
|
else
|
77
75
|
return fatal_error! e
|
78
76
|
end
|
79
|
-
end
|
80
77
|
|
81
|
-
|
82
|
-
|
78
|
+
else
|
79
|
+
# HTTP status 200: return data (hash from JSON)!
|
80
|
+
MultiJson.load json_data
|
81
|
+
end
|
83
82
|
end
|
84
83
|
|
85
84
|
|
@@ -91,16 +90,14 @@ module BlommingApi
|
|
91
90
|
def http_status_code_401?(e)
|
92
91
|
401 == e.response.code
|
93
92
|
end
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
# Invalid or blank request body given (sell services endpoints)
|
100
|
-
def http_status_code_422?(e)
|
101
|
-
422 == e.response.code
|
93
|
+
|
94
|
+
# 404: not found
|
95
|
+
# 422: Invalid or blank request body given (sell services endpoints)
|
96
|
+
def http_status_code_4xx?(e)
|
97
|
+
[400, 404, 422].include? e.response.code
|
102
98
|
end
|
103
|
-
|
99
|
+
|
100
|
+
# possible temporary server problem ?
|
104
101
|
def http_status_code_5xx?(e)
|
105
102
|
[500, 520].include? e.response.code
|
106
103
|
end
|
@@ -109,7 +106,7 @@ module BlommingApi
|
|
109
106
|
# Errors managers
|
110
107
|
#
|
111
108
|
def authenticate_refresh(e)
|
112
|
-
STDERR.puts "#{Time.now}:
|
109
|
+
STDERR.puts "#{Time.now}: HTTP status code: #{e.response.code}: #{e.response.body}. Invalid or expired token. Retry in #@retry_seconds seconds."
|
113
110
|
|
114
111
|
# sleep maybe useless here
|
115
112
|
sleep @retry_seconds
|
@@ -118,9 +115,14 @@ module BlommingApi
|
|
118
115
|
authenticate :refresh
|
119
116
|
end
|
120
117
|
|
118
|
+
def server_error!(e)
|
119
|
+
STDERR.puts "#{Time.now}: HTTP status code: #{e.response.code}: #{e.response.body}. Retry in #@retry_seconds seconds."
|
120
|
+
|
121
|
+
sleep @retry_seconds
|
122
|
+
end
|
121
123
|
|
122
124
|
def socket_error!(e)
|
123
|
-
STDERR.puts "#{Time.now}: socket error: #{e}. Possible net connection problems. Retry in
|
125
|
+
STDERR.puts "#{Time.now}: socket error: #{e}. Possible net connection problems. Retry in #@retry_seconds seconds."
|
124
126
|
|
125
127
|
sleep @retry_seconds
|
126
128
|
end
|
@@ -219,6 +219,30 @@ module BlommingApi
|
|
219
219
|
end
|
220
220
|
end
|
221
221
|
|
222
|
+
def sell_shop_item_tags_add(*tags, item_id, params)
|
223
|
+
url = api_url "/sell/shop/items/#{item_id}/add_tags"
|
224
|
+
req = request_params({currency: @currency, locale: @locale}.merge(params))
|
225
|
+
|
226
|
+
# with a hash sends parameters as a urlencoded form body
|
227
|
+
load = {:tags => tags.join(','), :multipart => true}
|
228
|
+
|
229
|
+
load_or_retry do
|
230
|
+
RestClient.post url, load, req
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def sell_shop_item_tags_remove(*tags, item_id, params)
|
235
|
+
url = api_url "/sell/shop/items/#{item_id}/remove_tag"
|
236
|
+
req = request_params({currency: @currency, locale: @locale}.merge(params))
|
237
|
+
|
238
|
+
# with a hash sends parameters as a urlencoded form body
|
239
|
+
load = {:tags => tags.join(','), :multipart => true}
|
240
|
+
|
241
|
+
load_or_retry do
|
242
|
+
RestClient.post url, load, req
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
222
246
|
|
223
247
|
#
|
224
248
|
# SHOP_ORDERS
|
data/lib/blomming_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blomming_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giorgio Robino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: method_source
|