Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 45 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,41 +49,65 @@ Everyone interacting in the Hyperwallet::Ruby project’s codebases, issue track
payees = payee_connector.index
```

#### create
#### Create
```ruby
payload2 = {:client_user_id => 'test5userid5',
:profile_type => 'INDIVIDUAL' ,
:first_name => 'Han',
:last_name => 'Solo' ,
:date_of_birth => '1980-11-12',
:email => 'jgtr7@hey.com',
:address_line1 => '675 Dolores St',
:city => 'Berkeley' ,
:state_province => 'CA' ,
:country => 'US',
:postal_code => '94704',
:program_token => 'prg-1bd466b5-2a58-4e3a-8942-6a93591a9a86' }
payload = {
:client_user_id => 'test5userid5',
:profile_type => 'INDIVIDUAL' ,
:first_name => 'Han',
:last_name => 'Solo',
:date_of_birth => '1980-11-12',
:email => 'jgtr7@hey.com',
:address_line1 => '675 Dolores St',
:city => 'Berkeley',
:state_province => 'CA',
:country => 'US',
:postal_code => '94704',
:program_token => 'prg-1bd466b5-2a58-4e3a-8942-6a93591a9a86'
}

new_payee2 = Hyperwallet::Resources::Payee.create(payload2)
new_payee2 = Hyperwallet::Resources::Payee.create(payload)

```
#### show
#### Show
```ruby
user_token = "usr-6ac6618e-44fe-4252-af8c-76cd4e68f601"
payee = Hyperwallet::Resources::Payee.new(token: user_token)
payee.show
```
#### Update
```ruby
user_token = "usr-6ac6618e-44fe-4252-af8c-76cd4e68f601"
payee = Hyperwallet::Resources::Payee.new
payee.show(token: user_token)
payee = Hyperwallet::Resources::Payee.new(token: user_token)

payload = {
:client_user_id => 'test5userid5',
:profile_type => 'INDIVIDUAL' ,
:first_name => 'Han',
:last_name => 'Solo',
:date_of_birth => '1980-11-12',
:email => 'jgtr7@hey.com',
:address_line1 => '675 Dolores St',
:city => 'Berkeley',
:state_province => 'CA',
:country => 'US',
:postal_code => '94704',
:program_token => 'prg-1bd466b5-2a58-4e3a-8942-6a93591a9a86'
}

payee.update(attributes: payload)
```
#### Getting a new auth token
```ruby
user_token = "usr-6ac6618e-44fe-4252-af8c-76cd4e68f601"
existing_payee = Hyperwallet::Resources::Payee.new(token: user_token)
token = existing_payee.get_authentication_token
payee = Hyperwallet::Resources::Payee.new(token: user_token)
token = payee.get_authentication_token
```
#### Getting the list of bank accounts for a user
```ruby
user_token = "usr-6ac6618e-44fe-4252-af8c-76cd4e68f601"
existing_payee = Hyperwallet::Resources::Payee.new(token: user_token)
bank_accounts = existing_payee.index_bank_accounts
payee = Hyperwallet::Resources::Payee.new(token: user_token)
bank_accounts = payee.index_bank_accounts
```
### Transfer Methods
#### Getting transfer methods
Expand Down
124 changes: 69 additions & 55 deletions lib/hyperwallet/api/client.rb
Original file line number Diff line number Diff line change
@@ -1,69 +1,83 @@
# frozen_string_literal: true

require 'faraday'

class Hyperwallet::Api::Client < Hyperwallet::Api::Config
module Hyperwallet
module Api
# Client configuration and functionalities class
class Client < Hyperwallet::Api::Config
attr_accessor :client_id, :conn, :response, :body, :errors, :previous_payload

attr_accessor :client_id, :conn, :response, :body, :errors, :previous_payload
def initialize
@conn = connector
add_headers
end

def initialize
# @client_id = client_id
@conn = get_connector
add_headers
end
def get(resource:)
self.response = conn.get do |request|
request.url resource
end
handle_response
end

def get(resource:)
self.response = conn.get do |request|
request.url resource
end
handle_response
end
def post(resource:, payload: nil)
@previous_payload = payload
self.response = conn.post do |request|
request.url resource
request.body = payload
end
handle_response
end

def post(resource:, payload: nil)
@previous_payload = payload
self.response = conn.post do |request|
request.url resource
request.body = payload
end
handle_response
end
def put(resource:, payload: nil)
@previous_payload = payload
self.response = conn.put do |request|
request.url resource
request.body = payload
end
handle_response
end

private
private

def handle_response
if self.response.success?
@body = JSON.parse(self.response.body) unless self.response.body.empty?
else
@errors = JSON.parse(self.response.body)
end
end
def handle_response
if response.success?
@body = JSON.parse(response.body) unless response.body.empty?
else
@errors = JSON.parse(response.body)
end
end

def get_connector
Faraday.new(url: base_url, proxy: self.class.superclass.proxy) do |conn|
conn.adapter :net_http
conn.basic_auth(self.class.superclass.api_user, self.class.superclass.api_password)
end
end
def connector
Faraday.new(url: base_url, proxy: self.class.superclass.proxy) do |conn|
conn.adapter :net_http
conn.basic_auth(self.class.superclass.api_user, self.class.superclass.api_password)
end
end

def request_url_for(resource)
base_url + "/" + resource
end
def request_url_for(resource)
"#{base_url}/#{resource}"
end

def base_url
active_url + API_VERSION
end
def base_url
active_url + API_VERSION
end

def active_url
if self.class.superclass.uat?
UAT_URL
elsif self.class.superclass.production?
PRODUCTION_URL
end
end
def active_url
if self.class.superclass.uat?
UAT_URL
elsif self.class.superclass.production?
PRODUCTION_URL
end
end

def add_headers
conn.headers.merge!(
{
'Content-Type'=> "application/json"
}
)
def add_headers
conn.headers.merge!(
{
'Content-Type' => 'application/json'
}
)
end
end
end
end
end
5 changes: 3 additions & 2 deletions lib/hyperwallet/resources/payee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ def show(token: nil)
handle_response
end

def update(token:, attributes_to_update: )
connector.put(resource: ENDPOINT + "/" + token, payload: JSON.generate(prepare_payload(payload_attributes: attributes_to_update)))
def update(attributes:, token: nil)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I like the name change, changing it from attributes_to_update to attributes means that an app using this gem would suddenly break after calling update. If we are sure that this method is not being used then it might be ok.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point; I don't think the method is being used, though it may cause issues in the future if we need to use it. Possibly the best is to keep it as flexible as possible.

token ||= @token
connector.put(resource: ENDPOINT + "/" + token, payload: JSON.generate(prepare_payload(payload_attributes: attributes)))
handle_response
end

Expand Down