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:



40
41
42
43
44
45
46
# File 'lib/gds_api/base.rb', line 40

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.



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

def default_options
  @default_options
end

.loggerObject



36
37
38
# File 'lib/gds_api/base.rb', line 36

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#clientObject



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

def client
  @client ||= create_client
end

#create_clientObject



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

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

#get_list!(url) ⇒ Object



52
53
54
55
56
# File 'lib/gds_api/base.rb', line 52

def get_list!(url)
  get_json!(url) do |r|
    GdsApi::ListResponse.new(r, self)
  end
end

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



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

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