Class: VenmoAPI::User
- Inherits:
-
Object
- Object
- VenmoAPI::User
- Defined in:
- lib/venmo/user.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#data ⇒ Object
Returns the value of attribute data.
-
#expires_in ⇒ Object
Returns the value of attribute expires_in.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#response_type ⇒ Object
Returns the value of attribute response_type.
-
#token_type ⇒ Object
Returns the value of attribute token_type.
-
#token_updated ⇒ Object
Returns the value of attribute token_updated.
Instance Method Summary collapse
- #get_friends(options = {}) ⇒ Object
- #get_info(update = true) ⇒ Object
- #get_payment(id) ⇒ Object
- #get_recent_payments ⇒ Object
- #get_user(id) ⇒ Object
-
#initialize(obj, response_type) ⇒ User
constructor
A new instance of User.
- #make_payment(options = {}) ⇒ Object
- #update_info ⇒ Object
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_token ⇒ Object
Returns the value of attribute access_token.
7 8 9 |
# File 'lib/venmo/user.rb', line 7 def access_token @access_token end |
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/venmo/user.rb', line 7 def data @data end |
#expires_in ⇒ Object
Returns the value of attribute expires_in.
7 8 9 |
# File 'lib/venmo/user.rb', line 7 def expires_in @expires_in end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
7 8 9 |
# File 'lib/venmo/user.rb', line 7 def refresh_token @refresh_token end |
#response_type ⇒ Object
Returns the value of attribute response_type.
7 8 9 |
# File 'lib/venmo/user.rb', line 7 def response_type @response_type end |
#token_type ⇒ Object
Returns the value of attribute token_type.
7 8 9 |
# File 'lib/venmo/user.rb', line 7 def token_type @token_type end |
#token_updated ⇒ Object
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 ( = {}) if [:id] url = VenmoAPI::Helper::VENMO_BASE_URL + 'users/' + [: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 += [:before] ? "&before=" + [:before] : '' url += [:after] ? "&after=" + [:after] : '' url += [:limit] ? "&limit=" + [: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_payments ⇒ Object
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 ( = {}) payment = Payment.new() return payment.send self.access_token end |
#update_info ⇒ Object
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 |