mercadolibre_api 0.1 → 0.2

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
  SHA256:
3
- metadata.gz: 10992099c067297a6ba5d2a9bcec468cadcfb3209e4802ef37762c76f2e40fae
4
- data.tar.gz: efa9f8c6ec53ded8c110d0c853987c90b0757ece3ca9f8dc651c2e63446cbe21
3
+ metadata.gz: a1ae34b484b9b1281810fd78c1b39e3890ef42de1035ef3dc0a1981792ef5046
4
+ data.tar.gz: c84a2db6daf5fa0303abdbd2b0faf89c7fd5f84a5deef651ead3b118d3cd67cb
5
5
  SHA512:
6
- metadata.gz: ee8cf859bc86c6d76ba85c4a5a19bdc72cfdc8bbef461c5d3ecc5b3158dfd2e789470170205d11a6466e6f4b722bb4f3b9dc2651b6daab022b1f562fb9d2baa0
7
- data.tar.gz: 40b6e4796879146a0397b18fd43fd818c2909b22bfd3b2f8e95e0cfb35c93226fb26b0494c302eaf842a76235f8e8e782fef89d62fafb0586aa3de817f7527c7
6
+ metadata.gz: 9f37b8bcc74dc1ba61afd1ac64f867515cd980a54fe8bcda365e8b1bb8b34c36effeb257c14917d2d444e12aa93c5afe4732168e3832bc6112e8f4029a855221
7
+ data.tar.gz: 431fadb67ec2d267abc19e99abfd015bdb5d9d28bd4cb83eac717e5a5fa7981c608bc85a7826bec5e1f3d8b924077f79b76b2dffadbe05296f8c03ba50596d8b
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  *.swp
14
14
  .DS_Store
15
15
  *.gem
16
+ .byebug_history
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mercadolibre_api (0.1.0)
4
+ mercadolibre_api (0.1)
5
5
  active_interaction (~> 3.6)
6
6
 
7
7
  GEM
@@ -18,16 +18,25 @@ GEM
18
18
  tzinfo (~> 1.1)
19
19
  addressable (2.5.2)
20
20
  public_suffix (>= 2.0.2, < 4.0)
21
+ ansi (1.5.0)
21
22
  ast (2.4.0)
23
+ byebug (10.0.2)
22
24
  concurrent-ruby (1.0.5)
23
25
  crack (0.4.3)
24
26
  safe_yaml (~> 1.0.0)
25
27
  diff-lcs (1.3)
28
+ grape-entity (0.7.1)
29
+ activesupport (>= 4.0)
30
+ multi_json (>= 1.3.2)
26
31
  hashdiff (0.3.7)
27
32
  i18n (1.1.0)
28
33
  concurrent-ruby (~> 1.0)
29
34
  jaro_winkler (1.5.1)
30
35
  minitest (5.11.3)
36
+ multi_json (1.13.1)
37
+ oga (2.15)
38
+ ast
39
+ ruby-ll (~> 2.1)
31
40
  parallel (1.12.1)
32
41
  parser (2.5.1.2)
33
42
  ast (~> 2.4.0)
@@ -56,6 +65,9 @@ GEM
56
65
  rainbow (>= 2.2.2, < 4.0)
57
66
  ruby-progressbar (~> 1.7)
58
67
  unicode-display_width (~> 1.0, >= 1.0.1)
68
+ ruby-ll (2.1.2)
69
+ ansi
70
+ ast
59
71
  ruby-progressbar (1.10.0)
60
72
  safe_yaml (1.0.4)
61
73
  thread_safe (0.3.6)
@@ -73,7 +85,10 @@ PLATFORMS
73
85
 
74
86
  DEPENDENCIES
75
87
  bundler (~> 1.16)
88
+ byebug (~> 10.0)
89
+ grape-entity (~> 0.7.1)
76
90
  mercadolibre_api!
91
+ oga (~> 2.15)
77
92
  rake (~> 12.3)
78
93
  rspec (~> 3.8)
79
94
  rubocop (~> 0.59)
data/README.md CHANGED
@@ -20,9 +20,16 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- ### Products by seller
23
+ ### Products
24
+ #### Find by ID
25
+
26
+ ```
27
+ MercadolibreApi::Products::Queries::Find.run!(product_id: 'MLU445694345')
28
+ ```
24
29
 
30
+ ### Products by seller
25
31
  #### Most sold
32
+
26
33
  ```
27
34
  MercadolibreApi::Sellers::Products::Queries::MostSold.run!(seller_id: 95592600, site_code: 'MLU')
28
35
  ```
@@ -0,0 +1,27 @@
1
+ require 'active_interaction'
2
+ require 'net/http'
3
+
4
+ module MercadolibreApi
5
+ module Products
6
+ module Descriptions
7
+ module Queries
8
+ class Find < ActiveInteraction::Base
9
+ string :description_id
10
+ string :product_id
11
+
12
+ def execute
13
+ response = Net::HTTP.get_response(description_uri)
14
+ response_body = JSON.parse(response.body, symbolize_names: true)
15
+ response_body.dig(:plain_text)
16
+ end
17
+
18
+ private
19
+
20
+ def description_uri
21
+ URI("https://api.mercadolibre.com/items/#{product_id}/descriptions/#{description_id}")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ require 'grape-entity'
2
+
3
+ module MercadolibreApi
4
+ module Products
5
+ module Entities
6
+ class Picture < Grape::Entity
7
+ expose :secure_url, as: :url
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ require 'grape-entity'
2
+ require './lib/mercadolibre_api/products/entities/picture'
3
+
4
+ module MercadolibreApi
5
+ module Products
6
+ module Entities
7
+ class Product < Grape::Entity
8
+ expose :id
9
+ expose :title
10
+ expose :price
11
+ expose :currency_id
12
+ expose :confirmed_sold_quantity, as: :sold_quantity, override: true
13
+ expose :description
14
+ expose :status
15
+
16
+ expose :seller_id do |product, _options|
17
+ product.dig(:seller, :id) || product[:seller_id]
18
+ end
19
+
20
+ expose :pictures, using: MercadolibreApi::Products::Entities::Picture
21
+ expose :geolocation
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ require 'active_interaction'
2
+ require 'net/http'
3
+ require './lib/mercadolibre_api/products/entities/product'
4
+ require './lib/mercadolibre_api/products/descriptions/queries/find'
5
+ require './lib/mercadolibre_api/products/queries/sold_quantity'
6
+
7
+ module MercadolibreApi
8
+ module Products
9
+ module Queries
10
+ class Find < ActiveInteraction::Base
11
+ string :product_id
12
+
13
+ def execute
14
+ response = Net::HTTP.get_response(product_uri)
15
+ response_body = JSON.parse(response.body, symbolize_names: true)
16
+ sold_quantity = MercadolibreApi::Products::Queries::SoldQuantity.run!(product_url: response_body[:permalink])
17
+ description = MercadolibreApi::Products::Descriptions::Queries::Find.run!(
18
+ product_id: product_id, description_id: response_body[:descriptions].dig(0, :id)
19
+ )
20
+
21
+ response_body[:description] = description
22
+ response_body[:confirmed_sold_quantity] = sold_quantity
23
+ MercadolibreApi::Products::Entities::Product.represent(response_body).as_json
24
+ end
25
+
26
+ private
27
+
28
+ def product_uri
29
+ URI("https://api.mercadolibre.com/items/#{product_id}")
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ require 'active_interaction'
2
+ require 'net/http'
3
+ require 'oga'
4
+
5
+ module MercadolibreApi
6
+ module Products
7
+ module Queries
8
+ class SoldQuantity < ActiveInteraction::Base
9
+ string :product_url
10
+
11
+ def execute
12
+ response = Net::HTTP.get(product_uri).force_encoding('UTF-8')
13
+ document = Oga.parse_html(response)
14
+ document.at_css('.item-conditions').text.scan(/\d+/).join.to_i
15
+ end
16
+
17
+ private
18
+
19
+ def product_uri
20
+ URI(product_url)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,6 @@
1
1
  require 'active_interaction'
2
2
  require 'net/http'
3
+ require './lib/mercadolibre_api/products/entities/product'
3
4
 
4
5
  module MercadolibreApi
5
6
  module Sellers
@@ -15,7 +16,7 @@ module MercadolibreApi
15
16
  JSON.parse(response.body, symbolize_names: true)[:results]
16
17
  end
17
18
 
18
- results.flatten!
19
+ results.flatten.map { |r| MercadolibreApi::Products::Entities::Product.represent(r).as_json }
19
20
  end
20
21
 
21
22
  private
@@ -32,11 +33,13 @@ module MercadolibreApi
32
33
  end
33
34
 
34
35
  def base_uri(offset: 0)
35
- if offset.positive?
36
- URI("https://api.mercadolibre.com/sites/#{site_code}/search?seller_id=#{seller_id}&offset=#{offset}")
37
- else
38
- URI("https://api.mercadolibre.com/sites/#{site_code}/search?seller_id=#{seller_id}")
39
- end
36
+ return URI("#{sites_api_url}/#{site_code}/search?seller_id=#{seller_id}") unless offset.positive?
37
+
38
+ URI("#{sites_api_url}/#{site_code}/search?seller_id=#{seller_id}&offset=#{offset}")
39
+ end
40
+
41
+ def sites_api_url
42
+ 'https://api.mercadolibre.com/sites'
40
43
  end
41
44
  end
42
45
  end
@@ -1,3 +1,3 @@
1
1
  module MercadolibreApi
2
- VERSION = '0.1'.freeze
2
+ VERSION = '0.2'.freeze
3
3
  end
@@ -24,6 +24,9 @@ Gem::Specification.new do |gem|
24
24
  gem.add_dependency 'active_interaction', '~> 3.6'
25
25
 
26
26
  gem.add_development_dependency 'bundler', '~> 1.16'
27
+ gem.add_development_dependency 'byebug', '~> 10.0'
28
+ gem.add_development_dependency 'grape-entity', '~> 0.7.1'
29
+ gem.add_development_dependency 'oga', '~> 2.15'
27
30
  gem.add_development_dependency 'rake', '~> 12.3'
28
31
  gem.add_development_dependency 'rspec', '~> 3.8'
29
32
  gem.add_development_dependency 'rubocop', '~> 0.59'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mercadolibre_api
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Gonzaga
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-27 00:00:00.000000000 Z
11
+ date: 2018-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_interaction
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: grape-entity
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.7.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.7.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: oga
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.15'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.15'
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: rake
43
85
  requirement: !ruby/object:Gem::Requirement
@@ -129,6 +171,11 @@ files:
129
171
  - bin/console
130
172
  - bin/setup
131
173
  - lib/mercadolibre_api.rb
174
+ - lib/mercadolibre_api/products/descriptions/queries/find.rb
175
+ - lib/mercadolibre_api/products/entities/picture.rb
176
+ - lib/mercadolibre_api/products/entities/product.rb
177
+ - lib/mercadolibre_api/products/queries/find.rb
178
+ - lib/mercadolibre_api/products/queries/sold_quantity.rb
132
179
  - lib/mercadolibre_api/sellers/products/queries/most_sold.rb
133
180
  - lib/mercadolibre_api/version.rb
134
181
  - mercadolibre_api.gemspec