Class: TransactPro::Request
- Inherits:
-
Object
- Object
- TransactPro::Request
- Defined in:
- lib/transact_pro/request.rb
Defined Under Namespace
Classes: ValidationError
Constant Summary collapse
- SUPPORTED_METHODS =
%i| init init_recurring_registration init_recurrent charge_recurrent status_request |.freeze
- RECURRING_METHODS =
%i|init_recurrent charge_recurrent|.freeze
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #call ⇒ Object
- #details ⇒ Object
-
#initialize(options) ⇒ Request
constructor
Do not use this default initializer! Instead, initialize a Gateway and call #request method on that.
Constructor Details
#initialize(options) ⇒ Request
Do not use this default initializer! Instead, initialize a Gateway and call #request method on that.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/transact_pro/request.rb', line 16 def initialize() @options = @method = @options[:method] unless SUPPORTED_METHODS.include?(@method) raise ArgumentError.new( "'#{@method}' is not a supported API request method" ) end end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
12 13 14 |
# File 'lib/transact_pro/request.rb', line 12 def method @method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/transact_pro/request.rb', line 12 def @options end |
Instance Method Details
#call ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/transact_pro/request.rb', line 27 def call # does prep details if [:VERBOSE] puts( ">> About to make a POST request to TransactPro at #{Time.now} GMT.\n"\ " url: #{@url}\n"\ " params: #{@postable_params.merge(pwd: "..redacted..")}" ) end @raw_response = RestClient.post(@url, @postable_params) @response = TransactPro::Response.new(@raw_response.to_s) end |
#details ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/transact_pro/request.rb', line 43 def details return @details if defined?(@details) # DEPRECATED @defaults ||= TransactPro::RequestSpecs.const_get( "#{method.to_s.upcase}_DEFAULTS" ) @request_options ||= @defaults.merge() @request_options[:rs] = routing_string @spec ||= spec_to_use @postable_params = {} @spec.each do |k, spec| do_validation = if spec[:mandatory] # mandatory key, always validate @postable_params[k] = @request_options[k] true else # non-mandatory key, include and validate only if it is present if @request_options[k].to_s.size > 0 @postable_params[k] = @request_options[k] true else false end end validate(k, @postable_params[k], spec[:format]) if do_validation end @url = "#{@request_options[:API_URI]}?a=#{sendable_method}" @details = {url: @url, params: @postable_params} end |