Class: Arbetsformedlingen::API::Response
- Inherits:
-
Object
- Object
- Arbetsformedlingen::API::Response
- Defined in:
- lib/arbetsformedlingen/api/response.rb
Overview
API response object
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#body ⇒ String
Response body.
-
#initialize(response, uri = nil) ⇒ Response
constructor
Initialize response.
-
#json ⇒ Hash
Response JSON.
-
#method_missing(method_name, *arguments, &block) ⇒ Object
Delegate missing values to response.
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Return true if missing method can be delegated.
-
#success? ⇒ Boolean
True if response is 200.
-
#xml ⇒ Nokogiri::XML::Document
Response XML.
Constructor Details
#initialize(response, uri = nil) ⇒ Response
Initialize response
15 16 17 18 19 |
# File 'lib/arbetsformedlingen/api/response.rb', line 15 def initialize(response, uri = nil) @response = response @json = nil @uri = uri end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
Delegate missing values to response
46 47 48 49 50 51 52 |
# File 'lib/arbetsformedlingen/api/response.rb', line 46 def method_missing(method_name, *arguments, &block) if response.respond_to?(method_name) response.public_send(method_name, *arguments, &block) else super end end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
12 13 14 |
# File 'lib/arbetsformedlingen/api/response.rb', line 12 def uri @uri end |
Instance Method Details
#body ⇒ String
Response body
29 30 31 |
# File 'lib/arbetsformedlingen/api/response.rb', line 29 def body response.read_body end |
#json ⇒ Hash
Response JSON
35 36 37 |
# File 'lib/arbetsformedlingen/api/response.rb', line 35 def json @json ||= parse_json(body) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Return true if missing method can be delegated
55 56 57 |
# File 'lib/arbetsformedlingen/api/response.rb', line 55 def respond_to_missing?(method_name, include_private = false) response.respond_to?(method_name) || super end |
#success? ⇒ Boolean
True if response is 200
23 24 25 |
# File 'lib/arbetsformedlingen/api/response.rb', line 23 def success? response.code == '200' end |
#xml ⇒ Nokogiri::XML::Document
Response XML
41 42 43 |
# File 'lib/arbetsformedlingen/api/response.rb', line 41 def xml @xml ||= parse_xml(body) end |