apsis-on-steroids 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +16 -13
- data/README.md +14 -0
- data/VERSION +1 -1
- data/apsis-on-steroids.gemspec +6 -6
- data/include/mailing_list.rb +45 -4
- data/include/open.rb +0 -1
- data/include/opt_out.rb +0 -1
- data/include/sending.rb +6 -6
- data/include/subscriber.rb +7 -6
- data/lib/apsis-on-steroids.rb +24 -1
- data/spec/apsis-on-steroids_spec.rb +39 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2c97fee6983418cf2f499e0f3f901f5d51bda48
|
4
|
+
data.tar.gz: ddd8592da71bc82976ceb05ba2ec3ebe9209d1a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9063c474acfba9d052f8186f76827753fc9d46f8f772104175551ea453e70a4593e4fded4d169913d4511cc2973221347503483a71f19033ec2532b2b04df0d7
|
7
|
+
data.tar.gz: b0506c2a5ae64f3e7a74858deae5809c2479eb7c3d6cc6a3c5735f4c54ec2b36ffe67d9be0eb4fc054f11dbf19c3f520232f794bd1bc5c6f6f189ceb7195b601
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
addressable (2.3.
|
4
|
+
addressable (2.3.8)
|
5
5
|
builder (3.2.2)
|
6
6
|
diff-lcs (1.1.3)
|
7
7
|
faraday (0.8.9)
|
8
8
|
multipart-post (~> 1.2.0)
|
9
|
-
git (1.2.
|
9
|
+
git (1.2.9.1)
|
10
10
|
github_api (0.10.1)
|
11
11
|
addressable
|
12
12
|
faraday (~> 0.8.1)
|
@@ -14,10 +14,10 @@ GEM
|
|
14
14
|
multi_json (~> 1.4)
|
15
15
|
nokogiri (~> 1.5.2)
|
16
16
|
oauth2
|
17
|
-
hashie (3.
|
18
|
-
highline (1.
|
19
|
-
http2 (0.0.
|
20
|
-
string-cases
|
17
|
+
hashie (3.4.1)
|
18
|
+
highline (1.7.2)
|
19
|
+
http2 (0.0.31)
|
20
|
+
string-cases (~> 0)
|
21
21
|
jeweler (1.8.8)
|
22
22
|
builder
|
23
23
|
bundler (~> 1.0)
|
@@ -27,9 +27,9 @@ GEM
|
|
27
27
|
nokogiri (= 1.5.10)
|
28
28
|
rake
|
29
29
|
rdoc
|
30
|
-
json (1.8.
|
31
|
-
jwt (1.
|
32
|
-
multi_json (1.
|
30
|
+
json (1.8.2)
|
31
|
+
jwt (1.5.0)
|
32
|
+
multi_json (1.11.0)
|
33
33
|
multi_xml (0.5.5)
|
34
34
|
multipart-post (1.2.0)
|
35
35
|
nokogiri (1.5.10)
|
@@ -39,8 +39,8 @@ GEM
|
|
39
39
|
multi_json (~> 1.3)
|
40
40
|
multi_xml (~> 0.5)
|
41
41
|
rack (~> 1.2)
|
42
|
-
rack (1.
|
43
|
-
rake (10.
|
42
|
+
rack (1.6.1)
|
43
|
+
rake (10.4.2)
|
44
44
|
rdoc (3.12.2)
|
45
45
|
json (~> 1.4)
|
46
46
|
rspec (2.8.0)
|
@@ -51,7 +51,7 @@ GEM
|
|
51
51
|
rspec-expectations (2.8.0)
|
52
52
|
diff-lcs (~> 1.1.2)
|
53
53
|
rspec-mocks (2.8.0)
|
54
|
-
string-cases (0.0.
|
54
|
+
string-cases (0.0.1)
|
55
55
|
tretry (0.0.2)
|
56
56
|
|
57
57
|
PLATFORMS
|
@@ -59,9 +59,12 @@ PLATFORMS
|
|
59
59
|
|
60
60
|
DEPENDENCIES
|
61
61
|
bundler (>= 1.0.0)
|
62
|
-
http2 (~> 0.0.
|
62
|
+
http2 (~> 0.0.31)
|
63
63
|
jeweler (~> 1.8.4)
|
64
64
|
rdoc (~> 3.12)
|
65
65
|
rspec (~> 2.8.0)
|
66
66
|
string-cases
|
67
67
|
tretry (= 0.0.2)
|
68
|
+
|
69
|
+
BUNDLED WITH
|
70
|
+
1.10.5
|
data/README.md
CHANGED
@@ -98,6 +98,20 @@ aos.subscribers do |sub|
|
|
98
98
|
end
|
99
99
|
```
|
100
100
|
|
101
|
+
### Bundle various field names in same request (which means they are already preloaded and won't cause an extra request each time you ask for the fields)
|
102
|
+
```ruby
|
103
|
+
aos.subscribers(field_names: ["MyData1", "MyData2"]) do |sub|
|
104
|
+
# do something
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
### Bundle all data in same request
|
109
|
+
```ruby
|
110
|
+
aos.subscribers(all_demographics: true) do |sub|
|
111
|
+
# do something
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
101
115
|
### Get sendings
|
102
116
|
```ruby
|
103
117
|
date_from = Date.new(2014, 6, 17)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.13
|
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.13 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.13"
|
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 = "
|
14
|
+
s.date = "2015-09-10"
|
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 = [
|
@@ -50,7 +50,7 @@ Gem::Specification.new do |s|
|
|
50
50
|
s.specification_version = 4
|
51
51
|
|
52
52
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
|
-
s.add_runtime_dependency(%q<http2>, ["~> 0.0.
|
53
|
+
s.add_runtime_dependency(%q<http2>, ["~> 0.0.31"])
|
54
54
|
s.add_runtime_dependency(%q<string-cases>, [">= 0"])
|
55
55
|
s.add_runtime_dependency(%q<tretry>, ["= 0.0.2"])
|
56
56
|
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
@@ -58,7 +58,7 @@ Gem::Specification.new do |s|
|
|
58
58
|
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
59
59
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
60
60
|
else
|
61
|
-
s.add_dependency(%q<http2>, ["~> 0.0.
|
61
|
+
s.add_dependency(%q<http2>, ["~> 0.0.31"])
|
62
62
|
s.add_dependency(%q<string-cases>, [">= 0"])
|
63
63
|
s.add_dependency(%q<tretry>, ["= 0.0.2"])
|
64
64
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
@@ -67,7 +67,7 @@ Gem::Specification.new do |s|
|
|
67
67
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
68
68
|
end
|
69
69
|
else
|
70
|
-
s.add_dependency(%q<http2>, ["~> 0.0.
|
70
|
+
s.add_dependency(%q<http2>, ["~> 0.0.31"])
|
71
71
|
s.add_dependency(%q<string-cases>, [">= 0"])
|
72
72
|
s.add_dependency(%q<tretry>, ["= 0.0.2"])
|
73
73
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
data/include/mailing_list.rb
CHANGED
@@ -28,17 +28,33 @@ class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase
|
|
28
28
|
data_subscribers
|
29
29
|
end
|
30
30
|
|
31
|
+
SUBSCRIBERS_VALID_ARGS = [:all_demographics, :timeout, :field_names, :allow_paginated]
|
32
|
+
|
31
33
|
# Returns the subscribers of the mailing list.
|
32
|
-
def subscribers
|
34
|
+
def subscribers(args = {}, &blk)
|
35
|
+
args.each do |key, value|
|
36
|
+
raise "Invalid argument: '#{key}'." unless SUBSCRIBERS_VALID_ARGS.include?(key)
|
37
|
+
end
|
38
|
+
|
39
|
+
all_demographics = args.key?(:all_demographics) ? args[:all_demographics] : false
|
40
|
+
timeout = args[:timeout] || 300
|
41
|
+
field_names = args[:field_names] || []
|
42
|
+
allow_paginated = args.key?(:allow_paginated) ? args[:allow_paginated] : true
|
43
|
+
|
44
|
+
# Abort and do paginated if no reason to get everything as JSON.
|
45
|
+
if allow_paginated && !all_demographics && field_names.empty?
|
46
|
+
return subscribers_paginated(&blk)
|
47
|
+
end
|
48
|
+
|
33
49
|
res = aos.req_json("v1/mailinglists/#{data(:id)}/subscribers/all", :post, json: {
|
34
|
-
"AllDemographics" =>
|
35
|
-
"FieldNames" =>
|
50
|
+
"AllDemographics" => all_demographics,
|
51
|
+
"FieldNames" => field_names
|
36
52
|
})
|
37
53
|
|
38
54
|
url = URI.parse(res["Result"]["PollURL"])
|
39
55
|
data_subscribers = nil
|
40
56
|
|
41
|
-
Timeout.timeout(
|
57
|
+
Timeout.timeout(timeout) do
|
42
58
|
loop do
|
43
59
|
sleep 1
|
44
60
|
res = aos.req_json(url.path)
|
@@ -62,6 +78,31 @@ class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase
|
|
62
78
|
data: aos.parse_obj(sub_data)
|
63
79
|
)
|
64
80
|
|
81
|
+
if all_demographics || !field_names.empty?
|
82
|
+
sub.instance_variable_set(:@dem_data_fields, sub_data["DemographicData"])
|
83
|
+
end
|
84
|
+
|
85
|
+
if blk
|
86
|
+
blk.call(sub)
|
87
|
+
else
|
88
|
+
ret << sub
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
return ret
|
93
|
+
end
|
94
|
+
|
95
|
+
# Returns the subscribers of the mailing list.
|
96
|
+
def subscribers_paginated
|
97
|
+
resource_url = "v1/mailinglists/#{data(:id)}/subscribers/%{page}/%{size}"
|
98
|
+
|
99
|
+
ret = []
|
100
|
+
aos.read_paginated_response(resource_url) do |sub_data|
|
101
|
+
sub = ApsisOnSteroids::Subscriber.new(
|
102
|
+
aos: self.aos,
|
103
|
+
data: aos.parse_obj(sub_data)
|
104
|
+
)
|
105
|
+
|
65
106
|
if block_given?
|
66
107
|
yield sub
|
67
108
|
else
|
data/include/open.rb
CHANGED
data/include/opt_out.rb
CHANGED
data/include/sending.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
class ApsisOnSteroids::Sending < ApsisOnSteroids::SubBase
|
2
|
-
def clicks
|
2
|
+
def clicks(args = {})
|
3
3
|
list_for("v1/clicks/sendqueues/%{send_queue_id}/page/%{page}/size/%{size}", "v1/sendqueues/%{send_queue_id}/clicks", "Click", args)
|
4
4
|
end
|
5
5
|
|
6
|
-
def opens
|
6
|
+
def opens(args = {})
|
7
7
|
list_for("v1/opens/sendqueues/%{send_queue_id}/page/%{page}/size/%{size}", "v1/sendqueues/%{send_queue_id}/opens", "Open", args)
|
8
8
|
end
|
9
9
|
|
10
|
-
def bounces
|
10
|
+
def bounces(args = {})
|
11
11
|
list_for("v1/bounces/sendqueues/%{send_queue_id}/page/%{page}/size/%{size}", "v1/sendqueues/%{send_queue_id}/bounces", "Bounce", args)
|
12
12
|
end
|
13
13
|
|
14
|
-
def opt_outs
|
14
|
+
def opt_outs(args = {})
|
15
15
|
list_for("v1/optouts/sendqueues/%{send_queue_id}/%{page}/%{size}", "v1/sendqueues/%{send_queue_id}/optouts", "OptOut", args)
|
16
16
|
end
|
17
17
|
|
@@ -26,7 +26,7 @@ class ApsisOnSteroids::Sending < ApsisOnSteroids::SubBase
|
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
def list_for_with_dates
|
29
|
+
def list_for_with_dates(resource_url, resource_name, args)
|
30
30
|
resource_url = resource_url.gsub("%{send_queue_id}", data(:send_queue_id).to_s)
|
31
31
|
|
32
32
|
ub = aos.new_url_builder
|
@@ -48,7 +48,7 @@ private
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def list_for
|
51
|
+
def list_for(resource_url, resource_url_with_dates, resource_name, args = {})
|
52
52
|
# OptOut counting does not work :-( We will have to do the date request to fix this...
|
53
53
|
# If date-arguments are given, we will have to use the date request.
|
54
54
|
if args[:date_from] || args[:date_to] || resource_name == "OptOut"
|
data/include/subscriber.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class ApsisOnSteroids::Subscriber < ApsisOnSteroids::SubBase
|
2
2
|
# Fetches the details from the server and returns them.
|
3
3
|
def details
|
4
|
-
|
4
|
+
unless @details
|
5
5
|
res = aos.req_json("v1/subscribers/id/#{data(:id)}")
|
6
6
|
|
7
7
|
ret = {}
|
@@ -19,18 +19,19 @@ class ApsisOnSteroids::Subscriber < ApsisOnSteroids::SubBase
|
|
19
19
|
def dem_data(key)
|
20
20
|
key = key.to_s.downcase
|
21
21
|
|
22
|
-
|
23
|
-
if dem_data["Key"].to_s.downcase == key
|
24
|
-
return dem_data["Value"]
|
25
|
-
end
|
22
|
+
dem_data_fields.each do |dem_data|
|
23
|
+
return dem_data["Value"] if dem_data["Key"].to_s.downcase == key
|
26
24
|
end
|
27
25
|
|
28
26
|
return nil
|
29
27
|
end
|
30
28
|
|
29
|
+
def dem_data_fields
|
30
|
+
@dem_data_fields ||= details[:DemDataFields]
|
31
|
+
end
|
32
|
+
|
31
33
|
# Returns true if the subscriber is active.
|
32
34
|
def active?
|
33
|
-
details = self.details
|
34
35
|
return false if details[:pending]
|
35
36
|
return true
|
36
37
|
end
|
data/lib/apsis-on-steroids.rb
CHANGED
@@ -191,6 +191,27 @@ class ApsisOnSteroids
|
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
194
|
+
def read_paginated_response(resource_url)
|
195
|
+
page = 1
|
196
|
+
resource_url = resource_url.gsub("%{size}", "1000")
|
197
|
+
|
198
|
+
loop do
|
199
|
+
resource_url_to_use = resource_url.gsub("%{page}", page.to_s)
|
200
|
+
result = req_json(resource_url_to_use)
|
201
|
+
|
202
|
+
result["Result"]["Items"].each do |resource_data|
|
203
|
+
yield resource_data
|
204
|
+
end
|
205
|
+
|
206
|
+
size_no = result["Result"]["TotalPages"]
|
207
|
+
if page >= size_no
|
208
|
+
break
|
209
|
+
else
|
210
|
+
page += 1
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
194
215
|
def parse_obj(obj)
|
195
216
|
if obj.is_a?(Array)
|
196
217
|
ret = []
|
@@ -231,6 +252,7 @@ private
|
|
231
252
|
host: "se.api.anpdm.com",
|
232
253
|
port: 8443,
|
233
254
|
ssl: true,
|
255
|
+
ssl_skip_verify: true,
|
234
256
|
follow_redirects: false,
|
235
257
|
debug: @args[:debug],
|
236
258
|
extra_headers: {
|
@@ -240,7 +262,8 @@ private
|
|
240
262
|
user: @args[:api_key],
|
241
263
|
passwd: ""
|
242
264
|
},
|
243
|
-
skip_port_in_host_header: true
|
265
|
+
skip_port_in_host_header: true,
|
266
|
+
raise_errors: false
|
244
267
|
)
|
245
268
|
end
|
246
269
|
end
|
@@ -33,6 +33,8 @@ describe "ApsisOnSteroids" do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "#sendings_by_date_interval" do
|
36
|
+
require 'date'
|
37
|
+
|
36
38
|
date_from = Date.new(2013, 4, 1)
|
37
39
|
date_to = Date.new(2013, 6, 2)
|
38
40
|
|
@@ -110,12 +112,47 @@ describe "ApsisOnSteroids" do
|
|
110
112
|
original_sub = sub
|
111
113
|
|
112
114
|
count = 0
|
113
|
-
mlist.subscribers do |sub_i|
|
115
|
+
mlist.subscribers(allow_paginated: false) do |sub_i|
|
114
116
|
count += 1
|
115
117
|
#puts "Subscriber: #{sub_i}"
|
116
118
|
end
|
117
119
|
|
118
|
-
|
120
|
+
count.should > 0
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should include demographics data when set" do
|
124
|
+
original_sub = sub
|
125
|
+
|
126
|
+
count = 0
|
127
|
+
mlist.subscribers(all_demographics: true) do |sub_i|
|
128
|
+
count += 1
|
129
|
+
sub_i.instance_variable_get(:@dem_data_fields).should_not eq nil
|
130
|
+
end
|
131
|
+
|
132
|
+
count.should > 0
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should include optional fields as demographic data when set" do
|
136
|
+
original_sub = sub
|
137
|
+
|
138
|
+
count = 0
|
139
|
+
mlist.subscribers(field_names: ["NaoshiID"]) do |sub_i|
|
140
|
+
count += 1
|
141
|
+
sub_i.instance_variable_get(:@dem_data_fields).should eq [{"Key" => "NaoshiID", "Value" => ""}]
|
142
|
+
end
|
143
|
+
|
144
|
+
count.should > 0
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should get subscribers paginated" do
|
148
|
+
original_sub = sub
|
149
|
+
|
150
|
+
count = 0
|
151
|
+
mlist.subscribers_paginated do |sub_i|
|
152
|
+
count += 1
|
153
|
+
end
|
154
|
+
|
155
|
+
count.should > 0
|
119
156
|
end
|
120
157
|
|
121
158
|
it "can remove subscribers from lists" do
|
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.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaspernj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http2
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.0.
|
19
|
+
version: 0.0.31
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0.
|
26
|
+
version: 0.0.31
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: string-cases
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|