Created
May 27, 2010 20:46
-
-
Save baldwindavid/416318 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'crack' | |
require 'httparty' | |
module Icontact | |
# http://developer.icontact.com/ | |
# change to your needs | |
def self.config | |
YAML.load_file("icontact.yml")["development"] | |
end | |
# In Rails, probably something like this... | |
# def self.config | |
# YAML.load_file("#{RAILS_ROOT}/config/icontact.yml")[RAILS_ENV] | |
# end | |
include HTTParty | |
base_uri "#{config["base_uri"]}a/#{config["account_id"]}/c/#{config["client_folder_id"]}" | |
headers "Api-Version" => "2.0", "Api-AppId" => config["app_id"], "Api-Username" => config["username"], "Api-Password" => config["app_password"], "Accept" => "application/json" | |
format :json | |
def self.account | |
get "#{config["base_uri"]}a" | |
end | |
def self.client_folder | |
get "#{config["base_uri"]}a/#{config["account_id"]}/c" | |
end | |
def self.add_contact(email, firstname = nil, lastname = nil) | |
post('/contacts/', :query => {"contact[email]" => email, "contact[firstName]" => firstname, "contact[lastName]" => lastname}) | |
end | |
def self.subscribe_contact(contact_id, list_id = config["default_list_id"], status = "normal") | |
post('/subscriptions/', :query => {"subscription[contactId]" => contact_id, "subscription[listId]" => list_id, "subscription[status]" => status}) | |
end | |
# Super simple crappy subscription | |
def self.subscription(email, firstname = nil, lastname = nil) | |
contact = add_contact(email, firstname, lastname) | |
subscribe_contact(contact['contacts'].first['contactId']) unless errors?(contact) | |
end | |
def self.errors?(resource) | |
!resource['warnings'].nil? | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
development: | |
app_id: XXXXXXXXXXXXXXXXXXXXXXXXXXX | |
username: username-sandbox | |
app_password: XXXXXXXXXX | |
default_list_id: XXXXXXXX | |
account_id: XXXXXXXX | |
client_folder_id: XXXXXXXX | |
base_uri: https://app.sandbox.icontact.com/icp/ | |
production: | |
app_id: XXXXXXXXXXXXXXXXXXXXXXXXXXX | |
username: username | |
app_password: XXXXXXXXXX | |
default_list_id: XXXXXXXX | |
account_id: XXXXXXXX | |
client_folder_id: XXXXXXXX | |
base_uri: https://app.icontact.com/icp/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment