mercadolibre 0.14.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/lib/mercadolibre.rb +4 -80
  4. data/lib/mercadolibre/api.rb +56 -20
  5. data/lib/mercadolibre/core/auth.rb +8 -12
  6. data/lib/mercadolibre/core/categories_and_listings.rb +8 -24
  7. data/lib/mercadolibre/core/collections.rb +10 -0
  8. data/lib/mercadolibre/core/items_and_searches.rb +25 -60
  9. data/lib/mercadolibre/core/locations_and_currencies.rb +8 -29
  10. data/lib/mercadolibre/core/order_management.rb +77 -47
  11. data/lib/mercadolibre/core/questions.rb +10 -27
  12. data/lib/mercadolibre/core/shippings.rb +2 -4
  13. data/lib/mercadolibre/core/users.rb +5 -13
  14. data/lib/mercadolibre/version.rb +1 -1
  15. data/lib/mercadopago/api.rb +55 -20
  16. data/lib/mercadopago/core/auth.rb +12 -18
  17. data/lib/mercadopago/core/payments.rb +3 -12
  18. metadata +3 -77
  19. data/lib/mercadolibre/entity/address.rb +0 -40
  20. data/lib/mercadolibre/entity/address_agency.rb +0 -21
  21. data/lib/mercadolibre/entity/answer.rb +0 -25
  22. data/lib/mercadolibre/entity/atm_transfer_reference.rb +0 -21
  23. data/lib/mercadolibre/entity/auth.rb +0 -21
  24. data/lib/mercadolibre/entity/billing_info.rb +0 -21
  25. data/lib/mercadolibre/entity/card_configuration.rb +0 -23
  26. data/lib/mercadolibre/entity/card_issuer.rb +0 -21
  27. data/lib/mercadolibre/entity/category.rb +0 -28
  28. data/lib/mercadolibre/entity/category_settings.rb +0 -26
  29. data/lib/mercadolibre/entity/city.rb +0 -27
  30. data/lib/mercadolibre/entity/collector.rb +0 -21
  31. data/lib/mercadolibre/entity/cost_components.rb +0 -21
  32. data/lib/mercadolibre/entity/country.rb +0 -26
  33. data/lib/mercadolibre/entity/currency.rb +0 -21
  34. data/lib/mercadolibre/entity/currency_conversion_ratio.rb +0 -21
  35. data/lib/mercadolibre/entity/featured_item.rb +0 -28
  36. data/lib/mercadolibre/entity/feedback.rb +0 -35
  37. data/lib/mercadolibre/entity/feedback_reply.rb +0 -25
  38. data/lib/mercadolibre/entity/geolocation.rb +0 -21
  39. data/lib/mercadolibre/entity/gtin.rb +0 -21
  40. data/lib/mercadolibre/entity/item.rb +0 -55
  41. data/lib/mercadolibre/entity/item_attribute.rb +0 -21
  42. data/lib/mercadolibre/entity/item_description.rb +0 -27
  43. data/lib/mercadolibre/entity/item_payment_method.rb +0 -21
  44. data/lib/mercadolibre/entity/item_picture.rb +0 -21
  45. data/lib/mercadolibre/entity/item_shipping.rb +0 -22
  46. data/lib/mercadolibre/entity/listing_exposure.rb +0 -21
  47. data/lib/mercadolibre/entity/listing_price.rb +0 -26
  48. data/lib/mercadolibre/entity/listing_type.rb +0 -21
  49. data/lib/mercadolibre/entity/mediation.rb +0 -25
  50. data/lib/mercadolibre/entity/mediation_interaction.rb +0 -21
  51. data/lib/mercadolibre/entity/municipality.rb +0 -21
  52. data/lib/mercadolibre/entity/neighborhood.rb +0 -21
  53. data/lib/mercadolibre/entity/order.rb +0 -44
  54. data/lib/mercadolibre/entity/order_coupon.rb +0 -21
  55. data/lib/mercadolibre/entity/order_feedback.rb +0 -25
  56. data/lib/mercadolibre/entity/order_item.rb +0 -25
  57. data/lib/mercadolibre/entity/order_note.rb +0 -25
  58. data/lib/mercadolibre/entity/order_shipping.rb +0 -33
  59. data/lib/mercadolibre/entity/payment.rb +0 -35
  60. data/lib/mercadolibre/entity/payment_method.rb +0 -33
  61. data/lib/mercadolibre/entity/payment_plan.rb +0 -21
  62. data/lib/mercadolibre/entity/payment_promotion.rb +0 -28
  63. data/lib/mercadolibre/entity/phone.rb +0 -21
  64. data/lib/mercadolibre/entity/product_identifier.rb +0 -25
  65. data/lib/mercadolibre/entity/question.rb +0 -30
  66. data/lib/mercadolibre/entity/search_location.rb +0 -27
  67. data/lib/mercadolibre/entity/shipment.rb +0 -41
  68. data/lib/mercadolibre/entity/shipment_status_history.rb +0 -24
  69. data/lib/mercadolibre/entity/shipping_delivery.rb +0 -25
  70. data/lib/mercadolibre/entity/shipping_item.rb +0 -21
  71. data/lib/mercadolibre/entity/shipping_option.rb +0 -28
  72. data/lib/mercadolibre/entity/shipping_speed.rb +0 -21
  73. data/lib/mercadolibre/entity/site.rb +0 -28
  74. data/lib/mercadolibre/entity/site_domain.rb +0 -21
  75. data/lib/mercadolibre/entity/site_trend.rb +0 -21
  76. data/lib/mercadolibre/entity/state.rb +0 -27
  77. data/lib/mercadolibre/entity/user.rb +0 -34
  78. data/lib/mercadolibre/entity/zip_code.rb +0 -29
  79. data/lib/mercadopago/entity/additional_info.rb +0 -27
  80. data/lib/mercadopago/entity/address.rb +0 -21
  81. data/lib/mercadopago/entity/auth.rb +0 -21
  82. data/lib/mercadopago/entity/collector.rb +0 -29
  83. data/lib/mercadopago/entity/fee_detail.rb +0 -21
  84. data/lib/mercadopago/entity/identification.rb +0 -21
  85. data/lib/mercadopago/entity/money_request.rb +0 -32
  86. data/lib/mercadopago/entity/order.rb +0 -21
  87. data/lib/mercadopago/entity/payer.rb +0 -27
  88. data/lib/mercadopago/entity/payment.rb +0 -83
  89. data/lib/mercadopago/entity/phone.rb +0 -21
  90. data/lib/mercadopago/entity/refund.rb +0 -25
  91. data/lib/mercadopago/entity/shipments.rb +0 -21
  92. data/lib/mercadopago/entity/source.rb +0 -21
  93. data/lib/mercadopago/entity/transaction_details.rb +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b5c5f27ea71eee142b1c096919f2032c0b6eaf0
4
- data.tar.gz: d48d5f815c342ff5eb2df25194453f72456f04ea
3
+ metadata.gz: 18de3ede412fce4880cacc3968f4fb9ea4958b00
4
+ data.tar.gz: 3c7f5ca25da212c014f52c613f683fd6541f91af
5
5
  SHA512:
6
- metadata.gz: 261558d0ce71558dff79d915e1cb7a718c708a12b3f157ca22f2537da62e0b4474189dc399544e5ce8e6a40cfd043342798218d6f6b39a8672950f6861fd6290
7
- data.tar.gz: 3bef58f55076619f512580988e290bc9a34bb3591b3221269e2dcafcc7ff191b57a6948d7228d136c881a7aa7ab1461b49f2ceb78f68b2048a3366eb441086ba
6
+ metadata.gz: c03b1318cf281ef41560730cef0e8a39843bc66719b08f7807f777724214d41a853ccb8358a20abc8a8e24960870fbc1b104a78ccbab8823b8c0f8f4a906e09b
7
+ data.tar.gz: 5fa91775520a8e2b4d8cb55e0971e5ebcf889fc355fc7ab7f406c901680e614d5c29b46367578f324d02e3a29d84ec1157c0aea01c8a716db97b130bf22f1206
data/CHANGELOG.md CHANGED
@@ -229,3 +229,7 @@
229
229
  ## v0.14.1
230
230
 
231
231
  * Added order entity for mercadopago
232
+
233
+ ## v1.0.0
234
+
235
+ * Full redesign for API, added messaging methods
data/lib/mercadolibre.rb CHANGED
@@ -1,97 +1,19 @@
1
1
  require "mercadolibre/version"
2
2
 
3
- # mercadolibre -> entities
4
- require "mercadolibre/entity/address"
5
- require "mercadolibre/entity/address_agency"
6
- require "mercadolibre/entity/answer"
7
- require "mercadolibre/entity/atm_transfer_reference"
8
- require "mercadolibre/entity/auth"
9
- require "mercadolibre/entity/billing_info"
10
- require "mercadolibre/entity/card_configuration"
11
- require "mercadolibre/entity/card_issuer"
12
- require "mercadolibre/entity/category"
13
- require "mercadolibre/entity/category_settings"
14
- require "mercadolibre/entity/city"
15
- require "mercadolibre/entity/collector"
16
- require "mercadolibre/entity/cost_components"
17
- require "mercadolibre/entity/country"
18
- require "mercadolibre/entity/currency"
19
- require "mercadolibre/entity/currency_conversion_ratio"
20
- require "mercadolibre/entity/featured_item"
21
- require "mercadolibre/entity/feedback"
22
- require "mercadolibre/entity/feedback_reply"
23
- require "mercadolibre/entity/geolocation"
24
- require "mercadolibre/entity/gtin"
25
- require "mercadolibre/entity/item"
26
- require "mercadolibre/entity/item_attribute"
27
- require "mercadolibre/entity/item_description"
28
- require "mercadolibre/entity/item_payment_method"
29
- require "mercadolibre/entity/item_picture"
30
- require "mercadolibre/entity/item_shipping"
31
- require "mercadolibre/entity/listing_exposure"
32
- require "mercadolibre/entity/listing_price"
33
- require "mercadolibre/entity/listing_type"
34
- require "mercadolibre/entity/mediation"
35
- require "mercadolibre/entity/mediation_interaction"
36
- require "mercadolibre/entity/municipality"
37
- require "mercadolibre/entity/neighborhood"
38
- require "mercadolibre/entity/order"
39
- require "mercadolibre/entity/order_coupon"
40
- require "mercadolibre/entity/order_feedback"
41
- require "mercadolibre/entity/order_item"
42
- require "mercadolibre/entity/order_note"
43
- require "mercadolibre/entity/order_shipping"
44
- require "mercadolibre/entity/payment"
45
- require "mercadolibre/entity/payment_method"
46
- require "mercadolibre/entity/payment_plan"
47
- require "mercadolibre/entity/payment_promotion"
48
- require "mercadolibre/entity/phone"
49
- require "mercadolibre/entity/product_identifier"
50
- require "mercadolibre/entity/question"
51
- require "mercadolibre/entity/search_location"
52
- require "mercadolibre/entity/shipment"
53
- require "mercadolibre/entity/shipment_status_history"
54
- require "mercadolibre/entity/shipping_delivery"
55
- require "mercadolibre/entity/shipping_item"
56
- require "mercadolibre/entity/shipping_option"
57
- require "mercadolibre/entity/shipping_speed"
58
- require "mercadolibre/entity/site"
59
- require "mercadolibre/entity/site_domain"
60
- require "mercadolibre/entity/site_trend"
61
- require "mercadolibre/entity/state"
62
- require "mercadolibre/entity/user"
63
- require "mercadolibre/entity/zip_code"
64
-
65
3
  # mercadolibre -> core
66
4
  require "mercadolibre/core/auth"
67
5
  require "mercadolibre/core/categories_and_listings"
6
+ require "mercadolibre/core/collections"
68
7
  require "mercadolibre/core/items_and_searches"
69
8
  require "mercadolibre/core/locations_and_currencies"
70
9
  require "mercadolibre/core/order_management"
71
- require "mercadolibre/core/shippings"
72
10
  require "mercadolibre/core/questions"
11
+ require "mercadolibre/core/shippings"
73
12
  require "mercadolibre/core/users"
74
13
 
75
14
  # mercadolibre -> api
76
15
  require "mercadolibre/api"
77
16
 
78
- # mercadopago -> entities
79
- require "mercadopago/entity/additional_info"
80
- require "mercadopago/entity/address"
81
- require "mercadopago/entity/auth"
82
- require "mercadopago/entity/collector"
83
- require "mercadopago/entity/fee_detail"
84
- require "mercadopago/entity/identification"
85
- require "mercadopago/entity/money_request"
86
- require "mercadopago/entity/order"
87
- require "mercadopago/entity/payer"
88
- require "mercadopago/entity/payment"
89
- require "mercadopago/entity/phone"
90
- require "mercadopago/entity/refund"
91
- require "mercadopago/entity/shipments"
92
- require "mercadopago/entity/source"
93
- require "mercadopago/entity/transaction_details"
94
-
95
17
  # mercadopago -> core
96
18
  require "mercadopago/core/auth"
97
19
  require "mercadopago/core/payments"
@@ -103,3 +25,5 @@ require "mercadopago/api"
103
25
  require 'rest-client'
104
26
  require 'singleton'
105
27
  require 'time'
28
+ require 'json'
29
+ require 'ostruct'
@@ -9,12 +9,12 @@ module Mercadolibre
9
9
  @access_token = args[:access_token]
10
10
  @endpoint_url = 'https://api.mercadolibre.com'
11
11
  @auth_url = 'https://auth.mercadolibre.com.ar'
12
- @debug = args[:debug]
13
12
  @site = args[:site]
14
13
  end
15
14
 
16
15
  include Mercadolibre::Core::Auth
17
16
  include Mercadolibre::Core::CategoriesAndListings
17
+ include Mercadolibre::Core::Collections
18
18
  include Mercadolibre::Core::ItemsAndSearches
19
19
  include Mercadolibre::Core::LocationsAndCurrencies
20
20
  include Mercadolibre::Core::OrderManagement
@@ -22,64 +22,100 @@ module Mercadolibre
22
22
  include Mercadolibre::Core::Shippings
23
23
  include Mercadolibre::Core::Users
24
24
 
25
+ def get_last_response
26
+ @last_response
27
+ end
28
+
25
29
  private
26
30
 
27
31
  def get_request(action, params={}, headers={})
28
32
  begin
29
- parse_response(RestClient.get("#{@endpoint_url}#{action}", {params: params}.merge(headers)))
33
+ api_response_kind = params.delete('api_response_kind')
34
+ api_response_kind = params.delete(:api_response_kind) if api_response_kind.nil?
35
+ api_response_kind = 'object' if api_response_kind.nil?
36
+
37
+ parse_response(api_response_kind, RestClient.get("#{@endpoint_url}#{action}", {params: params}.merge(headers)))
30
38
  rescue => e
31
- parse_response(e.response)
39
+ parse_response('object', e.response)
32
40
  end
33
41
  end
34
42
 
35
43
  def post_request(action, params={}, headers={})
36
44
  begin
37
- parse_response(RestClient.post("#{@endpoint_url}#{action}", params, headers))
45
+ api_response_kind = params.delete('api_response_kind')
46
+ api_response_kind = params.delete(:api_response_kind) if api_response_kind.nil?
47
+ api_response_kind = 'object' if api_response_kind.nil?
48
+
49
+ parse_response(api_response_kind, RestClient.post("#{@endpoint_url}#{action}", params, headers))
38
50
  rescue => e
39
- parse_response(e.response)
51
+ parse_response('object', e.response)
40
52
  end
41
53
  end
42
54
 
43
55
  def put_request(action, params={}, headers={})
44
56
  begin
45
- parse_response(RestClient.put("#{@endpoint_url}#{action}", params, headers))
57
+ api_response_kind = params.delete('api_response_kind')
58
+ api_response_kind = params.delete(:api_response_kind) if api_response_kind.nil?
59
+ api_response_kind = 'object' if api_response_kind.nil?
60
+
61
+ parse_response(api_response_kind, RestClient.put("#{@endpoint_url}#{action}", params, headers))
46
62
  rescue => e
47
- parse_response(e.response)
63
+ parse_response('object', e.response)
48
64
  end
49
65
  end
50
66
 
51
67
  def patch_request(action, params={}, headers={})
52
68
  begin
53
- parse_response(RestClient.patch("#{@endpoint_url}#{action}", params, headers))
69
+ api_response_kind = params.delete('api_response_kind')
70
+ api_response_kind = params.delete(:api_response_kind) if api_response_kind.nil?
71
+ api_response_kind = 'object' if api_response_kind.nil?
72
+
73
+ parse_response(api_response_kind, RestClient.patch("#{@endpoint_url}#{action}", params, headers))
54
74
  rescue => e
55
- parse_response(e.response)
75
+ parse_response('object', e.response)
56
76
  end
57
77
  end
58
78
 
59
79
  def head_request(action, params={})
60
80
  begin
61
- parse_response(RestClient.head("#{@endpoint_url}#{action}", params))
81
+ api_response_kind = params.delete('api_response_kind')
82
+ api_response_kind = params.delete(:api_response_kind) if api_response_kind.nil?
83
+ api_response_kind = 'object' if api_response_kind.nil?
84
+
85
+ parse_response(api_response_kind, RestClient.head("#{@endpoint_url}#{action}", params))
62
86
  rescue => e
63
- parse_response(e.response)
87
+ parse_response('object', e.response)
64
88
  end
65
89
  end
66
90
 
67
91
  def delete_request(action, params={})
68
92
  begin
69
- parse_response(RestClient.delete("#{@endpoint_url}#{action}", params))
93
+ api_response_kind = params.delete('api_response_kind')
94
+ api_response_kind = params.delete(:api_response_kind) if api_response_kind.nil?
95
+ api_response_kind = 'object' if api_response_kind.nil?
96
+
97
+ parse_response(api_response_kind, RestClient.delete("#{@endpoint_url}#{action}", params))
70
98
  rescue => e
71
- parse_response(e.response)
99
+ parse_response('object', e.response)
72
100
  end
73
101
  end
74
102
 
75
- def parse_response(response)
76
- result = {
77
- headers: response.headers,
78
- body: (JSON.parse(response.body) rescue response.body),
79
- status_code: response.code
80
- }
103
+ def parse_response(api_response_kind, response)
104
+ @last_response = response
81
105
 
82
- p "DEBUG: #{result}" if @debug
106
+ result = OpenStruct.new
107
+ result.status_code = response.code
108
+
109
+ if api_response_kind == 'object'
110
+ result.headers = (JSON.parse(response.headers.to_json, object_class: OpenStruct) rescue response.headers)
111
+ result.body = (JSON.parse(response.body, object_class: OpenStruct) rescue response.body)
112
+ elsif api_response_kind == 'hash'
113
+ result.headers = response.headers
114
+ result.body = (JSON.parse(response.body) rescue response.body)
115
+ else
116
+ result.headers = response.headers
117
+ result.body = response.body
118
+ end
83
119
 
84
120
  result
85
121
  end
@@ -18,13 +18,11 @@ module Mercadolibre
18
18
  client_secret: @app_secret,
19
19
  code: auth_code,
20
20
  redirect_uri: @callback_url
21
- })[:body]
21
+ })
22
22
 
23
- @access_token = response['access_token']
24
-
25
- Mercadolibre::Entity::Auth.new(response.merge({
26
- expired_at: (Time.now + response['expires_in'].to_i)
27
- }))
23
+ @access_token = response.body.access_token
24
+ response.body.expiration_time = (Time.now + response.body.expires_in.to_i)
25
+ response.body
28
26
  end
29
27
 
30
28
  def update_token(refresh_token)
@@ -33,13 +31,11 @@ module Mercadolibre
33
31
  client_id: @app_key,
34
32
  client_secret: @app_secret,
35
33
  refresh_token: refresh_token
36
- })[:body]
37
-
38
- @access_token = response['access_token']
34
+ })
39
35
 
40
- Mercadolibre::Entity::Auth.new(response.merge({
41
- expired_at: (Time.now + response['expires_in'].to_i)
42
- }))
36
+ @access_token = response.body.access_token
37
+ response.body.expiration_time = (Time.now + response.body.expires_in.to_i)
38
+ response.body
43
39
  end
44
40
  end
45
41
  end
@@ -2,54 +2,38 @@ module Mercadolibre
2
2
  module Core
3
3
  module CategoriesAndListings
4
4
  def get_sites
5
- results = get_request('/sites')
6
-
7
- results[:body].map { |r| Mercadolibre::Entity::Site.new(r) }
5
+ get_request('/sites').body
8
6
  end
9
7
 
10
8
  def get_site(site_id)
11
- result = get_request("/sites/#{site_id}")
12
-
13
- Mercadolibre::Entity::Site.new(result[:body])
9
+ get_request("/sites/#{site_id}").body
14
10
  end
15
11
 
16
12
  def get_site_domain_info(domain)
17
- result = get_request("/site_domains/#{domain}")
18
-
19
- Mercadolibre::Entity::SiteDomain.new(result[:body])
13
+ get_request("/site_domains/#{domain}").body
20
14
  end
21
15
 
22
16
  def get_listing_types(site_id)
23
- results = get_request("/sites/#{site_id}/listing_types")
24
-
25
- results[:body].map { |r| Mercadolibre::Entity::ListingType.new(r) }
17
+ get_request("/sites/#{site_id}/listing_types").body
26
18
  end
27
19
 
28
20
  def get_listing_exposures(site_id)
29
- results = get_request("/sites/#{site_id}/listing_exposures")
30
-
31
- results[:body].map { |r| Mercadolibre::Entity::ListingExposure.new(r) }
21
+ get_request("/sites/#{site_id}/listing_exposures").body
32
22
  end
33
23
 
34
24
  def get_listing_prices(filters)
35
25
  valid_filters = ['price', 'listing_type_id', 'quantity', 'category_id', 'currency_id']
36
26
  filters.keep_if { |k,v| valid_filters.include?(k.to_s) }
37
27
 
38
- results = get_request("/sites/#{site_id}/listing_prices", filters)
39
-
40
- results[:body].map { |r| Mercadolibre::Entity::ListingPrice.new(r) }
28
+ get_request("/sites/#{site_id}/listing_prices", filters).body
41
29
  end
42
30
 
43
31
  def get_site_categories(site_id)
44
- results = get_request("/sites/#{site_id}/categories")
45
-
46
- results[:body].map { |r| Mercadolibre::Entity::Category.new(r) }
32
+ get_request("/sites/#{site_id}/categories").body
47
33
  end
48
34
 
49
35
  def get_category(category_id)
50
- result = get_request("/categories/#{category_id}")
51
-
52
- Mercadolibre::Entity::Category.new(result[:body])
36
+ get_request("/categories/#{category_id}").body
53
37
  end
54
38
  end
55
39
  end
@@ -0,0 +1,10 @@
1
+ module Mercadolibre
2
+ module Core
3
+ module Collections
4
+ def get_collection(collection_id)
5
+ filters = { access_token: @access_token }
6
+ get_request("/collections/#{collection_id}", filters).body
7
+ end
8
+ end
9
+ end
10
+ end
@@ -6,36 +6,19 @@ module Mercadolibre
6
6
 
7
7
  filters.merge!({ access_token: @access_token, limit: 50, offset: 0 })
8
8
 
9
- response = get_request("/users/#{user_id}/items/search", filters)[:body]
10
-
11
- {
12
- results: response['results'],
13
- paging: response['paging']
14
- }
9
+ get_request("/users/#{user_id}/items/search", filters).body
15
10
  end
16
11
 
17
12
  def get_item_ids(filters={})
18
- response = get_request("/sites/#{@site}/search", filters)[:body]
19
-
20
- {
21
- results: response['results'].map { |r| r['id'] },
22
- paging: response['paging']
23
- }
13
+ get_request("/sites/#{@site}/search", filters).body
24
14
  end
25
15
 
26
16
  def search_items(filters={})
27
- response = get_request("/sites/#{@site}/search", filters)[:body]
28
-
29
- {
30
- results: response['results'].map { |x| Mercadolibre::Entity::Item.new(x) },
31
- paging: response['paging']
32
- }
17
+ get_request("/sites/#{@site}/search", filters).body
33
18
  end
34
19
 
35
20
  def get_item(item_id)
36
- result = get_request("/items/#{item_id}")
37
-
38
- Mercadolibre::Entity::Item.new(result[:body])
21
+ get_request("/items/#{item_id}").body
39
22
  end
40
23
 
41
24
  def get_item_visits(item_ids)
@@ -43,48 +26,39 @@ module Mercadolibre
43
26
  result = { }
44
27
 
45
28
  item_ids.each_slice(50) do |ids_group|
46
- result.merge!(get_request("/visits/items?ids=#{ids_group.join(',')}")[:body])
29
+ filters = { ids: ids_group.join(','), api_response_kind: 'hash' }
30
+ result.merge!(get_request('/visits/items', filters).body)
47
31
  end
48
32
 
49
33
  result
50
34
  else
51
- get_request("/visits/items?ids=#{item_ids}")[:body][item_ids]
35
+ filters = { ids: ids_group.join(','), api_response_kind: 'hash' }
36
+ get_request('/visits/items', filters).body[item_ids]
52
37
  end
53
38
  end
54
39
 
55
40
  def get_item_description(item_id)
56
- result = get_request("/items/#{item_id}/description")
57
-
58
- Mercadolibre::Entity::ItemDescription.new(result[:body])
41
+ get_request("/items/#{item_id}/description").body
59
42
  end
60
43
 
61
44
  def get_item_descriptions(item_id)
62
- results = get_request("/items/#{item_id}/descriptions")
63
-
64
- results[:body].map { |r| Mercadolibre::Entity::ItemDescription.new(r) }
45
+ get_request("/items/#{item_id}/descriptions").body
65
46
  end
66
47
 
67
48
  def get_item_available_upgrades(item_id)
68
- results = get_request("/items/#{item_id}/available_upgrades?access_token=@access_token")
69
-
70
- results[:body].map { |r| Mercadolibre::Entity::ListingType.new(r) }
49
+ get_request("/items/#{item_id}/available_upgrades?access_token=@access_token").body
71
50
  end
72
51
 
73
52
  def get_search_url(site_id, q)
74
- result = get_request("/sites/#{site_id}/searchUrl?q=#{q}")
75
- result[:body]['url']
53
+ get_request("/sites/#{site_id}/searchUrl?q=#{q}").body.url
76
54
  end
77
55
 
78
56
  def get_hot_items(site_id, category_id, limit=15)
79
- results = get_request("/sites/#{site_id}/hot_items/search?category=#{category_id}&limit=#{limit}")
80
-
81
- results[:body].map { |r| Mercadolibre::Entity::Item.new(r) }
57
+ get_request("/sites/#{site_id}/hot_items/search?category=#{category_id}&limit=#{limit}").body
82
58
  end
83
59
 
84
60
  def get_featured_items(site_id, pool_id)
85
- results = get_request("/sites/#{site_id}/featured_items/#{pool_id}")
86
-
87
- results[:body].map { |r| Mercadolibre::Entity::FeaturedItem.new(r) }
61
+ get_request("/sites/#{site_id}/featured_items/#{pool_id}").body
88
62
  end
89
63
 
90
64
  def get_site_trends(site_id, category_id=nil)
@@ -94,9 +68,7 @@ module Mercadolibre
94
68
  params = { }
95
69
  end
96
70
 
97
- results = get_request("/sites/#{site_id}/trends/search", params)
98
-
99
- results[:body].map { |r| Mercadolibre::Entity::SiteTrend.new(r) }
71
+ get_request("/sites/#{site_id}/trends/search", params).body
100
72
  end
101
73
 
102
74
  def item_valid?(attribs)
@@ -106,7 +78,7 @@ module Mercadolibre
106
78
 
107
79
  result = post_request("/items/validate?access_token=#{@access_token}", payload, headers)
108
80
 
109
- (result[:status_code].to_s == '204')
81
+ (result.status_code.to_s == '204')
110
82
  end
111
83
 
112
84
  def create_item(attribs)
@@ -114,9 +86,7 @@ module Mercadolibre
114
86
 
115
87
  headers = { content_type: :json }
116
88
 
117
- result = post_request("/items?access_token=#{@access_token}", payload, headers)
118
-
119
- Mercadolibre::Entity::Item.new(result[:body])
89
+ post_request("/items?access_token=#{@access_token}", payload, headers).body
120
90
  end
121
91
 
122
92
  def relist_item(item_id, price, quantity, listing_type_id)
@@ -124,9 +94,7 @@ module Mercadolibre
124
94
 
125
95
  headers = { content_type: :json, accept: :json }
126
96
 
127
- result = post_request("/items/#{item_id}/relist?access_token=#{@access_token}", payload, headers)
128
-
129
- Mercadolibre::Entity::Item.new(result[:body])
97
+ post_request("/items/#{item_id}/relist?access_token=#{@access_token}", payload, headers).body
130
98
  end
131
99
 
132
100
  def update_item_fields(item_id, attribs)
@@ -134,7 +102,7 @@ module Mercadolibre
134
102
 
135
103
  headers = { content_type: :json, accept: :json }
136
104
 
137
- put_request("/items/#{item_id}?access_token=#{@access_token}", payload, headers)[:body]
105
+ put_request("/items/#{item_id}?access_token=#{@access_token}", payload, headers).body
138
106
  end
139
107
 
140
108
  def update_item_listing_type(item_id, listing_type_id)
@@ -142,7 +110,7 @@ module Mercadolibre
142
110
 
143
111
  headers = { content_type: :json, accept: :json }
144
112
 
145
- post_request("/items/#{item_id}/listing_type?access_token=#{@access_token}", payload, headers)[:body]
113
+ post_request("/items/#{item_id}/listing_type?access_token=#{@access_token}", payload, headers).body
146
114
  end
147
115
 
148
116
  def add_item_description(item_id, text)
@@ -150,7 +118,7 @@ module Mercadolibre
150
118
 
151
119
  headers = { content_type: :json, accept: :json }
152
120
 
153
- post_request("/items/#{item_id}/descriptions?access_token=#{@access_token}", payload, headers)[:body]
121
+ post_request("/items/#{item_id}/descriptions?access_token=#{@access_token}", payload, headers).body
154
122
  end
155
123
 
156
124
  def update_item_attributes(item_id, attrs)
@@ -158,8 +126,7 @@ module Mercadolibre
158
126
 
159
127
  headers = { content_type: :json, accept: :json }
160
128
 
161
- put_request("/items/#{item_id}?access_token=#{@access_token}", payload, headers)[:status_code] == 200
162
-
129
+ put_request("/items/#{item_id}?access_token=#{@access_token}", payload, headers).status_code == 200
163
130
  end
164
131
 
165
132
  def delete_item_attributes(item_id, attr_list)
@@ -167,7 +134,7 @@ module Mercadolibre
167
134
 
168
135
  headers = { content_type: :json, accept: :json }
169
136
 
170
- put_request("/items/#{item_id}?access_token=#{@access_token}", payload, headers)[:status_code] == 200
137
+ put_request("/items/#{item_id}?access_token=#{@access_token}", payload, headers).status_code == 200
171
138
  end
172
139
 
173
140
  def update_item_identifiers(item_id, attrs)
@@ -175,13 +142,11 @@ module Mercadolibre
175
142
 
176
143
  headers = { content_type: :json }
177
144
 
178
- put_request("/items/#{item_id}/product_identifiers?access_token=#{@access_token}", payload, headers)[:status_code] == 200
145
+ put_request("/items/#{item_id}/product_identifiers?access_token=#{@access_token}", payload, headers).status_code == 200
179
146
  end
180
147
 
181
148
  def get_item_identifiers(item_id)
182
- result = get_request("/items/#{item_id}/product_identifiers")
183
-
184
- Mercadolibre::Entity::ProductIdentifier.new(result[:body])
149
+ get_request("/items/#{item_id}/product_identifiers").body
185
150
  end
186
151
  end
187
152
  end