Class: Suretax::Api::Request
- Inherits:
-
Object
- Object
- Suretax::Api::Request
- Includes:
- Concerns::Validatable
- Defined in:
- lib/suretax/api/request.rb
Instance Attribute Summary collapse
-
#business_unit ⇒ Object
Returns the value of attribute business_unit.
-
#client_number ⇒ Object
Returns the value of attribute client_number.
-
#client_tracking ⇒ Object
Returns the value of attribute client_tracking.
-
#data_month ⇒ Object
Returns the value of attribute data_month.
-
#data_year ⇒ Object
Returns the value of attribute data_year.
-
#industry_exemption ⇒ Object
Returns the value of attribute industry_exemption.
-
#items ⇒ Object
Returns the value of attribute items.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#response_group ⇒ Object
Returns the value of attribute response_group.
-
#response_type ⇒ Object
Returns the value of attribute response_type.
-
#return_file_code ⇒ Object
Returns the value of attribute return_file_code.
-
#stan ⇒ Object
Returns the value of attribute stan.
-
#total_revenue ⇒ Object
Returns the value of attribute total_revenue.
-
#validation_key ⇒ Object
Returns the value of attribute validation_key.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Request
constructor
A new instance of Request.
- #params ⇒ Object
- #rollback ⇒ Object
- #submit ⇒ Object
- #valid? ⇒ Boolean
Methods included from Concerns::Validatable
Constructor Details
#initialize(options = {}) ⇒ Request
Returns a new instance of Request.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/suretax/api/request.rb', line 36 def initialize( = {}) self.return_file_code = "0" self.client_number = .delete(:client_number) || configuration.client_number self.validation_key = .delete(:validation_key) || configuration.validation_key default_data_date() .each_pair do |key, value| send("#{key}=", value.to_s) end initialize_items() validate! end |
Instance Attribute Details
#business_unit ⇒ Object
Returns the value of attribute business_unit.
8 9 10 |
# File 'lib/suretax/api/request.rb', line 8 def business_unit @business_unit end |
#client_number ⇒ Object
Returns the value of attribute client_number.
8 9 10 |
# File 'lib/suretax/api/request.rb', line 8 def client_number @client_number end |
#client_tracking ⇒ Object
Returns the value of attribute client_tracking.
8 9 10 |
# File 'lib/suretax/api/request.rb', line 8 def client_tracking @client_tracking end |
#data_month ⇒ Object
Returns the value of attribute data_month.
8 9 10 |
# File 'lib/suretax/api/request.rb', line 8 def data_month @data_month end |
#data_year ⇒ Object
Returns the value of attribute data_year.
8 9 10 |
# File 'lib/suretax/api/request.rb', line 8 def data_year @data_year end |
#industry_exemption ⇒ Object
Returns the value of attribute industry_exemption.
8 9 10 |
# File 'lib/suretax/api/request.rb', line 8 def industry_exemption @industry_exemption end |
#items ⇒ Object
Returns the value of attribute items.
8 9 10 |
# File 'lib/suretax/api/request.rb', line 8 def items @items end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
22 23 24 |
# File 'lib/suretax/api/request.rb', line 22 def response @response end |
#response_group ⇒ Object
Returns the value of attribute response_group.
8 9 10 |
# File 'lib/suretax/api/request.rb', line 8 def response_group @response_group end |
#response_type ⇒ Object
Returns the value of attribute response_type.
8 9 10 |
# File 'lib/suretax/api/request.rb', line 8 def response_type @response_type end |
#return_file_code ⇒ Object
Returns the value of attribute return_file_code.
8 9 10 |
# File 'lib/suretax/api/request.rb', line 8 def return_file_code @return_file_code end |
#stan ⇒ Object
Returns the value of attribute stan.
8 9 10 |
# File 'lib/suretax/api/request.rb', line 8 def stan @stan end |
#total_revenue ⇒ Object
Returns the value of attribute total_revenue.
8 9 10 |
# File 'lib/suretax/api/request.rb', line 8 def total_revenue @total_revenue end |
#validation_key ⇒ Object
Returns the value of attribute validation_key.
8 9 10 |
# File 'lib/suretax/api/request.rb', line 8 def validation_key @validation_key end |
Instance Method Details
#params ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/suretax/api/request.rb', line 74 def params { "ClientNumber" => client_number, "BusinessUnit" => business_unit || "", "ValidationKey" => validation_key, "DataYear" => data_year, "DataMonth" => data_month, "TotalRevenue" => total_revenue.to_f, "ReturnFileCode" => return_file_code, "ClientTracking" => client_tracking || "", "IndustryExemption" => industry_exemption, "ResponseType" => response_type, "ResponseGroup" => response_group, "STAN" => stan || "", "ItemList" => items.map(&:params) } end |
#rollback ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/suretax/api/request.rb', line 66 def rollback if response CancelRequest.new(transaction: response.transaction, client_number: client_number, validation_key: validation_key, client_tracking: client_tracking).submit end end |
#submit ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/suretax/api/request.rb', line 52 def submit if valid? log_request suretax_response = connection.post(params) @response = Suretax::Api::Response.new(suretax_response.body) else raise(ValidationError, errors..join(", ")) end end |
#valid? ⇒ Boolean
62 63 64 |
# File 'lib/suretax/api/request.rb', line 62 def valid? errors.none? end |