Class: SynapsePay::Client

Inherits:
APIClient show all
Defined in:
lib/synapse_pay/client.rb

Instance Attribute Summary collapse

Attributes inherited from APIClient

#headers, #params

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from APIClient

#execute, #inspect

Constructor Details

#initialize(oauth_consumer_key = nil, refresh_token = nil) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
# File 'lib/synapse_pay/client.rb', line 12

def initialize(oauth_consumer_key=nil, refresh_token=nil)
  self.refresh_from({
    :oauth_consumer_key => oauth_consumer_key,
    :refresh_token => refresh_token
  })
end

Instance Attribute Details

#expires_atObject (readonly)

Returns the value of attribute expires_at.



3
4
5
# File 'lib/synapse_pay/client.rb', line 3

def expires_at
  @expires_at
end

#expires_inObject (readonly)

Returns the value of attribute expires_in.



3
4
5
# File 'lib/synapse_pay/client.rb', line 3

def expires_in
  @expires_in
end

#jsonObject (readonly)

Returns the value of attribute json.



3
4
5
# File 'lib/synapse_pay/client.rb', line 3

def json
  @json
end

#oauth_consumer_keyObject (readonly)

Returns the value of attribute oauth_consumer_key.



3
4
5
# File 'lib/synapse_pay/client.rb', line 3

def oauth_consumer_key
  @oauth_consumer_key
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



3
4
5
# File 'lib/synapse_pay/client.rb', line 3

def refresh_token
  @refresh_token
end

#user_idObject (readonly)

Returns the value of attribute user_id.



3
4
5
# File 'lib/synapse_pay/client.rb', line 3

def user_id
  @user_id
end

#usernameObject (readonly)

Returns the value of attribute username.



3
4
5
# File 'lib/synapse_pay/client.rb', line 3

def username
  @username
end

Class Method Details

.login(username, password) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/synapse_pay/client.rb', line 32

def self.(username, password)
  method = APIMethod.new(
    :post,
    "/user/login",
    { :username => username, :password => password }, {}, self)
  self.new.refresh_from(method.execute)
end

.refresh_access(refresh_token) ⇒ Object



41
42
43
44
# File 'lib/synapse_pay/client.rb', line 41

def self.refresh_access(refresh_token)
  c = Client.new(nil, refresh_token)
  c.refresh_access
end

Instance Method Details

#bank_mfa_devicesObject



62
63
64
# File 'lib/synapse_pay/client.rb', line 62

def bank_mfa_devices
  @bank_mfa_devices ||= BankMfaDeviceEndpoint.new(self)
end

#bank_mfa_questionsObject



66
67
68
# File 'lib/synapse_pay/client.rb', line 66

def bank_mfa_questions
  @bank_mfa_questions ||= BankMfaQuestionsEndpoint.new(self)
end

#bank_statusesObject



70
71
72
# File 'lib/synapse_pay/client.rb', line 70

def bank_statuses
  @bank_statuses ||= BankStatusEndpoint.new(self)
end

#banksObject



58
59
60
# File 'lib/synapse_pay/client.rb', line 58

def banks
  @banks ||= BankEndpoint.new(self)
end

#cardsObject



74
75
76
# File 'lib/synapse_pay/client.rb', line 74

def cards
  @cards ||= CardEndpoint.new(self)
end

#depositsObject



78
79
80
# File 'lib/synapse_pay/client.rb', line 78

def deposits
  @deposits ||= DepositEndpoint.new(self)
end

#mass_paysObject



82
83
84
# File 'lib/synapse_pay/client.rb', line 82

def mass_pays
  @mass_pays ||= MassPayEndpoint.new(self)
end

#ordersObject



86
87
88
# File 'lib/synapse_pay/client.rb', line 86

def orders
  @orders ||= OrderEndpoint.new(self)
end

#refresh_access(refresh_token = nil) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/synapse_pay/client.rb', line 46

def refresh_access(refresh_token=nil)
  method = APIMethod.new(
    :post,
    "/user/refresh",
    { :refresh_token => refresh_token || @refresh_token }, {}, self)
  self.refresh_from(method.execute)
end

#refresh_from(json) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/synapse_pay/client.rb', line 19

def refresh_from(json)
  @json = Util.symbolize_keys(json)

  @oauth_consumer_key = @json[:oauth_consumer_key]
  @refresh_token = @json[:refresh_token]
  @expires_at = @json[:expires_at]
  @expires_in = @json[:expires_in]
  @username = @json[:username]
  @user_id = @json[:user_id]

  super({}, { :oauth_consumer_key => oauth_consumer_key })
end

#userObject



54
55
56
# File 'lib/synapse_pay/client.rb', line 54

def user
  @user ||= UserEndpoint.new(self)
end

#wiresObject



90
91
92
# File 'lib/synapse_pay/client.rb', line 90

def wires
  @wires ||= WireEndpoint.new(self)
end

#withdrawalsObject



94
95
96
# File 'lib/synapse_pay/client.rb', line 94

def withdrawals
  @withdrawals ||= WithdrawalEndpoint.new(self)
end