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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da6e25604e62123bc4adc57549161d0d3b913804
4
- data.tar.gz: 6c3f75109da7efa3cfba2d58f727065e236d255f
3
+ metadata.gz: 9e68d30d6391b0b83d63f68c253850bfa881211d
4
+ data.tar.gz: 52e45bf9d99bee1a8511ee83528873fe7f7d1d07
5
5
  SHA512:
6
- metadata.gz: 0d16cc06bc53b7d79e8895e9cf5ef22f86aa007b162b4e93b1a1c591c110a9e30422290255a8f9382873ad2d01057f7bd88cb0aa56103f7128050eac131855fc
7
- data.tar.gz: a95f9c9e73991d3a0c8f6b9089d0525dc3baa7c228829155201c13ef3846b40bb8c54434f0fe351a0696b98c6ce01c395b7cda99ef0f9c5bd1819cf0a67a9bf3
6
+ metadata.gz: 436ddd6e358c4a8bb02668fc0b47f37d786a2d59689c23dd4887413a85869e2195fe6f01c48433f999b467022d02fa4ea9cec82ca53e1021c1292e1e8c10747b
7
+ data.tar.gz: ee03040cd62ffb1ae80f7320ed4e0031929a3d7a31b442352690f2a07a9d4b53c09121eb4d5e48dac6e1db63545877c0d508c875e752f3d4e5038ced4e697268
@@ -7,30 +7,49 @@ module BlommingApi
7
7
  #
8
8
  # CARTS
9
9
  #
10
- def carts_add(skus, params={})
11
- url = api_url '/carts/add'
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
- load = MultiJson.dump skus
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 carts_checkout(order, params={})
22
- url = api_url '/carts/checkout'
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
- # POST with raw JSON payloads ?
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 carts_create(sku_id, params={})
43
- url = api_url '/carts/create'
44
- req = request_params({sku_id: sku_id, currency: @currency}.merge(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 returned!).
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 http_status_code_404? e
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
- return fatal_error! e
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
- # HTTP status 200: return data (hash from JSON)!
82
- MultiJson.load json_data
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
- def http_status_code_404?(e)
96
- 404 == e.response.code
97
- end
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}: restclient error. http status code: #{e.response.code}: #{e.response.body}. Invalid or expired token. Retry in #{retry_seconds} seconds."
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 #{retry_seconds} seconds."
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
@@ -1,3 +1,3 @@
1
1
  module BlommingApi
2
- VERSION = "0.4.4"
2
+ VERSION = "0.4.5"
3
3
  end
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
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-07 00:00:00.000000000 Z
11
+ date: 2014-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_source