class VenmoAPI::Client
Attributes
client_id[RW]
response_type[RW]
scope[RW]
secret[RW]
Public Class Methods
new(options = {}) { |self| ... }
click to toggle source
# File lib/venmo/client.rb, line 9 def initialize (options = {}) yield(self) if block_given? validate_credentials end
Public Instance Methods
auth_link()
click to toggle source
# File lib/venmo/client.rb, line 14 def auth_link return VenmoAPI::Helper::VENMO_BASE_URL + 'oauth/authorize?client_id=' + client_id.to_s + '&scope=' + scope.join(' ') + '&response_type=' + response_type end
authenticate(key)
click to toggle source
# File lib/venmo/client.rb, line 18 def authenticate (key) if self.response_type == 'code' uri = URI(VenmoAPI::Helper::VENMO_BASE_URL + 'oauth/access_token') res = Net::HTTP.post_form(uri, 'client_id' => self.client_id, 'client_secret' => self.secret, 'code' => key) res_data = JSON.parse(res.body) puts res_data.inspect if res_data['access_token'] user = User.new(VenmoAPI::Helper::recursive_symbolize_keys!(res_data), self.response_type); else user = nil; end return user; else user = User.new({:access_token => key}, self.response_type) return user; end end
credentials()
click to toggle source
# File lib/venmo/client.rb, line 36 def credentials { :client_id => client_id, :secret => secret, :scope => scope, :response_type => response_type } end
get_payment(id, access_token)
click to toggle source
# File lib/venmo/client.rb, line 51 def get_payment (id, access_token) uri = URI(VenmoAPI::Helper::VENMO_BASE_URL + 'payments/' + id.to_s + '?access_token=' + access_token) res = Net::HTTP.get(uri) return JSON.parse(res) end
get_recent_payments(access_token)
click to toggle source
# File lib/venmo/client.rb, line 57 def get_recent_payments access_token uri = URI(VenmoAPI::Helper::VENMO_BASE_URL + 'payments?access_token=' + access_token) res = Net::HTTP.get(uri) return JSON.parse(res) end
get_user(id, access_token)
click to toggle source
# File lib/venmo/client.rb, line 45 def get_user(id, access_token) uri = URI(VenmoAPI::Helper::VENMO_BASE_URL + 'users/' + id.to_s + '?access_token=' + access_token) res = Net::HTTP.get(uri) return JSON.parse(res) end
Private Instance Methods
validate_credentials()
click to toggle source
# File lib/venmo/client.rb, line 64 def validate_credentials credentials.each do |credential, value| if credential == :client_id && !value.is_a?(Fixnum) raise "Client ID must be a number" elsif credential == :secret && !value.is_a?(String) raise "Secret must be a string" elsif credential == :scope && !value.is_a?(Array) raise "Scope must be an array" elsif credential == :response_type && !value.is_a?(String) && (value == 'code' || value == 'token') raise "Response Type must be equal to 'code' or 'token'" end end end