Class: ZipMoney::Api
- Inherits:
-
Object
- Object
- ZipMoney::Api
- Defined in:
- lib/zipMoney/api.rb
Constant Summary collapse
- HTTP_METHOD_POST =
:post
- HTTP_METHOD_GET =
:get
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#options ⇒ Object
Returns the value of attribute options.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
-
#append_api_credentials(params) ⇒ Object
Appends api credentials to the request object.
-
#cancel(params) ⇒ Object
Makes cancel call on the zipMoney endpoint.
-
#capture(params) ⇒ Object
Makes capture call on the zipMoney endpoint.
-
#checkout(params) ⇒ Object
Makes checkout call on the zipMoney endpoint.
-
#configure(params) ⇒ Object
Makes configure call on the zipMoney endpoint.
-
#heartbeat ⇒ Object
Makes heartbeat call on the zipMoney endpoint.
-
#initialize(conf, options = {}) ⇒ Object
constructor
Initializes a new api object.
-
#is_param_defined(params) ⇒ Object
Checks if data is a Struct and calls the block passed as parameter if true.
-
#prepare_params(params) ⇒ Object
Converts the parameters(Hash) to json.
-
#query(params) ⇒ Object
Makes query call on the zipMoney endpoint.
-
#quote(params) ⇒ Object
Makes quote call on the zipMoney endpoint.
-
#refund(params) ⇒ Object
Makes refund call on the zipMoney endpoint.
-
#request(resource, method, params = nil) ⇒ Object
Makes request to the zipMoney endpoint.
-
#settings ⇒ Object
Makes settings call on the zipMoney endpoint.
Constructor Details
#initialize(conf, options = {}) ⇒ Object
Initializes a new api object
15 16 17 18 19 20 21 22 |
# File 'lib/zipMoney/api.rb', line 15 def initialize(conf,={}) if conf.new.class == ZipMoney::Configuration @config = conf else raise ArgumentError, "Config is not valid" end @options = end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/zipMoney/api.rb', line 4 def config @config end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/zipMoney/api.rb', line 4 def @options end |
#payload ⇒ Object
Returns the value of attribute payload.
4 5 6 |
# File 'lib/zipMoney/api.rb', line 4 def payload @payload end |
#response ⇒ Object
Returns the value of attribute response.
4 5 6 |
# File 'lib/zipMoney/api.rb', line 4 def response @response end |
Instance Method Details
#append_api_credentials(params) ⇒ Object
Appends api credentials to the request object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/zipMoney/api.rb', line 29 def append_api_credentials(params) is_param_defined(params) do params = Struct::ApiCredentials.new params.version = Struct::Version.new end if params.merchant_id == nil params.merchant_id = self.config.merchant_id end if params.merchant_key == nil params.merchant_key = self.config.merchant_key end if params.version.client == nil params.version.client = ZipMoney::Configuration::API_NAME + " Version:" + ZipMoney::Configuration::API_VERSION end if params.version.platform == nil params.version.platform = ZipMoney::Configuration::API_PLATFORM end params end |
#cancel(params) ⇒ Object
Makes cancel call on the zipMoney endpoint
152 153 154 |
# File 'lib/zipMoney/api.rb', line 152 def cancel(params) request(Resources::RESOURCE_CANCEL, HTTP_METHOD_POST, params) end |
#capture(params) ⇒ Object
Makes capture call on the zipMoney endpoint
134 135 136 |
# File 'lib/zipMoney/api.rb', line 134 def capture(params) request(Resources::RESOURCE_CAPTURE, HTTP_METHOD_POST, params) end |
#checkout(params) ⇒ Object
Makes checkout call on the zipMoney endpoint
116 117 118 |
# File 'lib/zipMoney/api.rb', line 116 def checkout(params) request(Resources::RESOURCE_CHECKOUT, HTTP_METHOD_POST, params) end |
#configure(params) ⇒ Object
Makes configure call on the zipMoney endpoint
170 171 172 |
# File 'lib/zipMoney/api.rb', line 170 def configure(params) request(Resources::RESOURCE_CONFIGURE, HTTP_METHOD_POST, params) end |
#heartbeat ⇒ Object
Makes heartbeat call on the zipMoney endpoint
188 189 190 |
# File 'lib/zipMoney/api.rb', line 188 def heartbeat request(Resources::RESOURCE_HEARTBEAT, HTTP_METHOD_POST) end |
#is_param_defined(params) ⇒ Object
Checks if data is a Struct and calls the block passed as parameter if true
54 55 56 |
# File 'lib/zipMoney/api.rb', line 54 def is_param_defined(params) yield if !params.is_a?(Struct) end |
#prepare_params(params) ⇒ Object
Converts the parameters(Hash) to json
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/zipMoney/api.rb', line 92 def prepare_params(params) begin params = Util.struct_to_hash(params).to_json rescue TypeError => e if params.is_a?(Hash) params = params.to_json else raise ArgumentError, "Invalid params provided" end rescue JSON::ParserError => e if params.is_a?(Hash) params = params.to_json else raise ArgumentError, "Invalid params provided" end end params end |
#query(params) ⇒ Object
Makes query call on the zipMoney endpoint
161 162 163 |
# File 'lib/zipMoney/api.rb', line 161 def query(params) request(Resources::RESOURCE_QUERY, HTTP_METHOD_POST, params) end |
#quote(params) ⇒ Object
Makes quote call on the zipMoney endpoint
125 126 127 |
# File 'lib/zipMoney/api.rb', line 125 def quote(params) request(Resources::RESOURCE_QUOTE, HTTP_METHOD_POST, params) end |
#refund(params) ⇒ Object
Makes refund call on the zipMoney endpoint
143 144 145 |
# File 'lib/zipMoney/api.rb', line 143 def refund(params) request(Resources::RESOURCE_REFUND, HTTP_METHOD_POST, params) end |
#request(resource, method, params = nil) ⇒ Object
Makes request to the zipMoney endpoint
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/zipMoney/api.rb', line 65 def request(resource, method, params = nil) resource = Resources.get(resource, method, params) params = append_api_credentials(params) if method == :post payload = prepare_params(params) else payload = {} end headers = @options[:headers] || {} if method == :get resource.send(method, headers) do |response, request, result, &block| ZipMoney::Response.new(response) end else resource.send(method, payload, headers) do |response, request, result, &block| ZipMoney::Response.new(response) end end end |
#settings ⇒ Object
Makes settings call on the zipMoney endpoint
179 180 181 |
# File 'lib/zipMoney/api.rb', line 179 def settings request(Resources::RESOURCE_SETTINGS, HTTP_METHOD_POST) end |