mercadolibre 4.6.0 → 4.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0319c042c61737892354a4687fde0e7a9fece8381c289e2a2c3b69b5aef07a0f'
4
- data.tar.gz: 6eb9b2fb462a5f40561fe7c0c9a69bf3132d12d7430a1b142c0b2b804dce00fc
3
+ metadata.gz: a21c45766229a60b3ef28bc5425367c6c1b8f04a33b8811575df582fd673105d
4
+ data.tar.gz: 94d5622bf678185c699f3f9d98950d89dfba73cfea4bcc520ac952bf6303b79d
5
5
  SHA512:
6
- metadata.gz: '05965e87c3fd8d3e24b47ace43ef3cf0fe57e0729ddb6612ddff24c76e388c416f6ed9d071920e4c9421ed200f4c2dbbc116828af8e6ed56d24dfcf9124ec543'
7
- data.tar.gz: bca9852b354d401ddd977967017be22e1a65d42d52cb990a94ae5c06947c4253027334548012e58a819486a0acfa8b75f7c3d1daeb627a60f1951d07c607665a
6
+ metadata.gz: bfc42e8a76aa1caf50435fc9580515017b4df679a8530c3f4485ce7090fe925022656c4d11532346ec95335db81342a3e62d8cbe871085f91ac4e1c47505674b
7
+ data.tar.gz: ed781708c155494184f97fffc47e53af5d251d32a61e19411d7ba6d085874ec48e8da2196cca805936e006268394ee9c8ccbc80a14334e4c01edcffd55e6a69c
data/CHANGELOG.md CHANGED
@@ -348,4 +348,8 @@
348
348
 
349
349
  ## v4.6.0
350
350
 
351
- * Added method for availability to pickup store variations
351
+ * Added method for availability to pickup store variations
352
+
353
+ ## v4.7.0
354
+
355
+ * Added mercadoshops methods for orders
data/lib/mercadolibre.rb CHANGED
@@ -37,6 +37,10 @@ require "mercadopago/core/payments"
37
37
  # mercadopago -> api
38
38
  require "mercadopago/api"
39
39
 
40
+ # mercadoshops -> api
41
+ require "mercadoshops/api"
42
+ require "mercadoshops/core/orders"
43
+
40
44
  # dependencies
41
45
  require 'rest-client'
42
46
  require 'singleton'
@@ -1,3 +1,3 @@
1
1
  module Mercadolibre
2
- VERSION = '4.6.0'
2
+ VERSION = '4.7.0'
3
3
  end
@@ -0,0 +1,121 @@
1
+ module Mercadoshops
2
+ class Api
3
+ attr_accessor :access_token
4
+
5
+ def initialize(args={})
6
+ @access_token = args[:access_token]
7
+
8
+ if args[:endpoint_url].present?
9
+ @endpoint_url = args[:endpoint_url]
10
+ else
11
+ @endpoint_url = 'api.mercadoshops.com'
12
+ end
13
+ end
14
+
15
+ include Mercadoshops::Core::Orders
16
+
17
+ def get_last_response
18
+ @last_response
19
+ end
20
+
21
+ def get_last_result
22
+ @last_result
23
+ end
24
+
25
+ private
26
+
27
+ def get_request(action, params={}, headers={})
28
+ begin
29
+ api_response_kind = headers.delete('api_response_kind')
30
+ api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil?
31
+ api_response_kind = 'object' if api_response_kind.nil?
32
+
33
+ parse_response(api_response_kind, RestClient.get("#{@endpoint_url}#{action}", {params: params}.merge(headers)))
34
+ rescue => e
35
+ parse_response('object', e.response)
36
+ end
37
+ end
38
+
39
+ def post_request(action, params={}, headers={})
40
+ begin
41
+ api_response_kind = headers.delete('api_response_kind')
42
+ api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil?
43
+ api_response_kind = 'object' if api_response_kind.nil?
44
+
45
+ parse_response(api_response_kind, RestClient.post("#{@endpoint_url}#{action}", params, headers))
46
+ rescue => e
47
+ parse_response('object', e.response)
48
+ end
49
+ end
50
+
51
+ def put_request(action, params={}, headers={})
52
+ begin
53
+ api_response_kind = headers.delete('api_response_kind')
54
+ api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil?
55
+ api_response_kind = 'object' if api_response_kind.nil?
56
+
57
+ parse_response(api_response_kind, RestClient.put("#{@endpoint_url}#{action}", params, headers))
58
+ rescue => e
59
+ parse_response('object', e.response)
60
+ end
61
+ end
62
+
63
+ def patch_request(action, params={}, headers={})
64
+ begin
65
+ api_response_kind = headers.delete('api_response_kind')
66
+ api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil?
67
+ api_response_kind = 'object' if api_response_kind.nil?
68
+
69
+ parse_response(api_response_kind, RestClient.patch("#{@endpoint_url}#{action}", params, headers))
70
+ rescue => e
71
+ parse_response('object', e.response)
72
+ end
73
+ end
74
+
75
+ def head_request(action, params={}, headers={})
76
+ begin
77
+ api_response_kind = headers.delete('api_response_kind')
78
+ api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil?
79
+ api_response_kind = 'object' if api_response_kind.nil?
80
+
81
+ parse_response(api_response_kind, RestClient.head("#{@endpoint_url}#{action}", params))
82
+ rescue => e
83
+ parse_response('object', e.response)
84
+ end
85
+ end
86
+
87
+ def delete_request(action, params={}, headers={})
88
+ begin
89
+ api_response_kind = headers.delete('api_response_kind')
90
+ api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil?
91
+ api_response_kind = 'object' if api_response_kind.nil?
92
+
93
+ parse_response(api_response_kind, RestClient.delete("#{@endpoint_url}#{action}", params))
94
+ rescue => e
95
+ parse_response('object', e.response)
96
+ end
97
+ end
98
+
99
+ def parse_response(api_response_kind, response)
100
+ @last_response = response
101
+
102
+ result = OpenStruct.new
103
+ result.status_code = response.code
104
+
105
+ if api_response_kind == 'object'
106
+ result.headers = (JSON.parse(response.headers.to_json, object_class: OpenStruct) rescue response.headers)
107
+ result.body = (JSON.parse(response.body, object_class: OpenStruct) rescue response.body)
108
+ elsif api_response_kind == 'hash'
109
+ result.headers = response.headers
110
+ result.body = (JSON.parse(response.body) rescue response.body)
111
+ else
112
+ result.headers = response.headers
113
+ result.body = response.body
114
+ end
115
+
116
+ @last_result = result
117
+
118
+ result
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,11 @@
1
+ module Mercadoshops
2
+ module Core
3
+ module Orders
4
+ def search_orders(seller_id, filters={})
5
+ filters.merge!({ access_token: @access_token })
6
+
7
+ get_request("/v1/shops/#{seller_id}/orders/search", filters).body
8
+ end
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mercadolibre
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.6.0
4
+ version: 4.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matias Hick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-18 00:00:00.000000000 Z
11
+ date: 2019-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,6 +93,8 @@ files:
93
93
  - lib/mercadopago/api.rb
94
94
  - lib/mercadopago/core/oauth.rb
95
95
  - lib/mercadopago/core/payments.rb
96
+ - lib/mercadoshops/api.rb
97
+ - lib/mercadoshops/core/orders.rb
96
98
  homepage: https://github.com/unformattmh/mercadolibre
97
99
  licenses:
98
100
  - MIT