Module: Mercadolibre::Core::OrderManagement

Included in:
Api
Defined in:
lib/mercadolibre/core/order_management.rb

Instance Method Summary collapse

Instance Method Details

#add_user_to_orders_blacklist(seller_id, user_id) ⇒ Object


147
148
149
150
151
152
153
154
155
# File 'lib/mercadolibre/core/order_management.rb', line 147

def add_user_to_orders_blacklist(seller_id, user_id)
  payload = { user_id: user_id }.to_json

  headers = { content_type: :json }

  url = "/users/#{seller_id}/order_blacklist?access_token=#{@access_token}"

  post_request(url, payload, headers)[:status_code] == 200
end

#change_order_buyer_feedback(order_id, kind, feedback_data) ⇒ Object


106
107
108
109
110
111
112
# File 'lib/mercadolibre/core/order_management.rb', line 106

def change_order_buyer_feedback(order_id, kind, feedback_data)
  payload = feedback_data.to_json

  headers = { content_type: :json }

  put_request("/orders/#{order_id}/feedback/purchase?version=3.0&access_token=#{@access_token}", payload, headers)[:body]
end

#change_order_feedback(feedback_id, feedback_data) ⇒ Object


114
115
116
117
118
119
120
# File 'lib/mercadolibre/core/order_management.rb', line 114

def change_order_feedback(feedback_id, feedback_data)
  payload = feedback_data.to_json

  headers = { content_type: :json }

  put_request("/feedback/#{feedback_id}?version=3.0&access_token=#{@access_token}", payload, headers)[:body]
end

#change_order_seller_feedback(order_id, kind, feedback_data) ⇒ Object


98
99
100
101
102
103
104
# File 'lib/mercadolibre/core/order_management.rb', line 98

def change_order_seller_feedback(order_id, kind, feedback_data)
  payload = feedback_data.to_json

  headers = { content_type: :json }

  put_request("/orders/#{order_id}/feedback/sale?version=3.0&access_token=#{@access_token}", payload, headers)[:body]
end

#create_order_feedback(order_id, feedback_data) ⇒ Object


90
91
92
93
94
95
96
# File 'lib/mercadolibre/core/order_management.rb', line 90

def create_order_feedback(order_id, feedback_data)
  payload = feedback_data.to_json

  headers = { content_type: :json }

  post_request("/orders/#{order_id}/feedback?version=3.0&access_token=#{@access_token}", payload, headers)[:body]
end

#create_order_note(order_id, text) ⇒ Object


40
41
42
43
44
45
46
47
48
# File 'lib/mercadolibre/core/order_management.rb', line 40

def create_order_note(order_id, text)
  payload = { note: text }.to_json

  headers = { content_type: :json, accept: :json }

  result = post_request("/orders/#{order_id}/notes?access_token=#{@access_token}", payload, headers)

  Mercadolibre::Entity::OrderNote.new(result[:body]['note'])
end

#delete_order_note(order_id, note_id) ⇒ Object


60
61
62
63
64
# File 'lib/mercadolibre/core/order_management.rb', line 60

def delete_order_note(order_id, note_id)
  result = delete_request("/orders/#{order_id}/notes/#{note_id}?access_token=#{@access_token}")

  result[:status_code] == 200
end

#get_order(order_id) ⇒ Object


26
27
28
29
30
31
# File 'lib/mercadolibre/core/order_management.rb', line 26

def get_order(order_id)
  filters = { access_token: @access_token }
  r = get_request("/orders/#{order_id}", filters)

  Mercadolibre::Entity::Order.new(r[:body])
end

#get_order_buyer_feedback(order_id) ⇒ Object


74
75
76
77
78
79
80
# File 'lib/mercadolibre/core/order_management.rb', line 74

def get_order_buyer_feedback(order_id)
  filters = { version: '3.0', access_token: @access_token }

  result = get_request("/orders/#{order_id}/feedback/purchase", filters)

  Mercadolibre::Entity::Feedback.new(result[:body])
end

#get_order_feedbacks(order_id) ⇒ Object


66
67
68
69
70
71
72
# File 'lib/mercadolibre/core/order_management.rb', line 66

def get_order_feedbacks(order_id)
  filters = { version: '3.0', access_token: @access_token }

  result = get_request("/orders/#{order_id}/feedback", filters)

  Mercadolibre::Entity::OrderFeedback.new(result[:body])
end

#get_order_notes(order_id) ⇒ Object


33
34
35
36
37
38
# File 'lib/mercadolibre/core/order_management.rb', line 33

def get_order_notes(order_id)
  filters = { access_token: @access_token }
  results = get_request("/orders/#{order_id}/notes", filters)

  results[:body].first['results'].map { |r| Mercadolibre::Entity::OrderNote.new(r) }
end

#get_order_seller_feedback(order_id) ⇒ Object


82
83
84
85
86
87
88
# File 'lib/mercadolibre/core/order_management.rb', line 82

def get_order_seller_feedback(order_id)
  filters = { version: '3.0', access_token: @access_token }

  result = get_request("/orders/#{order_id}/feedback/sale", filters)

  Mercadolibre::Entity::Feedback.new(result[:body])
end

#get_orders(kind, filters = {}) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mercadolibre/core/order_management.rb', line 4

def get_orders(kind, filters={})
  filters.merge!({
    seller: get_my_user.id,
    access_token: @access_token
  })

  if kind.to_s == 'archived'
    url = '/orders/search/archived'
  elsif kind.to_s == 'pending'
    url = '/orders/search/pending'
  else
    url = '/orders/search'
  end

  response = get_request(url, filters)[:body]

  {
    results: response['results'].map { |r| Mercadolibre::Entity::Order.new(r) },
    paging: response['paging']
  }
end

#get_orders_blacklist(user_id) ⇒ Object


142
143
144
145
# File 'lib/mercadolibre/core/order_management.rb', line 142

def get_orders_blacklist(user_id)
  results = get_request("/users/#{user_id}/order_blacklist?access_token=#{@access_token}")
  results[:body].map { |r| r['user']['id'] }
end

#get_site_payment_method_info(site_id, payment_method_id) ⇒ Object


136
137
138
139
140
# File 'lib/mercadolibre/core/order_management.rb', line 136

def get_site_payment_method_info(site_id, payment_method_id)
  results = get_request("/sites/#{site_id}/payment_methods/#{payment_method_id}")

  Mercadolibre::Entity::PaymentMethod.new(results[:body])
end

#get_site_payment_methods(site_id) ⇒ Object


130
131
132
133
134
# File 'lib/mercadolibre/core/order_management.rb', line 130

def get_site_payment_methods(site_id)
  results = get_request("/sites/#{site_id}/payment_methods")

  results[:body].map { |r| Mercadolibre::Entity::PaymentMethod.new(r) }
end

#remove_user_from_orders_blacklist(seller_id, user_id) ⇒ Object


157
158
159
160
161
# File 'lib/mercadolibre/core/order_management.rb', line 157

def remove_user_from_orders_blacklist(seller_id, user_id)
  url = "/users/#{seller_id}/order_blacklist/#{user_id}?access_token=#{@access_token}"

  delete_request(url)[:status_code] == 200
end

#reply_order_feedback(feedback_id, text) ⇒ Object


122
123
124
125
126
127
128
# File 'lib/mercadolibre/core/order_management.rb', line 122

def reply_order_feedback(feedback_id, text)
  payload = { reply: text }.to_json

  headers = { content_type: :json }

  post_request("/feedback/{feedback_id}/reply?version=3.0&access_token=#{@access_token}", payload, headers)[:body]
end

#update_order_note(order_id, note_id, text) ⇒ Object


50
51
52
53
54
55
56
57
58
# File 'lib/mercadolibre/core/order_management.rb', line 50

def update_order_note(order_id, note_id, text)
  payload = { note: text }.to_json

  headers = { content_type: :json, accept: :json }

  result = put_request("/orders/#{order_id}/notes/#{note_id}?access_token=#{@access_token}", payload, headers)

  Mercadolibre::Entity::OrderNote.new(result[:body]['note'])
end