blaix-constant_contact 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Justin Blake
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ = Constant Contact
2
+
3
+ Ruby wrapper for Constant Contact API
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Justin Blake. See LICENSE for details.
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 2
3
+ :major: 0
4
+ :minor: 0
@@ -0,0 +1,55 @@
1
+ require 'httpclient'
2
+ require 'rexml/document'
3
+ require 'time' # required for Time.parse for some reason?
4
+
5
+ class ConstantContact
6
+ def initialize(username, password, api_key)
7
+ @username = username
8
+ @password = password
9
+ @api_key = api_key
10
+ @domain = "http://api.constantcontact.com/ws/customers/#{@username}"
11
+ login
12
+ end
13
+
14
+ def lists
15
+ lists = []
16
+ get('lists').each('feed/entry') do |entry|
17
+ item = {}
18
+ item[:id] = text_element(entry, 'id')
19
+ item[:title] = text_element(entry, 'title')
20
+ item[:updated_at] = time_element(entry 'updated')
21
+ item[:opt_in_default] = boolean_element(entry, 'content/ContactList/OptInDefault')
22
+ item[:short_name] = text_element(entry, 'content/ContactList/ShortName')
23
+ lists << item
24
+ end
25
+ lists
26
+ end
27
+
28
+ #def opt_in(list_id, email, first_name, last_name)
29
+
30
+ private
31
+
32
+ def login
33
+ auth_username = "#{@api_key}%#{@username}"
34
+ @client = HTTPClient.new
35
+ @client.set_auth(@domain, auth_username, @password)
36
+ @client.get(@domain).status == 200
37
+ end
38
+
39
+ def get(path)
40
+ xml = @client.content("#{@domain}/#{path}")
41
+ REXML::Document.new(xml)
42
+ end
43
+
44
+ def text_element(root, element)
45
+ root.elements[element].text if root.elements[element]
46
+ end
47
+
48
+ def time_element(root, element)
49
+ Time.parse(root.elements[element].text) if root.elements[element]
50
+ end
51
+
52
+ def boolean_element(root, element)
53
+ (root.elements[element] == "true") if root.elements[element]
54
+ end
55
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ConstantContact" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'constant_contact'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blaix-constant_contact
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Justin Blake
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-06 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: justin@megablaix.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE
25
+ files:
26
+ - README.rdoc
27
+ - VERSION.yml
28
+ - lib/constant_contact.rb
29
+ - spec/constant_contact_spec.rb
30
+ - spec/spec_helper.rb
31
+ - LICENSE
32
+ has_rdoc: true
33
+ homepage: http://github.com/blaix/constant_contact
34
+ post_install_message:
35
+ rdoc_options:
36
+ - --inline-source
37
+ - --charset=UTF-8
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ requirements: []
53
+
54
+ rubyforge_project:
55
+ rubygems_version: 1.2.0
56
+ signing_key:
57
+ specification_version: 2
58
+ summary: TODO
59
+ test_files: []
60
+