eroi 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/eroi.gemspec +1 -1
- data/lib/eroi/client.rb +18 -2
- data/lib/eroi/request.rb +14 -0
- data/test/eroi/client_test.rb +9 -0
- data/test/remote/client_test.rb +24 -0
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/eroi.gemspec
CHANGED
data/lib/eroi/client.rb
CHANGED
@@ -6,6 +6,11 @@ module EROI
|
|
6
6
|
class Client
|
7
7
|
attr_reader :user_token, :api_password
|
8
8
|
|
9
|
+
def self.api_available?
|
10
|
+
Request::Post.api_available? &&
|
11
|
+
Request::Get.api_available?
|
12
|
+
end
|
13
|
+
|
9
14
|
def initialize(user_token, api_password)
|
10
15
|
@user_token = user_token
|
11
16
|
@api_password = api_password
|
@@ -34,13 +39,24 @@ module EROI
|
|
34
39
|
:clear_record => 1 ))
|
35
40
|
end
|
36
41
|
|
42
|
+
def send_list_edition_to_contact(list, edition, email)
|
43
|
+
emails = ((email.is_a?(String)) ? [ email ] : email).join(',')
|
44
|
+
|
45
|
+
xml = Builder::XmlMarkup.new
|
46
|
+
xml.tag!('Send', emails, 'List' => list, 'Edition' => edition)
|
47
|
+
|
48
|
+
Request::Post.send(self, xml)
|
49
|
+
end
|
50
|
+
|
51
|
+
alias :send_list_edition_to_contacts :send_list_edition_to_contact
|
52
|
+
|
37
53
|
private
|
38
54
|
|
39
55
|
def build_contact_record(fields)
|
40
56
|
xml = Builder::XmlMarkup.new
|
41
|
-
xml.tag!('Record') do |
|
57
|
+
xml.tag!('Record') do |x|
|
42
58
|
fields.each do |k,v|
|
43
|
-
|
59
|
+
x.tag!(k.to_s.camelize, v)
|
44
60
|
end
|
45
61
|
end
|
46
62
|
xml
|
data/lib/eroi/request.rb
CHANGED
@@ -3,6 +3,13 @@ module EROI
|
|
3
3
|
class Get
|
4
4
|
API_URL = 'http://emailer.emailroi.com/dbadmin/xml_retrieve2.pl'
|
5
5
|
|
6
|
+
def self.api_available?
|
7
|
+
url = URI.parse(Request::Get::API_URL)
|
8
|
+
request = Net::HTTP::Get.new(url.path)
|
9
|
+
response = Net::HTTP.start(url.host, url.port) { |http| http.request(request) }
|
10
|
+
response.class == Net::HTTPOK
|
11
|
+
end
|
12
|
+
|
6
13
|
def self.send(client, fields)
|
7
14
|
uri = URI.parse(API_URL)
|
8
15
|
uri.query = fields.merge({
|
@@ -15,6 +22,13 @@ module EROI
|
|
15
22
|
class Post
|
16
23
|
API_URL = 'http://emailer.emailroi.com/dbadmin/xml_post.pl'
|
17
24
|
|
25
|
+
def self.api_available?
|
26
|
+
url = URI.parse(Request::Post::API_URL)
|
27
|
+
request = Net::HTTP::Get.new(url.path)
|
28
|
+
response = Net::HTTP.start(url.host, url.port) { |http| http.request(request) }
|
29
|
+
response.class == Net::HTTPOK
|
30
|
+
end
|
31
|
+
|
18
32
|
def self.send(client, xml)
|
19
33
|
response = Net::HTTP.post_form(
|
20
34
|
URI.parse(API_URL),
|
data/test/eroi/client_test.rb
CHANGED
@@ -75,6 +75,15 @@ class TestClient < Test::Unit::TestCase
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
context "when sending an email to a contact" do
|
79
|
+
should "respond with a success" do
|
80
|
+
response = @client.send_list_edition_to_contact('TestList', 'test', 'longbob@longbob.com')
|
81
|
+
|
82
|
+
assert_equal true, response.success?
|
83
|
+
assert_equal 1, response.number_of_records
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
78
87
|
context "when there is an error" do
|
79
88
|
setup do
|
80
89
|
FakeWeb.register_uri(
|
data/test/remote/client_test.rb
CHANGED
@@ -9,6 +9,12 @@ class TestClient < Test::Unit::TestCase
|
|
9
9
|
@client = EROI.new(credentials[:user_token], credentials[:api_password])
|
10
10
|
end
|
11
11
|
|
12
|
+
context "when checking if the api is available" do
|
13
|
+
should "responsd with a a success" do
|
14
|
+
assert true, EROI::Client.api_available?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
12
18
|
context "when finding a contact" do
|
13
19
|
should "respond with a success" do
|
14
20
|
@client.add_contact(
|
@@ -94,6 +100,24 @@ class TestClient < Test::Unit::TestCase
|
|
94
100
|
end
|
95
101
|
end
|
96
102
|
|
103
|
+
context "when sending an email to a contact" do
|
104
|
+
teardown do
|
105
|
+
# @client.remove_contact('longbob@longbob.com')
|
106
|
+
end
|
107
|
+
|
108
|
+
should "respond with a success" do
|
109
|
+
@client.add_contact(
|
110
|
+
:email => 'russ@bashme.org',
|
111
|
+
:firstname => 'Longbob',
|
112
|
+
:lastname => 'Longson',
|
113
|
+
:mailing_lists => 'MainList')
|
114
|
+
|
115
|
+
response = @client.send_list_edition_to_contact('MainList', 'Testing', 'russ@bashme.org')
|
116
|
+
|
117
|
+
assert_equal true, response.success?
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
97
121
|
context "when there is an error" do
|
98
122
|
setup do
|
99
123
|
@client = EROI.new('wrong', 'credentials')
|