Created
August 4, 2009 15:03
-
-
Save baldwindavid/161292 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 'httparty' | |
module Icontact | |
# This info was gleaned from developer.icontact.com | |
# Get a sandbox APP ID from here | |
APP_ID = "XXXXXXXXXXXXXXXXXXXXX" | |
# This is your Production / Sandbox Username | |
USERNAME = "XXXXXXXXXXXXXXXXXXXXX" | |
# The app password is not the same as your Production / Sandbox password | |
APP_PASSWORD = "XXXXXXXXXXXXXXXXXXXXX" | |
# Automatically add contacts to this List | |
DEFAULT_LIST_ID = 1111111111111111111111 | |
# to find your Account ID just call Icontact.account_id | |
ACCOUNT_ID = "XXXXXXXXXXXXXXXXXXXXX" | |
# Once you have your Account ID filled in, call Icontact.client_folder_id | |
CLIENT_FOLDER_ID = "XXXXXXXXXXXXXXXXXXXXX" | |
include HTTParty | |
base_uri "https://app.sandbox.icontact.com/icp/a/#{ACCOUNT_ID}/c/#{CLIENT_FOLDER_ID}" | |
headers "Api-Version" => "2.0", "Api-AppId" => APP_ID, "Api-Username" => USERNAME, "Api-Password" => APP_PASSWORD, "Accept" => "application/json" | |
format :json | |
def self.account_id | |
get 'https://app.sandbox.icontact.com/icp/a' | |
end | |
def self.client_folder_id | |
get "https://app.sandbox.icontact.com/icp/a/#{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 = 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 | |
# resources should be their own class, but works in a pinch | |
def self.errors?(resource) | |
!resource['warnings'].nil? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment