apsis-on-steroids 0.0.11 → 0.0.12
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.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/README.md +10 -0
- data/VERSION +1 -1
- data/apsis-on-steroids.gemspec +6 -3
- data/include/mailing_list.rb +47 -41
- data/include/subscriber.rb +19 -19
- data/lib/apsis-on-steroids.rb +46 -22
- data/spec/apsis-on-steroids_spec.rb +8 -4
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7222efc62bbf76dd9716343cc6ff40b9da839fea
|
4
|
+
data.tar.gz: 2107858d19cd4ecbeb3815c2a1e31f584bbaa545
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a4b44a4f25ebdfdadbba1a55acdeb6b074350de838cb057c0cb411716ed6d531341fa575ddbaf29cbc5c22c716ae9cd520b2f7c00f027d02efe002b1ddf3f0f
|
7
|
+
data.tar.gz: e8655a0feb8c2b51c452475cea4bf388cacf6ba5a9b1d450ca6fa86db616fcec07cce4fc19b9ef9422c5eed3c4a4cac2e95d8fcc95aa27fe1eee5a56d9f1466d
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -43,6 +43,11 @@ mlist.delete
|
|
43
43
|
sub = mlist.subscriber_by_email("some@email.com")
|
44
44
|
```
|
45
45
|
|
46
|
+
### Get a specific subscriber without dealing with mailing lists:
|
47
|
+
```ruby
|
48
|
+
sub = aos.subscriber_by_email("some@email.com")
|
49
|
+
```
|
50
|
+
|
46
51
|
### Create one or more subscribers in a mailing list.
|
47
52
|
```ruby
|
48
53
|
mlist.create_subscribers(
|
@@ -58,6 +63,11 @@ mlist.create_subscribers(
|
|
58
63
|
)
|
59
64
|
```
|
60
65
|
|
66
|
+
### Count subscribers on a mailing list.
|
67
|
+
```ruby
|
68
|
+
mlist.count_subscribers #=> 105
|
69
|
+
```
|
70
|
+
|
61
71
|
### Get details about subscribers.
|
62
72
|
```ruby
|
63
73
|
puts "Details: #{sub.details}"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.12
|
data/apsis-on-steroids.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: apsis-on-steroids 0.0.
|
5
|
+
# stub: apsis-on-steroids 0.0.12 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "apsis-on-steroids"
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.12"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["kaspernj"]
|
14
|
-
s.date = "2014-
|
14
|
+
s.date = "2014-11-21"
|
15
15
|
s.description = "A Ruby API for the Apsis mail service. "
|
16
16
|
s.email = "k@spernj.org"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -52,6 +52,7 @@ Gem::Specification.new do |s|
|
|
52
52
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
53
|
s.add_runtime_dependency(%q<http2>, ["~> 0.0.25"])
|
54
54
|
s.add_runtime_dependency(%q<string-cases>, [">= 0"])
|
55
|
+
s.add_runtime_dependency(%q<tretry>, ["= 0.0.2"])
|
55
56
|
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
56
57
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
57
58
|
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
@@ -59,6 +60,7 @@ Gem::Specification.new do |s|
|
|
59
60
|
else
|
60
61
|
s.add_dependency(%q<http2>, ["~> 0.0.25"])
|
61
62
|
s.add_dependency(%q<string-cases>, [">= 0"])
|
63
|
+
s.add_dependency(%q<tretry>, ["= 0.0.2"])
|
62
64
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
63
65
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
64
66
|
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
@@ -67,6 +69,7 @@ Gem::Specification.new do |s|
|
|
67
69
|
else
|
68
70
|
s.add_dependency(%q<http2>, ["~> 0.0.25"])
|
69
71
|
s.add_dependency(%q<string-cases>, [">= 0"])
|
72
|
+
s.add_dependency(%q<tretry>, ["= 0.0.2"])
|
70
73
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
71
74
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
72
75
|
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
data/include/mailing_list.rb
CHANGED
@@ -2,11 +2,11 @@ require "uri"
|
|
2
2
|
|
3
3
|
class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase
|
4
4
|
def create_subscribers(data)
|
5
|
-
res = aos.req_json("v1/subscribers/mailinglist/#{data(:id)}/queue", :post, :
|
5
|
+
res = aos.req_json("v1/subscribers/mailinglist/#{data(:id)}/queue", :post, json: data)
|
6
6
|
|
7
7
|
url = URI.parse(res["Result"]["PollURL"])
|
8
8
|
data_subscribers = nil
|
9
|
-
|
9
|
+
|
10
10
|
Timeout.timeout(300) do
|
11
11
|
loop do
|
12
12
|
sleep 1
|
@@ -27,22 +27,22 @@ class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase
|
|
27
27
|
|
28
28
|
data_subscribers
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
# Returns the subscribers of the mailing list.
|
32
32
|
def subscribers
|
33
|
-
res = aos.req_json("v1/mailinglists/#{data(:id)}/subscribers/all", :post, :
|
33
|
+
res = aos.req_json("v1/mailinglists/#{data(:id)}/subscribers/all", :post, json: {
|
34
34
|
"AllDemographics" => false,
|
35
35
|
"FieldNames" => []
|
36
36
|
})
|
37
|
-
|
37
|
+
|
38
38
|
url = URI.parse(res["Result"]["PollURL"])
|
39
39
|
data_subscribers = nil
|
40
|
-
|
40
|
+
|
41
41
|
Timeout.timeout(300) do
|
42
42
|
loop do
|
43
43
|
sleep 1
|
44
44
|
res = aos.req_json(url.path)
|
45
|
-
|
45
|
+
|
46
46
|
if res["State"] == "2"
|
47
47
|
data_url = URI.parse(res["DataUrl"])
|
48
48
|
data_subscribers = aos.req_json(data_url.path)
|
@@ -54,24 +54,24 @@ class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
ret = []
|
59
59
|
data_subscribers.each do |sub_data|
|
60
60
|
sub = ApsisOnSteroids::Subscriber.new(
|
61
|
-
:
|
62
|
-
:
|
61
|
+
aos: self.aos,
|
62
|
+
data: aos.parse_obj(sub_data)
|
63
63
|
)
|
64
|
-
|
64
|
+
|
65
65
|
if block_given?
|
66
66
|
yield sub
|
67
67
|
else
|
68
68
|
ret << sub
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
return ret
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
# Adds the given email as a new subscriber and subscribes the created subscriber to the mailing list.
|
76
76
|
def subscriber_by_email(email)
|
77
77
|
sub = aos.subscriber_by_email(email)
|
@@ -81,10 +81,10 @@ class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase
|
|
81
81
|
mailinglist_ids = res["Result"]["Mailinglists"].map { |m| m["Id"].to_i }
|
82
82
|
return sub if mailinglist_ids.include?(self.data(:id))
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
raise "Could not find subscriber by that email: '#{email}' on this mailing list '#{self.data(:name)}'."
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
# Adds the given subscriber to the mailing list.
|
89
89
|
def add_subscriber(subscriber)
|
90
90
|
res = aos.req_json("v1/mailinglists/#{self.data(:id)}/subscriptions/#{subscriber.data(:id)}", :post)
|
@@ -94,7 +94,7 @@ class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase
|
|
94
94
|
raise "Unexpected result: '#{res["Result"]}'."
|
95
95
|
end
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
# Removes the given subscriber from the mailing list.
|
99
99
|
def remove_subscriber(subscriber)
|
100
100
|
res = aos.req_json("v1/mailinglists/#{self.data(:id)}/subscriptions/#{subscriber.data(:id)}", :delete)
|
@@ -104,20 +104,20 @@ class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase
|
|
104
104
|
raise "Unexpected result: '#{res["Result"]}'."
|
105
105
|
end
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
# Removes all subscribers from the mailing list.
|
109
109
|
def remove_all_subscribers
|
110
110
|
res = aos.req_json("v1/mailinglists/#{self.data(:id)}/subscriptions/all", :delete)
|
111
111
|
raise "Unexpected result: #{res}" if res["Code"] != 1
|
112
112
|
url = URI.parse(res["Result"]["PollURL"])
|
113
113
|
data = nil
|
114
|
-
|
114
|
+
|
115
115
|
Timeout.timeout(300) do
|
116
116
|
loop do
|
117
117
|
sleep 1
|
118
|
-
|
118
|
+
|
119
119
|
res = aos.req_json(url.path)
|
120
|
-
|
120
|
+
|
121
121
|
if res["State"] == "2"
|
122
122
|
url_data = URI.parse(res["DataUrl"])
|
123
123
|
data = aos.req_json(url_data.path)
|
@@ -129,10 +129,16 @@ class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
return nil
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
|
+
def count_subscribers
|
137
|
+
res = aos.req_json("v1/mailinglists/#{self.data(:id)}/subscriptions/count")
|
138
|
+
raise "Unexpected result: #{res}" if res["Code"] != 1
|
139
|
+
return res["Result"]
|
140
|
+
end
|
141
|
+
|
136
142
|
# Returns true if the given subscriber is a member of the mailing list.
|
137
143
|
def member?(sub)
|
138
144
|
sub.mailing_lists.each do |mlist|
|
@@ -140,22 +146,22 @@ class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase
|
|
140
146
|
return true
|
141
147
|
end
|
142
148
|
end
|
143
|
-
|
149
|
+
|
144
150
|
return false
|
145
151
|
end
|
146
|
-
|
152
|
+
|
147
153
|
# Deletes the mailing list from APSIS.
|
148
154
|
def delete
|
149
|
-
res = aos.req_json("v1/mailinglists/", :delete, :
|
150
|
-
|
155
|
+
res = aos.req_json("v1/mailinglists/", :delete, json: [data(:id)])
|
156
|
+
|
151
157
|
url = URI.parse(res["Result"]["PollURL"])
|
152
158
|
data = nil
|
153
|
-
|
159
|
+
|
154
160
|
Timeout.timeout(300) do
|
155
161
|
loop do
|
156
162
|
sleep 1
|
157
163
|
res = aos.req_json(url.path)
|
158
|
-
|
164
|
+
|
159
165
|
if res["State"] == "2"
|
160
166
|
data_url = URI.parse(res["DataUrl"])
|
161
167
|
data = aos.req_json(data_url.path)
|
@@ -167,15 +173,15 @@ class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase
|
|
167
173
|
end
|
168
174
|
end
|
169
175
|
end
|
170
|
-
|
176
|
+
|
171
177
|
data.each do |element|
|
172
178
|
raise "Unexpected result: '#{data}'." if element["Value"] != "Succefully deleted"
|
173
179
|
end
|
174
180
|
end
|
175
|
-
|
181
|
+
|
176
182
|
# Moves a subscriber to the opt-out-list.
|
177
183
|
def opt_out_subscriber(sub)
|
178
|
-
res = aos.req_json("v1/optouts/mailinglists/#{data(:id)}/subscribers/queued", :post, :
|
184
|
+
res = aos.req_json("v1/optouts/mailinglists/#{data(:id)}/subscribers/queued", :post, json: [{
|
179
185
|
"ExternalId" => "",
|
180
186
|
"Reason" => "",
|
181
187
|
"SendQueueId" => 0,
|
@@ -183,42 +189,42 @@ class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase
|
|
183
189
|
}])
|
184
190
|
raise "Unexpected result: #{res}" if res["Code"] != 1
|
185
191
|
data = aos.read_queued_response(res["Result"]["PollURL"])
|
186
|
-
|
192
|
+
|
187
193
|
raise data if data["FailedSubscriberIds"] && data["FailedSubscriberIds"].any?
|
188
194
|
end
|
189
|
-
|
195
|
+
|
190
196
|
# Returns a list of subscribers on the opt-out-list.
|
191
197
|
def opt_out_list
|
192
198
|
res = aos.req_json("v1/optouts/mailinglists/#{data(:id)}/queued", :post)
|
193
199
|
raise "Unexpected result: #{res}" if res["Code"] != 1
|
194
200
|
data = aos.read_queued_response(res["Result"]["PollURL"])
|
195
|
-
|
201
|
+
|
196
202
|
ret = []
|
197
203
|
data.each do |opt_out_data|
|
198
|
-
sub = ApsisOnSteroids::Subscriber.new(:
|
199
|
-
|
204
|
+
sub = ApsisOnSteroids::Subscriber.new(aos: aos, data: {id: opt_out_data["Id"], email: opt_out_data["Email"]})
|
205
|
+
|
200
206
|
if block_given?
|
201
207
|
yield sub
|
202
208
|
else
|
203
209
|
ret << sub
|
204
210
|
end
|
205
211
|
end
|
206
|
-
|
212
|
+
|
207
213
|
return ret
|
208
214
|
end
|
209
|
-
|
215
|
+
|
210
216
|
# Returns true if the given subscriber is on the opt-out-list.
|
211
217
|
def opt_out?(sub)
|
212
218
|
opt_out_list do |sub_opt_out|
|
213
219
|
return true if sub_opt_out.data(:email) == sub.data(:email) || sub.data(:id).to_i == sub_opt_out.data(:id).to_i
|
214
220
|
end
|
215
|
-
|
221
|
+
|
216
222
|
return false
|
217
223
|
end
|
218
|
-
|
224
|
+
|
219
225
|
# Removes the given subscriber from the opt-out-list.
|
220
226
|
def opt_out_remove_subscriber(sub)
|
221
|
-
res = aos.req_json("v1/optouts/mailinglists/#{data(:id)}/subscribers/queued", :delete, :
|
227
|
+
res = aos.req_json("v1/optouts/mailinglists/#{data(:id)}/subscribers/queued", :delete, json: [
|
222
228
|
sub.data(:email)
|
223
229
|
])
|
224
230
|
data = aos.read_queued_response(res["Result"]["PollURL"])
|
data/include/subscriber.rb
CHANGED
@@ -3,50 +3,50 @@ class ApsisOnSteroids::Subscriber < ApsisOnSteroids::SubBase
|
|
3
3
|
def details
|
4
4
|
if !@details
|
5
5
|
res = aos.req_json("v1/subscribers/id/#{data(:id)}")
|
6
|
-
|
6
|
+
|
7
7
|
ret = {}
|
8
8
|
res["Result"].each do |key, val|
|
9
9
|
ret[key.to_sym] = val
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
@details = ret
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
return @details
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# Returns the DemDataField by the given key.
|
19
19
|
def dem_data(key)
|
20
20
|
key = key.to_s.downcase
|
21
|
-
|
21
|
+
|
22
22
|
self.details[:DemDataFields].each do |dem_data|
|
23
23
|
if dem_data["Key"].to_s.downcase == key
|
24
24
|
return dem_data["Value"]
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
return nil
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
# Returns true if the subscriber is active.
|
32
32
|
def active?
|
33
33
|
details = self.details
|
34
34
|
return false if details[:pending]
|
35
35
|
return true
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
# Update one or more details on the subscriber.
|
39
39
|
def update(data)
|
40
40
|
begin
|
41
|
-
res = aos.req_json("v1/subscribers/queue", :post, :
|
41
|
+
res = aos.req_json("v1/subscribers/queue", :post, json: [data.merge(:Id => self.data(:id))])
|
42
42
|
url = URI.parse(res["Result"]["PollURL"])
|
43
43
|
data = nil
|
44
|
-
|
44
|
+
|
45
45
|
Timeout.timeout(300) do
|
46
46
|
loop do
|
47
47
|
sleep 1
|
48
48
|
res = aos.req_json(url.path)
|
49
|
-
|
49
|
+
|
50
50
|
if res["State"] == "2"
|
51
51
|
url_data = URI.parse(res["DataUrl"])
|
52
52
|
data = aos.req_json(url_data.path)
|
@@ -58,10 +58,10 @@ class ApsisOnSteroids::Subscriber < ApsisOnSteroids::SubBase
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
if data["FailedUpdatedSubscribers"] && data["FailedUpdatedSubscribers"].any?
|
63
63
|
msg = raise data["FailedUpdatedSubscribers"].to_s
|
64
|
-
|
64
|
+
|
65
65
|
if msg.include?("Timeout expired.")
|
66
66
|
raise Errno::EAGAIN, msg
|
67
67
|
else
|
@@ -71,23 +71,23 @@ class ApsisOnSteroids::Subscriber < ApsisOnSteroids::SubBase
|
|
71
71
|
rescue Errno::EAGAIN
|
72
72
|
retry
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
@details = nil
|
76
76
|
return nil
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
# Returns an array of mailing lists that the sucscriber is subscribed to.
|
80
80
|
def mailing_lists
|
81
81
|
ret = []
|
82
|
-
|
82
|
+
|
83
83
|
res = aos.req_json("v1/subscribers/#{self.data(:id)}/mailinglists")
|
84
84
|
raise "Unexpected result: #{res}" if res["Code"] != 1 || !res["Result"].is_a?(Hash)
|
85
|
-
|
85
|
+
|
86
86
|
res["Result"]["Mailinglists"].each do |mlist_data|
|
87
|
-
mlist = ApsisOnSteroids::MailingList.new(:
|
87
|
+
mlist = ApsisOnSteroids::MailingList.new(data: mlist_data, aos: aos)
|
88
88
|
ret << mlist
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
return ret
|
92
92
|
end
|
93
93
|
end
|
data/lib/apsis-on-steroids.rb
CHANGED
@@ -3,6 +3,7 @@ require "http2"
|
|
3
3
|
require "string-cases"
|
4
4
|
require "timeout"
|
5
5
|
require "cgi"
|
6
|
+
require "tretry"
|
6
7
|
|
7
8
|
class ApsisOnSteroids
|
8
9
|
STRFTIME_FORMAT = "%Y%m%dT%H%M%S"
|
@@ -19,21 +20,7 @@ class ApsisOnSteroids
|
|
19
20
|
raise "Invalid API key: '#{args[:api_key]}' from: '#{args}'." if args[:api_key].to_s.strip.empty?
|
20
21
|
|
21
22
|
@args = args
|
22
|
-
|
23
|
-
host: "se.api.anpdm.com",
|
24
|
-
port: 8443,
|
25
|
-
ssl: true,
|
26
|
-
follow_redirects: false,
|
27
|
-
debug: args[:debug],
|
28
|
-
extra_headers: {
|
29
|
-
"Accept" => "text/json, application/json"
|
30
|
-
},
|
31
|
-
basic_auth: {
|
32
|
-
user: @args[:api_key],
|
33
|
-
passwd: ""
|
34
|
-
},
|
35
|
-
skip_port_in_host_header: true
|
36
|
-
)
|
23
|
+
reconnect
|
37
24
|
|
38
25
|
if block_given?
|
39
26
|
begin
|
@@ -143,13 +130,28 @@ class ApsisOnSteroids
|
|
143
130
|
|
144
131
|
def req_json(url, type = :get, method_args = {})
|
145
132
|
# Parse arguments, send and parse the result.
|
146
|
-
args = {
|
147
|
-
|
133
|
+
args = {url: url.start_with?('/') ? url[1..-1] : url}.merge(method_args)
|
134
|
+
try = ::Tretry.new
|
135
|
+
try.timeout = 300
|
148
136
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
137
|
+
if type == :get
|
138
|
+
try.tries = 3
|
139
|
+
try.before_retry { @http.reconnect }
|
140
|
+
else
|
141
|
+
# Don't retry a manipulatable method!
|
142
|
+
try.tries = 1
|
143
|
+
end
|
144
|
+
|
145
|
+
res = nil
|
146
|
+
try.try do
|
147
|
+
http_res = @http.__send__(type, args)
|
148
|
+
|
149
|
+
# Throw custom JSON error for debugging if the JSON was corrupt (this actually happens!).
|
150
|
+
begin
|
151
|
+
res = JSON.parse(http_res.body)
|
152
|
+
rescue JSON::ParserError
|
153
|
+
raise "Invalid JSON given: '#{http_res.body}'."
|
154
|
+
end
|
153
155
|
end
|
154
156
|
|
155
157
|
# Check for various kind of server errors and raise them as Ruby errors if present.
|
@@ -180,7 +182,7 @@ class ApsisOnSteroids
|
|
180
182
|
end
|
181
183
|
end
|
182
184
|
|
183
|
-
def read_resources_from_array
|
185
|
+
def read_resources_from_array(resource_class_name, resource_array)
|
184
186
|
Enumerator.new do |yielder|
|
185
187
|
resource_array.each do |resource_data|
|
186
188
|
resource = ApsisOnSteroids.const_get(resource_class_name).new(aos: self, data: resource_data)
|
@@ -219,4 +221,26 @@ class ApsisOnSteroids
|
|
219
221
|
return obj
|
220
222
|
end
|
221
223
|
end
|
224
|
+
|
225
|
+
private
|
226
|
+
|
227
|
+
def reconnect
|
228
|
+
@http.destroy if @http
|
229
|
+
|
230
|
+
@http = Http2.new(
|
231
|
+
host: "se.api.anpdm.com",
|
232
|
+
port: 8443,
|
233
|
+
ssl: true,
|
234
|
+
follow_redirects: false,
|
235
|
+
debug: @args[:debug],
|
236
|
+
extra_headers: {
|
237
|
+
"Accept" => "text/json, application/json"
|
238
|
+
},
|
239
|
+
basic_auth: {
|
240
|
+
user: @args[:api_key],
|
241
|
+
passwd: ""
|
242
|
+
},
|
243
|
+
skip_port_in_host_header: true
|
244
|
+
)
|
245
|
+
end
|
222
246
|
end
|
@@ -3,8 +3,8 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
describe "ApsisOnSteroids" do
|
4
4
|
let(:aos) do
|
5
5
|
ApsisOnSteroids.new(
|
6
|
-
:
|
7
|
-
:
|
6
|
+
api_key: File.read("#{File.dirname(__FILE__)}/api_key.txt").strip,
|
7
|
+
debug: false
|
8
8
|
)
|
9
9
|
end
|
10
10
|
|
@@ -40,7 +40,7 @@ describe "ApsisOnSteroids" do
|
|
40
40
|
raise "list is empty!?" if list.empty?
|
41
41
|
|
42
42
|
sending = list.first
|
43
|
-
puts "Sending data: #{sending.data_hash}"
|
43
|
+
# puts "Sending data: #{sending.data_hash}"
|
44
44
|
|
45
45
|
# Test the call doesnt fail.
|
46
46
|
sending.mailing_lists.first
|
@@ -49,7 +49,6 @@ describe "ApsisOnSteroids" do
|
|
49
49
|
bounce = sending.bounces.first
|
50
50
|
|
51
51
|
opt_outs_count = sending.opt_outs(count: true)
|
52
|
-
puts "Opt outs count: #{opt_outs_count}"
|
53
52
|
end
|
54
53
|
|
55
54
|
context do
|
@@ -102,6 +101,11 @@ describe "ApsisOnSteroids" do
|
|
102
101
|
mlist.subscriber_by_email(sub.data(:email)).should_not eq nil
|
103
102
|
end
|
104
103
|
|
104
|
+
it "should count subscribers on mailing lists" do
|
105
|
+
count = mlist.count_subscribers
|
106
|
+
count.is_a?(Integer).should eq true
|
107
|
+
end
|
108
|
+
|
105
109
|
it "can get lists of subscribers from lists" do
|
106
110
|
original_sub = sub
|
107
111
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apsis-on-steroids
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaspernj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http2
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tretry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.2
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|