Class: Etsy::User

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/etsy/user.rb

Overview

User

Represents a single Etsy user - has the following attributes:

[id] The unique identifier for this user [username] This user's username [email] This user's email address (authenticated calls only)

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

included, #initialize, #result, #secret, #token

Class Method Details

.find(*identifiers_and_options) ⇒ Object

Retrieve one or more users by name or ID:

Etsy::User.find('reagent')

You can find multiple users by passing an array of identifiers:

Etsy::User.find(['reagent', 'littletjane'])


31
32
33
# File 'lib/etsy/user.rb', line 31

def self.find(*identifiers_and_options)
  find_one_or_more('users', identifiers_and_options)
end

.myself(token, secret, options = {}) ⇒ Object

Retrieve the currently authenticated user.



37
38
39
# File 'lib/etsy/user.rb', line 37

def self.myself(token, secret, options = {})
  find('__SELF__', {:access_token => token, :access_secret => secret}.merge(options))
end

Instance Method Details

#addressesObject

The addresses associated with this user.



49
50
51
52
# File 'lib/etsy/user.rb', line 49

def addresses
  options = (token && secret) ? {:access_token => token, :access_secret => secret} : {}
  @addresses ||= Address.find(username, options)
end

#created_atObject

Time that this user was created



86
87
88
# File 'lib/etsy/user.rb', line 86

def created_at
  Time.at(created)
end

#profileObject

The profile associated with this user.



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/etsy/user.rb', line 56

def profile
  unless @profile
    if associated_profile
      @profile = Profile.new(associated_profile)
    else
      options = {:fields => 'user_id', :includes => 'Profile'}
      options = options.merge(:access_token => token, :access_secret => secret) if (token && secret)
      tmp = User.find(username, options)
      @profile = Profile.new(tmp.associated_profile)
    end
  end
  @profile
end

#shopObject

The shop associated with this user.



43
44
45
# File 'lib/etsy/user.rb', line 43

def shop
  @shop ||= shops.first
end

#shopsObject



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/etsy/user.rb', line 70

def shops
  unless @shops
    if associated_shops
      @shops = associated_shops.map { |shop| Shop.new(shop) }
    else
      options = {:fields => 'user_id', :includes => 'Shops'}
      options = options.merge(:access_token => token, :access_secret => secret) if (token && secret)
      tmp = User.find(username, options)
      @shops = tmp.associated_shops.map { |shop| Shop.new(shop) }
    end
  end
  @shops
end