Class: GdsApi::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gds_api/base.rb

Defined Under Namespace

Classes: InvalidAPIURL

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint_url, options = {}) ⇒ Base

Returns a new instance of Base.

Raises:



37
38
39
40
41
42
43
# File 'lib/gds_api/base.rb', line 37

def initialize(endpoint_url, options={})
  options[:endpoint_url] = endpoint_url
  raise InvalidAPIURL unless endpoint_url =~ URI::regexp
  default_options = GdsApi::Base.default_options || {}
  @options = default_options.merge(options)
  self.endpoint = options[:endpoint_url]
end

Class Attribute Details

.default_optionsObject

Returns the value of attribute default_options.



30
31
32
# File 'lib/gds_api/base.rb', line 30

def default_options
  @default_options
end

.loggerObject



33
34
35
# File 'lib/gds_api/base.rb', line 33

def self.logger
  @logger ||= NullLogger.instance
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



26
27
28
# File 'lib/gds_api/base.rb', line 26

def options
  @options
end

Instance Method Details

#adapter_nameObject



45
46
47
# File 'lib/gds_api/base.rb', line 45

def adapter_name
  self.class.to_s.split("::").last.downcase
end

#clientObject



12
13
14
# File 'lib/gds_api/base.rb', line 12

def client
  @client ||= create_client
end

#create_clientObject



16
17
18
# File 'lib/gds_api/base.rb', line 16

def create_client
  GdsApi::JsonClient.new(options)
end

#url_for_slug(slug, options = {}) ⇒ Object



49
50
51
# File 'lib/gds_api/base.rb', line 49

def url_for_slug(slug, options={})
  base = "#{base_url}/#{slug}.json#{query_string(options)}"
end