Class: MDOT::Response
- Inherits:
-
Common::Base
- Object
- Common::Base
- MDOT::Response
- Defined in:
- lib/mdot/response.rb
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Attributes inherited from Common::Base
Instance Method Summary collapse
- #accepted? ⇒ Boolean
- #determine_eligibility ⇒ Object
-
#initialize(args) ⇒ Response
constructor
A new instance of Response.
- #ok? ⇒ Boolean
Methods inherited from Common::Base
#changed, #changed?, #changes, default_sort, filterable_attributes, max_per_page, per_page, sortable_attributes
Constructor Details
#initialize(args) ⇒ Response
Returns a new instance of Response.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mdot/response.rb', line 19 def initialize(args) validate_response_against_schema(args[:schema], args[:response]) @uuid = args[:uuid] @response = args[:response] @token = @response.response_headers['VAAPIKEY'] @body = @response.body @parsed_body = @body.is_a?(String) ? JSON.parse(@body) : @body self.permanent_address = @parsed_body['permanent_address'] self.temporary_address = @parsed_body['temporary_address'] self.supplies = @parsed_body['supplies'] self.vet_email = @parsed_body['vet_email'] self.eligibility = determine_eligibility @status = args[:response][:status] update_token end |
Instance Attribute Details
#status ⇒ Object (readonly)
Returns the value of attribute status.
11 12 13 |
# File 'lib/mdot/response.rb', line 11 def status @status end |
Instance Method Details
#accepted? ⇒ Boolean
50 51 52 |
# File 'lib/mdot/response.rb', line 50 def accepted? @status == 202 end |
#determine_eligibility ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mdot/response.rb', line 35 def determine_eligibility eligibility = MDOT::Eligibility.new supplies.each do |supply| group = supply.product_group.downcase.pluralize.to_sym eligibility.send("#{group}=", true) if eligibility.attributes.key?(group) && supply.available_for_reorder end eligibility end |
#ok? ⇒ Boolean
46 47 48 |
# File 'lib/mdot/response.rb', line 46 def ok? @status == 200 end |