market_hub 0.1.0 → 0.23.5
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/CHANGELOG.md +145 -1
- data/lib/market_hub/api/base.rb +25 -0
- data/lib/market_hub/api/mercado_livre/authorization.rb +30 -0
- data/lib/market_hub/api/mercado_livre/catalog.rb +48 -0
- data/lib/market_hub/api/mercado_livre/category.rb +76 -0
- data/lib/market_hub/api/mercado_livre/client.rb +59 -0
- data/lib/market_hub/api/mercado_livre/description.rb +44 -0
- data/lib/market_hub/api/mercado_livre/image.rb +43 -0
- data/lib/market_hub/api/mercado_livre/invoice.rb +93 -0
- data/lib/market_hub/api/mercado_livre/item.rb +63 -0
- data/lib/market_hub/api/mercado_livre/order.rb +68 -0
- data/lib/market_hub/api/mercado_livre/publication_type.rb +75 -0
- data/lib/market_hub/api/mercado_livre/question_answer.rb +64 -0
- data/lib/market_hub/api/mercado_livre/shipment.rb +48 -0
- data/lib/market_hub/api/mercado_livre/user.rb +34 -0
- data/lib/market_hub/api/mercado_livre/variation.rb +59 -0
- data/lib/market_hub/base.rb +11 -0
- data/lib/market_hub/client.rb +11 -0
- data/lib/market_hub/configuration.rb +29 -0
- data/lib/market_hub/exception.rb +11 -0
- data/lib/market_hub/models/base.rb +60 -0
- data/lib/market_hub/models/mercado_livre/item.rb +139 -0
- data/lib/market_hub/models/mercado_livre/variation.rb +95 -0
- data/lib/market_hub/utils/error.rb +78 -0
- data/lib/market_hub/utils/http.rb +55 -0
- data/lib/market_hub/utils/o_auth_20.rb +41 -0
- data/lib/market_hub/utils/validation.rb +206 -0
- data/lib/market_hub/version.rb +1 -1
- data/lib/market_hub.rb +48 -3
- metadata +28 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1760a6a9c3ae4ecec00019f4f8da4e5999c854120f43f57fda69ea2d5eba6196
|
4
|
+
data.tar.gz: b1c739c5a8a1a4dabf1cda7102dfd1fb32c4773cdac0a450b5e159922de2d1ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: deceb080b25318b1c3e7c640c039a7b88483d6b6cbf4d2c3242af76ac87069480c1cc4af3f253bc00aab40e8dffe9262a7cb8c11dfca74ae3cd742684fc131d1
|
7
|
+
data.tar.gz: d728cdd1c25025d5cbe320dbe98cb4aecb4933d14dc2fe8950fe34d2450887eedad8c9dd8e41f52477ce2d4d66e34d62083c0c62d394064253e9ea4f1281fc69
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,148 @@
|
|
1
|
-
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
## [0.23.5] - 2024-03-19
|
4
|
+
|
5
|
+
- Fix find with merge in Variation Model
|
6
|
+
|
7
|
+
## [0.23.4] - 2024-03-15
|
8
|
+
|
9
|
+
- Fix assign channel to variable in Item Model
|
10
|
+
|
11
|
+
## [0.23.3] - 2024-03-15
|
12
|
+
|
13
|
+
- Fix assign id to variable in Item Model
|
14
|
+
|
15
|
+
## [0.23.2] - 2024-03-15
|
16
|
+
|
17
|
+
- Fix check new? method in Base Model
|
18
|
+
|
19
|
+
## [0.23.1] - 2024-03-14
|
20
|
+
|
21
|
+
- Fix nomenclature in Item Model (MercadoLivre)
|
22
|
+
|
23
|
+
## [0.23.0] - 2024-03-14
|
24
|
+
|
25
|
+
- Add Item Model to MercadoLivre
|
26
|
+
- Add Variation Model to MercadoLivre
|
27
|
+
- Fix item_id argument in variation class API
|
28
|
+
|
29
|
+
## [0.22.0] - 2024-03-12
|
30
|
+
|
31
|
+
- Add domain method in category module
|
32
|
+
|
33
|
+
## [0.21.0] - 2024-03-11
|
34
|
+
|
35
|
+
- Add billing_info method in order module
|
36
|
+
|
37
|
+
## [0.20.0] - 2024-01-30
|
38
|
+
|
39
|
+
- Add find, create, update and errors to MercadoLivre::Invoice
|
40
|
+
- Add billing_info type to MercadoLivre::Shipment
|
41
|
+
- Add invoice objects to MercadoLivre::Client
|
42
|
+
- Fix content type application/xml in HTTP module
|
43
|
+
|
44
|
+
## [0.19.0] - 2024-01-29
|
45
|
+
|
46
|
+
- Add find and labels to MercadoLivre::Shipment
|
47
|
+
- Add order and shipment objects to MercadoLivre::Client
|
48
|
+
|
49
|
+
## [0.18.0] - 2024-01-29
|
50
|
+
|
51
|
+
- Add all, recent, find and notes to MercadoLivre::Order
|
52
|
+
|
53
|
+
## [0.17.0] - 2024-01-29
|
54
|
+
|
55
|
+
- Change attributes method with new tag argument
|
56
|
+
- Add validation and Error class to Models
|
57
|
+
- Add news methods to MercadoLivre::Client
|
58
|
+
- Add base code to Base class (API and Model)
|
59
|
+
|
60
|
+
## [0.16.0] - 2024-01-25
|
61
|
+
|
62
|
+
- Add metrics, all, find, anwser and destroy to MercadoLivre::QuestionAnswer
|
63
|
+
|
64
|
+
## [0.15.0] - 2024-01-24
|
65
|
+
|
66
|
+
- Add all, find, create, update and destroy to MercadoLivre::Variation
|
67
|
+
- Add delete verb to HTTP module
|
68
|
+
|
69
|
+
## [0.14.1] - 2024-01-24
|
70
|
+
|
71
|
+
- Remove excess space
|
72
|
+
- Add optional header argument in the HTTP module
|
73
|
+
- Change attributes in MarketHub::Configuration
|
74
|
+
|
75
|
+
## [0.14.0] - 2024-01-23
|
76
|
+
|
77
|
+
- Add all, find and optin to MercadoLivre::Catalog
|
78
|
+
|
79
|
+
## [0.13.0] - 2024-01-23
|
80
|
+
|
81
|
+
- Add me and currency to MercadoLivre::User
|
82
|
+
- Fix destroy method in MercadoLivre::Item
|
83
|
+
|
84
|
+
## [0.12.2] - 2024-01-22
|
85
|
+
|
86
|
+
- Add currency_id in MarketHub::Configuration
|
87
|
+
|
88
|
+
## [0.12.1] - 2024-01-22
|
89
|
+
|
90
|
+
- Add layout Meli Item and change Meli Token Test
|
91
|
+
|
92
|
+
## [0.12.0] - 2024-01-22
|
93
|
+
|
94
|
+
- Add upload, add and change to MercadoLivre::Image
|
95
|
+
- Change HTTP module to support file upload
|
96
|
+
|
97
|
+
## [0.11.0] - 2024-01-21
|
98
|
+
|
99
|
+
- Add find, create and update to MercadoLivre::Description
|
100
|
+
|
101
|
+
## [0.10.0] - 2024-01-21
|
102
|
+
|
103
|
+
- Change tests with global token variables
|
104
|
+
- Add sale_terms to MercadoLivre::Category
|
105
|
+
- Add all, find, find_by_sku, create, update and destroy to MercadoLivre::Item
|
106
|
+
- Add post_form and put to HTTP module
|
107
|
+
- Change HTTP module to simplify code patters
|
108
|
+
|
109
|
+
## [0.9.0] - 2024-01-18
|
110
|
+
|
111
|
+
- Add HTTP module to simplify HTTP requests
|
112
|
+
- Change all files that were using Net::HTTP
|
113
|
+
|
114
|
+
## [0.8.0] - 2024-01-18
|
115
|
+
|
116
|
+
- Add listing_types_availables, listing_types_downgrades, listing_types_upgrades and update in MercadoLivre::PublicationType
|
117
|
+
|
118
|
+
## [0.7.0] - 2024-01-18
|
119
|
+
|
120
|
+
- Add listing_types and listing_exposures methods in MercadoLivre::PublicationType
|
121
|
+
|
122
|
+
## [0.6.1] - 2024-01-18
|
123
|
+
|
124
|
+
- Fix test_o_auth_20 file
|
125
|
+
|
126
|
+
## [0.6.0] - 2024-01-18
|
127
|
+
|
128
|
+
- Add site, find and attributes methods in MercadoLivre::Category
|
129
|
+
|
130
|
+
## [0.5.0] - 2024-01-18
|
131
|
+
|
132
|
+
- Add predict_category in MercadoLivre::Category
|
133
|
+
|
134
|
+
## [0.4.0] - 2024-01-18
|
135
|
+
|
136
|
+
- Add MercadoLivre::Authorization with OAuth 2.0
|
137
|
+
- Change Utils::OAuth20 with new args and generic behavior
|
138
|
+
|
139
|
+
## [0.3.0] - 2024-01-18
|
140
|
+
|
141
|
+
- Organize library folders and classes
|
142
|
+
|
143
|
+
## [0.2.0] - 2024-01-12
|
144
|
+
|
145
|
+
- Add OAuth20 autentication method
|
2
146
|
|
3
147
|
## [0.1.0] - 2024-01-10
|
4
148
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MarketHub
|
4
|
+
module API
|
5
|
+
# Classe base para todas as integrações (API)
|
6
|
+
class Base < MarketHub::Base
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
end
|
10
|
+
|
11
|
+
def connected?
|
12
|
+
raise MarketHub::NotImplemented, 'Sobreescreva este método na classe referente ao marketplace que você esta criando'
|
13
|
+
end
|
14
|
+
|
15
|
+
def find(id)
|
16
|
+
raise MarketHub::NotImplemented, 'Sobreescreva este método na classe referente ao marketplace que você esta criando'
|
17
|
+
end
|
18
|
+
|
19
|
+
def quantity(id, available_quantity)
|
20
|
+
raise MarketHub::NotImplemented, 'Sobreescreva este método na classe referente ao marketplace que você esta criando'
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MarketHub
|
4
|
+
module API
|
5
|
+
module MercadoLivre
|
6
|
+
# Classe para integrar/autenticar com o Mercado Livre
|
7
|
+
class Authorization
|
8
|
+
|
9
|
+
def initialize( client_id = MarketHub.configure.meli_client_id,
|
10
|
+
client_secret = MarketHub.configure.meli_client_secret,
|
11
|
+
redirect_uri = MarketHub.configure.meli_redirect_uri)
|
12
|
+
@oauth20 = MarketHub::OAuth20.new(client_id, client_secret, redirect_uri)
|
13
|
+
end
|
14
|
+
|
15
|
+
def authorize_url(state = nil)
|
16
|
+
@oauth20.authorize_url(MarketHub.configure.meli_auth_uri, '/authorization', state)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_token(code)
|
20
|
+
@oauth20.get_token(MarketHub.configure.meli_api_uri, '/oauth/token', code)
|
21
|
+
end
|
22
|
+
|
23
|
+
def renew_token(refresh_token)
|
24
|
+
@oauth20.renew_token(MarketHub.configure.meli_api_uri, '/oauth/token', refresh_token)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MarketHub
|
4
|
+
module API
|
5
|
+
module MercadoLivre
|
6
|
+
# Classe API de Catálogo
|
7
|
+
class Catalog
|
8
|
+
|
9
|
+
attr_accessor :access_token
|
10
|
+
|
11
|
+
def initialize(access_token)
|
12
|
+
@access_token = access_token
|
13
|
+
end
|
14
|
+
|
15
|
+
def all(site_id, q, domain_id = nil, status = 'active', options = {})
|
16
|
+
host = MarketHub.configure.meli_api_uri
|
17
|
+
path = "/products/search"
|
18
|
+
params = { site_id: site_id, q: q }.merge(options)
|
19
|
+
params.merge!({ domain_id: domain_id }) if domain_id
|
20
|
+
params.merge!({ status: status }) if status
|
21
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
22
|
+
endpoint.query = URI.encode_www_form(params)
|
23
|
+
response = MarketHub::HTTP.get(endpoint, headers: { authorization: "Bearer #{@access_token}" })
|
24
|
+
JSON.parse(response.body)
|
25
|
+
end
|
26
|
+
|
27
|
+
def find(catalog_product_id)
|
28
|
+
host = MarketHub.configure.meli_api_uri
|
29
|
+
path = "/products/#{catalog_product_id}"
|
30
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
31
|
+
response = MarketHub::HTTP.get(endpoint, headers: { authorization: "Bearer #{@access_token}" })
|
32
|
+
JSON.parse(response.body)
|
33
|
+
end
|
34
|
+
|
35
|
+
def optin(item_id, catalog_product_id, variation_id = nil)
|
36
|
+
host = MarketHub.configure.meli_api_uri
|
37
|
+
path = "/items/catalog_listings"
|
38
|
+
body = { item_id: item_id, catalog_product_id: catalog_product_id }
|
39
|
+
body[:variation_id] = variation_id if variation_id
|
40
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
41
|
+
response = MarketHub::HTTP.post(endpoint, headers: { authorization: "Bearer #{@access_token}" }, body: body)
|
42
|
+
JSON.parse(response.body)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MarketHub
|
4
|
+
module API
|
5
|
+
module MercadoLivre
|
6
|
+
# Classe API de Categoria
|
7
|
+
class Category
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
end
|
11
|
+
|
12
|
+
def predict(site_id, q, options = {})
|
13
|
+
host = MarketHub.configure.meli_api_uri
|
14
|
+
path = "/sites/#{site_id}/domain_discovery/search"
|
15
|
+
params = { q: q }.merge(options)
|
16
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
17
|
+
endpoint.query = URI.encode_www_form(params)
|
18
|
+
response = MarketHub::HTTP.get(endpoint)
|
19
|
+
JSON.parse(response.body)
|
20
|
+
end
|
21
|
+
|
22
|
+
def site(site_id)
|
23
|
+
host = MarketHub.configure.meli_api_uri
|
24
|
+
path = "/sites/#{site_id}/categories"
|
25
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
26
|
+
response = MarketHub::HTTP.get(endpoint)
|
27
|
+
JSON.parse(response.body)
|
28
|
+
end
|
29
|
+
|
30
|
+
def find(category_id)
|
31
|
+
host = MarketHub.configure.meli_api_uri
|
32
|
+
path = "/categories/#{category_id}"
|
33
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
34
|
+
response = MarketHub::HTTP.get(endpoint)
|
35
|
+
JSON.parse(response.body)
|
36
|
+
end
|
37
|
+
|
38
|
+
def domain(domain_id)
|
39
|
+
host = MarketHub.configure.meli_api_uri
|
40
|
+
path = "/catalog_domains/#{domain_id}"
|
41
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
42
|
+
response = MarketHub::HTTP.get(endpoint)
|
43
|
+
JSON.parse(response.body)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Principais tags existentes: required, catalog_required, allow_variations e variation_attribute
|
47
|
+
# @category.attributes('MLB40411') => Retorna todos os atributos
|
48
|
+
# @category.attributes('MLB40411', { required: true }) => Retorna todos os atributos primários obrigatórios
|
49
|
+
# @category.attributes('MLB40411', { allow_variations: true }) => Retorna todos os atributos primários obrigatórios
|
50
|
+
# @category.attributes('MLB40411', { variation_attribute: true }) => Retorna todos os atributos secundários de variação
|
51
|
+
def attributes(category_id, tags = {})
|
52
|
+
host = MarketHub.configure.meli_api_uri
|
53
|
+
path = "/categories/#{category_id}/attributes"
|
54
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
55
|
+
response = MarketHub::HTTP.get(endpoint)
|
56
|
+
json = JSON.parse(response.body)
|
57
|
+
if json.is_a?(Array)
|
58
|
+
tags.each do |tag, value|
|
59
|
+
json = json.select { |attribute| attribute['tags'][tag.to_s] == value }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
json
|
63
|
+
end
|
64
|
+
|
65
|
+
def sale_terms(category_id)
|
66
|
+
host = MarketHub.configure.meli_api_uri
|
67
|
+
path = "/categories/#{category_id}/sale_terms"
|
68
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
69
|
+
response = MarketHub::HTTP.get(endpoint)
|
70
|
+
JSON.parse(response.body)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MarketHub
|
4
|
+
module API
|
5
|
+
module MercadoLivre
|
6
|
+
# Principal classe para integração com Mercado Livre
|
7
|
+
class Client < MarketHub::API::Base
|
8
|
+
|
9
|
+
attr_reader :user
|
10
|
+
attr_reader :me
|
11
|
+
attr_reader :currency
|
12
|
+
attr_reader :catalog
|
13
|
+
attr_reader :category
|
14
|
+
attr_reader :variation
|
15
|
+
attr_reader :description
|
16
|
+
attr_reader :image
|
17
|
+
attr_reader :invoice
|
18
|
+
attr_reader :item
|
19
|
+
attr_reader :order
|
20
|
+
attr_reader :publication_type
|
21
|
+
attr_reader :question_answer
|
22
|
+
attr_reader :shipment
|
23
|
+
|
24
|
+
def initialize(access_token)
|
25
|
+
@user = MarketHub::API::MercadoLivre::User.new(access_token)
|
26
|
+
@me = @user.me
|
27
|
+
|
28
|
+
if connected?
|
29
|
+
@currency = @user.currency['currency_id']
|
30
|
+
@catalog = MarketHub::API::MercadoLivre::Catalog.new(access_token)
|
31
|
+
@category = MarketHub::API::MercadoLivre::Category.new
|
32
|
+
@variation = MarketHub::API::MercadoLivre::Variation.new(access_token)
|
33
|
+
@description = MarketHub::API::MercadoLivre::Description.new(access_token)
|
34
|
+
@image = MarketHub::API::MercadoLivre::Image.new(access_token)
|
35
|
+
@invoice = MarketHub::API::MercadoLivre::Invoice.new(access_token, @me['site_id'])
|
36
|
+
@item = MarketHub::API::MercadoLivre::Item.new(access_token, @me['id'])
|
37
|
+
@order = MarketHub::API::MercadoLivre::Order.new(access_token, @me['id'])
|
38
|
+
@publication_type = MarketHub::API::MercadoLivre::PublicationType.new(access_token)
|
39
|
+
@question_answer = MarketHub::API::MercadoLivre::QuestionAnswer.new(access_token, @me['id'])
|
40
|
+
@shipment = MarketHub::API::MercadoLivre::Shipment.new(access_token)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def connected?
|
45
|
+
@me['id'] ? true : false
|
46
|
+
end
|
47
|
+
|
48
|
+
def find(id)
|
49
|
+
@item.find(id) if connected?
|
50
|
+
end
|
51
|
+
|
52
|
+
def quantity(id, available_quantity)
|
53
|
+
@item.update(id, { available_quantity: available_quantity })
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MarketHub
|
4
|
+
module API
|
5
|
+
module MercadoLivre
|
6
|
+
# Classe API de Descrição de Produto
|
7
|
+
class Description
|
8
|
+
|
9
|
+
attr_accessor :access_token
|
10
|
+
|
11
|
+
def initialize(access_token)
|
12
|
+
@access_token = access_token
|
13
|
+
end
|
14
|
+
|
15
|
+
def find(item_id)
|
16
|
+
host = MarketHub.configure.meli_api_uri
|
17
|
+
path = "/items/#{item_id}/description"
|
18
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
19
|
+
response = MarketHub::HTTP.get(endpoint, headers: { authorization: "Bearer #{@access_token}" })
|
20
|
+
JSON.parse(response.body)
|
21
|
+
end
|
22
|
+
|
23
|
+
def create(item_id, description)
|
24
|
+
host = MarketHub.configure.meli_api_uri
|
25
|
+
path = "/items/#{item_id}/description"
|
26
|
+
body = { plain_text: description }
|
27
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
28
|
+
response = MarketHub::HTTP.post(endpoint, headers: { authorization: "Bearer #{@access_token}" }, body: body)
|
29
|
+
JSON.parse(response.body)
|
30
|
+
end
|
31
|
+
|
32
|
+
def update(item_id, description)
|
33
|
+
host = MarketHub.configure.meli_api_uri
|
34
|
+
path = "/items/#{item_id}/description"
|
35
|
+
body = { plain_text: description }
|
36
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
37
|
+
response = MarketHub::HTTP.put(endpoint, headers: { authorization: "Bearer #{@access_token}" }, body: body)
|
38
|
+
JSON.parse(response.body)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MarketHub
|
4
|
+
module API
|
5
|
+
module MercadoLivre
|
6
|
+
# Classe API de Imagem
|
7
|
+
class Image
|
8
|
+
|
9
|
+
attr_accessor :access_token
|
10
|
+
|
11
|
+
def initialize(access_token)
|
12
|
+
@access_token = access_token
|
13
|
+
end
|
14
|
+
|
15
|
+
def upload(file)
|
16
|
+
host = MarketHub.configure.meli_api_uri
|
17
|
+
path = "/pictures/items/upload"
|
18
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
19
|
+
response = MarketHub::HTTP.post_form(endpoint, headers: { authorization: "Bearer #{@access_token}" }, body: nil, files: [ file ])
|
20
|
+
JSON.parse(response.body)
|
21
|
+
end
|
22
|
+
|
23
|
+
def add(item_id, image_id)
|
24
|
+
host = MarketHub.configure.meli_api_uri
|
25
|
+
path = "/items/#{item_id}/pictures"
|
26
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
27
|
+
response = MarketHub::HTTP.post(endpoint, headers: { authorization: "Bearer #{@access_token}" }, body: { id: image_id })
|
28
|
+
JSON.parse(response.body)
|
29
|
+
end
|
30
|
+
|
31
|
+
def change(item_id, images)
|
32
|
+
host = MarketHub.configure.meli_api_uri
|
33
|
+
path = "/items/#{item_id}"
|
34
|
+
body = { pictures: images.map { |image_id| { id: image_id } } }
|
35
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
36
|
+
response = MarketHub::HTTP.put(endpoint, headers: { authorization: "Bearer #{@access_token}" }, body: body)
|
37
|
+
JSON.parse(response.body)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MarketHub
|
4
|
+
module API
|
5
|
+
module MercadoLivre
|
6
|
+
# Classe API de Nota Fiscal de Produto
|
7
|
+
class Invoice
|
8
|
+
|
9
|
+
attr_accessor :access_token
|
10
|
+
attr_accessor :site_id
|
11
|
+
|
12
|
+
def initialize(access_token, site_id)
|
13
|
+
@access_token = access_token
|
14
|
+
@site_id = site_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def find(shipment_id)
|
18
|
+
host = MarketHub.configure.meli_api_uri
|
19
|
+
path = "/shipments/#{shipment_id}/invoice_data"
|
20
|
+
params = { siteId: @site_id }
|
21
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
22
|
+
endpoint.query = URI.encode_www_form(params)
|
23
|
+
response = MarketHub::HTTP.get(endpoint, headers: { authorization: "Bearer #{@access_token}" })
|
24
|
+
try_to_convert_to_json(response.body)
|
25
|
+
end
|
26
|
+
|
27
|
+
def create(shipment_id, invoice_data)
|
28
|
+
host = MarketHub.configure.meli_api_uri
|
29
|
+
path = "/shipments/#{shipment_id}/invoice_data"
|
30
|
+
params = { siteId: @site_id }
|
31
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
32
|
+
endpoint.query = URI.encode_www_form(params)
|
33
|
+
response = MarketHub::HTTP.post(endpoint, headers: { authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/xml' }, body: invoice_data)
|
34
|
+
JSON.parse(response.body)
|
35
|
+
end
|
36
|
+
|
37
|
+
def update(shipment_id, invoice_data)
|
38
|
+
host = MarketHub.configure.meli_api_uri
|
39
|
+
path = "/shipments/#{shipment_id}/invoice_data"
|
40
|
+
params = { siteId: @site_id }
|
41
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
42
|
+
endpoint.query = URI.encode_www_form(params)
|
43
|
+
response = MarketHub::HTTP.put(endpoint, headers: { authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/xml' }, body: invoice_data)
|
44
|
+
JSON.parse(response.body)
|
45
|
+
end
|
46
|
+
|
47
|
+
def errors
|
48
|
+
{
|
49
|
+
shipment_invoice_already_saved: { message: 'Já existe uma nota fiscal salva para o envio informado.', hit: 'Para que a nota fiscal possa ser salva, o envio necessita estar no substatus de invoice_pending, para verificar se o envio se encontra nesse substatus, consulte /shipments/{shipment_id}, ou consulte se já não foi salva a nota fiscal para o envio informado através do endpoint /shipments/{id}/invoice_data.' },
|
50
|
+
duplicated_fiscal_key: { message: 'Já existe uma nota fiscal salva com a chave fiscal informada.', hit: 'O número de chave fiscal da nota precisa ser único.' },
|
51
|
+
wrong_invoice_date: { message: 'A data informada na nota fiscal é inválida.', hit: 'Verifique a data informada.' },
|
52
|
+
wrong_sender_zipcode: { message: 'O CEP do vendedor informado na nota fiscal é inválido ou nulo.', hit: 'Verifique o CEP do vendedor informado.' },
|
53
|
+
wrong_receiver_zipcode: { message: 'O CEP do comprador informado na nota fiscal é inválido ou nulo.', hit: 'Verifique o CEP do comprador informado.' },
|
54
|
+
wrong_receiver_cnpj: { message: 'O CNPJ do comprador informado na nota fiscal é inválido ou nulo.', hit: 'Verifique o CNPJ do comprador informado.' },
|
55
|
+
wrong_receiver_cpf: { message: 'O CPF do comprador informado na nota fiscal é inválido ou nulo.', hit: 'Verifique o CPF do comprador informado.' },
|
56
|
+
wrong_receiver_state_tax: { message: 'A Inscrição Estadual do comprador informada na nota fiscal é inválida ou nula.', hit: 'Verifique a Inscrição Estadual do comprador informada.' },
|
57
|
+
invalid_user: { message: 'Você não tem permissão para realizar operações no envio informado.', hit: 'Verifique o número de envio informado e se você tem permissões sobre ele.' },
|
58
|
+
seller_not_allowed_to_import_nfe: { message: 'Você não tem permissão para realizar a importação de NF-e', hit: 'Verifique se você tem permissão para importar notas fiscais ou use nosso emissor de notas fiscais.' },
|
59
|
+
shipment_invoice_should_contain_company_state_tax_id: { message: 'A Inscrição Estadual do comprador não foi informada na nota fiscal.', hit: 'Verifique a Inscrição Estadual do comprador informada.' },
|
60
|
+
invalid_state_tax_id: { message: 'A Inscrição Estadual do comprador informada na nota fiscal é inválida ou nula.', hit: 'Verifique a Inscrição Estadual do comprador informada.' },
|
61
|
+
invalid_operation_for_site_id: { message: 'Operação inválida para a região informada.', hit: 'Só é permitida a execução de operações para o site MLB.' },
|
62
|
+
error_parse_invoice_data: { message: 'Erro ao converter dados da nota fiscal para json.', hit: 'Verifique se a nota fiscal foi informada de forma correta.' },
|
63
|
+
invalid_parameter: { message: 'A nota fiscal informada não contém o número de identificação.', hit: 'Verifique o número de identificação na nota fiscal informada.' },
|
64
|
+
invalid_caller_id: { message: 'Caller Id informado é inválido ou não foi informado.', hit: 'Verifique se o Caller Id esta sendo informado ao realizar o request.' },
|
65
|
+
sender_ie_not_found: { message: 'O cnpj do vendedor não está cadastrado na Sefaz como contribuinte ou está bloqueado.', hit: 'Não é possível informar a NF-e porque seus dados cadastrados no Mercado Livre são diferentes dos que você tem cadastrados na SEFAZ. Revise o CNPJ, a Inscrição Estadual (IE) e o estado (UF). Corrija as informações do seu cadastro no Mercado Livre e tente novamente.' },
|
66
|
+
invalid_sender_ie_for_state: { message: 'A inscrição estadual do vendedor é inválida para o estado cadastrado.', hit: 'Não é possível informar a NF-e porque seu dado de IE cadastrado no Mercado Livre está incorreto para o estado cadastrado no endereço. Revise o CNPJ, a Inscrição Estadual (IE) e o estado (UF). Corrija as informações do seu cadastro no Mercado Livre e tente novamente.' },
|
67
|
+
invalid_sender_ie: { message: 'A inscrição estadual do vendedor é diferente da cadastrada junto à Sefaz.', hit: 'Não é possível informar a NF-e porque seus dados cadastrados no Mercado Livre são diferentes dos que você tem cadastrados na SEFAZ. Revise a Inscrição Estadual (IE). Corrija as informações do seu cadastro no Mercado Livre e tente novamente' },
|
68
|
+
invalid_sender_cnpj: { message: 'O CNPJ do vendedor é diferente do cadastrado junto à Sefaz.', hit: 'Não é possível informar a NF-e porque seus dados cadastrados no Mercado Livre são diferentes dos que você tem cadastrados na SEFAZ. Revise o CNPJ. Corrija as informações do seu cadastro no Mercado Livre, e tente novamente.' },
|
69
|
+
different_state_nfe_shipment_origin: { message: 'A UF da nota é diferente do estado de origem do envio.', hit: 'Não é possível informar a NF-e porque a UF do XML da nota é diferente da UF onde o envio foi gerado. Corrija as informações do XML e tente novamente.' },
|
70
|
+
nfe_order_value_divergence: { message: 'O valor da nota fiscal diverge do valor total dos itens do pedido.', hit: 'O valor da NF-e é diferente do valor da venda. Confira os valores preenchidos como preço, descontos e frete e emita uma nova nota com o valor corrigido' },
|
71
|
+
wrong_invoice_type: { message: 'Nota fiscal de serviço ou contem valor de ISSQN', hit: 'Emita uma NF-e de venda para seus produtos. Notas fiscais de serviços não são aceitas no Mercado Livre.' },
|
72
|
+
unexpected_error_post_biller: { message: 'XML invalido ou com campos incorretos.', hit: 'Enviar XML no formato aprovado pelo emissor de nota fiscal e validado pelo governo.' },
|
73
|
+
shipment_already_being_processed: { message: 'Foi enviada mais de uma requisição ao mesmo tempo,', hit: 'Aguardar o processamento da primeira requisição.' },
|
74
|
+
batch_nfe_not_supported: { message: 'Não é possível informar nota fiscal com formato em lote', hit: 'Enviar XML de uma nota fiscal individual' },
|
75
|
+
nfe_layout_not_supported: { message: 'Não é possível informar nota fiscal com esse formato', hit: 'Enviar XML de uma nota fiscal no formato aprovado pelo emissor fiscal e validado pelo governo do seu estado, seguindo a estrutura correta do XML com as tags: , ,' },
|
76
|
+
nf_already_generated: { message: 'Já existe uma NFe emitida pelo faturador.', hit: 'Verifique o status da NFe. Caso a NFe esteja anulada ou inutilizada, emitir novamente pelo faturador.' },
|
77
|
+
internal_error: { message: 'Houve um erro interno', hit: 'Aguarde e tente novamente.' },
|
78
|
+
invalid_shipment: { message: 'O shipment se encontra em um status em que a importação da NF-e não é aceita', hit: 'Verifique o status do shipment antes de enviar a NF-e.' }
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def try_to_convert_to_json(body)
|
85
|
+
JSON.parse(body)
|
86
|
+
rescue
|
87
|
+
body
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MarketHub
|
4
|
+
module API
|
5
|
+
module MercadoLivre
|
6
|
+
# Classe API de Produtos
|
7
|
+
class Item
|
8
|
+
|
9
|
+
attr_accessor :access_token
|
10
|
+
attr_accessor :user_id
|
11
|
+
|
12
|
+
def initialize(access_token, user_id)
|
13
|
+
@access_token = access_token
|
14
|
+
@user_id = user_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def all(params = {})
|
18
|
+
host = MarketHub.configure.meli_api_uri
|
19
|
+
path = "/users/#{@user_id}/items/search"
|
20
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
21
|
+
endpoint.query = URI.encode_www_form(params)
|
22
|
+
response = MarketHub::HTTP.get(endpoint, headers: { authorization: "Bearer #{@access_token}" })
|
23
|
+
JSON.parse(response.body)
|
24
|
+
end
|
25
|
+
|
26
|
+
def find(item_id)
|
27
|
+
host = MarketHub.configure.meli_api_uri
|
28
|
+
path = "/items/#{item_id}"
|
29
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
30
|
+
response = MarketHub::HTTP.get(endpoint, headers: { authorization: "Bearer #{@access_token}" })
|
31
|
+
JSON.parse(response.body)
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_by_sku(seller_sku)
|
35
|
+
item_ids = all({ seller_sku: seller_sku }).dig('results')
|
36
|
+
item_ids.map { |item_id| find(item_id) } if item_ids
|
37
|
+
end
|
38
|
+
|
39
|
+
def create(body)
|
40
|
+
host = MarketHub.configure.meli_api_uri
|
41
|
+
path = '/items'
|
42
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
43
|
+
response = MarketHub::HTTP.post(endpoint, headers: { authorization: "Bearer #{@access_token}" }, body: body)
|
44
|
+
JSON.parse(response.body)
|
45
|
+
end
|
46
|
+
|
47
|
+
def update(item_id, body)
|
48
|
+
host = MarketHub.configure.meli_api_uri
|
49
|
+
path = "/items/#{item_id}"
|
50
|
+
endpoint = URI::HTTPS.build(host: host, path: path)
|
51
|
+
response = MarketHub::HTTP.put(endpoint, headers: { authorization: "Bearer #{@access_token}" }, body: body)
|
52
|
+
JSON.parse(response.body)
|
53
|
+
end
|
54
|
+
|
55
|
+
def destroy(item_id)
|
56
|
+
update(item_id, { status: "closed" })
|
57
|
+
update(item_id, { deleted: true })
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|