Module: Mercadolibre::Core::Users

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

Instance Method Summary collapse

Instance Method Details

#get_my_userObject



29
30
31
# File 'lib/mercadolibre/core/users.rb', line 29

def get_my_user
  get_request('/users/me', { access_token: @access_token }).body
end

#get_seller(nickname) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/mercadolibre/core/users.rb', line 12

def get_seller(nickname)
  response = search_items({ nickname: nickname, limit: 0 })
  if response.seller.present?
    get_user(response.seller.id)
  else
    nil
  end
end

#get_user(user_id) ⇒ Object



8
9
10
# File 'lib/mercadolibre/core/users.rb', line 8

def get_user(user_id)
  get_request("/users/#{user_id}", { access_token: @access_token }).body
end

#get_user_accepted_payment_methods(user_id) ⇒ Object



37
38
39
# File 'lib/mercadolibre/core/users.rb', line 37

def get_user_accepted_payment_methods(user_id)
  get_request("/users/#{user_id}/accepted_payment_methods").body
end

#get_user_addresses(user_id) ⇒ Object



33
34
35
# File 'lib/mercadolibre/core/users.rb', line 33

def get_user_addresses(user_id)
  get_request("/users/#{user_id}/addresses", { access_token: @access_token }).body
end

#get_user_available_listing_types(user_id, category_id) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/mercadolibre/core/users.rb', line 69

def get_user_available_listing_types(user_id, category_id)
  filters = {
    access_token: @access_token,
    category_id: category_id
  }

  get_request("/users/#{user_id}/available_listing_types", filters).body
end

#get_user_brand(user_id, brand_id) ⇒ Object



49
50
51
# File 'lib/mercadolibre/core/users.rb', line 49

def get_user_brand(user_id, brand_id)
  get_request("/users/#{user_id}/brands/#{brand_id}", { access_token: @access_token }).body
end

#get_user_brands(user_id) ⇒ Object



45
46
47
# File 'lib/mercadolibre/core/users.rb', line 45

def get_user_brands(user_id)
  get_request("/users/#{user_id}/brands", { access_token: @access_token }).body
end

#get_user_items(user_id, filters = {}) ⇒ Object



87
88
89
90
91
# File 'lib/mercadolibre/core/users.rb', line 87

def get_user_items(user_id, filters={})
  token_attr = { access_token: @access_token }

  get_request("/users/#{user_id}/items/search", filters.merge(token_attr)).body
end

#get_user_listing_type_availability(listing_type, category_id) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/mercadolibre/core/users.rb', line 78

def get_user_listing_type_availability(listing_type, category_id)
  filters = {
    access_token: @access_token,
    category_id: category_id
  }

  get_request("/users/#{user_id}/available_listing_type/#{listing_type}", filters).body
end

#get_user_payment_methods(user_id) ⇒ Object



41
42
43
# File 'lib/mercadolibre/core/users.rb', line 41

def get_user_payment_methods(user_id)
  get_request("/users/#{user_id}/payment_methods", { access_token: @access_token }).body
end

#get_user_promotion_packs(user_id, listing_type = nil, category_id = nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/mercadolibre/core/users.rb', line 53

def get_user_promotion_packs(user_id, listing_type=nil, category_id=nil)
  filters = { access_token: @access_token }

  if category_id.present?
    filters[:categoryId] = category_id
  end

  if listing_type.present?
    url = "/users/#{user_id}/classifieds_promotion_packs/#{listing_type}"
  else
    url = "/users/#{user_id}/classifieds_promotion_packs"
  end

  get_request(url, filters).body
end

#get_users(user_ids) ⇒ Object



4
5
6
# File 'lib/mercadolibre/core/users.rb', line 4

def get_users(user_ids)
  get_request('/users', { ids: user_ids.join(',') }).body
end

#update_user(user_id, attrs) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/mercadolibre/core/users.rb', line 21

def update_user(user_id, attrs)
  payload = attrs.to_json

  headers = { content_type: :json }

  put_request("/users/#{user_id}?access_token=#{@access_token}", payload, headers).body
end