Class: TaobaoApi::User

Inherits:
Object
  • Object
show all
Includes:
BaseApi
Defined in:
lib/taobao_api/user.rb

Constant Summary collapse

@@configurable_attrs =
[:address, :level, :praise_rate, :type, :seller_credit, :nick, :location]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BaseApi

included, init_config, valid_config

Constructor Details

#initialize(nick) ⇒ User

Returns a new instance of User.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/taobao_api/user.rb', line 18

def initialize(nick)
  return if (options = self.class.get_result(nick)).blank?
  
  @@configurable_attrs.each do |attr_name|
    instance_variable_set("@#{attr_name}", options.search(attr_name.to_s))
  end

  @level       = @level.to_i
  @praise_rate = count_praise_rate(options)
  @address     = get_address(options)
end

Class Method Details

.<<(item) ⇒ Object



11
12
13
14
15
16
# File 'lib/taobao_api/user.rb', line 11

def @@configurable_attrs.<<(item)
  return self if item.blank?
  super(item.to_sym).uniq!
  TaobaoApi::User.send :attr_reader, item.to_sym
  self
end

.get_buyer_users_level(*nicks) ⇒ Object

获得买家用户等级 返回Hash { ‘tumayun’ => 10, ‘jcw’ => 12 } get_buyer_users_level(‘tumayun’, ‘jcw’)



33
34
35
36
37
# File 'lib/taobao_api/user.rb', line 33

def self.get_buyer_users_level(*nicks)
  options = { :method => 'taobao.users.get', :timestamp => Time.now.to_s(:db), :fields => 'nick, buyer_credit', :nicks => nicks.join(',') }
  users   = taobao_api_get(options).search('user') || []
  users.inject({}){ |h, user| h[user['nick']] = user['buyer_credit'].try(:[], 'level'); h }
end