Class: NRB::BCSInterrogator::API::Endpoint
- Inherits:
-
Object
- Object
- NRB::BCSInterrogator::API::Endpoint
- Includes:
- Enumerable
- Defined in:
- lib/bcs_interrogator/api/endpoint.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #api_call(args = {}) ⇒ Object
- #data ⇒ Object
- #each(&block) ⇒ Object
- #endpoint ⇒ Object
-
#initialize(args = {}) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #to_a ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Endpoint
Returns a new instance of Endpoint.
39 40 41 42 |
# File 'lib/bcs_interrogator/api/endpoint.rb', line 39 def initialize(args={}) @api = args.delete(:api) raise ArgumentError.new("Please supply an API object") unless @api end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/bcs_interrogator/api/endpoint.rb', line 8 def response @response end |
Class Method Details
.descriptions ⇒ Object
10 11 12 |
# File 'lib/bcs_interrogator/api/endpoint.rb', line 10 def self.descriptions const_defined?(:DESCRIPTIONS) ? const_get(:DESCRIPTIONS) : nil end |
.endpoint ⇒ Object
15 16 17 |
# File 'lib/bcs_interrogator/api/endpoint.rb', line 15 def self.endpoint const_defined?(:ENDPOINT) ? const_get(:ENDPOINT) : nil end |
Instance Method Details
#api_call(args = {}) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/bcs_interrogator/api/endpoint.rb', line 20 def api_call(args={}) args[:verb] ||= :get args[:url] ||= endpoint @response = @api.api_call args @data = @response.body @response end |
#data ⇒ Object
45 46 47 48 49 |
# File 'lib/bcs_interrogator/api/endpoint.rb', line 45 def data return @data if @data api_call @data end |
#each(&block) ⇒ Object
29 30 31 |
# File 'lib/bcs_interrogator/api/endpoint.rb', line 29 def each(&block) data.each(block) end |
#endpoint ⇒ Object
34 35 36 |
# File 'lib/bcs_interrogator/api/endpoint.rb', line 34 def endpoint @api.base_url + self.class.endpoint end |
#to_a ⇒ Object
52 |
# File 'lib/bcs_interrogator/api/endpoint.rb', line 52 def to_a; data; end |
#to_h ⇒ Object
54 55 56 |
# File 'lib/bcs_interrogator/api/endpoint.rb', line 54 def to_h self.class.descriptions.each_with_index { |descr,i| data[descr] = @response.body[i] } end |