Module: PayTrace::Debug
- Defined in:
- lib/paytrace/debug.rb
Overview
Useful helper methods for debugging.
Class Method Summary collapse
-
.configure_test(un = "demo123", pw = "demo123", domain = "stage.paytrace.com") ⇒ Object
Helper method to configure a default test environment.
-
.diff_requests(expected_raw, actual_raw, case_sensitive = false) ⇒ Object
verify whether two requests match.
-
.dump_transaction ⇒ Object
Helper that loops through the response values and dumps them out.
-
.log(msg) ⇒ Object
Formatted output for a text message.
-
.split_request_string(raw) ⇒ Object
split a raw request string into an array of name-value tuples.
-
.split_tuples(raw, case_sensitive = false) ⇒ Object
helper method to make CodeClimate happy.
-
.trace(&block) ⇒ Object
Helper method to dump a request response pair.
Class Method Details
.configure_test(un = "demo123", pw = "demo123", domain = "stage.paytrace.com") ⇒ Object
Helper method to configure a default test environment. Accepts username, password, and domain parameters. domain defaults to “stage.paytrace.com” and the username/password default to the credentials for the sandbox account
57 58 59 60 61 62 63 |
# File 'lib/paytrace/debug.rb', line 57 def self.configure_test(un = "demo123", pw = "demo123", domain = "stage.paytrace.com") PayTrace.configure do |config| config.user_name = un config.password = pw config.domain = domain end end |
.diff_requests(expected_raw, actual_raw, case_sensitive = false) ⇒ Object
verify whether two requests match
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/paytrace/debug.rb', line 71 def self.diff_requests(expected_raw, actual_raw, case_sensitive = false) whats_wrong = [] expected = PayTrace::Debug.split_tuples(expected_raw, case_sensitive) actual = PayTrace::Debug.split_tuples(actual_raw, case_sensitive) expected_remaining = [] actual_extra = actual.dup expected.each do |tuple| idx = actual_extra.find_index(tuple) if idx.nil? expected_remaining << tuple else actual_extra.delete_at(idx) end end expected_remaining.each do |tuple| whats_wrong << "Missing expected property #{tuple[0]}~#{tuple[1]}" end actual_extra.each do |tuple| whats_wrong << "Extra unexpected property #{tuple[0]}~#{tuple[1]}" end whats_wrong end |
.dump_transaction ⇒ Object
Helper that loops through the response values and dumps them out
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/paytrace/debug.rb', line 10 def self.dump_transaction puts "[REQUEST] #{PayTrace::API::Gateway.last_request}" response = PayTrace::API::Gateway.last_response_object if(response.has_errors?) response.errors.each do |key, value| puts "[RESPONSE] ERROR: #{key.ljust(20)}#{value}" end else response.values.each do |key, value| puts "[RESPONSE] #{key.ljust(20)}#{value}" end end end |
.log(msg) ⇒ Object
Formatted output for a text message.
25 26 27 |
# File 'lib/paytrace/debug.rb', line 25 def self.log(msg) puts ">>>>>> #{msg}" end |
.split_request_string(raw) ⇒ Object
split a raw request string into an array of name-value tuples
30 31 32 |
# File 'lib/paytrace/debug.rb', line 30 def self.split_request_string(raw) raw.split('|').map {|kv_pair| kv_pair.split('~')} end |
.split_tuples(raw, case_sensitive = false) ⇒ Object
helper method to make CodeClimate happy
66 67 68 |
# File 'lib/paytrace/debug.rb', line 66 def self.split_tuples(raw, case_sensitive = false) PayTrace::Debug.split_request_string(raw).map {|tuple| case_sensitive ? tuple : [tuple[0].upcase, tuple[1]]} end |
.trace(&block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/paytrace/debug.rb', line 40 def self.trace(&block) PayTrace::API::Gateway.debug = true begin yield rescue PayTrace::Exceptions::ErrorResponse => e puts "[REQUEST] #{PayTrace::API::Gateway.last_request}" puts "[RESPONSE] #{PayTrace::API::Gateway.last_response}" raise else dump_transaction end end |