blomming_api 0.4.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c2456b1f3eb51b26cc2aae945cef36703ca9db8
4
+ data.tar.gz: e1e42675078f500ce983a3693b8d956101fa208d
5
+ SHA512:
6
+ metadata.gz: 33ead1f763c3de18beae8866d348f52afe2651c7fc70817e87c97df7445459a42551c185ad02c0227e76457e0b06e79ea6fff0e45cd62cfcd12d0566a7788764
7
+ data.tar.gz: 8b5f3d687c512039f06cb3b462097ad24f5c2af0670dbae0cdb305434b5185b23866761eb93cd50e167b7dfdf1dbfd0863f55a870ebebdf1ead0fbff2463bce1
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in blomming_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Giorgio Robino
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # BlommingApi
2
+
3
+ www.blomming.com social commerce API's wrapper: supply a client access layer that embed authentication and communication details, supply API endpoints wrappers.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'blomming_api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install blomming_api
18
+
19
+ ## Usage
20
+
21
+ https://github.com/solyaris/blomming_api
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/blomming_api ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ require 'blomming_api'
4
+
5
+ USAGE = <<ENDUSAGE
6
+
7
+ Usage: blomming_api [option]
8
+ \t-a: Authentication set-up help
9
+ \t-e: Endpoints methods list
10
+ \t-v: Version and gem info
11
+
12
+ ENDUSAGE
13
+
14
+ if ARGV.empty?
15
+ puts USAGE
16
+ exit
17
+ end
18
+
19
+ option = ARGV[0].downcase
20
+
21
+ if option == "-v"
22
+ puts
23
+ puts "About gem:"
24
+ puts BlommingApi::about
25
+ puts
26
+ elsif option == "-a"
27
+ puts
28
+ puts "Authentication set-up help:"
29
+ puts BlommingApi::authentication_help
30
+ puts
31
+ elsif option == "-e"
32
+ puts
33
+ puts "Endpoints methods list:\n"
34
+ BlommingApi::endpoints_help
35
+ puts
36
+ else
37
+ puts USAGE
38
+ end
39
+
40
+
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'blomming_api/version'
5
+ require 'blomming_api/help'
6
+ require 'blomming_api/config'
7
+ require 'blomming_api/private_helpers'
8
+ require 'blomming_api/oauth_endpoint'
9
+ require 'blomming_api/buy_endpoints'
10
+ require 'blomming_api/sell_endpoints'
11
+ require 'blomming_api/public_helpers'
12
+
13
+
14
+ Gem::Specification.new do |spec|
15
+ spec.name = "blomming_api"
16
+ spec.version = BlommingApi::VERSION
17
+ spec.authors = BlommingApi::AUTHORS
18
+ spec.email = BlommingApi::EMAILS
19
+ spec.summary = BlommingApi::SUMMARY
20
+ spec.description = BlommingApi::DESCRIPTION
21
+ spec.homepage = BlommingApi::HOMEPAGE
22
+ spec.license = "MIT"
23
+
24
+ spec.files = `git ls-files`.split($/)
25
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
27
+ spec.require_paths = ["lib"]
28
+
29
+ # because of local variable scope in blocks
30
+ spec.required_ruby_version = '>= 1.9.0'
31
+
32
+ # runtime dependencies, from others gem
33
+ spec.add_runtime_dependency "method_source"
34
+ spec.add_runtime_dependency "rest-client"
35
+ spec.add_runtime_dependency "multi_json"
36
+ spec.add_runtime_dependency "oj"
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.3"
39
+ spec.add_development_dependency "rake"
40
+ end
@@ -0,0 +1,355 @@
1
+ # encoding: utf-8
2
+ require 'multi_json'
3
+ require 'rest_client'
4
+
5
+ module BlommingApi
6
+ module BuyEndpoints
7
+ #
8
+ # CARTS
9
+ #
10
+ def carts_add(skus, params={})
11
+ url = api_url '/carts/add'
12
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
13
+ load = MultiJson.dump skus
14
+
15
+ load_or_retry do
16
+ # POST with raw JSON payloads ?
17
+ RestClient.put url, load, req
18
+ end
19
+ end
20
+
21
+ def carts_checkout(order, params={})
22
+ url = api_url '/carts/checkout'
23
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
24
+ load = MultiJson.dump order
25
+
26
+ load_or_retry do
27
+ # POST with raw JSON payloads ?
28
+ RestClient.post url, load, req
29
+ end
30
+ end
31
+
32
+ def carts_clear(params={})
33
+ url = api_url '/carts/clear'
34
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
35
+
36
+ load_or_retry do
37
+ # PUT with a hash sends parameters as a urlencoded form body ?
38
+ RestClient.put url, req
39
+ end
40
+ end
41
+
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
63
+
64
+ load_or_retry do
65
+ RestClient.post url, load, req
66
+ end
67
+ end
68
+ =end
69
+
70
+
71
+ def carts_place_paypal_order(paypal_order, params={})
72
+ url = api_url '/carts/place_paypal_order'
73
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
74
+ load = MultiJson.dump paypal_order
75
+
76
+ load_or_retry do
77
+ RestClient.post url, load, req
78
+ end
79
+ end
80
+
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
+
91
+ def carts_shipping_countries(params={})
92
+ url = api_url '/carts/shipping_countries'
93
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
94
+
95
+ load_or_retry do
96
+ RestClient.get url, req
97
+ end
98
+ end
99
+
100
+ def carts_show(cart_id, params={})
101
+ url = api_url '/carts/#{cart_id}/show'
102
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
103
+
104
+ load_or_retry do
105
+ RestClient.get url, req
106
+ end
107
+ end
108
+
109
+ def carts_validate(cart_id, params={})
110
+ url = api_url '/carts/#{cart_id}/validate'
111
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
112
+
113
+ load_or_retry do
114
+ RestClient.get url, req
115
+ end
116
+ end
117
+
118
+
119
+ #
120
+ # CATEGORIES
121
+ #
122
+ def categories(params={})
123
+ url = api_url '/categories'
124
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
125
+
126
+ load_or_retry do
127
+ RestClient.get url, req
128
+ end
129
+ end
130
+
131
+ def category_items (category_id, params={})
132
+ url = api_url "/categories/#{category_id}/items"
133
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
134
+
135
+ load_or_retry do
136
+ RestClient.get url, req
137
+ end
138
+ end
139
+
140
+ #
141
+ # COLLECTIONS
142
+ #
143
+ def collections(params={})
144
+ url = api_url '/collections'
145
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
146
+
147
+ load_or_retry do
148
+ RestClient.get url, req
149
+ end
150
+ end
151
+
152
+ def collection_items (collection_id, params={})
153
+ url = api_url "/collections/#{collection_id}/items"
154
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
155
+
156
+ load_or_retry do
157
+ RestClient.get url, req
158
+ end
159
+ end
160
+
161
+ #
162
+ # COUNTRIES
163
+ #
164
+ def countries(params={})
165
+ url = api_url '/countries'
166
+ req = request_params({locale: @locale}.merge(params))
167
+
168
+ load_or_retry do
169
+ RestClient.get url, req
170
+ end
171
+ end
172
+
173
+ #
174
+ # CURRENCIES
175
+ #
176
+ def currencies(params={})
177
+ url = api_url '/currencies'
178
+ req = request_params({locale: @locale}.merge(params))
179
+
180
+ load_or_retry do
181
+ RestClient.get url, req
182
+ end
183
+ end
184
+
185
+ #
186
+ # ITEMS
187
+ #
188
+ def items_discounted(params={})
189
+ url = api_url '/items/discounted'
190
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
191
+
192
+ load_or_retry do
193
+ RestClient.get url, req
194
+ end
195
+ end
196
+
197
+ def items_featured(params={})
198
+ url = api_url '/items/featured'
199
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
200
+
201
+ load_or_retry do
202
+ RestClient.get url, req
203
+ end
204
+ end
205
+
206
+ def items_hand_picked(params={})
207
+ url = api_url '/items/hand_picked'
208
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
209
+
210
+ load_or_retry do
211
+ RestClient.get url, req
212
+ end
213
+ end
214
+
215
+ def items_list (item_id, params={})
216
+ url = api_url '/items/list'
217
+ req = request_params({id: item_id, currency: @currency, locale: @locale}.merge(params))
218
+
219
+ load_or_retry do
220
+ RestClient.get url, req
221
+ end
222
+ end
223
+
224
+ def items_most_liked(params={})
225
+ url = api_url '/items/most_liked'
226
+ req = request_params({currency: @currency, locale: @locale}.merge(params))
227
+
228
+ load_or_retry do
229
+ RestClient.get url, req
230
+ end
231
+ end
232
+
233
+ def items_search (keyword, params={})
234
+ url = api_url '/items/search'
235
+ req = request_params({q: keyword, currency: @currency, locale: @locale}.merge(params))
236
+
237
+ load_or_retry do
238
+ RestClient.get url, req
239
+ end
240
+ end
241
+
242
+ #
243
+ # MACROCATEGORIES
244
+ #
245
+ def macrocategories(params={})
246
+ url = api_url '/macrocategories'
247
+ req = request_params({locale: @locale}.merge(params))
248
+
249
+ load_or_retry do
250
+ RestClient.get url, req
251
+ end
252
+ end
253
+
254
+ def macrocategory_categories (macrocategory_id​, params={})
255
+ url = api_url "/macrocategories​/:macrocategory_id​/categories"
256
+ req = request_params({locale: @locale}.merge(params))
257
+
258
+ load_or_retry do
259
+ RestClient.get url, req
260
+ end
261
+ end
262
+
263
+ def macrocategory_items (macrocategory_id​, params={})
264
+ url = api_url "/macrocategories​/:macrocategory_id​/items"
265
+ req = request_params({locale: @locale}.merge(params))
266
+
267
+ load_or_retry do
268
+ RestClient.get url, req
269
+ end
270
+ end
271
+
272
+
273
+ #
274
+ # PASSWORD_RESETS
275
+ #
276
+ def password_resets (email_of_user, params={})
277
+ url = api_url "/password_resets"
278
+
279
+ load_or_retry do
280
+ # payload JSON ?
281
+ RestClient.post url, {email_of_user: email_of_user}.merge(params)
282
+ end
283
+ end
284
+
285
+
286
+ #
287
+ # PROVINCES
288
+ #
289
+ def provinces (province_country_code, params={})
290
+ url = api_url "/provinces/#{province_country_code}"
291
+
292
+ load_or_retry do
293
+ RestClient.get url, request_params(params)
294
+ end
295
+ end
296
+
297
+ #
298
+ # SHOPS
299
+ #
300
+ def shops (params={})
301
+ url = api_url '/shops'
302
+
303
+ load_or_retry do
304
+ RestClient.get url, request_params(params)
305
+ end
306
+ end
307
+
308
+ def shop_items (shop_id, params={})
309
+ url = api_url "/shops/#{shop_id}/items"
310
+
311
+ data = load_or_retry do
312
+ RestClient.get url, request_params(params)
313
+ end
314
+
315
+ #puts_response_header(__method__, data) if @verbose
316
+ data
317
+ end
318
+
319
+ def shop_item (shop_id, item_id, params={})
320
+ url = api_url "/shops/#{shop_id}/items/#{item_id}"
321
+
322
+ load_or_retry do
323
+ RestClient.get url, request_params(params)
324
+ end
325
+ end
326
+
327
+ def shops_find (shop_id, params={})
328
+ url = api_url "/shops/#{shop_id}"
329
+
330
+ load_or_retry do
331
+ RestClient.get url, request_params(params)
332
+ end
333
+ end
334
+
335
+ #
336
+ # TAGS
337
+ #
338
+ def tags (params={})
339
+ url = api_url "/tags"
340
+
341
+ load_or_retry do
342
+ RestClient.get url, request_params(params)
343
+ end
344
+ end
345
+
346
+ def tags_items (tag_id, params={})
347
+ url = api_url "/tags/#{tag_id}/items"
348
+
349
+ load_or_retry do
350
+ RestClient.get url, request_params(params)
351
+ end
352
+ end
353
+
354
+ end
355
+ end
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+ require 'yaml'
3
+
4
+ module BlommingApi
5
+ module Config
6
+
7
+ def read_config_file(config_filename)
8
+
9
+ # initialize instance variables, from config file
10
+ config = YAML.load_file config_filename
11
+
12
+ #
13
+ # initialize instance variables, from config files
14
+ # validating mandatory fields
15
+
16
+ @description = config['description']
17
+
18
+ # services: buy or sell
19
+ @services = config['services']
20
+ if (@services.downcase =~ /buy|sell/).nil?
21
+ raise "FATAL: config value for: services (#@services): invalid"
22
+ end
23
+
24
+ @username = config['username']
25
+ if !(@services.downcase =~ /sell/).nil? && @username.nil?
26
+ raise "FATAL: config value for: username: must be specified"
27
+ end
28
+
29
+ @password = config['password']
30
+ if !(@services.downcase =~ /sell/).nil? && @password.nil?
31
+ raise "FATAL: config value for: password: must be specified"
32
+ end
33
+
34
+ @client_id = config['client_id']
35
+ raise "FATAL: config value for: client_id: must be specified" if @client_id.nil?
36
+
37
+ @client_secret = config['client_secret']
38
+ raise "FATAL: value for: client_secret: must be specified" if @client_secret.nil?
39
+
40
+ @domain = config['domain']
41
+ if (@domain.downcase =~ /https:\/\/|blomming/).nil?
42
+ raise "FATAL: config value for: domain (#@services) invalid"
43
+ end
44
+
45
+ @api_version = config['api_version']
46
+ if (@api_version =~ /\/v\d+/).nil?
47
+ raise "FATAL: config value for: api_version (#@api_version): invalid"
48
+ end
49
+
50
+ # default API endpoint parameters values
51
+ @currency = config['default_currency']
52
+ @locale = config['default_locale']
53
+
54
+ # other behaviours
55
+ @verbose = config['verbose']
56
+ @verbose_access_token = @verbose
57
+ puts to_s(config_filename) if @verbose
58
+ end
59
+ private :read_config_file
60
+
61
+ def show_config_file (config_file)
62
+ "config file: #{config_file}\n\n" +
63
+ "\tdescription: #@description\n" +
64
+ "\tservices: #@services\n" +
65
+ "\tusername: #@username\n" +
66
+ "\tpassword: #@password\n" +
67
+ "\tclient_id: #@client_id\n" +
68
+ "\tclient_secret: #@client_secret\n" +
69
+ "\tdomain: #@domain\n" +
70
+ "\tdefault_currency: #@currency\n" +
71
+ "\tdefault_locale: #@locale\n\n"
72
+ end
73
+ public :show_config_file
74
+
75
+ end
76
+ end