Module: ActsAsIcontact
- Defined in:
- lib/acts_as_icontact.rb,
lib/acts_as_icontact/config.rb,
lib/acts_as_icontact/resource.rb,
lib/acts_as_icontact/connection.rb,
lib/acts_as_icontact/exceptions.rb,
lib/acts_as_icontact/rails/lists.rb,
lib/acts_as_icontact/rails/macro.rb,
lib/acts_as_icontact/rails/mappings.rb,
lib/acts_as_icontact/resources/list.rb,
lib/acts_as_icontact/rails/callbacks.rb,
lib/acts_as_icontact/resources/client.rb,
lib/acts_as_icontact/resources/account.rb,
lib/acts_as_icontact/resources/contact.rb,
lib/acts_as_icontact/resources/message.rb,
lib/acts_as_icontact/resource_collection.rb,
lib/acts_as_icontact/resources/custom_field.rb,
lib/acts_as_icontact/resources/subscription.rb,
bin/icontact
Defined Under Namespace
Modules: Config, Rails Classes: Account, Client, ConfigError, Contact, CustomField, List, Message, QueryError, RecordNotSaved, Resource, ResourceCollection, Subscription, ValidationError
Class Method Summary collapse
-
.account ⇒ Object
RestClient subresource scoped to the specific account ID.
-
.account_id ⇒ Object
The accountId retrieved from iContact.
-
.account_id=(val) ⇒ Object
Manually sets the accountId used in subsequent calls.
-
.client ⇒ Object
RestClient subresource scoped to the specific account ID.
-
.client_id ⇒ Object
The clientFolderId retrieved from iContact.
-
.client_id=(val) ⇒ Object
Manually sets the clientFolderId used in subsequent calls.
-
.connection ⇒ Object
Returns an instance of RestClient::Resource with iContact authentication headers.
-
.reset_account! ⇒ Object
Clears the account resource from memory.
-
.reset_client! ⇒ Object
Clears the account resource from memory.
-
.reset_connection! ⇒ Object
Clears the connection object from memory.
Class Method Details
.account ⇒ Object
RestClient subresource scoped to the specific account ID. Most other iContact calls will derive from this one.
34 35 36 |
# File 'lib/acts_as_icontact/resources/account.rb', line 34 def self.account @account ||= connection["a/#{account_id}"] end |
.account_id ⇒ Object
The accountId retrieved from iContact. Can also be set manually for performance optimization, but remembers it so that it won’t be pulled more than once anyway.
22 23 24 |
# File 'lib/acts_as_icontact/resources/account.rb', line 22 def self.account_id @account_id ||= Account.first.id.to_i end |
.account_id=(val) ⇒ Object
Manually sets the accountId used in subsequent calls. Setting this in your initializer will save at least one unnecessary request to the iContact server.
28 29 30 |
# File 'lib/acts_as_icontact/resources/account.rb', line 28 def self.account_id=(val) @account_id = val end |
.client ⇒ Object
RestClient subresource scoped to the specific account ID. Most other iContact calls will derive from this one.
41 42 43 |
# File 'lib/acts_as_icontact/resources/client.rb', line 41 def self.client @client ||= account["c/#{client_id}"] end |
.client_id ⇒ Object
The clientFolderId retrieved from iContact. Can also be set manually for performance optimization, but remembers it so that it won’t be pulled more than once anyway.
29 30 31 |
# File 'lib/acts_as_icontact/resources/client.rb', line 29 def self.client_id @client_id ||= Client.first.clientFolderId.to_i end |
.client_id=(val) ⇒ Object
Manually sets the clientFolderId used in subsequent calls. Setting this in your initializer will save at least one unnecessary request to the iContact server.
35 36 37 |
# File 'lib/acts_as_icontact/resources/client.rb', line 35 def self.client_id=(val) @client_id = val end |
.connection ⇒ Object
Returns an instance of RestClient::Resource with iContact authentication headers. All other resource classes build from this method. Throws an ActsAsIcontact::ConfigError if the username or password are missing from configuration.
(Author’s Note: I’m not especially thrilled with this name, since it implies some sort of keepalive or other persistent state. I’d rather call this ‘client’ – but that’s already a bit overloaded within iContact’s nomenclature. And calling it ‘server’ got me confused. This is the best of a motley array of possibilities.)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/acts_as_icontact/connection.rb', line 10 def self.connection @connection or begin raise ConfigError, "Username is required" unless Config.username raise ConfigError, "Password is required" unless Config.password @connection = RestClient::Resource.new(Config.url, :headers => { :accept => Config.content_type, :content_type => Config.content_type, :api_version => Config.api_version, :api_appid => Config.app_id, :api_username => Config.username, :api_password => Config.password }) end end |
.reset_account! ⇒ Object
Clears the account resource from memory. Called by reset_connection! since the only likely reason to do this is connecting as a different user.
40 41 42 |
# File 'lib/acts_as_icontact/resources/account.rb', line 40 def self.reset_account! @account = nil end |
.reset_client! ⇒ Object
Clears the account resource from memory. Called by reset_connection! since the only likely reason to do this is connecting as a different user.
47 48 49 |
# File 'lib/acts_as_icontact/resources/client.rb', line 47 def self.reset_client! @client = nil end |
.reset_connection! ⇒ Object
Clears the connection object from memory. This will force a reload the next time it’s accessed. Because nothing is directly cached within the client, the only likely reason to do this is if the username and password are changed. Also resets the account subresource.
28 29 30 31 |
# File 'lib/acts_as_icontact/connection.rb', line 28 def self.reset_connection! reset_account! @connection = nil end |