Method: Megam::API#initialize

Defined in:
lib/megam/api.rb

#initialize(options = {}) ⇒ API

It is assumed that every API call will use an API_KEY/email. This ensures validity of the person really the same guy on who he claims. 3 levels of options exits

  1. The global OPTIONS as available inside the API (OPTIONS)

  2. The options as passed via the instantiation of API will override global options. The ones that are passed are :email and :api_key and will

be merged into a class variable @options

  1. Upon merge of the options, the api_key, email as available in the @options is deleted.

Raises:

  • (ArgumentError)


140
141
142
143
144
145
# File 'lib/megam/api.rb', line 140

def initialize(options={})
  @options = OPTIONS.merge(options)
  @api_key = @options.delete(:api_key) || ENV['MEGAM_API_KEY']
  @email = @options.delete(:email)
  raise ArgumentError, "You must specify [:email, :api_key]" if @email.nil? || @api_key.nil?
end