Module: Mercadolibre::Core::Messaging

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

Instance Method Summary collapse

Instance Method Details

#create_attachment(file) ⇒ Object



44
45
46
47
48
# File 'lib/mercadolibre/core/messaging.rb', line 44

def create_attachment(file)
  payload = { file: file }
  headers = { content_type: 'multipart/form-data' }
  post_request("/messages/attachments?access_token=#{@access_token}", payload, headers).body
end

#create_order_message(message_data) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/mercadolibre/core/messaging.rb', line 22

def create_order_message(message_data)
  payload = message_data.to_json

  headers = { content_type: :json }

  post_request("/messages?access_token=#{@access_token}&application_id=#{@app_key}",
    payload, headers).body
end

#create_pack_message(pack_id, user_id, message_data) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/mercadolibre/core/messaging.rb', line 61

def create_pack_message(pack_id, user_id, message_data)
  url = "/messages/packs/#{pack_id}/sellers/#{user_id}?access_token=#{@access_token}"
  url += "&application_id=#{@app_key}"

  payload = message_data.to_json

  headers = { content_type: :json }

  post_request(url, payload, headers).body
end

#get_attachment(attachment_id) ⇒ Object



50
51
52
53
# File 'lib/mercadolibre/core/messaging.rb', line 50

def get_attachment(attachment_id)
  params = { access_token: @access_token }
  get_request("/messages/attachments/#{attachment_id}", params, { api_response_kind: 'raw' }).body
end

#get_order_message(message_id) ⇒ Object



16
17
18
19
20
# File 'lib/mercadolibre/core/messaging.rb', line 16

def get_order_message(message_id)
  params = { access_token: @access_token }

  get_request("/messages/#{message_id}", params).body
end

#get_order_messages(order_id, filters = {}) ⇒ Object



4
5
6
7
8
# File 'lib/mercadolibre/core/messaging.rb', line 4

def get_order_messages(order_id, filters={})
  filters.merge!({ access_token: @access_token })

  get_request("/messages/orders/#{order_id}", filters).body
end

#get_pack_messages(pack_id, user_id, filters = {}) ⇒ Object



55
56
57
58
59
# File 'lib/mercadolibre/core/messaging.rb', line 55

def get_pack_messages(pack_id, user_id, filters={})
  filters.merge!({ access_token: @access_token })

  get_request("/messages/packs/#{pack_id}/sellers/#{user_id}", filters).body
end

#get_unread_order_messages(filters = {}) ⇒ Object



10
11
12
13
14
# File 'lib/mercadolibre/core/messaging.rb', line 10

def get_unread_order_messages(filters={})
  filters.merge!({ access_token: @access_token })

  get_request("/messages/unread", filters).body
end

#mark_order_message_as_read(message_ids) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mercadolibre/core/messaging.rb', line 31

def mark_order_message_as_read(message_ids)
  if message_ids.is_a?(Array)
    message_ids_data = message_ids.join(',')
  else
    message_ids_data = message_ids
  end

  headers = { content_type: :json }

  put_request("/messages/mark_as_read/#{message_ids_data}?access_token=#{@access_token}",
    { }, headers).body
end