mercadolibre 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 109433bc0bc93bd09049b12c922ae897da49ebcf
4
- data.tar.gz: 2536ee8cc03c6e55ece0ad965a38d3692b7c5c22
3
+ metadata.gz: 708793ddaed462f4cf427fcda6ee24be535d4fbf
4
+ data.tar.gz: a57c90e75cca9786ed727a058e9ebfed401f3347
5
5
  SHA512:
6
- metadata.gz: be3ccf0b25f7b902ee1e84f826fd834e63f0608a2a7c2a108c3bf95fea2541e45e100395aad91424ec6c1b11c5c80457760840f9b19ca3d8e07c576492a5c484
7
- data.tar.gz: 77fb2773f99b47d6bf762941aa4f5ce7fff8f3569c1003b17e7ecd0c9ed787261bf19a010c2565cf4495af10a57012b3df4f99a0682f1cc23094fd1c42c2af80
6
+ metadata.gz: c107e184972090b735c937d6ba5865dd17f820665620c124d46c75a9380ccf358fe2dc34bcd9f9e4aca60b18b6038959c62727410ae1857f45cd596790fabdf9
7
+ data.tar.gz: 544c96a1aa372407eb69d032bb6c0078f4818c681e893595e956cf1feb057751c1741aff9099eeb100d60ad75bbb8acaa950075269e47af2cbfc6ab4018a4dd2
data/CHANGELOG.md CHANGED
@@ -133,3 +133,7 @@
133
133
  ## v0.7.1
134
134
 
135
135
  * Bugfix mistype
136
+
137
+ ## v0.8.0
138
+
139
+ * Added attributes to orders, users, added methods to items search
@@ -1,6 +1,19 @@
1
1
  module Mercadolibre
2
2
  module Core
3
3
  module ItemsAndSearches
4
+ def get_my_item_ids(filters={})
5
+ user_id = get_my_user.id
6
+
7
+ filters.merge!({ access_token: @access_token, limit: 50, offset: 0 })
8
+
9
+ response = get_request("/users/#{user_id}/items/search", filters)[:body]
10
+
11
+ {
12
+ results: response['results'],
13
+ paging: response['paging']
14
+ }
15
+ end
16
+
4
17
  # This method is meant to be used when you need to save all data in your local database
5
18
  def get_all_my_item_ids(filters={})
6
19
  user_id = get_my_user.id
@@ -23,15 +36,11 @@ module Mercadolibre
23
36
  results
24
37
  end
25
38
 
26
- def get_my_item_ids(filters={})
27
- user_id = get_my_user.id
28
-
29
- filters.merge!({ access_token: @access_token, limit: 50, offset: 0 })
30
-
31
- response = get_request("/users/#{user_id}/items/search", filters)[:body]
39
+ def get_item_ids(filters={})
40
+ response = get_request("/sites/#{@site}/search", filters)[:body]
32
41
 
33
42
  {
34
- results: response['results'],
43
+ results: response['results'].map { |r| r['id'] },
35
44
  paging: response['paging']
36
45
  }
37
46
  end
@@ -56,15 +65,35 @@ module Mercadolibre
56
65
  results
57
66
  end
58
67
 
59
- def get_item_ids(filters={})
68
+ def search_items(filters={})
60
69
  response = get_request("/sites/#{@site}/search", filters)[:body]
61
70
 
62
71
  {
63
- results: response['results'].map { |r| r['id'] },
72
+ results: response['results'].map { |x| Mercadolibre::Entity::Item.new(x) },
64
73
  paging: response['paging']
65
74
  }
66
75
  end
67
76
 
77
+ # This method is meant to be used when you need to save all data in your local database
78
+ def search_all_items(filters={})
79
+ filters.merge!({ limit: 50, offset: 0 })
80
+
81
+ results = []
82
+ has_results = true
83
+
84
+ pages_remaining = filters[:pages_count] || -1
85
+
86
+ while (has_results && (pages_remaining != 0)) do
87
+ partial_results = get_request("/sites/#{@site}/search", filters)[:body]['results']
88
+ results += partial_results.map { |x| Mercadolibre::Entity::Item.new(x) }
89
+ has_results = partial_results.any?
90
+ filters[:offset] += 50
91
+ pages_remaining -= 1
92
+ end
93
+
94
+ results
95
+ end
96
+
68
97
  def get_item(item_id)
69
98
  result = get_request("/items/#{item_id}")
70
99
 
File without changes
@@ -0,0 +1,25 @@
1
+ module Mercadolibre
2
+ module Entity
3
+ class Mediation
4
+ def self.attr_list
5
+ [:id, :status, :interactions]
6
+ end
7
+
8
+ attr_reader *attr_list
9
+
10
+ def initialize(attributes={})
11
+ attributes.each do |k, v|
12
+ if k.to_s == 'interactions'
13
+ self.interactions = MediationInteraction.new(v) unless v.nil?
14
+ else
15
+ self.send("#{k}=", v) if self.respond_to?(k)
16
+ end
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ attr_writer *attr_list
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ module Mercadolibre
2
+ module Entity
3
+ class MediationInteraction
4
+ def self.attr_list
5
+ [:current_responsible]
6
+ end
7
+
8
+ attr_reader *attr_list
9
+
10
+ def initialize(attributes={})
11
+ attributes.each do |k, v|
12
+ self.send("#{k}=", v) if self.respond_to?(k)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ attr_writer *attr_list
19
+ end
20
+ end
21
+ end
@@ -24,6 +24,8 @@ module Mercadolibre
24
24
  self.coupon = OrderCoupon.new(v) unless v.nil?
25
25
  elsif ['buyer', 'seller'].include?(k.to_s)
26
26
  self.send("#{k}=", User.new(v)) unless v.nil?
27
+ elsif k.to_s == 'mediations'
28
+ self.mediations = v.map { |x| Mediation.new(x) } unless v.nil?
27
29
  elsif ['date_created', 'date_closed', 'last_updated'].include?(k.to_s)
28
30
  self.send("#{k}=", Time.parse(v)) unless v.nil?
29
31
  else
@@ -4,7 +4,8 @@ module Mercadolibre
4
4
  def self.attr_list
5
5
  [:id, :nickname, :registration_date, :first_name, :last_name, :blocked,
6
6
  :country_id, :email, :user_type, :points, :site_id, :permalink, :phone,
7
- :alternative_phone, :billing_info, :status]
7
+ :alternative_phone, :billing_info, :status, :power_seller_status,
8
+ :car_dealer, :real_estate_agency]
8
9
  end
9
10
 
10
11
  attr_reader *attr_list
@@ -1,3 +1,3 @@
1
1
  module Mercadolibre
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.0"
3
3
  end
data/lib/mercadolibre.rb CHANGED
@@ -29,6 +29,8 @@ require "mercadolibre/entity/item_shipping"
29
29
  require "mercadolibre/entity/listing_exposure"
30
30
  require "mercadolibre/entity/listing_price"
31
31
  require "mercadolibre/entity/listing_type"
32
+ require "mercadolibre/entity/mediation"
33
+ require "mercadolibre/entity/mediation_interaction"
32
34
  require "mercadolibre/entity/municipality"
33
35
  require "mercadolibre/entity/neighborhood"
34
36
  require "mercadolibre/entity/order"
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: 0.7.1
4
+ version: 0.8.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: 2015-07-21 00:00:00.000000000 Z
11
+ date: 2015-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,6 +100,8 @@ files:
100
100
  - lib/mercadolibre/entity/listing_exposure.rb
101
101
  - lib/mercadolibre/entity/listing_price.rb
102
102
  - lib/mercadolibre/entity/listing_type.rb
103
+ - lib/mercadolibre/entity/mediation.rb
104
+ - lib/mercadolibre/entity/mediation_interaction.rb
103
105
  - lib/mercadolibre/entity/municipality.rb
104
106
  - lib/mercadolibre/entity/neighborhood.rb
105
107
  - lib/mercadolibre/entity/order.rb