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'])


33
34
35
# File 'lib/etsy/user.rb', line 33

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.



39
40
41
# File 'lib/etsy/user.rb', line 39

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.



51
52
53
54
# File 'lib/etsy/user.rb', line 51

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

#bill_chargesObject



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/etsy/user.rb', line 86

def bill_charges
  unless @bill_charges
    if associated_bill_charges
      @bill_charges = associated_bill_charges.map { |bill_charge| BillCharge.new(bill_charge) }
    else
      options = {:fields => 'user_id', :includes => 'BillCharges'}
      options = options.merge(:access_token => token, :access_secret => secret) if (token && secret)
      tmp = User.find(username, options)
      @bill_charges = tmp.associated_bill_charges.map { |bill_charge| BillCharge.new(bill_charge) }
    end
  end
  @bill_charges
end

#bill_paymentsObject



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/etsy/user.rb', line 100

def bill_payments
  unless @bill_payments
    if associated_bill_payments
      @bill_payments = associated_bill_payments.map { |bill_payment| BillPayment.new(bill_payment) }
    else
      options = {:fields => 'user_id', :includes => 'BillPayments'}
      options = options.merge(:access_token => token, :access_secret => secret) if (token && secret)
      tmp = User.find(username, options)
      @bill_payments = tmp.associated_bill_payments.map { |bill_payment| BillPayment.new(bill_payment) }
    end
  end
  @bill_payments
end

#bought_listingsObject

Return a set of listings that have been bought



131
132
133
134
135
136
# File 'lib/etsy/user.rb', line 131

def bought_listings
  unless @bought_listings
    @bought_listings = Listing.bought_listings(id, {:access_token => token, :access_secret => secret})
  end
  @bought_listings
end

#created_atObject

Time that this user was created



116
117
118
# File 'lib/etsy/user.rb', line 116

def created_at
  Time.at(created)
end

#favoritesObject

Retrieve list of favorited items for this user



122
123
124
125
126
127
# File 'lib/etsy/user.rb', line 122

def favorites
  unless @favorites
    @favorites = Listing.find_all_user_favorite_listings(id, {:access_token => token, :access_secret => secret})
  end
  @favorites
end

#profileObject

The profile associated with this user.



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

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.



45
46
47
# File 'lib/etsy/user.rb', line 45

def shop
  @shop ||= shops.first
end

#shopsObject



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

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