Class: Dwolla::User

Inherits:
Object
  • Object
show all
Includes:
Connection
Defined in:
lib/dwolla/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ User

Returns a new instance of User.



16
17
18
# File 'lib/dwolla/user.rb', line 16

def initialize(attrs={})
  update_attributes(attrs)
end

Instance Attribute Details

#cityObject

Returns the value of attribute city.



5
6
7
# File 'lib/dwolla/user.rb', line 5

def city
  @city
end

#contact_typeObject

Returns the value of attribute contact_type.



5
6
7
# File 'lib/dwolla/user.rb', line 5

def contact_type
  @contact_type
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/dwolla/user.rb', line 5

def id
  @id
end

#imageObject

Returns the value of attribute image.



5
6
7
# File 'lib/dwolla/user.rb', line 5

def image
  @image
end

#latitudeObject

Returns the value of attribute latitude.



5
6
7
# File 'lib/dwolla/user.rb', line 5

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude.



5
6
7
# File 'lib/dwolla/user.rb', line 5

def longitude
  @longitude
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/dwolla/user.rb', line 5

def name
  @name
end

#oauth_tokenObject

Returns the value of attribute oauth_token.



5
6
7
# File 'lib/dwolla/user.rb', line 5

def oauth_token
  @oauth_token
end

#stateObject

Returns the value of attribute state.



5
6
7
# File 'lib/dwolla/user.rb', line 5

def state
  @state
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/dwolla/user.rb', line 5

def type
  @type
end

Class Method Details

.me(access_token) ⇒ Object



20
21
22
# File 'lib/dwolla/user.rb', line 20

def self.me(access_token)
  User.new(:oauth_token => access_token)
end

Instance Method Details

#balanceObject



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

def balance
  get('balance')
end

#contacts(options = {}) ⇒ Object



41
42
43
44
45
46
# File 'lib/dwolla/user.rb', line 41

def contacts(options = {})
  contacts_url = 'contacts'
  contacts = get(contacts_url, options)

  instances_from_contacts(contacts)
end

#fetchObject



24
25
26
27
28
# File 'lib/dwolla/user.rb', line 24

def fetch
  user_attributes = get('users')
  update_attributes(user_attributes)
  self
end

#request_money_from(source, amount, pin) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/dwolla/user.rb', line 58

def request_money_from(source, amount, pin)
  transaction = Transaction.new(:origin => self,
                                :source => source,
                                :type => :request,
                                :amount => amount,
                                :pin => pin)
  transaction.execute
end

#send_money_to(destination, amount, pin) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/dwolla/user.rb', line 48

def send_money_to(destination, amount, pin)
  transaction = Transaction.new(:origin => self,
                                :destination => destination,
                                :type => :send,
                                :amount => amount,
                                :pin => pin)

  transaction.execute
end

#update_attributes(attrs) ⇒ Object



30
31
32
33
34
35
# File 'lib/dwolla/user.rb', line 30

def update_attributes(attrs)
  attrs.each do |key, value|
    key_string = key.is_a?(String) ? key : key.to_s
    send("#{key_string.downcase}=".to_sym, value)
  end
end