apsis-on-steroids 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +74 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/apsis-on-steroids.gemspec +69 -0
- data/include/mailing_list.rb +39 -0
- data/include/sub_base.rb +25 -0
- data/include/subscriber.rb +49 -0
- data/lib/apsis-on-steroids.rb +139 -0
- data/spec/apsis-on-steroids_spec.rb +63 -0
- data/spec/spec_helper.rb +12 -0
- metadata +161 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "http2", ">= 0.0.15"
|
7
|
+
gem "string-cases"
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "rspec", "~> 2.8.0"
|
13
|
+
gem "rdoc", "~> 3.12"
|
14
|
+
gem "bundler", ">= 1.0.0"
|
15
|
+
gem "jeweler", "~> 1.8.4"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
http2 (0.0.15)
|
7
|
+
jeweler (1.8.4)
|
8
|
+
bundler (~> 1.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
rdoc
|
12
|
+
json (1.8.0)
|
13
|
+
rake (10.1.0)
|
14
|
+
rdoc (3.12.2)
|
15
|
+
json (~> 1.4)
|
16
|
+
rspec (2.8.0)
|
17
|
+
rspec-core (~> 2.8.0)
|
18
|
+
rspec-expectations (~> 2.8.0)
|
19
|
+
rspec-mocks (~> 2.8.0)
|
20
|
+
rspec-core (2.8.0)
|
21
|
+
rspec-expectations (2.8.0)
|
22
|
+
diff-lcs (~> 1.1.2)
|
23
|
+
rspec-mocks (2.8.0)
|
24
|
+
string-cases (0.0.0)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler (>= 1.0.0)
|
31
|
+
http2 (>= 0.0.15)
|
32
|
+
jeweler (~> 1.8.4)
|
33
|
+
rdoc (~> 3.12)
|
34
|
+
rspec (~> 2.8.0)
|
35
|
+
string-cases
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 kaspernj
|
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/README.rdoc
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
= apsis-on-steroids
|
2
|
+
|
3
|
+
Library that implements the Apsis API in Ruby in regards to administrating subscribers and such for newsletters.
|
4
|
+
|
5
|
+
== Examples
|
6
|
+
|
7
|
+
=== Connecting
|
8
|
+
|
9
|
+
aos = ApsisOnSteroids.new(
|
10
|
+
:api_key => "[your api key]"
|
11
|
+
)
|
12
|
+
|
13
|
+
=== Get a mailing list.
|
14
|
+
|
15
|
+
mlist = aos.mailing_list_by_name("test_list")
|
16
|
+
|
17
|
+
=== Get a subscriber from a mailing list.
|
18
|
+
|
19
|
+
sub = mlist.subscriber_by_email("some@email.com")
|
20
|
+
|
21
|
+
=== Create one or more subscribers in a mailing list.
|
22
|
+
|
23
|
+
mlist.create_subscribers(
|
24
|
+
[
|
25
|
+
{
|
26
|
+
:Email => "some@email.com",
|
27
|
+
:Name => "Some Name"
|
28
|
+
},{
|
29
|
+
:Email => "some_other@email.com",
|
30
|
+
:Name => "Some Name"
|
31
|
+
}
|
32
|
+
]
|
33
|
+
)
|
34
|
+
|
35
|
+
=== Get details about subscribers.
|
36
|
+
|
37
|
+
puts "Details: #{sub.details}"
|
38
|
+
|
39
|
+
=== Update subscribers.
|
40
|
+
|
41
|
+
sub.update(:Email => "some_third@email.com")
|
42
|
+
|
43
|
+
=== Remove subscriber from a mailing list.
|
44
|
+
|
45
|
+
mlist.remove_subscriber(sub)
|
46
|
+
|
47
|
+
=== Get a list of subscribers from a mailing list.
|
48
|
+
|
49
|
+
list = mlist.subscribers
|
50
|
+
list.each do |sub|
|
51
|
+
# do something
|
52
|
+
end
|
53
|
+
|
54
|
+
=== Get a total list of subscribers.
|
55
|
+
|
56
|
+
aos.subscribers do |sub|
|
57
|
+
# do something
|
58
|
+
end
|
59
|
+
|
60
|
+
== Contributing to apsis-on-steroids
|
61
|
+
|
62
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
63
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
64
|
+
* Fork the project.
|
65
|
+
* Start a feature/bugfix branch.
|
66
|
+
* Commit and push until you are happy with your contribution.
|
67
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
68
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
69
|
+
|
70
|
+
== Copyright
|
71
|
+
|
72
|
+
Copyright (c) 2013 kaspernj. See LICENSE.txt for
|
73
|
+
further details.
|
74
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "apsis-on-steroids"
|
18
|
+
gem.homepage = "http://github.com/kaspernj/apsis-on-steroids"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A Ruby API for the Apsis mail service. }
|
21
|
+
gem.description = %Q{A Ruby API for the Apsis mail service. }
|
22
|
+
gem.email = "k@spernj.org"
|
23
|
+
gem.authors = ["kaspernj"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "apsis-on-steroids #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "apsis-on-steroids"
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["kaspernj"]
|
12
|
+
s.date = "2013-06-21"
|
13
|
+
s.description = "A Ruby API for the Apsis mail service. "
|
14
|
+
s.email = "k@spernj.org"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"apsis-on-steroids.gemspec",
|
29
|
+
"include/mailing_list.rb",
|
30
|
+
"include/sub_base.rb",
|
31
|
+
"include/subscriber.rb",
|
32
|
+
"lib/apsis-on-steroids.rb",
|
33
|
+
"spec/apsis-on-steroids_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = "http://github.com/kaspernj/apsis-on-steroids"
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = "1.8.23"
|
40
|
+
s.summary = "A Ruby API for the Apsis mail service."
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<http2>, [">= 0.0.15"])
|
47
|
+
s.add_runtime_dependency(%q<string-cases>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
49
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
50
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
51
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<http2>, [">= 0.0.15"])
|
54
|
+
s.add_dependency(%q<string-cases>, [">= 0"])
|
55
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
56
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
57
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<http2>, [">= 0.0.15"])
|
62
|
+
s.add_dependency(%q<string-cases>, [">= 0"])
|
63
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
64
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
65
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase
|
2
|
+
def create_subscribers(data)
|
3
|
+
aos.req_json("v1/subscribers/mailinglist/#{data(:id)}/queue", :post, :json => data)
|
4
|
+
end
|
5
|
+
|
6
|
+
def subscribers
|
7
|
+
res = aos.req_json("v1/mailinglists/#{data(:id)}/subscribers/all", :post, :json => {
|
8
|
+
"AllDemographics" => true,
|
9
|
+
"FieldNames" => []
|
10
|
+
})
|
11
|
+
|
12
|
+
url = URI.parse(res["Result"]["PollURL"])
|
13
|
+
|
14
|
+
Timeout.timeout(30) do
|
15
|
+
loop do
|
16
|
+
sleep 0.5
|
17
|
+
res = aos.req_json(url.path)
|
18
|
+
|
19
|
+
puts "Status res: #{res}"
|
20
|
+
|
21
|
+
if res["State"] == "2"
|
22
|
+
break
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
puts "Test: #{res}"
|
28
|
+
raise "Finish me!"
|
29
|
+
end
|
30
|
+
|
31
|
+
def remove_subscriber(subscriber)
|
32
|
+
res = aos.req_json("v1/mailinglists/#{self.data(:id)}/subscriptions/#{subscriber.data(:id)}", :delete)
|
33
|
+
if res["Result"] == "Deleted"
|
34
|
+
return nil
|
35
|
+
else
|
36
|
+
raise "Unexpected result: '#{res["Result"]}'."
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/include/sub_base.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
class ApsisOnSteroids::SubBase
|
2
|
+
def initialize(args)
|
3
|
+
@args = args
|
4
|
+
|
5
|
+
@data = {}
|
6
|
+
@args[:data].each do |key, val|
|
7
|
+
@data[StringCases.camel_to_snake(key).to_sym] = val
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def aos
|
12
|
+
return @args[:aos]
|
13
|
+
end
|
14
|
+
|
15
|
+
def data(name)
|
16
|
+
name = name.to_sym
|
17
|
+
return @data[name] if @data.key?(name)
|
18
|
+
raise "No such data: '#{name}'."
|
19
|
+
end
|
20
|
+
|
21
|
+
def method_missing(name, *args, &blk)
|
22
|
+
return @data[name.to_sym] if @data && @data.key?(name.to_sym)
|
23
|
+
raise "No such method: '#{name}'."
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class ApsisOnSteroids::Subscriber < ApsisOnSteroids::SubBase
|
2
|
+
# Fetches the details from the server and returns them.
|
3
|
+
def details
|
4
|
+
res = aos.req_json("v1/subscribers/id/#{data(:id)}")
|
5
|
+
|
6
|
+
ret = {}
|
7
|
+
res["Result"].each do |key, val|
|
8
|
+
ret[key.to_sym] = val
|
9
|
+
end
|
10
|
+
|
11
|
+
return ret
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns true if the subscriber is active.
|
15
|
+
def active?
|
16
|
+
details = self.details
|
17
|
+
|
18
|
+
if details[:pending]
|
19
|
+
return false
|
20
|
+
end
|
21
|
+
|
22
|
+
return true
|
23
|
+
end
|
24
|
+
|
25
|
+
# Update one or more details on the subscriber.
|
26
|
+
def update(data)
|
27
|
+
res = aos.req_json("v1/subscribers/queue", :post, :json => [
|
28
|
+
{
|
29
|
+
:Id => data(:id)
|
30
|
+
}.merge(data)
|
31
|
+
])
|
32
|
+
|
33
|
+
url = URI.parse(res["Result"]["PollURL"])
|
34
|
+
data = nil
|
35
|
+
|
36
|
+
loop do
|
37
|
+
res = aos.req_json(url.path)
|
38
|
+
|
39
|
+
if res["State"] == "2"
|
40
|
+
url_data = URI.parse(res["DataUrl"])
|
41
|
+
data = aos.req_json(url_data.path)
|
42
|
+
break
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
raise data["FailedUpdatedSubscribers"].to_s if data["FailedUpdatedSubscribers"] && data["FailedUpdatedSubscribers"].any?
|
47
|
+
return nil
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require "json"
|
2
|
+
require "http2"
|
3
|
+
require "string-cases"
|
4
|
+
require "timeout"
|
5
|
+
require "cgi"
|
6
|
+
|
7
|
+
class ApsisOnSteroids
|
8
|
+
attr_reader :http
|
9
|
+
|
10
|
+
def self.const_missing(name)
|
11
|
+
require "#{File.dirname(__FILE__)}/../include/#{::StringCases.camel_to_snake(name)}"
|
12
|
+
raise "Still not loaded: '#{name}'." unless ApsisOnSteroids.const_defined?(name)
|
13
|
+
return ApsisOnSteroids.const_get(name)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(args)
|
17
|
+
@args = args
|
18
|
+
@http = Http2.new(
|
19
|
+
:host => "se.api.anpdm.com",
|
20
|
+
:port => 8443,
|
21
|
+
:ssl => true,
|
22
|
+
:follow_redirects => false,
|
23
|
+
:debug => args[:debug],
|
24
|
+
:extra_headers => {
|
25
|
+
"Accept" => "text/json, application/json"
|
26
|
+
},
|
27
|
+
:basic_auth => {
|
28
|
+
:user => @args[:api_key],
|
29
|
+
:passwd => ""
|
30
|
+
}
|
31
|
+
)
|
32
|
+
|
33
|
+
if block_given?
|
34
|
+
begin
|
35
|
+
yield self
|
36
|
+
ensure
|
37
|
+
@http.destroy
|
38
|
+
@http = nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def mailing_lists
|
44
|
+
res = req_json("v1/mailinglists/1/10")
|
45
|
+
|
46
|
+
ret = []
|
47
|
+
res["Result"]["Items"].each do |mlist|
|
48
|
+
ret << ApsisOnSteroids::MailingList.new(
|
49
|
+
:aos => self,
|
50
|
+
:data => mlist
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
return ret
|
55
|
+
end
|
56
|
+
|
57
|
+
def mailing_list_by_name(name)
|
58
|
+
self.mailing_lists.each do |mlist|
|
59
|
+
return mlist if name.to_s == mlist.name.to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
raise "Could not find mailing list by that name: '#{name}'."
|
63
|
+
end
|
64
|
+
|
65
|
+
def subscribers
|
66
|
+
# Request a list of all subs.
|
67
|
+
res = req_json("v1/subscribers/all", :post, :json => {
|
68
|
+
"AllDemographics" => true,
|
69
|
+
"FieldNames" => []
|
70
|
+
})
|
71
|
+
|
72
|
+
# Wait for the server to generate the list.
|
73
|
+
url = URI.parse(res["Result"]["PollURL"])
|
74
|
+
data = nil
|
75
|
+
|
76
|
+
Timeout.timeout(30) do
|
77
|
+
loop do
|
78
|
+
sleep 0.5
|
79
|
+
res = req_json(url.path)
|
80
|
+
|
81
|
+
if res["State"] == "2"
|
82
|
+
url_data = URI.parse(res["DataUrl"])
|
83
|
+
data = req_json(url_data.path)
|
84
|
+
break
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Parse the list of subscribers.
|
90
|
+
ret = [] unless block_given?
|
91
|
+
|
92
|
+
data.each do |sub_data|
|
93
|
+
sub = ApsisOnSteroids::Subscriber.new(
|
94
|
+
:aos => self,
|
95
|
+
:data => sub_data
|
96
|
+
)
|
97
|
+
|
98
|
+
if block_given?
|
99
|
+
yield sub
|
100
|
+
else
|
101
|
+
ret << sub
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
if block_given?
|
106
|
+
return nil
|
107
|
+
else
|
108
|
+
return ret
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def subscriber_by_email(email)
|
113
|
+
res = req_json("v1/subscribers/email/lookup/#{CGI.escape(email)}")
|
114
|
+
|
115
|
+
sub = ApsisOnSteroids::Subscriber.new(
|
116
|
+
:aos => self,
|
117
|
+
:data => {
|
118
|
+
"Id" => res["Result"],
|
119
|
+
"Email" => email
|
120
|
+
}
|
121
|
+
)
|
122
|
+
|
123
|
+
return sub
|
124
|
+
end
|
125
|
+
|
126
|
+
def req_json(url, type = :get, method_args = {})
|
127
|
+
# Parse arguments, send and parse the result.
|
128
|
+
args = {:url => url}.merge(method_args)
|
129
|
+
http_res = @http.__send__(type, args)
|
130
|
+
res = JSON.parse(http_res.body)
|
131
|
+
|
132
|
+
# Check for various kind of server errors and raise them as Ruby errors if present.
|
133
|
+
raise "Failed on server with code #{res["Code"]}: #{res["Message"]}" if res.is_a?(Hash) && res.key?("Code") && res["Code"] < 0
|
134
|
+
raise "Failed on server with state #{res["State"]} and name '#{res["StateName"]}': #{res["Message"]}" if res.is_a?(Hash) && res.key?("State") && res["State"].to_i < 0
|
135
|
+
|
136
|
+
# Return the result.
|
137
|
+
return res
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "ApsisOnSteroids" do
|
4
|
+
it "can connect" do
|
5
|
+
$aos = ApsisOnSteroids.new(
|
6
|
+
:api_key => File.read("#{File.dirname(__FILE__)}/api_key.txt").strip,
|
7
|
+
:debug => false
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "can get a mailing list" do
|
12
|
+
$mlist = $aos.mailing_list_by_name("kj")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can create subscribers" do
|
16
|
+
$mlist.create_subscribers([{
|
17
|
+
"Email" => "kj@gfish.com",
|
18
|
+
"Name" => "Kasper Johansen"
|
19
|
+
}])
|
20
|
+
end
|
21
|
+
|
22
|
+
it "can get subscribers and their details" do
|
23
|
+
$sub = $aos.subscriber_by_email("kj@gfish.com")
|
24
|
+
details = $sub.details
|
25
|
+
details.is_a?(Hash).should eql(true)
|
26
|
+
details.key?(:pending).should eql(true)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can update subscribers" do
|
30
|
+
new_email = "kaspernj#{Time.now.to_f}@naoshi-dev.com"
|
31
|
+
$sub.update(:Email => new_email)
|
32
|
+
$sub.details[:Email].should eql(new_email)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should not overwrite data when updating" do
|
36
|
+
addr = Time.now.to_f.to_s
|
37
|
+
$sub.update(:Address => addr)
|
38
|
+
|
39
|
+
new_email = "kaspernj#{Time.now.to_f}@naoshi-dev.com"
|
40
|
+
$sub.update(:Email => new_email)
|
41
|
+
|
42
|
+
$sub.details[:Address].should eql(addr)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "can remove subscribers from lists" do
|
46
|
+
$mlist.remove_subscriber($sub)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "can get lists of subscribers from lists" do
|
50
|
+
$mlist.subscribers do |sub|
|
51
|
+
puts "Subscriber: #{sub}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it "can validate if a subscriber is active or not" do
|
56
|
+
$sub.active?.should eql(true)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can get a list of all subscribers" do
|
60
|
+
total_list = $aos.subscribers
|
61
|
+
total_list.is_a?(Array).should eql(true)
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'apsis-on-steroids'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: apsis-on-steroids
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- kaspernj
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
none: false
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.0.15
|
21
|
+
name: http2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
requirement: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.15
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
version_requirements: !ruby/object:Gem::Requirement
|
32
|
+
none: false
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
name: string-cases
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
version_requirements: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ~>
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.8.0
|
53
|
+
name: rspec
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.8.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.12'
|
69
|
+
name: rdoc
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.12'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.0.0
|
85
|
+
name: bundler
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
requirement: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.0.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ~>
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 1.8.4
|
101
|
+
name: jeweler
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
requirement: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.8.4
|
110
|
+
description: ! 'A Ruby API for the Apsis mail service. '
|
111
|
+
email: k@spernj.org
|
112
|
+
executables: []
|
113
|
+
extensions: []
|
114
|
+
extra_rdoc_files:
|
115
|
+
- LICENSE.txt
|
116
|
+
- README.rdoc
|
117
|
+
files:
|
118
|
+
- .document
|
119
|
+
- .rspec
|
120
|
+
- Gemfile
|
121
|
+
- Gemfile.lock
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.rdoc
|
124
|
+
- Rakefile
|
125
|
+
- VERSION
|
126
|
+
- apsis-on-steroids.gemspec
|
127
|
+
- include/mailing_list.rb
|
128
|
+
- include/sub_base.rb
|
129
|
+
- include/subscriber.rb
|
130
|
+
- lib/apsis-on-steroids.rb
|
131
|
+
- spec/apsis-on-steroids_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
homepage: http://github.com/kaspernj/apsis-on-steroids
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
segments:
|
146
|
+
- 0
|
147
|
+
hash: -1005707843598481402
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ! '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 1.8.23
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: A Ruby API for the Apsis mail service.
|
161
|
+
test_files: []
|