mercadolibre 1.8.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mercadolibre.rb +20 -7
  3. data/lib/mercadolibre/api.rb +18 -7
  4. data/lib/mercadolibre/core/apps.rb +17 -0
  5. data/lib/mercadolibre/core/bookmarks.rb +21 -0
  6. data/lib/mercadolibre/core/categories.rb +47 -0
  7. data/lib/mercadolibre/core/currencies.rb +18 -0
  8. data/lib/mercadolibre/core/deals.rb +3 -4
  9. data/lib/mercadolibre/core/feedbacks.rb +63 -0
  10. data/lib/mercadolibre/core/item_variations.rb +35 -0
  11. data/lib/mercadolibre/core/items.rb +87 -0
  12. data/lib/mercadolibre/core/listings.rb +43 -0
  13. data/lib/mercadolibre/core/{locations_and_currencies.rb → locations.rb} +7 -13
  14. data/lib/mercadolibre/core/messaging.rb +55 -0
  15. data/lib/mercadolibre/core/metrics.rb +53 -0
  16. data/lib/mercadolibre/core/money.rb +21 -0
  17. data/lib/mercadolibre/core/order_blacklist.rb +25 -0
  18. data/lib/mercadolibre/core/order_notes.rb +33 -0
  19. data/lib/mercadolibre/core/orders.rb +39 -0
  20. data/lib/mercadolibre/core/pictures.rb +33 -0
  21. data/lib/mercadolibre/core/projects.rb +42 -0
  22. data/lib/mercadolibre/core/question_blacklist.rb +27 -0
  23. data/lib/mercadolibre/core/{questions_and_answers.rb → questions.rb} +10 -31
  24. data/lib/mercadolibre/core/searching.rb +33 -0
  25. data/lib/mercadolibre/core/shipping.rb +6 -6
  26. data/lib/mercadolibre/core/{users_and_apps.rb → users.rb} +21 -23
  27. data/lib/mercadolibre/version.rb +1 -1
  28. metadata +22 -9
  29. data/lib/mercadolibre/core/categories_and_listings.rb +0 -59
  30. data/lib/mercadolibre/core/collections.rb +0 -10
  31. data/lib/mercadolibre/core/items_and_searches.rb +0 -153
  32. data/lib/mercadolibre/core/orders_and_feedback.rb +0 -202
@@ -17,21 +17,15 @@ module Mercadolibre
17
17
  get_request("/cities/#{city_id}").body
18
18
  end
19
19
 
20
- def get_currencies
21
- get_request('/currencies').body
22
- end
23
-
24
- def get_currency(currency_id)
25
- get_request("/currencies/#{currency_id}").body
26
- end
27
-
28
- def currency_convertion_rate(currency_from, currency_to)
29
- filters = { from: currency_from, to: currency_to }
30
- get_request('/currency_conversions/search', filters).body
20
+ def get_zip_code(country_id, zip_code)
21
+ get_request("/countries/#{country_id}/zip_codes/#{zip_code}").body
31
22
  end
32
23
 
33
- def get_zip_code_info(country_id, zip_code)
34
- get_request("/countries/#{country_id}/zip_codes/#{zip_code}").body
24
+ def search_zip_codes(country_id, zip_code_from, zip_code_to)
25
+ get_request("/countries/#{country_id}/zip_codes/search_between", {
26
+ zip_code_from: zip_code_from,
27
+ zip_code_to: zip_code_to
28
+ }).body
35
29
  end
36
30
  end
37
31
  end
@@ -0,0 +1,55 @@
1
+ module Mercadolibre
2
+ module Core
3
+ module Messaging
4
+ def get_order_messages(order_id, filters={})
5
+ filters.merge!({ access_token: @access_token })
6
+
7
+ get_request("/messages/orders/#{order_id}", filters).body
8
+ end
9
+
10
+ def get_unread_order_messages(filters={})
11
+ filters.merge!({ access_token: @access_token })
12
+
13
+ get_request("/messages/pending_read", filters).body
14
+ end
15
+
16
+ def get_order_message(message_id)
17
+ params = { access_token: @access_token }
18
+
19
+ get_request("/messages/#{message_id}", params).body
20
+ end
21
+
22
+ def create_order_message(message_data)
23
+ payload = message_data.to_json
24
+
25
+ headers = { content_type: :json }
26
+
27
+ post_request("/messages?access_token=#{@access_token}&application_id=#{@app_key}",
28
+ payload, headers).body
29
+ end
30
+
31
+ def mark_order_message_as_read(message_ids)
32
+ if message_ids.is_a?(Array)
33
+ message_ids_data = message_ids.join(',')
34
+ else
35
+ message_ids_data = message_ids
36
+ end
37
+
38
+ headers = { content_type: :json }
39
+
40
+ put_request("/messages/mark_as_read/#{message_ids_data}?access_token=#{@access_token}",
41
+ payload, headers).body
42
+ end
43
+
44
+ def create_attachment(path_to_file)
45
+ payload = { file: File.new(path_to_file, 'rb') }
46
+ post_request("/messages/attachments?access_token=#{@access_token}", payload).body
47
+ end
48
+
49
+ def get_attachment(attachment_id)
50
+ params = { access_token: @access_token }
51
+ get_request("/messages/attachments/#{attachment_id}", params, { api_response_kind: 'raw' }).body
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,6 +1,59 @@
1
1
  module Mercadolibre
2
2
  module Core
3
3
  module Metrics
4
+ def get_user_visits(user_id, args)
5
+ get_request("/users/#{user_id}/items_visits", args).body
6
+ end
7
+
8
+ def get_user_visits_tw(user_id, args)
9
+ get_request("/users/#{user_id}/items_visits/time_window", args).body
10
+ end
11
+
12
+ def get_user_question_quantities(user_id, args)
13
+ get_request("/users/#{user_id}/contacts/questions", args).body
14
+ end
15
+
16
+ def get_user_question_quantities_tw(user_id, args)
17
+ get_request("/users/#{user_id}/contacts/questions/time_window", args).body
18
+ end
19
+
20
+ def get_user_see_phone_clicked_quantities(user_id, args)
21
+ get_request("/users/#{user_id}/contacts/phone_views", args).body
22
+ end
23
+
24
+ def get_user_see_phone_clicked_quantities_tw(user_id, args)
25
+ get_request("/users/#{user_id}/contacts/phone_views/time_window", args).body
26
+ end
27
+
28
+ def get_items_visits(item_ids, args)
29
+ item_ids_desc = (item_ids.is_a?(Array) ? item_ids.join(',') : item_ids)
30
+ get_request("/items/visits", args.merge(ids: item_ids_desc)).body
31
+ end
32
+
33
+ def get_item_visits_tw(item_id, args)
34
+ get_request("/items/#{item_id}/visits/time_window", args).body
35
+ end
36
+
37
+ def get_total_items_visits(item_ids)
38
+ if item_ids.is_a? Array
39
+ result = { }
40
+
41
+ item_ids.each_slice(50) do |ids_group|
42
+ filters = { ids: ids_group.join(',') }
43
+ result.merge!(get_request('/visits/items', filters, { api_response_kind: 'hash' }).body)
44
+ end
45
+
46
+ result
47
+ else
48
+ filters = { ids: ids_group.join(',') }
49
+ get_request('/visits/items', filters, { api_response_kind: 'hash' }).body[item_ids]
50
+ end
51
+ end
52
+
53
+ def get_user_items_see_phone_clicked_quantities_tw(item_ids, args)
54
+ item_ids_desc = (item_ids.is_a?(Array) ? item_ids.join(',') : item_ids)
55
+ get_request("/items/contacts/phone_views/time_window", args.merge(ids: item_ids_desc)).body
56
+ end
4
57
  end
5
58
  end
6
59
  end
@@ -0,0 +1,21 @@
1
+ module Mercadolibre
2
+ module Core
3
+ module Money
4
+ def get_collection(collection_id)
5
+ filters = { access_token: @access_token }
6
+
7
+ get_request("/collections/#{collection_id}", filters).body
8
+ end
9
+
10
+ def get_payment(payment_id)
11
+ get_request("/payments/#{payment_id}", { access_token: @access_token }).body
12
+ end
13
+
14
+ def get_user_mercadopago_balance(user_id)
15
+ params = { access_token: @access_token }
16
+
17
+ get_request("/users/#{user_id}/mercadopago_account/balance", params).body
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ module Mercadolibre
2
+ module Core
3
+ module OrderBlacklist
4
+ def get_orders_blacklist(user_id)
5
+ results = get_request("/users/#{user_id}/order_blacklist?access_token=#{@access_token}")
6
+ results.body.map { |r| r.user.id }
7
+ end
8
+
9
+ def add_user_to_orders_blacklist(seller_id, user_id)
10
+ payload = { user_id: user_id }.to_json
11
+
12
+ headers = { content_type: :json }
13
+
14
+ url = "/users/#{seller_id}/order_blacklist?access_token=#{@access_token}"
15
+ post_request(url, payload, headers).status_code == 200
16
+ end
17
+
18
+ def remove_user_from_orders_blacklist(seller_id, user_id)
19
+ url = "/users/#{seller_id}/order_blacklist/#{user_id}?access_token=#{@access_token}"
20
+
21
+ delete_request(url).status_code == 200
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ module Mercadolibre
2
+ module Core
3
+ module OrderNotes
4
+ def get_order_notes(order_id)
5
+ filters = { access_token: @access_token }
6
+ get_request("/orders/#{order_id}/notes", filters).body
7
+ end
8
+
9
+ def create_order_note(order_id, text)
10
+ payload = { note: text }.to_json
11
+
12
+ headers = { content_type: :json, accept: :json }
13
+
14
+ result = post_request("/orders/#{order_id}/notes?access_token=#{@access_token}", payload, headers)
15
+ result.body.note
16
+ end
17
+
18
+ def update_order_note(order_id, note_id, text)
19
+ payload = { note: text }.to_json
20
+
21
+ headers = { content_type: :json, accept: :json }
22
+
23
+ result = put_request("/orders/#{order_id}/notes/#{note_id}?access_token=#{@access_token}", payload, headers)
24
+ result.body.note
25
+ end
26
+
27
+ def delete_order_note(order_id, note_id)
28
+ result = delete_request("/orders/#{order_id}/notes/#{note_id}?access_token=#{@access_token}")
29
+ result.status_code == 200
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,39 @@
1
+ module Mercadolibre
2
+ module Core
3
+ module Orders
4
+ def search_orders(filters={})
5
+ if filters[:seller_id].present?
6
+ seller_id = filters[:seller_id]
7
+ else
8
+ seller_id = get_my_user.id
9
+ end
10
+
11
+ orders_suffix = filters.delete(:orders_suffix).to_s
12
+
13
+ filters.merge!({
14
+ seller: seller_id,
15
+ access_token: @access_token
16
+ })
17
+
18
+ get_request("/orders/search#{orders_suffix}", filters).body
19
+ end
20
+
21
+ def search_archived_orders(filters={})
22
+ search_orders(filters.merge(orders_suffix: '/archived'))
23
+ end
24
+
25
+ def search_pending_orders(filters={})
26
+ search_orders(filters.merge(orders_suffix: '/pending'))
27
+ end
28
+
29
+ def search_recent_orders(filters={})
30
+ search_orders(filters.merge(orders_suffix: '/recent'))
31
+ end
32
+
33
+ def get_order(order_id)
34
+ filters = { access_token: @access_token }
35
+ get_request("/orders/#{order_id}", filters).body
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ module Mercadolibre
2
+ module Core
3
+ module Pictures
4
+ def create_picture(path_to_file)
5
+ payload = { file: File.new(path_to_file, 'rb') }
6
+ post_request("/pictures?access_token=#{@access_token}", payload).body
7
+ end
8
+
9
+ def get_pictures(picture_id)
10
+ get_request("/pictures/#{picture_id}").body
11
+ end
12
+
13
+ def delete_picture(picture_id)
14
+ delete_request("/pictures/#{picture_id}?access_token=#{@access_token}").body
15
+ end
16
+
17
+ def add_item_picture(picture_id, item_id)
18
+ curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d
19
+ '{"id":"MLA430387888_032012"}'
20
+
21
+ https://api.mercadolibre.com/items/MLA421101451/pictures?access_token=$ACCESS_TOKEN
22
+ end
23
+
24
+ def replace_item_pictures(item_id, images)
25
+ payload = images.to_json
26
+
27
+ headers = { content_type: :json }
28
+
29
+ put_request("/items/#{item_id}?access_token=#{@access_token}", payload, headers).body
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,42 @@
1
+ module Mercadolibre
2
+ module Core
3
+ module Projects
4
+ def get_user_project(project_id)
5
+ get_request("/projects/#{project_id}", { access_token: @access_token }).body
6
+ end
7
+
8
+ def create_user_project(attrs)
9
+ payload = attrs.to_json
10
+
11
+ headers = { content_type: :json }
12
+
13
+ post_request("/projects?access_token=#{@access_token}", payload, headers).body
14
+ end
15
+
16
+ def update_user_project(project_id, attrs)
17
+ payload = attrs.to_json
18
+
19
+ headers = { content_type: :json }
20
+
21
+ put_request("/projects/#{project_id}?access_token=#{@access_token}", payload, headers).body
22
+ end
23
+
24
+ def delete_user_project(project_id)
25
+ delete_request("/projects/#{project_id}?access_token=#{@access_token}").body
26
+ end
27
+
28
+ def add_application_to_project(application_id, project_id)
29
+ payload = { application_id: application_id }.to_json
30
+
31
+ headers = { content_type: :json }
32
+
33
+ post_request("/projects/#{project_id}/applications?access_token=#{@access_token}",
34
+ payload, headers).body
35
+ end
36
+
37
+ def remove_application_from_project(application_id, project_id)
38
+ delete_request("/projects/#{project_id}/applications/#{application_id}?access_token=#{@access_token}").body
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,27 @@
1
+ module Mercadolibre
2
+ module Core
3
+ module QuestionBlacklist
4
+ def get_questions_blacklist(seller_id, args)
5
+ result = get_request("/users/#{seller_id}/questions_blacklist", args.merge({
6
+ access_token: @access_token
7
+ })).body
8
+ end
9
+
10
+ def add_user_to_questions_blacklist(seller_id, user_id)
11
+ payload = { user_id: user_id }.to_json
12
+
13
+ headers = { content_type: :json }
14
+
15
+ url = "/users/#{seller_id}/questions_blacklist?access_token=#{@access_token}"
16
+
17
+ post_request(url, payload, headers).status_code == 200
18
+ end
19
+
20
+ def remove_user_from_questions_blacklist(seller_id, user_id)
21
+ url = "/users/#{seller_id}/questions_blacklist/#{user_id}?access_token=#{@access_token}"
22
+
23
+ delete_request(url).status_code == 200
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,18 +1,7 @@
1
1
  module Mercadolibre
2
2
  module Core
3
- module QuestionsAndAnswers
4
- def get_my_questions(filters={})
5
- filters.merge!({ access_token: @access_token })
6
-
7
- get_request('/my/received_questions/search', filters).body
8
- end
9
-
10
- def get_my_questions_count(filters={})
11
- filters.merge!({ access_token: @access_token, limit: 1, offset: 0 })
12
- get_request('/my/received_questions/search', filters).body.total.to_i
13
- end
14
-
15
- def get_questions(filters={})
3
+ module Questions
4
+ def search_questions(filters={})
16
5
  if @access_token.present?
17
6
  filters.merge!({ access_token: @access_token })
18
7
  end
@@ -20,7 +9,7 @@ module Mercadolibre
20
9
  get_request('/questions/search', filters).body
21
10
  end
22
11
 
23
- def get_questions_count(filters={})
12
+ def search_questions_total(filters={})
24
13
  if @access_token.present?
25
14
  filters.merge!({ access_token: @access_token })
26
15
  end
@@ -47,7 +36,7 @@ module Mercadolibre
47
36
 
48
37
  headers = { content_type: :json }
49
38
 
50
- post_request("/questions?access_token=#{@access_token}", payload, headers).body
39
+ post_request("/questions/#{item_id}?access_token=#{@access_token}", payload, headers).body
51
40
  end
52
41
 
53
42
  def answer_question(question_id, text)
@@ -58,25 +47,15 @@ module Mercadolibre
58
47
  post_request("/answers?access_token=#{@access_token}", payload, headers).body
59
48
  end
60
49
 
61
- def get_questions_blacklist(seller_id)
62
- result = get_request("/users/#{seller_id}/questions_blacklist?access_token=#{@access_token}")
63
- result.body.map { |r| r.user.id }
64
- end
65
-
66
- def add_user_to_questions_blacklist(seller_id, user_id)
67
- payload = { user_id: user_id }.to_json
68
-
69
- headers = { content_type: :json }
70
-
71
- url = "/users/#{seller_id}/questions_blacklist?access_token=#{@access_token}"
50
+ def search_my_questions(filters={})
51
+ filters.merge!({ access_token: @access_token })
72
52
 
73
- post_request(url, payload, headers).status_code == 200
53
+ get_request('/my/received_questions/search', filters).body
74
54
  end
75
55
 
76
- def remove_user_from_questions_blacklist(seller_id, user_id)
77
- url = "/users/#{seller_id}/questions_blacklist/#{user_id}?access_token=#{@access_token}"
78
-
79
- delete_request(url).status_code == 200
56
+ def search_my_questions_total(filters={})
57
+ filters.merge!({ access_token: @access_token, limit: 1, offset: 0 })
58
+ get_request('/my/received_questions/search', filters).body.total.to_i
80
59
  end
81
60
  end
82
61
  end
@@ -0,0 +1,33 @@
1
+ module Mercadolibre
2
+ module Core
3
+ module Searching
4
+ def search_items(filters={})
5
+ get_request("/sites/#{@site}/search", filters).body
6
+ end
7
+
8
+ def search_item_ids(filters={})
9
+ get_request("/sites/#{@site}/search", filters).body.results.map(&:id)
10
+ end
11
+
12
+ def search_my_item_ids(filters={})
13
+ user_id = filters[:user_id] || get_my_user.id
14
+
15
+ filters.merge!({ access_token: @access_token, limit: 50, offset: 0 })
16
+
17
+ get_request("/users/#{user_id}/items/search", filters).body
18
+ end
19
+
20
+ def get_search_url(site_id, q)
21
+ get_request("/sites/#{site_id}/searchUrl?q=#{q}").body
22
+ end
23
+
24
+ def get_hot_items(site_id, category_id, limit=15)
25
+ get_request("/sites/#{site_id}/hot_items/search?category=#{category_id}&limit=#{limit}").body
26
+ end
27
+
28
+ def get_featured_items(site_id, pool_id)
29
+ get_request("/sites/#{site_id}/featured_items/#{pool_id}").body
30
+ end
31
+ end
32
+ end
33
+ end