lomadee_api 0.1.0 → 0.2.0
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/README.md +50 -4
- data/lib/lomadee_api.rb +1 -1
- data/lib/lomadee_api/base.rb +50 -0
- data/lib/lomadee_api/version.rb +1 -1
- data/lomadee_api.gemspec +2 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d204aa65e075f0fb77e54664c34b9143ab0b7294
|
4
|
+
data.tar.gz: 042643ea85d114474c18cde383c013283523390c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8982940d5e8dd0fda72f9778e0ba944b65f06fd40c887c2e5ad3e76f6bdef39d1a7e8ca2d0dc67aa93f80b79a1010f1cb0d4f7b1a6f3be7666210f66e2632b9
|
7
|
+
data.tar.gz: c2e767363637e7d4d16fb03a3918edccd4f1c47b6a7afeabc9c0e7f2577353b8b9969973b70a0d6c6a75a8025e713b95d2f5dae9fe9b093dd6392ad5922bd230
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# LomadeeApi
|
2
2
|
|
3
|
-
|
3
|
+
A Ruby client for the official Lomadee API.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -16,9 +16,55 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install lomadee_api
|
18
18
|
|
19
|
-
##
|
19
|
+
## Configuration
|
20
20
|
|
21
|
-
|
21
|
+
To start using the gem, you can instantiate a new Base object from LomadeeApi module with three configuration options (application_id, sandbox and country)
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
lomadee = LomadeeApi::Base.new(application_id: 'YOUR_APPLICATION_ID', sandbox: true)
|
25
|
+
```
|
26
|
+
|
27
|
+
The following table shows which options are accepted and its default values.
|
28
|
+
|
29
|
+
| Options | Values |
|
30
|
+
|----------------|-----------------------------------------------------------------------------------------------------------------------------|
|
31
|
+
| application_id | Encrypted ID that is generated when you create a lomadee application |
|
32
|
+
| country | "BR" (Brazil), "AR" (Argentina), "CO" (Colombia), "CL" (Chile), "MX" (Mexico), "PE" (Peru), "VE" (Venezuela), default: "BR" |
|
33
|
+
| sandbox | true/false, default: false |
|
34
|
+
|
35
|
+
## Usage Examples
|
36
|
+
|
37
|
+
After configuring a lomadee object, you can do the following things.
|
38
|
+
|
39
|
+
### Get all products from a given category id
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
lomadee = LomadeeApi::Base.new(application_id: 'YOUR_APPLICATION_ID')
|
43
|
+
category_products = []
|
44
|
+
|
45
|
+
lomadee.products(77) do |products|
|
46
|
+
products.each do |product|
|
47
|
+
category_products << product['product']
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
puts category_products.count
|
52
|
+
```
|
53
|
+
|
54
|
+
### Get all offers from a given product id
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
lomadee = LomadeeApi::Base.new(application_id: 'YOUR_APPLICATION_ID')
|
58
|
+
product_offers = []
|
59
|
+
|
60
|
+
lomadee.offers(572767) do |offers|
|
61
|
+
offers.each do |offer|
|
62
|
+
product_offers << offer['offer']
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
puts product_offers.count
|
67
|
+
```
|
22
68
|
|
23
69
|
## Contributing
|
24
70
|
|
@@ -26,4 +72,4 @@ TODO: Write usage instructions here
|
|
26
72
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
73
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
74
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create a new Pull Request
|
75
|
+
5. Create a new Pull Request
|
data/lib/lomadee_api.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
module LomadeeApi
|
2
|
+
class Base
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
def initialize(params = {})
|
6
|
+
raise "You need to inform your :application_id" if params[:application_id].nil?
|
7
|
+
|
8
|
+
@application_id = params[:application_id]
|
9
|
+
@country = params[:country] || 'BR'
|
10
|
+
|
11
|
+
sandbox = params[:sandbox] || false
|
12
|
+
|
13
|
+
case sandbox
|
14
|
+
when false
|
15
|
+
self.class.base_uri "http://bws.buscape.com"
|
16
|
+
else
|
17
|
+
self.class.base_uri "http://sandbox.buscape.com"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def products(category_id)
|
23
|
+
@page = @totalpages = 1
|
24
|
+
|
25
|
+
while @page <= @totalpages
|
26
|
+
products = self.class.get("/service/findProductList/lomadee/#{@application_id}/#{@country}/", query: {categoryId: category_id, format: 'json', page: @page})
|
27
|
+
|
28
|
+
@response = JSON.parse(products.body)
|
29
|
+
@totalpages = @response['totalpages']
|
30
|
+
@page += 1
|
31
|
+
|
32
|
+
yield @response['product']
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def offers(product_id)
|
37
|
+
@page = @totalpages = 1
|
38
|
+
|
39
|
+
while @page <= @totalpages
|
40
|
+
offers = self.class.get("/service/findOfferList/lomadee/#{@application_id}/#{@country}/", query: {productId: product_id, format: 'json', page: @page})
|
41
|
+
|
42
|
+
@response = JSON.parse(offers.body)
|
43
|
+
@totalpages = @response['totalpages']
|
44
|
+
@page += 1
|
45
|
+
|
46
|
+
yield @response['offer']
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/lomadee_api/version.rb
CHANGED
data/lomadee_api.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = LomadeeApi::VERSION
|
9
9
|
spec.authors = ["Guilherme Kenedy Ferreira"]
|
10
10
|
spec.email = ["guilhermekfe@outlook.com"]
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{
|
11
|
+
spec.summary = %q{ Ruby client for the official Lomadee API }
|
12
|
+
spec.description = %q{ Ruby client for the official Lomadee API }
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lomadee_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilherme Kenedy Ferreira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description: " Ruby client for the official Lomadee API "
|
70
70
|
email:
|
71
71
|
- guilhermekfe@outlook.com
|
72
72
|
executables: []
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- README.md
|
80
80
|
- Rakefile
|
81
81
|
- lib/lomadee_api.rb
|
82
|
+
- lib/lomadee_api/base.rb
|
82
83
|
- lib/lomadee_api/version.rb
|
83
84
|
- lomadee_api.gemspec
|
84
85
|
homepage: ''
|
@@ -104,5 +105,5 @@ rubyforge_project:
|
|
104
105
|
rubygems_version: 2.2.2
|
105
106
|
signing_key:
|
106
107
|
specification_version: 4
|
107
|
-
summary:
|
108
|
+
summary: Ruby client for the official Lomadee API
|
108
109
|
test_files: []
|