silverpop 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gemtest +0 -0
- data/.gitignore +38 -0
- data/.rspec +2 -0
- data/.yardopts +3 -0
- data/Gemfile +4 -0
- data/LICENSE.md +12 -0
- data/README.md +79 -0
- data/Rakefile +16 -0
- data/lib/client/contact.rb +45 -0
- data/lib/client/reporting.rb +71 -0
- data/lib/silverpop.rb +23 -0
- data/lib/silverpop/client.rb +19 -0
- data/lib/silverpop/connection.rb +23 -0
- data/lib/silverpop/request.rb +22 -0
- data/lib/silverpop/version.rb +3 -0
- data/silverpop.gemspec +28 -0
- data/spec/client/contact_spec.rb +28 -0
- data/spec/client/reporting_spec.rb +74 -0
- data/spec/fixtures/contact.xml +10 -0
- data/spec/fixtures/reporting.xml +14 -0
- data/spec/helper.rb +25 -0
- data/spec/silverpop_spec.rb +15 -0
- metadata +239 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTNhZDM1YzIwY2RjODQwNjQ1MTY3NTk1NmQzYjBjYTFhOWYwMjk3Nw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NWNkMWQwYmUwNTY4NDc0NmYwM2YyZTNlNjZhM2FjNmJlNjllYmQyNw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZGFkZGM5ZTRiMjc5MzBiNTg1NWJlMGQ1MzJlYjhhMWY3MDVjYzUyNmFmZWZm
|
10
|
+
MmViNjA2ZjMyZTA5MzYyZGRlNmU5YmFhZTUxNzIxM2JiNzQ5ZWUyYjAyNWNk
|
11
|
+
YTY0Zjc5YzIwOGUyY2QyMTAxZTI4YTk3NDM3MzAyMmE2YjRlYmM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
M2U1ZjI2MzJiZDVjZmRhYjhiZDM2NGViYmU3MWZhNjdhMTljZTE2MzgzNGI2
|
14
|
+
OTg3NzA0MzkyZmJiNGY5ZWI4MTFhZGJmMzU5MDAzNGE2NDc3YzcxN2E4YjI4
|
15
|
+
M2NiMDE5NzZjNzQyY2EzZjliNDcwNTUyYzZjY2FmZDdjNDE5YjM=
|
data/.gemtest
ADDED
File without changes
|
data/.gitignore
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
*.sw[a-p]
|
4
|
+
*.tmproj
|
5
|
+
*.tmproject
|
6
|
+
*.un~
|
7
|
+
*~
|
8
|
+
.Spotlight-V100
|
9
|
+
.Trashes
|
10
|
+
._*
|
11
|
+
.bundle
|
12
|
+
.config
|
13
|
+
.directory
|
14
|
+
.elc
|
15
|
+
.emacs.desktop
|
16
|
+
.emacs.desktop.lock
|
17
|
+
.redcar
|
18
|
+
.yardoc
|
19
|
+
Desktop.ini
|
20
|
+
Gemfile.lock
|
21
|
+
Icon?
|
22
|
+
InstalledFiles
|
23
|
+
Session.vim
|
24
|
+
\#*\#
|
25
|
+
_yardoc
|
26
|
+
auto-save-list
|
27
|
+
coverage
|
28
|
+
doc
|
29
|
+
lib/bundler/man
|
30
|
+
pkg
|
31
|
+
pkg/*
|
32
|
+
rdoc
|
33
|
+
spec/reports
|
34
|
+
test/tmp
|
35
|
+
test/version_tmp
|
36
|
+
tmp
|
37
|
+
tmtags
|
38
|
+
tramp
|
data/.rspec
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Copyright (c) 2013, Cloud Tiger Media d.b.a. Upworthy
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
5
|
+
|
6
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
7
|
+
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
9
|
+
|
10
|
+
3. Neither the name of the Cloud Tiger Media d.b.a Upworthy nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# SilverPop API
|
2
|
+
A Ruby wrapper for the SilverPop API
|
3
|
+
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
## Documentation
|
8
|
+
|
9
|
+
|
10
|
+
## Usage Examples
|
11
|
+
require 'silverpop'
|
12
|
+
require 'oauth2'
|
13
|
+
|
14
|
+
#Generate your OAuth2 access token
|
15
|
+
client = OAuth2::Client.new(SILVERPOP_CLIENT_ID, SILVERPOP_CLIENT_SECRET, site: "https://api1.silverpop.com/oauth/token")
|
16
|
+
access_token = OAuth2::AccessToken.from_hash(client, refresh_token: SILVERPOP_REFRESH_TOKEN).refresh!
|
17
|
+
|
18
|
+
@client = SilverPop.new({access_token: access_token.token, url: "https://api1.silverpop.com"})
|
19
|
+
|
20
|
+
#add_recipeint
|
21
|
+
#pass in user variables, database contact list, and contact list id
|
22
|
+
a = @client.add_recipient({email:"test@example.com"}, 123, [456])
|
23
|
+
resp.Envelope.Body.RESULT.SUCCESS # => "TRUE"
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
In the spirit of [free software][free-sw], **everyone** is encouraged to help improve
|
27
|
+
this project.
|
28
|
+
|
29
|
+
[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
|
30
|
+
|
31
|
+
Here are some ways *you* can contribute:
|
32
|
+
|
33
|
+
* by using alpha, beta, and prerelease versions
|
34
|
+
* by reporting bugs
|
35
|
+
* by suggesting new features
|
36
|
+
* by writing or editing documentation
|
37
|
+
* by writing specifications
|
38
|
+
* by writing code (**no patch is too small**: fix typos, add comments, clean up
|
39
|
+
inconsistent whitespace)
|
40
|
+
* by refactoring code
|
41
|
+
* by fixing [issues][]
|
42
|
+
* by reviewing patches
|
43
|
+
|
44
|
+
[issues]: http://github.com/upworthy/silverpop/issues
|
45
|
+
|
46
|
+
## Submitting an Issue
|
47
|
+
We use the [GitHub issue tracker][issues] to track bugs and features. Before
|
48
|
+
submitting a bug report or feature request, check to make sure it hasn't
|
49
|
+
already been submitted. When submitting a bug report, please include a [Gist][]
|
50
|
+
that includes a stack trace and any details that may be necessary to reproduce
|
51
|
+
the bug, including your gem version, Ruby version, and operating system.
|
52
|
+
Ideally, a bug report should include a pull request with failing specs.
|
53
|
+
|
54
|
+
[gist]: https://gist.github.com/
|
55
|
+
|
56
|
+
## Submitting a Pull Request
|
57
|
+
1. [Fork the repository.][fork]
|
58
|
+
2. [Create a topic branch.][branch]
|
59
|
+
3. Add specs for your unimplemented feature or bug fix.
|
60
|
+
4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
|
61
|
+
5. Implement your feature or bug fix.
|
62
|
+
6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
|
63
|
+
7. Run `open coverage/index.html`. If your changes are not completely covered
|
64
|
+
by your tests, return to step 3.
|
65
|
+
8. Add documentation for your feature or bug fix.
|
66
|
+
9. Run `bundle exec rake yard`. If your changes are not 100% documented, go
|
67
|
+
back to step 8.
|
68
|
+
10. Add, commit, and push your changes.
|
69
|
+
11. [Submit a pull request.][pr]
|
70
|
+
|
71
|
+
[fork]: http://help.github.com/fork-a-repo/
|
72
|
+
[branch]: http://learn.github.com/p/branching.html
|
73
|
+
[pr]: http://help.github.com/send-pull-requests/
|
74
|
+
|
75
|
+
## Copyright
|
76
|
+
Copyright (c) 2013 Upworthy. See [LICENSE][] for details.
|
77
|
+
|
78
|
+
[license]: https://github.com/upworthy/silverpop/blob/master/LICENSE.md
|
79
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task :default => :spec
|
8
|
+
task :test => :spec
|
9
|
+
|
10
|
+
require 'yard'
|
11
|
+
namespace :doc do
|
12
|
+
YARD::Rake::YardocTask.new do |task|
|
13
|
+
task.files = ['LICENSE.md', 'lib/**/*.rb']
|
14
|
+
task.options = ['--markup', 'markdown']
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module SilverPop
|
2
|
+
class Client
|
3
|
+
module Contact
|
4
|
+
|
5
|
+
# Adds one new contact to an existing database.
|
6
|
+
#
|
7
|
+
# @param fields [Hash] The list of fields to be passed into SilverPop.
|
8
|
+
# @param list_id [Integer] The ID of the database which you are adding the contact
|
9
|
+
# @param contact_list_id [Array] The id of the contact list.
|
10
|
+
# @return [Mash] Mashify body from the API call
|
11
|
+
# @example Add a new email to the database and contact list
|
12
|
+
# s = SilverPop::Client.new(access_token)
|
13
|
+
# s.add_recipient({email: "test@example.com", firstname: "Hello"}, 12345, [4567])
|
14
|
+
def add_recipient(fields, list_id, contact_list_id, created_from=1, options={})
|
15
|
+
builder = Builder::XmlMarkup.new
|
16
|
+
xml = builder.Envelope {
|
17
|
+
builder.Body {
|
18
|
+
builder.AddRecipient {
|
19
|
+
builder.LIST_ID list_id
|
20
|
+
builder.CREATED_FROM created_from
|
21
|
+
builder.CONTACT_LISTS {
|
22
|
+
contact_list_id.each do |id|
|
23
|
+
builder.CONTACT_LIST_ID id
|
24
|
+
end
|
25
|
+
}
|
26
|
+
unless options.empty?
|
27
|
+
options.each do |opt|
|
28
|
+
builder.tag! opt[0], opt[1]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
fields.each do |field|
|
32
|
+
builder.COLUMN {
|
33
|
+
builder.NAME field[0].to_s
|
34
|
+
builder.VALUE field[1]
|
35
|
+
}
|
36
|
+
end
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
response = post(xml, options)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module SilverPop
|
2
|
+
class Client
|
3
|
+
module Reporting
|
4
|
+
|
5
|
+
# RawRecipientDataExport - Allows exporting unique contact-level events and creates a .zip file containing a single flat file with all metrics
|
6
|
+
#
|
7
|
+
# @param query_params [Hash] The list of fields to run the query against MAILING_ID, REPORT_ID, etc.
|
8
|
+
# @param options [Hash] The various options on how to export the data EXPORT_FORMAT, FILE_ENCODING, etc.
|
9
|
+
# @param columns [Array] Optional list of columns to limit the flat file.
|
10
|
+
# @return [Mash] Mashify body from the API call
|
11
|
+
# @example Export raw data events for mailing id
|
12
|
+
# s = SilverPop.new({access_token: "abc123", url: "https://api1.silverpop.com"})
|
13
|
+
# s.raw_recipient_data_export({MAILING_ID: 1234},{MOVE_TO_FTP: nil})
|
14
|
+
def raw_recipient_data_export(query_params={}, options={}, columns=[])
|
15
|
+
builder = Builder::XmlMarkup.new
|
16
|
+
xml = builder.Envelope {
|
17
|
+
builder.Body {
|
18
|
+
builder.RawRecipientDataExport {
|
19
|
+
unless query_params.empty?
|
20
|
+
query_params.each do |q|
|
21
|
+
if q[0] == :MAILING_ID || q[0] == :REPORT_ID
|
22
|
+
builder.MAILING {
|
23
|
+
builder.tag! q[0], q[1]
|
24
|
+
}
|
25
|
+
else
|
26
|
+
builder.tag! q[0], q[1]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
unless options.empty?
|
31
|
+
options.each do |opt|
|
32
|
+
builder.tag! opt[0], opt[1]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
unless columns.empty?
|
36
|
+
builder.COLUMNS {
|
37
|
+
columns.each do |column|
|
38
|
+
builder.COLUMN {
|
39
|
+
builder.NAME column
|
40
|
+
}
|
41
|
+
end
|
42
|
+
}
|
43
|
+
end
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
post(xml)
|
48
|
+
end
|
49
|
+
|
50
|
+
# GetJobStatus - After initiating a data job, you can monitor the status of the job using this operation.
|
51
|
+
#
|
52
|
+
# @param job_id [Integer] The Job ID of the data job
|
53
|
+
# @return [Mash] Mashify body from the API call
|
54
|
+
# @example Get Job Status for JOB_ID 1234
|
55
|
+
# s = SilverPop.new({access_token: "abc123", url: "https://api1.silverpop.com"})
|
56
|
+
# s.get_job_status(1234)
|
57
|
+
def get_job_status(job_id)
|
58
|
+
builder = Builder::XmlMarkup.new
|
59
|
+
xml = builder.Envelope {
|
60
|
+
builder.Body {
|
61
|
+
builder.GetJobStatus {
|
62
|
+
builder.JOB_ID job_id
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
post(xml)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/silverpop.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'silverpop/client'
|
2
|
+
|
3
|
+
module SilverPop
|
4
|
+
class << self
|
5
|
+
# Alias for SilverPop::Client.new
|
6
|
+
#
|
7
|
+
# @return [SilverPop::Client]
|
8
|
+
def new(options={})
|
9
|
+
SilverPop::Client.new(options)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Delegate to SilverPop::Client.new
|
13
|
+
def method_missing(method, *args, &block)
|
14
|
+
return super unless new.respond_to?(method)
|
15
|
+
new.send(method, *args, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def respond_to?(method, include_private=false)
|
19
|
+
new.respond_to?(method, include_private) || super(method, include_private)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'builder'
|
2
|
+
require 'silverpop/connection'
|
3
|
+
require 'silverpop/request'
|
4
|
+
require 'client/contact'
|
5
|
+
require 'client/reporting'
|
6
|
+
|
7
|
+
module SilverPop
|
8
|
+
class Client
|
9
|
+
def initialize(options={})
|
10
|
+
@access_token = options[:access_token]
|
11
|
+
@silverpop_url = options[:url]
|
12
|
+
end
|
13
|
+
|
14
|
+
include SilverPop::Connection
|
15
|
+
include SilverPop::Request
|
16
|
+
include SilverPop::Client::Contact
|
17
|
+
include SilverPop::Client::Reporting
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
|
3
|
+
module SilverPop
|
4
|
+
# @private
|
5
|
+
module Connection
|
6
|
+
private
|
7
|
+
|
8
|
+
def connection(options={})
|
9
|
+
connection = Faraday.new @silverpop_url do |conn|
|
10
|
+
# Uncomment if want to log to stdout
|
11
|
+
#conn.response :logger
|
12
|
+
|
13
|
+
conn.request :oauth2, @access_token
|
14
|
+
conn.request :url_encoded
|
15
|
+
conn.response :mashify
|
16
|
+
|
17
|
+
conn.response :xml, :content_type => /\bxml$/
|
18
|
+
conn.adapter Faraday.default_adapter
|
19
|
+
end
|
20
|
+
connection
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SilverPop
|
2
|
+
module Request
|
3
|
+
def post(path, options={})
|
4
|
+
request(:post, path, options)
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
# POST the XML to the SilverPop end point.
|
10
|
+
#
|
11
|
+
# @param body [String] The formatted XML of the API call make sure to call builder.to_xml.
|
12
|
+
# @return [XML] XML Body from the API call
|
13
|
+
def request(method, body, options)
|
14
|
+
response = connection.send(method) do |request|
|
15
|
+
request.url "/XMLAPI"
|
16
|
+
request.headers['Content-type'] = "text/xml"
|
17
|
+
request.body = body
|
18
|
+
end
|
19
|
+
response.body
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/silverpop.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path('../lib/silverpop/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.add_dependency 'addressable', '~> 2.3'
|
6
|
+
gem.add_dependency 'faraday', '~> 0.8'
|
7
|
+
gem.add_dependency 'faraday_middleware', '~> 0.8'
|
8
|
+
gem.add_dependency 'hashie', '~> 2.0'
|
9
|
+
gem.add_dependency 'builder', '~> 3.0'
|
10
|
+
gem.add_development_dependency 'oauth2'
|
11
|
+
gem.add_development_dependency 'rake'
|
12
|
+
gem.add_development_dependency 'rdiscount'
|
13
|
+
gem.add_development_dependency 'rspec'
|
14
|
+
gem.add_development_dependency 'simplecov'
|
15
|
+
gem.add_development_dependency 'webmock'
|
16
|
+
gem.add_development_dependency 'yard'
|
17
|
+
gem.author = "Upworthy"
|
18
|
+
gem.description = %q{A Ruby wrapper for the SilverPop API}
|
19
|
+
gem.email = 'webmaster@upworthy.com'
|
20
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
21
|
+
gem.files = `git ls-files`.split("\n")
|
22
|
+
gem.homepage = ''
|
23
|
+
gem.name = 'silverpop'
|
24
|
+
gem.require_paths = ['lib']
|
25
|
+
gem.summary = gem.description
|
26
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
27
|
+
gem.version = SilverPop::VERSION
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe SilverPop::Client::Contact do
|
4
|
+
before do
|
5
|
+
@client = SilverPop::Client.new({access_token: "abc123",url: 'https://api1.silverpop.com'})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#add_recipient" do
|
9
|
+
it "should add a recipient to an existing database" do
|
10
|
+
stub_post("/XMLAPI?access_token=abc123").
|
11
|
+
with(:body => "<Envelope><Body><AddRecipient><LIST_ID>123</LIST_ID><CREATED_FROM>1</CREATED_FROM><CONTACT_LISTS><CONTACT_LIST_ID>456</CONTACT_LIST_ID></CONTACT_LISTS><COLUMN><NAME>email</NAME><VALUE>test@example.com</VALUE></COLUMN></AddRecipient></Body></Envelope>").
|
12
|
+
to_return(:status => 200, :body => fixture("contact.xml"), :headers => {'Content-type' => "text/xml"})
|
13
|
+
|
14
|
+
resp = @client.add_recipient({email:"test@example.com"}, 123, [456])
|
15
|
+
resp.Envelope.Body.RESULT.SUCCESS.should eql "TRUE"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should add a recipient to an existing database with options" do
|
19
|
+
stub_post("/XMLAPI?access_token=abc123").
|
20
|
+
with(:body => "<Envelope><Body><AddRecipient><LIST_ID>123</LIST_ID><CREATED_FROM>1</CREATED_FROM><CONTACT_LISTS><CONTACT_LIST_ID>456</CONTACT_LIST_ID></CONTACT_LISTS><UPDATE_IF_FOUND>true</UPDATE_IF_FOUND><COLUMN><NAME>email</NAME><VALUE>test@example.com</VALUE></COLUMN></AddRecipient></Body></Envelope>").
|
21
|
+
to_return(:status => 200, :body => fixture("contact.xml"), :headers => {'Content-type' => "text/xml"})
|
22
|
+
|
23
|
+
resp = @client.add_recipient({email:"test@example.com"}, 123, [456], 1, {UPDATE_IF_FOUND: "true"})
|
24
|
+
resp.Envelope.Body.RESULT.SUCCESS.should eql "TRUE"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe SilverPop::Client::Reporting do
|
4
|
+
before do
|
5
|
+
@client = SilverPop.new({access_token: "abc123",url: 'https://api1.silverpop.com'})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe ".raw_recipient_data_export" do
|
9
|
+
it "should return true when passing a MAILING_ID" do
|
10
|
+
stub_post("/XMLAPI?access_token=abc123").
|
11
|
+
with(:body => "<Envelope><Body><RawRecipientDataExport><MAILING><MAILING_ID>1234</MAILING_ID></MAILING></RawRecipientDataExport></Body></Envelope>").
|
12
|
+
to_return(:status => 200, :body => fixture("reporting.xml"), :headers => {'Content-type' => "text/xml"})
|
13
|
+
|
14
|
+
|
15
|
+
resp = @client.raw_recipient_data_export({MAILING_ID: 1234})
|
16
|
+
resp.Envelope.Body.RESULT.SUCCESS.should eql "TRUE"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return true when passing a REPORT_ID" do
|
20
|
+
stub_post("/XMLAPI?access_token=abc123").
|
21
|
+
with(:body => "<Envelope><Body><RawRecipientDataExport><MAILING><REPORT_ID>5678</REPORT_ID></MAILING></RawRecipientDataExport></Body></Envelope>").
|
22
|
+
to_return(:status => 200, :body => fixture("reporting.xml"), :headers => {'Content-type' => "text/xml"})
|
23
|
+
|
24
|
+
|
25
|
+
resp = @client.raw_recipient_data_export({REPORT_ID: 5678})
|
26
|
+
resp.Envelope.Body.RESULT.SUCCESS.should eql "TRUE"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return true when passing a EVENT_DATE_START and EVENT_DATE_END" do
|
30
|
+
stub_post("/XMLAPI?access_token=abc123").
|
31
|
+
with(:body => "<Envelope><Body><RawRecipientDataExport><EVENT_DATE_START>1/1/2013</EVENT_DATE_START><EVENT_DATE_END>7/1/2013</EVENT_DATE_END></RawRecipientDataExport></Body></Envelope>").
|
32
|
+
to_return(:status => 200, :body => fixture("reporting.xml"), :headers => {'Content-type' => "text/xml"})
|
33
|
+
|
34
|
+
|
35
|
+
resp = @client.raw_recipient_data_export({EVENT_DATE_START: "1/1/2013", EVENT_DATE_END: "7/1/2013"})
|
36
|
+
resp.Envelope.Body.RESULT.SUCCESS.should eql "TRUE"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return true when passing options" do
|
40
|
+
stub_post("/XMLAPI?access_token=abc123").
|
41
|
+
with(:body => "<Envelope><Body><RawRecipientDataExport><MAILING><MAILING_ID>1234</MAILING_ID></MAILING><MOVE_TO_FTP/></RawRecipientDataExport></Body></Envelope>").
|
42
|
+
to_return(:status => 200, :body => fixture("reporting.xml"), :headers => {'Content-type' => "text/xml"})
|
43
|
+
|
44
|
+
resp = @client.raw_recipient_data_export({MAILING_ID: 1234},{MOVE_TO_FTP: nil})
|
45
|
+
resp.Envelope.Body.RESULT.SUCCESS.should eql "TRUE"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return true when passing extra columns to export" do
|
49
|
+
stub_post("/XMLAPI?access_token=abc123").
|
50
|
+
with(:body => "<Envelope><Body><RawRecipientDataExport><MAILING><MAILING_ID>1234</MAILING_ID></MAILING><COLUMNS><COLUMN><NAME>CustomerID</NAME></COLUMN><COLUMN><NAME>Address</NAME></COLUMN></COLUMNS></RawRecipientDataExport></Body></Envelope>").
|
51
|
+
to_return(:status => 200, :body => fixture("reporting.xml"), :headers => {'Content-type' => "text/xml"})
|
52
|
+
|
53
|
+
resp = @client.raw_recipient_data_export({MAILING_ID: 1234},{}, ["CustomerID", "Address"])
|
54
|
+
resp.Envelope.Body.RESULT.SUCCESS.should eql "TRUE"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe ".get_job_status" do
|
59
|
+
it "returns the job_status for the given job_id" do
|
60
|
+
stub_post("/XMLAPI?access_token=abc123").
|
61
|
+
with(:body => "<Envelope><Body><GetJobStatus><JOB_ID>1234</JOB_ID></GetJobStatus></Body></Envelope>").
|
62
|
+
to_return(:status => 200, :body => '<Envelope><Body><RESULT><SUCCESS>TRUE</SUCCESS>
|
63
|
+
<JOB_ID>1234</JOB_ID><JOB_STATUS>COMPLETE</JOB_STATUS>
|
64
|
+
<JOB_DESCRIPTION> Creating new contact source, Master Database</JOB_DESCRIPTION>
|
65
|
+
<PARAMETERS><PARAMETER><NAME>NOT_ALLOWED</NAME><VALUE>0</VALUE></PARAMETER></PARAMETERS>
|
66
|
+
</RESULT></Body></Envelope>', :headers => {'Content-type' => "text/xml"})
|
67
|
+
|
68
|
+
|
69
|
+
resp = @client.get_job_status(1234)
|
70
|
+
resp.Envelope.Body.RESULT.JOB_STATUS.should eql "COMPLETE"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
unless ENV['CI']
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter 'spec'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
require 'silverpop'
|
8
|
+
require 'rspec'
|
9
|
+
require 'webmock/rspec'
|
10
|
+
|
11
|
+
def stub_post(url)
|
12
|
+
stub_request(:post, silverpop_url(url))
|
13
|
+
end
|
14
|
+
|
15
|
+
def fixture_path
|
16
|
+
File.expand_path("../fixtures", __FILE__)
|
17
|
+
end
|
18
|
+
|
19
|
+
def fixture(file)
|
20
|
+
File.new(fixture_path + '/' + file)
|
21
|
+
end
|
22
|
+
|
23
|
+
def silverpop_url(url)
|
24
|
+
"https://api1.silverpop.com#{url}"
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe SilverPop do
|
4
|
+
describe ".new" do
|
5
|
+
it "should be a new SilverPop::Client" do
|
6
|
+
SilverPop.new.should be_a SilverPop::Client
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".respond_to?" do
|
11
|
+
it "should be true if method exists" do
|
12
|
+
SilverPop.respond_to?(:new, true).should be_true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,239 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: silverpop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Upworthy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: addressable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday_middleware
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.8'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hashie
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: builder
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: oauth2
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rdiscount
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ! '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: webmock
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ! '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ! '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: yard
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ! '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
description: A Ruby wrapper for the SilverPop API
|
182
|
+
email: webmaster@upworthy.com
|
183
|
+
executables: []
|
184
|
+
extensions: []
|
185
|
+
extra_rdoc_files: []
|
186
|
+
files:
|
187
|
+
- .gemtest
|
188
|
+
- .gitignore
|
189
|
+
- .rspec
|
190
|
+
- .yardopts
|
191
|
+
- Gemfile
|
192
|
+
- LICENSE.md
|
193
|
+
- README.md
|
194
|
+
- Rakefile
|
195
|
+
- lib/client/contact.rb
|
196
|
+
- lib/client/reporting.rb
|
197
|
+
- lib/silverpop.rb
|
198
|
+
- lib/silverpop/client.rb
|
199
|
+
- lib/silverpop/connection.rb
|
200
|
+
- lib/silverpop/request.rb
|
201
|
+
- lib/silverpop/version.rb
|
202
|
+
- silverpop.gemspec
|
203
|
+
- spec/client/contact_spec.rb
|
204
|
+
- spec/client/reporting_spec.rb
|
205
|
+
- spec/fixtures/contact.xml
|
206
|
+
- spec/fixtures/reporting.xml
|
207
|
+
- spec/helper.rb
|
208
|
+
- spec/silverpop_spec.rb
|
209
|
+
homepage: ''
|
210
|
+
licenses: []
|
211
|
+
metadata: {}
|
212
|
+
post_install_message:
|
213
|
+
rdoc_options: []
|
214
|
+
require_paths:
|
215
|
+
- lib
|
216
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
217
|
+
requirements:
|
218
|
+
- - ! '>='
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: '0'
|
221
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
222
|
+
requirements:
|
223
|
+
- - ! '>='
|
224
|
+
- !ruby/object:Gem::Version
|
225
|
+
version: '0'
|
226
|
+
requirements: []
|
227
|
+
rubyforge_project:
|
228
|
+
rubygems_version: 2.1.10
|
229
|
+
signing_key:
|
230
|
+
specification_version: 4
|
231
|
+
summary: A Ruby wrapper for the SilverPop API
|
232
|
+
test_files:
|
233
|
+
- spec/client/contact_spec.rb
|
234
|
+
- spec/client/reporting_spec.rb
|
235
|
+
- spec/fixtures/contact.xml
|
236
|
+
- spec/fixtures/reporting.xml
|
237
|
+
- spec/helper.rb
|
238
|
+
- spec/silverpop_spec.rb
|
239
|
+
has_rdoc:
|