Class: OpenSecrets::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/opensecrets.rb

Direct Known Subclasses

Candidate, Committee, Member, Organization

Instance Method Summary collapse

Constructor Details

#initialize(apikey = nil) ⇒ Base

OpenSecrets Base constructor. All OpenSecrets API classes inherit from this one which provides the common initialization function. For convenience you can skip providing an ‘apikey’ to the constructor if you instead export a OPENSECRETS_API_KEY environment variable which is set to the value of your API key.

Parameters:

  • options (Hash)

    a customizable set of options

Raises:

  • (ArgumentError)


19
20
21
22
23
# File 'lib/opensecrets.rb', line 19

def initialize(apikey = nil)
  key =  apikey ||= ENV['OPENSECRETS_API_KEY']
  raise ArgumentError, 'You must provide an API Key' if key.nil? || key.empty?
  self.class.default_params :apikey => key
end