Module: ActsAsIcontact::Config

Defined in:
lib/acts_as_icontact/config.rb

Overview

Predefined and user-supplied parameters for interfacing with iContact. Most of these are required by the iContact API for authentication.

Class Method Summary collapse

Class Method Details

.api_versionObject

The API version that this code is designed to interface with.



43
44
45
# File 'lib/acts_as_icontact/config.rb', line 43

def self.api_version
  2.0
end

.app_idObject

Passed in the header of every request as the API-AppId: parameter. You should not need to change this. Ever.



33
34
35
36
37
38
39
40
# File 'lib/acts_as_icontact/config.rb', line 33

def self.app_id
  case mode
  when :beta, :sandbox
    "Ml5SnuFhnoOsuZeTOuZQnLUHTbzeUyhx" 
  when :production
    "IYDOhgaZGUKNjih3hl1ItLln7zpAtWN2"
  end
end

.content_typeObject

Used in the “Accept:” and “Content-Type:” headers of every API request. Defaults to JSON, and if you’re simply using the gem methods there’s no reason you should ever change this, as the results are auto-parsed into Ruby structures. But you can set it to text/xml if you want to.



69
70
71
# File 'lib/acts_as_icontact/config.rb', line 69

def self.content_type
  @content_type ||= "application/json"
end

.content_type=(val) ⇒ Object

If you change this to anything other than application/json or text/xml you’ll get an error. So sayeth iContact; so say we all.



75
76
77
78
79
80
81
82
83
84
# File 'lib/acts_as_icontact/config.rb', line 75

def self.content_type=(val)
  case val
  when "text/xml"
    @content_type = val
  when "application/json"
    @content_type = val
  else
    raise ActsAsIcontact::ConfigError, "Content Type must be application/json or text/xml"
  end
end

.modeObject

Determines whether to return the sandbox or production AppId and URL.

If not explicitly set, it will first look for an ICONTACT_MODE environment variable. If it doesn’t find one, it will attempt to detect a Rails or Rack environment; in either case it will default to :production if RAILS_ENV or RACK_ENV is ‘production’, and :sandbox otherwise. If none of these conditions apply, it assumes :production. (Because that probably means someone’s doing ad hoc queries.)



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/acts_as_icontact/config.rb', line 17

def self.mode
  @mode ||= case
  when ENV["ICONTACT_MODE"] 
    ENV["ICONTACT_MODE"].to_sym
  when Object.const_defined?(:Rails)
    (ENV["RAILS_ENV"] == 'production' ? :production : :sandbox)
  when Object.const_defined?(:Rack)
    (ENV["RACK_ENV"] == 'production' ? :production : :sandbox)
  else
    :production
  end
end

.mode=(val) ⇒ Object

Sets :production or :sandbox. This changes the AppId and URL.



7
8
9
# File 'lib/acts_as_icontact/config.rb', line 7

def self.mode=(val)
  @mode = val
end

.passwordObject

Required for every API request. If you’re using these methods in a Rails app, the recommended way to set the password is in a Rails initializer file. You can also set the ICONTACT_PASSWORD environment variable.



100
101
102
# File 'lib/acts_as_icontact/config.rb', line 100

def self.password
  @password ||= ENV['ICONTACT_PASSWORD']
end

.password=(val) ⇒ Object



104
105
106
# File 'lib/acts_as_icontact/config.rb', line 104

def self.password=(val)
  @password = val
end

.urlObject

Prefixed to the beginning of every API request. You can override this if you have some special need (e.g. working against a testing server, or if iContact changes their URL and you have to fix it before the gem gets updated), but for the most part you can leave it alone.



50
51
52
53
54
55
56
57
58
59
# File 'lib/acts_as_icontact/config.rb', line 50

def self.url
  @url ||= case mode
  when :production
    "https://app.icontact.com/icp/"
  when :sandbox
    "https://app.sandbox.icontact.com/icp/"
  when :beta  # The 'beta' environment still works as of 7/25/2009
    "https://app.beta.icontact.com/icp/"
  end
end

.url=(val) ⇒ Object

Overrides the base URL for the API request.



62
63
64
# File 'lib/acts_as_icontact/config.rb', line 62

def self.url=(val)
  @url = val
end

.usernameObject

Required for every API request. If you’re using these methods in a Rails app, the recommended way to set the username is in a Rails initializer file. You can also set the ICONTACT_USERNAME environment variable.



89
90
91
# File 'lib/acts_as_icontact/config.rb', line 89

def self.username
  @username ||= ENV['ICONTACT_USERNAME']
end

.username=(val) ⇒ Object



93
94
95
# File 'lib/acts_as_icontact/config.rb', line 93

def self.username=(val)
  @username = val
end