eroi 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Russ Smith
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.
data/Manifest ADDED
@@ -0,0 +1,8 @@
1
+ Manifest
2
+ Rakefile
3
+ lib/eroi.rb
4
+ lib/eroi/client.rb
5
+ lib/eroi/response.rb
6
+ lib/eroi/version.rb
7
+ test/eroi/client_test.rb
8
+ test/test_helper.rb
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = eroi
2
+
3
+ API interface to eROI.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2009 CardPlayer. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "eroi"
8
+ gem.summary = "API interface to eROI."
9
+ gem.description = "API interface to eROI."
10
+ gem.email = "techteam@cardplayer.com"
11
+ gem.homepage = "http://github.com/cardplayer/eroi"
12
+ gem.authors = ["CardPlayer"]
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'eroi'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'eroi'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+ task :test => :check_dependencies
40
+
41
+ task :default => :test
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "eroi #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/eroi.gemspec ADDED
@@ -0,0 +1,53 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{eroi}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["CardPlayer"]
12
+ s.date = %q{2009-12-03}
13
+ s.description = %q{API interface to eROI.}
14
+ s.email = %q{techteam@cardplayer.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "LICENSE",
21
+ "Manifest",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "eroi.gemspec",
26
+ "lib/eroi.rb",
27
+ "lib/eroi/client.rb",
28
+ "lib/eroi/response.rb",
29
+ "lib/eroi/version.rb",
30
+ "test/eroi/client_test.rb",
31
+ "test/test_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/cardplayer/eroi}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.5}
37
+ s.summary = %q{API interface to eROI.}
38
+ s.test_files = [
39
+ "test/eroi/client_test.rb",
40
+ "test/test_helper.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
+ else
49
+ end
50
+ else
51
+ end
52
+ end
53
+
@@ -0,0 +1,74 @@
1
+ module EROI
2
+ def self.new(user_token, api_password)
3
+ EROI::Client.new(user_token, api_password)
4
+ end
5
+
6
+ class Client
7
+ POST_API_URL = 'http://emailer.emailroi.com/dbadmin/xml_post.pl'
8
+ GET_API_URL = 'http://emailer.emailroi.com/dbadmin/xml_retrieve2.pl'
9
+
10
+ def initialize(user_token, api_password)
11
+ @user_token = user_token
12
+ @api_password = api_password
13
+ end
14
+
15
+ def add_contact(fields)
16
+ send_post(build_contact_record(fields))
17
+ end
18
+
19
+ alias :update_contact :add_contact
20
+
21
+ def change_contact_email(current_email, new_email)
22
+ send_post(build_contact_record(
23
+ :email => current_email, :change_email => new_email))
24
+ end
25
+
26
+ def remove_contact(email)
27
+ send_post(build_contact_record( :email => email, :clear_record => 1 ))
28
+ end
29
+
30
+ def user_field_definitions
31
+ response = send_get(:getUserFieldDefinitions => 1)
32
+
33
+ if response.success?
34
+ fields = {}
35
+ response.data['UserFieldDefinitions']['UserField'].each_with_index do |field,i|
36
+ fields[field] = "User#{i + 1}"
37
+ end
38
+ [ response, fields ]
39
+ else
40
+ [ response, {} ]
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def build_contact_record(fields)
47
+ xml = Builder::XmlMarkup.new
48
+ xml.record do |r|
49
+ fields.each do |k,v|
50
+ r.tag!(k.to_s.camelize, v)
51
+ end
52
+ end
53
+ xml
54
+ end
55
+
56
+ def send_get(fields)
57
+ uri = URI.parse(GET_API_URL)
58
+ uri.query = fields.merge({
59
+ :user_token => @user_token,
60
+ :api_password => @api_password }).collect { |k,v| "#{k}=#{v}" }.join('&')
61
+
62
+ Response::Get.new(Crack::XML.parse(Net::HTTP.get(uri))['Retrieve'])
63
+ end
64
+
65
+ def send_post(xml)
66
+ response = Net::HTTP.post_form(
67
+ URI.parse(POST_API_URL),
68
+ { :user_token => @user_token,
69
+ :api_password => @api_password,
70
+ :body => xml }).body
71
+ Response::Post.new(Crack::XML.parse("<Response>#{response}</Response>")['Response'])
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+
3
+ module EROI
4
+ module Response
5
+ class Base
6
+ attr_reader :data
7
+
8
+ def initialize(data)
9
+ @data = data
10
+ end
11
+ end
12
+
13
+ class Get < Base
14
+ def success?
15
+ !@data['ErrorCode']
16
+ end
17
+
18
+ def error_message
19
+ case @data['ErrorCode'].to_i
20
+ when 1
21
+ 'Invalid username/password was provided.'
22
+ when 2
23
+ 'Invalid mailing list was provided.'
24
+ when 3
25
+ 'Invalid edition was provided.'
26
+ end
27
+ end
28
+ end
29
+
30
+ class Post < Base
31
+ def success?
32
+ @data['Compiled'] == 'Yes' &&
33
+ @data['DBConnect'] == 'OK' &&
34
+ @data['XMLUpload'] == 'Complete'
35
+ end
36
+
37
+ def number_of_records
38
+ @data['ImportRecords'].to_i
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module EROI
2
+ VERSION = '0.0.1'
3
+ end
data/lib/eroi.rb ADDED
@@ -0,0 +1,12 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require 'net/http'
5
+ require 'uri'
6
+ require 'crack'
7
+ require 'builder'
8
+ require 'activesupport'
9
+
10
+ require 'eroi/version'
11
+ require 'eroi/response'
12
+ require 'eroi/client'
@@ -0,0 +1,96 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
2
+
3
+ class TestClient < Test::Unit::TestCase
4
+ context "client module" do
5
+ should "create a new eroi client" do
6
+ client = EROI.new(user_token, api_password)
7
+ assert_equal EROI::Client, client.class
8
+ end
9
+ end
10
+
11
+ context "using the eroi client" do
12
+ setup do
13
+ @client = EROI.new(user_token, api_password)
14
+ FakeWeb.register_uri(
15
+ :post, EROI::Client::POST_API_URL,
16
+ :body => successful_post_response)
17
+ end
18
+
19
+ context "when adding a contact" do
20
+ should "respond with a success" do
21
+ response = @client.add_contact(
22
+ :email => 'longbob@longbob.com',
23
+ :firstname => 'Longbob',
24
+ :lastname => 'Longson',
25
+ :mailing_lists => 'List1,List2')
26
+
27
+ assert_equal true, response.success?
28
+ assert_equal 1, response.number_of_records
29
+ end
30
+ end
31
+
32
+ context "when changing a contact's email" do
33
+ should "respond with a success" do
34
+ response = @client.change_contact_email(
35
+ 'longbob@longbob.com', 'longbob@boblong.com')
36
+
37
+ assert_equal true, response.success?
38
+ assert_equal 1, response.number_of_records
39
+ end
40
+ end
41
+
42
+ context "when updating a contact" do
43
+ should "respond with a success" do
44
+ response = @client.update_contact(
45
+ :email => 'longbob@longbob.com',
46
+ :firstname => 'Longbob',
47
+ :lastname => 'Longson',
48
+ :mailing_lists => 'List1,List2')
49
+
50
+ assert_equal true, response.success?
51
+ assert_equal 1, response.number_of_records
52
+ end
53
+ end
54
+
55
+ context "when removing a contact" do
56
+ should "respond with a success" do
57
+ response = @client.remove_contact('longbob@longbob.com')
58
+
59
+ assert_equal true, response.success?
60
+ assert_equal 1, response.number_of_records
61
+ end
62
+ end
63
+
64
+ context "when retreiving user field definitions" do
65
+ setup do
66
+ FakeWeb.register_uri(
67
+ :get, /#{EROI::Client::GET_API_URL}*/,
68
+ :body => successful_get_response)
69
+ end
70
+
71
+ should "respond with a success" do
72
+ response, user_fields = @client.user_field_definitions
73
+
74
+ expected_fields = { 'State' => 'User1', 'City' => 'User2' }
75
+
76
+ assert_equal true, response.success?
77
+ assert_equal expected_fields, user_fields
78
+ end
79
+ end
80
+
81
+ context "when there is an error" do
82
+ setup do
83
+ FakeWeb.register_uri(
84
+ :get, /#{EROI::Client::GET_API_URL}*/,
85
+ :body => unsuccessful_get_response(1))
86
+ end
87
+
88
+ should "respond with a failure" do
89
+ response, fields = @client.user_field_definitions
90
+
91
+ assert_equal false, response.success?
92
+ assert /Invalid/ =~ response.error_message
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,78 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'shoulda'
4
+ require 'mocha'
5
+ require 'fakeweb'
6
+
7
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'eroi')
8
+
9
+ FakeWeb.allow_net_connect = false
10
+
11
+ def fixture_file(filename)
12
+ return '' if filename == ''
13
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
14
+ File.read(file_path)
15
+ end
16
+
17
+ def stub_get(url, filename, status=nil)
18
+ options = { :body => fixture_file(filename) }
19
+ options.merge!({ :status => status }) unless status.nil?
20
+
21
+ FakeWeb.register_uri(:get, url, options)
22
+ end
23
+
24
+ def user_token
25
+ 'test_user_token'
26
+ end
27
+
28
+ def api_password
29
+ 'test_api_password'
30
+ end
31
+
32
+ def successful_post_response
33
+ <<-EOF
34
+ <Compiled>Yes</Compiled>
35
+ <DBConnect>OK</DBConnect>
36
+ <EditionSuccess>MailingListName_someEditionName</EditionSuccess>
37
+ <ImportRecords>1</ImportRecords>
38
+ <ExistingRecords>1526</ExistingRecords>
39
+ <FinalCompleted>1</FinalCompleted>
40
+ <Duplicates>1</Duplicates>
41
+ <InvalidLists>0</InvalidLists>
42
+ <Triggers></Triggers>
43
+ <XMLUpload>Complete</XMLUpload>
44
+ EOF
45
+ end
46
+
47
+ def successful_get_response
48
+ <<-EOF
49
+ <Retrieve>
50
+ <Record>
51
+ <rec>523</rec>
52
+ <Email>someone@somecompany.com</Email>
53
+ <Firstname>Joe</Firstname>
54
+ <Lastname>Somebody</Lastname>
55
+ <Company>Some Company</Company>
56
+ <User1>some data here</User1>
57
+ <User2>We'll put more data here</User2>
58
+ <Notes>And we'll put more notes here</Notes>
59
+ <Edition Name="SomeEdition">
60
+ <Sent Format="YYYYMMDDhhmm">20030913143010</Sent>
61
+ <Read>5</Read>
62
+ <Click URL="http://www.somelink.com">3</Click>
63
+ <Click URL="http://www.anotherlink.com/page.htm">1</Click>
64
+ <S2F>2</S2F>
65
+ </Edition>
66
+ <Event id="1" ListEdition="somelist_someedition" Date="2003-Nov-11">Sent</Event>
67
+ </Record>
68
+ <UserFieldDefinitions>
69
+ <UserField Field="User1" Type="Text">State</UserField>
70
+ <UserField Field="User2" Type="Text">City</UserField>
71
+ </UserFieldDefinitions>
72
+ </Retrieve>
73
+ EOF
74
+ end
75
+
76
+ def unsuccessful_get_response(code = 1)
77
+ "<Retrieve><ErrorCode>#{code}</ErrorCode></Retrieve>"
78
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eroi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - CardPlayer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-03 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: API interface to eROI.
17
+ email: techteam@cardplayer.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - LICENSE
27
+ - Manifest
28
+ - README.rdoc
29
+ - Rakefile
30
+ - VERSION
31
+ - eroi.gemspec
32
+ - lib/eroi.rb
33
+ - lib/eroi/client.rb
34
+ - lib/eroi/response.rb
35
+ - lib/eroi/version.rb
36
+ - test/eroi/client_test.rb
37
+ - test/test_helper.rb
38
+ has_rdoc: true
39
+ homepage: http://github.com/cardplayer/eroi
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --charset=UTF-8
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.3.5
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: API interface to eROI.
66
+ test_files:
67
+ - test/eroi/client_test.rb
68
+ - test/test_helper.rb