Class: CommissionJunction::CjObject

Inherits:
Object
  • Object
show all
Defined in:
lib/commission_junction.rb

Direct Known Subclasses

Advertiser, Product

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ CjObject

Returns a new instance of CjObject.

Raises:

  • (ArgumentError)


108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/commission_junction.rb', line 108

def initialize(params)
  raise ArgumentError, "params must be a Hash; got #{params.class} instead" unless params.is_a?(Hash)
  raise ArgumentError, 'Expecting at least one parameter' unless params.size > 0

  # Create instance variables and attribute readers on the fly.
  # Credit:  http://listlibrary.net/ruby-talk/2004/03/00sGI1cD
  params.each do |key, val|
    raise ArgumentError, "key must be a String; got #{key.class} instead" unless key.is_a?(String)
    instance_variable_set("@#{key}".intern, val)
    instance_eval %Q{ class << self ; attr_reader #{key.intern.inspect} ; end }
  end
end