Class: Trustly::Api
- Inherits:
-
Object
- Object
- Trustly::Api
- Defined in:
- lib/trustly/api.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Signed
Instance Attribute Summary collapse
-
#api_host ⇒ Object
Returns the value of attribute api_host.
-
#api_is_https ⇒ Object
Returns the value of attribute api_is_https.
-
#api_port ⇒ Object
Returns the value of attribute api_port.
-
#last_request ⇒ Object
Returns the value of attribute last_request.
-
#trustly_publickey ⇒ Object
Returns the value of attribute trustly_publickey.
-
#trustly_verifyer ⇒ Object
Returns the value of attribute trustly_verifyer.
Instance Method Summary collapse
- #handle_response(request, httpcall) ⇒ Object
-
#initialize(host, port, is_https, pem_file) ⇒ Api
constructor
A new instance of Api.
- #insert_credentials(request) ⇒ Object
- #load_trustly_publickey(file) ⇒ Object
- #serialize_data(object) ⇒ Object
- #url_path(request = nil) ⇒ Object
- #verify_trustly_signed_notification(response) ⇒ Object
Constructor Details
#initialize(host, port, is_https, pem_file) ⇒ Api
Returns a new instance of Api.
25 26 27 28 29 30 31 |
# File 'lib/trustly/api.rb', line 25 def initialize(host,port,is_https,pem_file) self.api_host = host self.api_port = port self.api_is_https = is_https self.load_trustly_publickey(pem_file) end |
Instance Attribute Details
#api_host ⇒ Object
Returns the value of attribute api_host.
4 5 6 |
# File 'lib/trustly/api.rb', line 4 def api_host @api_host end |
#api_is_https ⇒ Object
Returns the value of attribute api_is_https.
4 5 6 |
# File 'lib/trustly/api.rb', line 4 def api_is_https @api_is_https end |
#api_port ⇒ Object
Returns the value of attribute api_port.
4 5 6 |
# File 'lib/trustly/api.rb', line 4 def api_port @api_port end |
#last_request ⇒ Object
Returns the value of attribute last_request.
4 5 6 |
# File 'lib/trustly/api.rb', line 4 def last_request @last_request end |
#trustly_publickey ⇒ Object
Returns the value of attribute trustly_publickey.
4 5 6 |
# File 'lib/trustly/api.rb', line 4 def trustly_publickey @trustly_publickey end |
#trustly_verifyer ⇒ Object
Returns the value of attribute trustly_verifyer.
4 5 6 |
# File 'lib/trustly/api.rb', line 4 def trustly_verifyer @trustly_verifyer end |
Instance Method Details
#handle_response(request, httpcall) ⇒ Object
41 42 43 |
# File 'lib/trustly/api.rb', line 41 def handle_response(request,httpcall) raise NotImplementedError end |
#insert_credentials(request) ⇒ Object
45 46 47 |
# File 'lib/trustly/api.rb', line 45 def insert_credentials(request) raise NotImplementedError end |
#load_trustly_publickey(file) ⇒ Object
33 34 35 |
# File 'lib/trustly/api.rb', line 33 def load_trustly_publickey(file) self.trustly_publickey = OpenSSL::PKey::RSA.new(File.read(file)) #.public_key end |
#serialize_data(object) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/trustly/api.rb', line 6 def serialize_data(object) serialized = "" if object.is_a?(Array) # Its an array object.each do |obj| serialized.concat(obj.is_a?(Hash) ? serialize_data(obj) : obj.to_s) end elsif object.is_a?(Hash) # Its a Hash object.sort.to_h.each do |key,value| serialized.concat(key.to_s).concat(serialize_data(value)) end else # Anything else: numbers, symbols, values serialized.concat object.to_s end return serialized end |
#url_path(request = nil) ⇒ Object
37 38 39 |
# File 'lib/trustly/api.rb', line 37 def url_path(request=nil) raise NotImplementedError end |
#verify_trustly_signed_notification(response) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/trustly/api.rb', line 49 def verify_trustly_signed_notification(response) method = response.get_method() uuid = response.get_uuid() signature = response.get_signature() data = response.get_data() return self._verify_trustly_signed_data(method, uuid, signature, data) end |