-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from MortarStone/deb/add_exceptions
Add exceptions
- Loading branch information
Showing
31 changed files
with
344 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
example_id | status | run_time | | ||
-------------------------------------------------- | ------ | --------------- | | ||
./spec/deka/client_spec.rb[1:1:1:1] | passed | 0.00168 seconds | | ||
./spec/deka/client_spec.rb[1:1:2:1] | passed | 0.00481 seconds | | ||
./spec/deka/endpoints/families_spec.rb[1:1:1] | passed | 0.00204 seconds | | ||
./spec/deka/endpoints/families_spec.rb[1:1:2] | passed | 0.0032 seconds | | ||
./spec/deka/endpoints/families_spec.rb[1:2:1] | passed | 0.00226 seconds | | ||
./spec/deka/endpoints/organizations_spec.rb[1:1:1] | passed | 0.00175 seconds | | ||
./spec/deka/endpoints/purposes_spec.rb[1:1:1] | passed | 0.00204 seconds | | ||
./spec/deka/endpoints/purposes_spec.rb[1:1:2] | passed | 0.0018 seconds | | ||
./spec/deka/endpoints/transactions_spec.rb[1:1:1] | passed | 0.00204 seconds | | ||
./spec/deka/endpoints/transactions_spec.rb[1:1:2] | passed | 0.00262 seconds | | ||
./spec/deka/endpoints/transactions_spec.rb[1:2:1] | passed | 0.00206 seconds | | ||
./spec/deka/endpoints/users_spec.rb[1:1:1] | passed | 0.00269 seconds | | ||
./spec/deka/endpoints/users_spec.rb[1:1:2] | passed | 0.00471 seconds | | ||
./spec/deka/endpoints/users_spec.rb[1:2:1] | passed | 0.00218 seconds | | ||
./spec/deka_spec.rb[1:1] | passed | 0.00083 seconds | | ||
./spec/deka/client_spec.rb[1:1:1:1] | passed | 0.00242 seconds | | ||
./spec/deka/client_spec.rb[1:1:2:1] | passed | 0.23839 seconds | | ||
./spec/deka/endpoints/families_spec.rb[1:1:1] | passed | 0.24978 seconds | | ||
./spec/deka/endpoints/families_spec.rb[1:1:2] | passed | 0.22075 seconds | | ||
./spec/deka/endpoints/families_spec.rb[1:2:1] | passed | 0.24196 seconds | | ||
./spec/deka/endpoints/organizations_spec.rb[1:1:1] | passed | 0.26343 seconds | | ||
./spec/deka/endpoints/purposes_spec.rb[1:1:1] | passed | 0.22289 seconds | | ||
./spec/deka/endpoints/purposes_spec.rb[1:1:2] | passed | 0.21893 seconds | | ||
./spec/deka/endpoints/transactions_spec.rb[1:1:1] | passed | 0.26693 seconds | | ||
./spec/deka/endpoints/transactions_spec.rb[1:1:2] | passed | 0.31352 seconds | | ||
./spec/deka/endpoints/transactions_spec.rb[1:2:1] | passed | 0.24392 seconds | | ||
./spec/deka/endpoints/users_spec.rb[1:1:1] | passed | 0.2215 seconds | | ||
./spec/deka/endpoints/users_spec.rb[1:1:2] | passed | 0.2559 seconds | | ||
./spec/deka/endpoints/users_spec.rb[1:2:1] | passed | 0.25194 seconds | | ||
./spec/deka_spec.rb[1:1] | passed | 0.00128 seconds | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require_relative 'helper' | ||
|
||
user = @client.user(100_000_000) | ||
print_user(user) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require_relative 'helper' | ||
|
||
transactions = @client.transactions | ||
# transactions = @client.transactions('filter[status]' => 'success,settled,refunded') | ||
transactions = @client.transactions('filter[status]' => 'failed,voided,pending,declined', 'page[number]' => 11) | ||
print_transactions(transactions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require_relative 'helper' | ||
|
||
family = @client.user_family(1) | ||
family = @client.user_family(613) | ||
print_family(family) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require_relative 'helper' | ||
|
||
users = @client.users | ||
users = @client.users('filter[has_family]': false) | ||
print_users(users) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require_relative 'deka/client' | ||
require_relative 'deka/exceptions' | ||
require_relative 'deka/version' | ||
|
||
module Deka | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
require 'faraday' | ||
require 'json' | ||
|
||
require_relative 'exceptions' | ||
require_relative 'endpoints/families' | ||
require_relative 'endpoints/organizations' | ||
require_relative 'endpoints/purposes' | ||
require_relative 'endpoints/transactions' | ||
require_relative 'endpoints/users' | ||
require_relative 'response_handler' | ||
|
||
Dir[File.join(__dir__, 'endpoints', '*.rb')].each { |file| require file } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
|
||
module Deka | ||
class ResponseHandler | ||
attr_accessor :response | ||
|
||
def initialize(response) | ||
@response = response | ||
end | ||
|
||
def call | ||
handle_response | ||
end | ||
|
||
private | ||
|
||
def handle_response | ||
case response.status | ||
when 200..201 | ||
format_response | ||
when 202..299 | ||
nil # nothing to do | ||
when 400 | ||
raise Deka::Exceptions::BadRequestError, error_message | ||
when 401 | ||
raise Deka::Exceptions::UnauthorizedError, error_message | ||
when 403 | ||
raise Deka::Exceptions::ForbiddenError, error_message | ||
when 404 | ||
raise Deka::Exceptions::NotFoundError, error_message | ||
when 500 | ||
raise Deka::Exceptions::ResponseError, error_message | ||
end | ||
end | ||
|
||
def error_message | ||
"#{response.status} #{response.reason_phrase}" | ||
end | ||
|
||
def format_response | ||
results = JSON.parse(response.body, symbolize_names: true) | ||
results[:headers] = response.headers | ||
results | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 9 additions & 13 deletions
22
spec/vcr_cassettes/Deka_Client/_connect/with_invalid_organization_uuid/raises_an_error.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.