Class: ApiAdaptor::Base
- Inherits:
-
Object
- Object
- ApiAdaptor::Base
- Extended by:
- Forwardable
- Defined in:
- lib/api_adaptor/base.rb
Defined Under Namespace
Classes: InvalidAPIURL
Class Attribute Summary collapse
-
.default_options ⇒ Object
Returns the value of attribute default_options.
- .logger ⇒ Object
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #client ⇒ Object
- #create_client ⇒ Object
- #get_list(url) ⇒ Object
-
#initialize(endpoint_url, options = {}) ⇒ Base
constructor
A new instance of Base.
- #url_for_slug(slug, options = {}) ⇒ Object
Constructor Details
#initialize(endpoint_url, options = {}) ⇒ Base
Returns a new instance of Base.
45 46 47 48 49 50 51 52 53 |
# File 'lib/api_adaptor/base.rb', line 45 def initialize(endpoint_url, = {}) [:endpoint_url] = endpoint_url raise InvalidAPIURL unless endpoint_url =~ URI::RFC3986_Parser::RFC3986_URI = { logger: ApiAdaptor::Base.logger } = .merge(ApiAdaptor::Base. || {}) @options = .merge() self.endpoint = [:endpoint_url] end |
Class Attribute Details
.default_options ⇒ Object
Returns the value of attribute default_options.
38 39 40 |
# File 'lib/api_adaptor/base.rb', line 38 def @default_options end |
.logger ⇒ Object
41 42 43 |
# File 'lib/api_adaptor/base.rb', line 41 def self.logger @logger ||= ApiAdaptor::NullLogger.new end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
34 35 36 |
# File 'lib/api_adaptor/base.rb', line 34 def @options end |
Instance Method Details
#client ⇒ Object
15 16 17 |
# File 'lib/api_adaptor/base.rb', line 15 def client @client ||= create_client end |
#create_client ⇒ Object
19 20 21 |
# File 'lib/api_adaptor/base.rb', line 19 def create_client ApiAdaptor::JsonClient.new() end |
#get_list(url) ⇒ Object
59 60 61 62 63 |
# File 'lib/api_adaptor/base.rb', line 59 def get_list(url) get_json(url) do |r| ApiAdaptor::ListResponse.new(r, self) end end |
#url_for_slug(slug, options = {}) ⇒ Object
55 56 57 |
# File 'lib/api_adaptor/base.rb', line 55 def url_for_slug(slug, = {}) "#{base_url}/#{slug}.json#{query_string()}" end |