Class: VenmoAPI::User

Inherits:
Object
  • Object
show all
Defined in:
lib/venmo/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj, response_type) ⇒ User

Returns a new instance of User.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/venmo/user.rb', line 8

def initialize(obj, response_type)
  self.access_token = obj[:access_token]
  self.response_type = response_type
  if response_type == 'code'
    self.expires_in = obj[:expires_in]
    self.refresh_token = obj[:refresh_token]
    self.token_type = obj[:bearer]
    self.token_updated = Time.now
    self.data = obj[:user]
  end
  VenmoAPI::Helper::recursive_symbolize_keys! self.data
  validate_properties response_type
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



7
8
9
# File 'lib/venmo/user.rb', line 7

def access_token
  @access_token
end

#dataObject

Returns the value of attribute data.



7
8
9
# File 'lib/venmo/user.rb', line 7

def data
  @data
end

#expires_inObject

Returns the value of attribute expires_in.



7
8
9
# File 'lib/venmo/user.rb', line 7

def expires_in
  @expires_in
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



7
8
9
# File 'lib/venmo/user.rb', line 7

def refresh_token
  @refresh_token
end

#response_typeObject

Returns the value of attribute response_type.



7
8
9
# File 'lib/venmo/user.rb', line 7

def response_type
  @response_type
end

#token_typeObject

Returns the value of attribute token_type.



7
8
9
# File 'lib/venmo/user.rb', line 7

def token_type
  @token_type
end

#token_updatedObject

Returns the value of attribute token_updated.



7
8
9
# File 'lib/venmo/user.rb', line 7

def token_updated
  @token_updated
end

Instance Method Details

#get_friends(options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/venmo/user.rb', line 38

def get_friends (options = {})
  if options[:id]
    url = VenmoAPI::Helper::VENMO_BASE_URL + 'users/' + options[:id] + '/friends?access_token=' + self.access_token
  else
    if self.data[:user][:id]
      url = VenmoAPI::Helper::VENMO_BASE_URL + 'users/' + self.data[:user][:id] + '/friends?access_token=' + self.access_token
    else
      raise "get_friends must be called with an id if there is no id present on the current user"
    end
  end
  url += options[:before] ? "&before=" + options[:before] : ''
  url += options[:after] ? "&after=" + options[:after] : ''
  url += options[:limit] ? "&limit=" + options[:limit] : ''
  res = Net::HTTP.get(URI(url))
  return JSON.parse(res)
end

#get_info(update = true) ⇒ Object



31
32
33
34
35
36
# File 'lib/venmo/user.rb', line 31

def get_info(update = true)
  if update
    update_info
  end
  return self.data
end

#get_payment(id) ⇒ Object



66
67
68
69
70
# File 'lib/venmo/user.rb', line 66

def get_payment (id)
  uri = URI(VenmoAPI::Helper::VENMO_BASE_URL + 'payments/' + id.to_s + '?access_token=' + self.access_token)
  res = Net::HTTP.get(uri)
  return JSON.parse(res)
end

#get_recent_paymentsObject



72
73
74
75
76
# File 'lib/venmo/user.rb', line 72

def get_recent_payments
  uri = URI(VenmoAPI::Helper::VENMO_BASE_URL + 'payments?access_token=' + self.access_token)
  res = Net::HTTP.get(uri)
  return JSON.parse(res)
end

#get_user(id) ⇒ Object



55
56
57
58
59
# File 'lib/venmo/user.rb', line 55

def get_user(id)
  uri = URI(VenmoAPI::Helper::VENMO_BASE_URL + 'users/' + id.to_s + '?access_token=' + self.access_token)
  res = Net::HTTP.get(uri)
  return JSON.parse(res)
end

#make_payment(options = {}) ⇒ Object



61
62
63
64
# File 'lib/venmo/user.rb', line 61

def make_payment (options = {})
  payment = Payment.new(options)
  return payment.send self.access_token
end

#update_infoObject



22
23
24
25
26
27
28
29
# File 'lib/venmo/user.rb', line 22

def update_info
  uri = URI(VenmoAPI::Helper::VENMO_BASE_URL + 'me?access_token=' + self.access_token)
  res = Net::HTTP.get(uri)
  res_data = JSON.parse(res)
  if res_data["data"]
    self.data = VenmoAPI::Helper::recursive_symbolize_keys! res_data["data"]
  end
end