mercadolibre_api 0.2 → 0.3

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: a1ae34b484b9b1281810fd78c1b39e3890ef42de1035ef3dc0a1981792ef5046
4
- data.tar.gz: c84a2db6daf5fa0303abdbd2b0faf89c7fd5f84a5deef651ead3b118d3cd67cb
3
+ metadata.gz: fe63e2e14d42068d0b573d5513c14f05cd8a398f5f8f692c1b069ce589e57fc6
4
+ data.tar.gz: e8782119fe722381ff997169c82c59b11066318c2c39f725dd349cc05b808c31
5
5
  SHA512:
6
- metadata.gz: 9f37b8bcc74dc1ba61afd1ac64f867515cd980a54fe8bcda365e8b1bb8b34c36effeb257c14917d2d444e12aa93c5afe4732168e3832bc6112e8f4029a855221
7
- data.tar.gz: 431fadb67ec2d267abc19e99abfd015bdb5d9d28bd4cb83eac717e5a5fa7981c608bc85a7826bec5e1f3d8b924077f79b76b2dffadbe05296f8c03ba50596d8b
6
+ metadata.gz: 9e652be3b93516c8d4c9b0f3a2132263f80af972e11bb40d3fd577cd94486f7e63323949340eaa556f36cfdffe84f49256246c4f3d730c75e06b268b608c3ca4
7
+ data.tar.gz: 13607616acb33146030783965d4ec8c35c8db2da030795aee7042541114cf41a0bcf84192a8996cb077ec27fd9c917b732feb5d93de731662caa697fd70addd9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mercadolibre_api (0.1)
4
+ mercadolibre_api (0.2)
5
5
  active_interaction (~> 3.6)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # MercadolibreApi
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mercadolibre_api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
3
  ## Installation
6
4
 
7
5
  Add this line to your application's Gemfile:
@@ -20,6 +18,14 @@ Or install it yourself as:
20
18
 
21
19
  ## Usage
22
20
 
21
+ ### Categories
22
+ #### Find by ID
23
+
24
+ ```
25
+ MercadolibreApi::Categories::Queries::Find.run!(category_id: 'MLU1246')
26
+ ```
27
+
28
+
23
29
  ### Products
24
30
  #### Find by ID
25
31
 
@@ -0,0 +1,14 @@
1
+ require 'grape-entity'
2
+
3
+ module MercadolibreApi
4
+ module Categories
5
+ module Entities
6
+ class Category < Grape::Entity
7
+ expose :id
8
+ expose :name
9
+ expose :path_from_root
10
+ expose :children_categories
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ require 'active_interaction'
2
+ require 'net/http'
3
+ require './lib/mercadolibre_api/categories/entities/category'
4
+
5
+ module MercadolibreApi
6
+ module Categories
7
+ module Queries
8
+ class Find < ActiveInteraction::Base
9
+ string :category_id
10
+
11
+ def execute
12
+ response = Net::HTTP.get_response(uri)
13
+ response_body = JSON.parse(response.body, symbolize_names: true)
14
+ MercadolibreApi::Categories::Entities::Category.represent(response_body).as_json
15
+ end
16
+
17
+ private
18
+
19
+ def uri
20
+ URI("https://api.mercadolibre.com/categories/#{category_id}")
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ require 'active_interaction'
2
+ require './lib/mercadolibre_api/sites/queries/get_code'
3
+
4
+ module MercadolibreApi
5
+ module Products
6
+ module Queries
7
+ class GetID < ActiveInteraction::Base
8
+ string :product_url
9
+
10
+ def execute
11
+ return unless product_code
12
+
13
+ "#{site_code}#{product_code}"
14
+ end
15
+
16
+ private
17
+
18
+ def site_code
19
+ @site_code ||= MercadolibreApi::Sites::Queries::GetCode.run!(product_url: product_url)
20
+ end
21
+
22
+ def product_code
23
+ code_matches = URI(product_url).path.match(/#{site_code}-(\d*)-/)
24
+ return unless code_matches
25
+
26
+ code_matches[1]
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,11 @@
1
+ json.product do
2
+ json.partial! 'api_web/partials/basic_product', product: @product
3
+
4
+ json.category do
5
+ json.partial! 'api_web/partials/full_category', category: @product.category
6
+ end
7
+
8
+ json.related_products @related_products do |related_product|
9
+ json.partial! 'api_web/partials/basic_product', product: related_product
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ require 'active_interaction'
2
+ require 'net/http'
3
+
4
+ module MercadolibreApi
5
+ module Sellers
6
+ module Queries
7
+ class GetID < ActiveInteraction::Base
8
+ integer :product_id
9
+ string :site_code
10
+
11
+ def execute
12
+ response = Net::HTTP.get_response(product_uri)
13
+ JSON.parse(response.body, symbolize_names: true).dig(:seller_id)
14
+ end
15
+
16
+ private
17
+
18
+ def product_uri
19
+ URI("https://api.mercadolibre.com/items/#{site_code}#{product_id}")
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,55 @@
1
+ require 'active_interaction'
2
+ require 'uri'
3
+
4
+ module MercadolibreApi
5
+ module Sites
6
+ module Queries
7
+ class GetCode < ActiveInteraction::Base
8
+ string :product_url
9
+
10
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
11
+ def execute
12
+ case URI(product_url).host
13
+ when 'articulo.mercadolibre.com.ar'
14
+ 'MLA'
15
+ when 'articulo.mercadolibre.com.bo'
16
+ 'MBO'
17
+ when 'produto.mercadolivre.com.br'
18
+ 'MLB'
19
+ when 'articulo.mercadolibre.cl'
20
+ 'MLC'
21
+ when 'articulo.mercadolibre.com.co'
22
+ 'MCO'
23
+ when 'articulo.mercadolibre.co.cr'
24
+ 'MCR'
25
+ when 'articulo.mercadolibre.com.do'
26
+ 'MRD'
27
+ when 'articulo.mercadolibre.com.ec'
28
+ 'MEC'
29
+ when 'articulo.mercadolibre.com.gt'
30
+ 'MGT'
31
+ when 'articulo.mercadolibre.com.hn'
32
+ 'MHN'
33
+ when 'articulo.mercadolibre.com.mx'
34
+ 'MLM'
35
+ when 'articulo.mercadolibre.com.ni'
36
+ 'MNI'
37
+ when 'articulo.mercadolibre.com.pa'
38
+ 'MPA'
39
+ when 'articulo.mercadolibre.com.py'
40
+ 'MPY'
41
+ when 'articulo.mercadolibre.com.pe'
42
+ 'MPE'
43
+ when 'articulo.mercadolibre.com.sv'
44
+ 'MSV'
45
+ when 'articulo.mercadolibre.com.uy'
46
+ 'MLU'
47
+ when 'articulo.mercadolibre.com.ve'
48
+ 'MLV'
49
+ end
50
+ end
51
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,3 +1,3 @@
1
1
  module MercadolibreApi
2
- VERSION = '0.2'.freeze
2
+ VERSION = '0.3'.freeze
3
3
  end
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.2'
4
+ version: '0.3'
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-28 00:00:00.000000000 Z
11
+ date: 2018-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_interaction
@@ -171,12 +171,18 @@ files:
171
171
  - bin/console
172
172
  - bin/setup
173
173
  - lib/mercadolibre_api.rb
174
+ - lib/mercadolibre_api/categories/entities/category.rb
175
+ - lib/mercadolibre_api/categories/queries/find.rb
174
176
  - lib/mercadolibre_api/products/descriptions/queries/find.rb
175
177
  - lib/mercadolibre_api/products/entities/picture.rb
176
178
  - lib/mercadolibre_api/products/entities/product.rb
177
179
  - lib/mercadolibre_api/products/queries/find.rb
180
+ - lib/mercadolibre_api/products/queries/get_id.rb
178
181
  - lib/mercadolibre_api/products/queries/sold_quantity.rb
182
+ - lib/mercadolibre_api/sellers/product.json.jbuilder
179
183
  - lib/mercadolibre_api/sellers/products/queries/most_sold.rb
184
+ - lib/mercadolibre_api/sellers/queries/get_id.rb
185
+ - lib/mercadolibre_api/sites/queries/get_code.rb
180
186
  - lib/mercadolibre_api/version.rb
181
187
  - mercadolibre_api.gemspec
182
188
  homepage: https://github.com/pgonzaga/mercadolibre_api_gem