apsis-on-steroids 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/apsis-on-steroids.gemspec +3 -2
- data/include/errors.rb +3 -0
- data/include/mailing_list.rb +10 -2
- data/include/subscriber.rb +23 -5
- data/lib/apsis-on-steroids.rb +2 -2
- data/spec/apsis-on-steroids_spec.rb +8 -2
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/apsis-on-steroids.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "apsis-on-steroids"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["kaspernj"]
|
12
|
-
s.date = "2013-07-
|
12
|
+
s.date = "2013-07-26"
|
13
13
|
s.description = "A Ruby API for the Apsis mail service. "
|
14
14
|
s.email = "k@spernj.org"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
28
|
"apsis-on-steroids.gemspec",
|
29
|
+
"include/errors.rb",
|
29
30
|
"include/mailing_list.rb",
|
30
31
|
"include/sub_base.rb",
|
31
32
|
"include/subscriber.rb",
|
data/include/errors.rb
ADDED
data/include/mailing_list.rb
CHANGED
@@ -28,6 +28,7 @@ class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase
|
|
28
28
|
data_subscribers
|
29
29
|
end
|
30
30
|
|
31
|
+
# Returns the subscribers of the mailing list.
|
31
32
|
def subscribers
|
32
33
|
res = aos.req_json("v1/mailinglists/#{data(:id)}/subscribers/all", :post, :json => {
|
33
34
|
"AllDemographics" => false,
|
@@ -53,15 +54,22 @@ class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase
|
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
56
|
-
|
57
|
+
|
58
|
+
ret = []
|
57
59
|
data_subscribers.each do |sub_data|
|
58
60
|
sub = ApsisOnSteroids::Subscriber.new(
|
59
61
|
:aos => self.aos,
|
60
62
|
:data => aos.parse_obj(sub_data)
|
61
63
|
)
|
62
64
|
|
63
|
-
|
65
|
+
if block_given?
|
66
|
+
yield sub
|
67
|
+
else
|
68
|
+
ret << sub
|
69
|
+
end
|
64
70
|
end
|
71
|
+
|
72
|
+
return ret
|
65
73
|
end
|
66
74
|
|
67
75
|
# Adds the given email as a new subscriber and subscribes the created subscriber to the mailing list.
|
data/include/subscriber.rb
CHANGED
@@ -1,14 +1,31 @@
|
|
1
1
|
class ApsisOnSteroids::Subscriber < ApsisOnSteroids::SubBase
|
2
2
|
# Fetches the details from the server and returns them.
|
3
3
|
def details
|
4
|
-
|
4
|
+
if !@details
|
5
|
+
res = aos.req_json("v1/subscribers/id/#{data(:id)}")
|
6
|
+
|
7
|
+
ret = {}
|
8
|
+
res["Result"].each do |key, val|
|
9
|
+
ret[key.to_sym] = val
|
10
|
+
end
|
11
|
+
|
12
|
+
@details = ret
|
13
|
+
end
|
14
|
+
|
15
|
+
return @details
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns the DemDataField by the given key.
|
19
|
+
def dem_data(key)
|
20
|
+
key = key.to_s.downcase
|
5
21
|
|
6
|
-
|
7
|
-
|
8
|
-
|
22
|
+
self.details[:DemDataFields].each do |dem_data|
|
23
|
+
if dem_data["Key"].to_s.downcase == key
|
24
|
+
return dem_data["Value"]
|
25
|
+
end
|
9
26
|
end
|
10
27
|
|
11
|
-
return
|
28
|
+
return nil
|
12
29
|
end
|
13
30
|
|
14
31
|
# Returns true if the subscriber is active.
|
@@ -42,6 +59,7 @@ class ApsisOnSteroids::Subscriber < ApsisOnSteroids::SubBase
|
|
42
59
|
end
|
43
60
|
|
44
61
|
raise data["FailedUpdatedSubscribers"].to_s if data["FailedUpdatedSubscribers"] && data["FailedUpdatedSubscribers"].any?
|
62
|
+
@details = nil
|
45
63
|
return nil
|
46
64
|
end
|
47
65
|
|
data/lib/apsis-on-steroids.rb
CHANGED
@@ -82,12 +82,12 @@ class ApsisOnSteroids
|
|
82
82
|
|
83
83
|
raise "Could not find mailing list by that name: '#{name}'."
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
def subscriber_by_email(email)
|
87
87
|
begin
|
88
88
|
res = req_json("v1/subscribers/email/lookup/#{CGI.escape(email)}")
|
89
89
|
rescue
|
90
|
-
raise "Could not find subscriber by that email in the system"
|
90
|
+
raise ApsisOnSteroids::Errors::SubscriberNotFound, "Could not find subscriber by that email in the system: '#{email}'."
|
91
91
|
end
|
92
92
|
|
93
93
|
sub = ApsisOnSteroids::Subscriber.new(
|
@@ -51,7 +51,7 @@ describe "ApsisOnSteroids" do
|
|
51
51
|
it "can create subscribers" do
|
52
52
|
sub
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
it "can get subscribers and their details" do
|
56
56
|
details = sub.details
|
57
57
|
details.is_a?(Hash).should eql(true)
|
@@ -91,7 +91,7 @@ describe "ApsisOnSteroids" do
|
|
91
91
|
#puts "Subscriber: #{sub_i}"
|
92
92
|
end
|
93
93
|
|
94
|
-
raise "Expected more than one." if count
|
94
|
+
raise "Expected more than one." if count < 1
|
95
95
|
end
|
96
96
|
|
97
97
|
it "can remove subscribers from lists" do
|
@@ -118,5 +118,11 @@ describe "ApsisOnSteroids" do
|
|
118
118
|
mlist.opt_out_remove_subscriber(sub)
|
119
119
|
mlist.opt_out?(sub).should eql(false)
|
120
120
|
end
|
121
|
+
|
122
|
+
it "trying to an email that does not exist should raise the correct error" do
|
123
|
+
expect{
|
124
|
+
aos.subscriber_by_email("asd@asd.com")
|
125
|
+
}.to raise_error(ApsisOnSteroids::Errors::SubscriberNotFound)
|
126
|
+
end
|
121
127
|
end
|
122
128
|
end
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: apsis-on-steroids
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- kaspernj
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- Rakefile
|
125
125
|
- VERSION
|
126
126
|
- apsis-on-steroids.gemspec
|
127
|
+
- include/errors.rb
|
127
128
|
- include/mailing_list.rb
|
128
129
|
- include/sub_base.rb
|
129
130
|
- include/subscriber.rb
|
@@ -144,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
145
|
- !ruby/object:Gem::Version
|
145
146
|
segments:
|
146
147
|
- 0
|
147
|
-
hash:
|
148
|
+
hash: 2611720975442987225
|
148
149
|
version: '0'
|
149
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
151
|
none: false
|