Class: VenmoAPI::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



9
10
11
12
# File 'lib/venmo/client.rb', line 9

def initialize (options = {})
  yield(self) if block_given?
  validate_credentials
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



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

def client_id
  @client_id
end

#response_typeObject

Returns the value of attribute response_type.



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

def response_type
  @response_type
end

#scopeObject

Returns the value of attribute scope.



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

def scope
  @scope
end

#secretObject

Returns the value of attribute secret.



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

def secret
  @secret
end

Instance Method Details



14
15
16
# 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) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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

#credentialsObject



36
37
38
39
40
41
42
43
# 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) ⇒ Object



51
52
53
54
55
# 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) ⇒ Object



57
58
59
60
61
# 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) ⇒ Object



45
46
47
48
49
# 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