Class: MDOT::Response
Instance Attribute Summary collapse
Attributes inherited from Common::Base
#errors_hash, #metadata
Instance Method Summary
collapse
#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.['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
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
|
#update_token ⇒ Object
56
57
58
59
60
|
# File 'lib/mdot/response.rb', line 56
def update_token
token_params = { REDIS_CONFIG[:mdot][:namespace] => @uuid }
token = MDOT::Token.new(token_params)
token.update(token: @token, uuid: @uuid)
end
|
#validate_response_against_schema(schema, response) ⇒ Object
62
63
64
65
|
# File 'lib/mdot/response.rb', line 62
def validate_response_against_schema(schema, response)
schema_path = Rails.root.join('lib', 'mdot', 'schemas', "#{schema}.json").to_s
JSON::Validator.validate!(schema_path, response.body, strict: false)
end
|