blomming_api 0.5.1 → 0.6.1

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: 9ffd881cfdd0c8498bd0392a6b5c0e8922219f9c
4
- data.tar.gz: 0036add36a945f228b8b0bc67eb6aab79af3ac44
3
+ metadata.gz: 6876fd023df19ccb0a6d8dde18e50b1dbe36bd30
4
+ data.tar.gz: 457d04eb4e71e806a98d2ea3e3cf39503c5c54ea
5
5
  SHA512:
6
- metadata.gz: c206d43a3fb1dbdf5d47aa426e80c2b74179675cab503668fa02bfe48e40c169ee9fc7f7161136e125552bb02f0bdd819fa0a2681dc7549d1524d1a7085bcf79
7
- data.tar.gz: f004dc99860ce60a36b2be52406ba8172e38695188a3d0727a61ed13257a034712c466c3d4967e725d939479a2b0004423d33908806704c80e2eb65d95bb5131
6
+ metadata.gz: 55b70b6d3118e54f1f615289ef0b268ee8d2312a232394e0ef03abf7e2d61bc7a58b8a5ea6718025aff0ffba007828bc1cc57a7d300769385c458ebfecb3bbbe
7
+ data.tar.gz: 0abc6e593f89c2752b0991fa0548e4cc1fa55f12c0550e60f918911d329133149786ed13d14bce63f26e3e76caff21e159b7304dd8637e04041fb3439b28cd26
@@ -5,9 +5,7 @@ module BlommingApi
5
5
  AUTHORS = ["Giorgio Robino"]
6
6
  EMAILS = ["giorgio.robino@gmail.com"]
7
7
  SUMMARY = %q{www.blomming.com social commerce API's wrapper}
8
- DESCRIPTION = %q{www.blomming.com social commerce API's wrapper. \
9
- Supply a client access layer embedding authentication and communication details, \
10
- simple API endpoints.}
8
+ DESCRIPTION = SUMMARY
11
9
  HOMEPAGE = "https://github.com/solyaris/blomming_api"
12
10
 
13
11
  def BlommingApi::about
@@ -60,7 +60,7 @@ module BlommingApi
60
60
  rescue RestClient::Exception => e
61
61
 
62
62
  if http_status_code_401? e
63
- authenticate_refresh e
63
+ re_authenticate e
64
64
  retry
65
65
 
66
66
  elsif http_status_code_4xx? e
@@ -79,8 +79,12 @@ module BlommingApi
79
79
  return unknown_error! e
80
80
 
81
81
  else
82
- # HTTP status 200: return data (hash from JSON)!
83
- MultiJson.load json_data
82
+ #
83
+ # HTTP status 200:
84
+ # return
85
+ # nil if there are no data!
86
+ # data as a Ruby hash (loaded from JSON)
87
+ (json_data.empty? || json_data.nil?) ? nil : (MultiJson.load json_data)
84
88
  end
85
89
  end
86
90
 
@@ -108,14 +112,25 @@ module BlommingApi
108
112
  #
109
113
  # Errors managers
110
114
  #
111
- def authenticate_refresh(e)
115
+ def re_authenticate(e)
112
116
  STDERR.puts "#{Time.now}: HTTP status code: #{e.response.code}: #{e.response.body}. Invalid or expired token. Retry in #@retry_seconds seconds."
113
117
 
114
118
  # sleep maybe useless here
115
119
  sleep @retry_seconds
116
120
 
117
- # authenticate with refresh token
118
- authenticate :refresh
121
+ #
122
+ # Normal/expected behaviour with http status code == 401
123
+ # would be to authenticate with refresh token after the 401, so:
124
+ #
125
+ # authenticate :refresh
126
+ #
127
+ # but in production sometime authentication with refresh token
128
+ # after an initial 401 bring to dead-end (getting 401 permanently),
129
+ #
130
+ # so the agreed solution with Blomming tech team
131
+ # have been to authenticate again from from scratch:
132
+ #
133
+ authenticate :initialize
119
134
  end
120
135
 
121
136
  def server_error!(e)
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ require 'time'
2
3
  require 'multi_json'
3
4
  require 'rest_client'
4
5
 
@@ -101,6 +102,49 @@ module BlommingApi
101
102
  return nil if array.nil?
102
103
  return array.collect { |item| item[key_name] }
103
104
  end
105
+
106
+ #
107
+ # TIME CONVERSIONS
108
+ #
109
+
110
+ #
111
+ # Convert a timestamp in ISO 8601 format to Time
112
+ #
113
+ # example:
114
+ #
115
+ # timestamp = '2014-01-14T15:17:42Z'
116
+ # to_time timestamp => 2014-01-14 15:17:42 UTC
117
+ #
118
+ def self.to_time (iso8601_timestamp)
119
+ Time.iso8601(iso8601_timestamp)
120
+ end
121
+
122
+ #
123
+ # Print timestamp from Time in UTC
124
+ # to local time in "European" timestamp format
125
+ #
126
+ # example:
127
+ #
128
+ # time = 2014-01-14 15:17:42 UTC
129
+ # to_eurolocal_timestamp time => => '14-01-2014 16:17:42'
130
+ #
131
+ def self.to_eurolocal_timestamp (time)
132
+ time.localtime if time.utc?
133
+ time.strftime "%d-%m-%Y %H:%M:%S"
134
+ end
135
+
136
+
137
+ #
138
+ # Convert a timestamp in ISO 8601 format to Time
139
+ #
140
+ # example:
141
+ #
142
+ # timestamp = '2014-01-14T15:17:42Z'
143
+ # to_eurolocal timestamp => '14-01-2014 16:17:42'
144
+ #
145
+ def self.to_eurolocal (iso8601_timestamp)
146
+ to_eurolocal_timestamp to_time iso8601_timestamp
147
+ end
104
148
 
105
149
  end
106
150
  end
@@ -244,9 +244,23 @@ module BlommingApi
244
244
  #
245
245
  # Create a new shop item
246
246
  #
247
- def sell_shop_item_create (payload, params={})
247
+ # example:
248
+ #
249
+ # item = { "category_ids": [101],
250
+ # "source_shipping_profile_id": "",
251
+ # "price": 8.50,
252
+ # "title": "An Item",
253
+ # "quantity": 1,
254
+ # "description": "New description",
255
+ # "published": true,
256
+ # "original_price": 10.00
257
+ # }
258
+ #
259
+ # blomming.sell_shop_item_create item
260
+ #
261
+ def sell_shop_item_create (item, params={})
248
262
  url = api_url "/sell/shop/items/new"
249
- load = MultiJson.dump payload
263
+ load = MultiJson.dump item
250
264
  req = request_params(params)
251
265
 
252
266
  feed_or_retry do
@@ -269,9 +283,24 @@ module BlommingApi
269
283
  #
270
284
  # Update some of the properties of the Item
271
285
  #
272
- def sell_shop_item_update (item_id, payload, params={})
286
+ # example:
287
+ #
288
+ # item = { "category_ids": [101],
289
+ # "source_shipping_profile_id": "",
290
+ # "price": 8.50,
291
+ # "title": "An Item",
292
+ # "quantity": 1,
293
+ # "description": "New description",
294
+ # "published": true,
295
+ # "original_price": 10.00
296
+ # }
297
+ #
298
+ # blomming.sell_shop_item_update 60034, item
299
+ #
300
+ #
301
+ def sell_shop_item_update (item_id, item, params={})
273
302
  url = api_url "/sell/shop/items/#{item_id}"
274
- load = MultiJson.dump payload
303
+ load = MultiJson.dump item
275
304
  req = request_params(params)
276
305
 
277
306
  feed_or_retry do
@@ -319,6 +348,33 @@ module BlommingApi
319
348
  end
320
349
  end
321
350
 
351
+
352
+ #
353
+ # Add an Item (:item_id) to a section (:section_name)
354
+ #
355
+ def sell_shop_item_section_add(item_id, section_name, params={})
356
+ url = api_url "/sell/shop/items/#{item_id}/add_section"
357
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
358
+ load = MultiJson.dump section: section_name
359
+
360
+ feed_or_retry do
361
+ RestClient.post url, load, req
362
+ end
363
+ end
364
+
365
+
366
+ #
367
+ # Remove an Item (:item_id) from a section (:section_id)
368
+ #
369
+ def sell_shop_item_section_remove(item_id, section_id, params={})
370
+ url = api_url "/sell/shop/items/#{item_id}/remove_section/#{section_id}"
371
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
372
+
373
+ feed_or_retry do
374
+ RestClient.delete url, req
375
+ end
376
+ end
377
+
322
378
  #
323
379
  # SELL
324
380
  # SHOP_SECTIONS
@@ -1,3 +1,3 @@
1
1
  module BlommingApi
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.1"
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.5.1
4
+ version: 0.6.1
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-19 00:00:00.000000000 Z
11
+ date: 2014-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_source
@@ -94,9 +94,7 @@ dependencies:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: "www.blomming.com social commerce API's wrapper. \\\n Supply a client
98
- access layer embedding authentication and communication details, \\ \n simple API
99
- endpoints."
97
+ description: www.blomming.com social commerce API's wrapper
100
98
  email:
101
99
  - giorgio.robino@gmail.com
102
100
  executables: