Module: Nihaopay::Api::ClassMethods
- Defined in:
- lib/nihaopay/mixins/api.rb
Instance Method Summary collapse
- #authorization ⇒ Object
- #base_url ⇒ Object
- #host ⇒ Object
- #merchant_token ⇒ Object
- #validate_collection!(response) ⇒ Object
- #validate_resource!(response) ⇒ Object
Instance Method Details
#authorization ⇒ Object
20 21 22 |
# File 'lib/nihaopay/mixins/api.rb', line 20 def { 'Authorization' => "Bearer #{merchant_token}" } end |
#base_url ⇒ Object
16 17 18 |
# File 'lib/nihaopay/mixins/api.rb', line 16 def base_url "#{host}/#{VERSION}" end |
#host ⇒ Object
12 13 14 |
# File 'lib/nihaopay/mixins/api.rb', line 12 def host Nihaopay.test_mode ? TEST_HOST : LIVE_HOST end |
#merchant_token ⇒ Object
24 25 26 |
# File 'lib/nihaopay/mixins/api.rb', line 24 def merchant_token @token || Nihaopay.token end |
#validate_collection!(response) ⇒ Object
34 35 36 37 38 |
# File 'lib/nihaopay/mixins/api.rb', line 34 def validate_collection!(response) return if response.parsed_response['transactions'] parsed_response = response.parsed_response.map { |k, v| "#{k}: #{v}" }.join(', ') fail Nihaopay::TransactionError, parsed_response end |
#validate_resource!(response) ⇒ Object
28 29 30 31 32 |
# File 'lib/nihaopay/mixins/api.rb', line 28 def validate_resource!(response) return if response.parsed_response['id'] parsed_response = response.parsed_response.map { |k, v| "#{k}: #{v}" }.join(', ') fail Nihaopay::TransactionError, parsed_response end |