sailthru-client 2.0.0 → 3.0.0
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 +15 -0
- data/.gitignore +6 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +22 -0
- data/MIT-LICENSE +20 -0
- data/README.md +11 -4
- data/Rakefile +19 -0
- data/lib/sailthru.rb +115 -101
- data/sailthru-client.gemspec +26 -0
- data/test/fixtures/blast_delete_invalid.json +1 -0
- data/test/fixtures/blast_delete_valid.json +1 -0
- data/test/fixtures/blast_get_invalid.json +1 -0
- data/test/fixtures/blast_get_valid.json +1 -0
- data/test/fixtures/blast_post_invalid_email.json +1 -0
- data/test/fixtures/blast_post_invalid_list.json +1 -0
- data/test/fixtures/blast_post_update_valid.json +1 -0
- data/test/fixtures/blast_post_valid.json +1 -0
- data/test/fixtures/content_valid.json +1 -0
- data/test/fixtures/email_get_listed_email.json +1 -0
- data/test/fixtures/email_get_not_listed_email.json +1 -0
- data/test/fixtures/list_delete_invalid.json +1 -0
- data/test/fixtures/list_delete_valid.json +1 -0
- data/test/fixtures/list_get_all.json +14 -0
- data/test/fixtures/list_get_invalid.json +1 -0
- data/test/fixtures/list_get_invalid.txt +4 -0
- data/test/fixtures/list_get_valid.json +8 -0
- data/test/fixtures/list_get_valid.txt +3 -0
- data/test/fixtures/list_save_valid.json +8 -0
- data/test/fixtures/purchase_post_invalid_email.json +1 -0
- data/test/fixtures/purchase_post_invalid_empty_items.json +1 -0
- data/test/fixtures/purchase_post_valid_multiple_items.json +1 -0
- data/test/fixtures/purchase_post_valid_single_item.json +1 -0
- data/test/fixtures/send_cancel.json +1 -0
- data/test/fixtures/send_get_invalid.json +1 -0
- data/test/fixtures/send_get_valid.json +1 -0
- data/test/fixtures/send_post_invalid.json +1 -0
- data/test/fixtures/send_post_multiple_valid.json +1 -0
- data/test/fixtures/stat_get_invalid.json +1 -0
- data/test/fixtures/stat_get_valid.json +1 -0
- data/test/fixtures/stats_lists_invalid.json +1 -0
- data/test/fixtures/stats_lists_valid.json +1 -0
- data/test/fixtures/template_delete_invalid.json +1 -0
- data/test/fixtures/template_delete_valid.json +1 -0
- data/test/fixtures/template_invalid_get.json +1 -0
- data/test/fixtures/template_save.json +1 -0
- data/test/fixtures/template_valid_get.json +1 -0
- data/test/fixtures/user_update_post_valid.json +3 -0
- data/test/fixtures/user_update_valid.json +1 -0
- data/test/sailthru/blast_test.rb +116 -0
- data/test/sailthru/content_test.rb +36 -0
- data/test/sailthru/email_test.rb +23 -0
- data/test/sailthru/error_test.rb +30 -0
- data/test/sailthru/file_upload_test.rb +75 -0
- data/test/sailthru/helpers_test.rb +23 -0
- data/test/sailthru/list_test.rb +69 -0
- data/test/sailthru/purchase_test.rb +67 -0
- data/test/sailthru/send_test.rb +81 -0
- data/test/sailthru/stats_test.rb +53 -0
- data/test/sailthru/template_test.rb +61 -0
- data/test/test_helper.rb +68 -0
- metadata +117 -19
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/sailthru', __FILE__)
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "sailthru-client"
|
7
|
+
s.version = Sailthru::VERSION
|
8
|
+
|
9
|
+
s.authors = ["Prajwal Tuladhar", "Dennis Yu"]
|
10
|
+
s.date = Date.today.to_s
|
11
|
+
s.email = "praj@sailthru.com"
|
12
|
+
s.extra_rdoc_files = ["README.md"]
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- test/*`.split("\n")
|
15
|
+
s.homepage = "http://docs.sailthru.com"
|
16
|
+
s.rdoc_options = ["--main", "README.md"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.summary = "A simple client library to remotely access the Sailthru REST API."
|
19
|
+
s.license = "MIT"
|
20
|
+
|
21
|
+
s.add_dependency(%q<json>, [">= 0"])
|
22
|
+
s.add_dependency(%q<multipart-post>, [">= 0"])
|
23
|
+
s.add_development_dependency(%q<fakeweb>, [">= 0"])
|
24
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
25
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
26
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errormsg":"Unknown blast_id: 42499","error":13}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"ok":true,"blast_id":42499}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errormsg":"Unknown blast_id: 42182","error":13}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"name":"Default Blast","list":null,"from_name":null,"is_google_analytics":true,"subject":null,"report_email":null,"content_html":"","blast_id":665215,"replyto":null,"status":"created","is_link_tracking":true,"from_email":"dynamism360@gmail.com","content_text":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errormsg":"Invalid email: praj","error":11}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errormsg":"Unknown blast_id: 42182","error":13}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"name":"blast name changed","list":"default-list","from_name":"prajwal tuladhar","is_google_analytics":false,"subject":"Hello World!","report_email":null,"content_html":"aaaa\n<p><small>If you believe this has been sent to you in error, please safely <a href=\"{optout_confirm_url}\">unsubscribe</a>.</small></p>","blast_id":42499,"replyto":null,"status":"scheduled","is_link_tracking":false,"from_email":"praj@sailthru.com","schedule_time":"Tue, 25 Jan 2011 08:12:29 -0500","content_text":"aa\n\nIf you believe this has been sent to you in error, please click <{optout_confirm_url}> to safely unsubscribe."}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"name":"Default Blast 222","list":"default-list","from_name":"Daily Newsletter","is_google_analytics":false,"subject":"Hello World!","report_email":null,"content_html":"aaaa\n<p><small>If you believe this has been sent to you in error, please safely <a href=\"{optout_confirm_url}\">unsubscribe</a>.</small></p>","blast_id":42499,"replyto":null,"status":"scheduled","is_link_tracking":false,"from_email":"praj@sailthru.com","schedule_time":"Tue, 25 Jan 2011 08:12:29 -0500","content_text":"aa\n\nIf you believe this has been sent to you in error, please click <{optout_confirm_url}> to safely unsubscribe."}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"content":[{"title":"unix is awesome","vars":{"price":55,"description":"Hello World"},"url":"http://example.com/hello-world","tags":["unix","linux"],"date":"Wed, 02 Feb 2011 01:55:43 -0500","client_id":1}]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"lists":{"default":1},"vars":[],"optout":"none","verified":0,"hardbounce":0,"email":"praj@sailthru.com"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"vars":[],"optout":"none","verified":0,"hardbounce":0,"email":"apraj@sailthru.com"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errormsg":"Unknown list: invalid-list","error":15}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"list":"my-list","ok":true}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errormsg":"Unknown list: invalid-list","error":15}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errormsg":"Invalid email: prajsailthru.com","error":11}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errormsg":"No items in purchase","error":99}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"purchase":{"qty":24,"price":25178,"items":[{"price":1099,"qty":22,"title":"High-Impact Water Bottle","url":"http://example.com/234/high-impact-water-bottle","id":"234"},{"price":500,"qty":2,"title":"Lorem Ispum","url":"http://example.com/2304/lorem-ispum","id":"2304"}],"time":"Tue, 25 Jan 2011 12:04:07 -0500","_id":"4d3f02876763d9c10f000900"}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"purchase":{"qty":22,"price":24178,"items":[{"price":1099,"qty":22,"title":"High-Impact Water Bottle","url":"http://example.com/234/high-impact-water-bottle","id":"234"}],"time":"Tue, 25 Jan 2011 11:36:06 -0500","_id":"4d3efbf66763d9020e0006ea"}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"send_id":"TT4gSGdj2Z17AAGb","ok":true}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errormsg":"Unknown send_id: aaaaTT1ClGdj2bRHAAP6","error":12}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"send_id":"TT1ClGdj2bRHAAP6","view_url":"http://link.sailthru.com/view/TT1ClGdj2bRHAAP6/3f7f9f72","send_time":"Mon, 24 Jan 2011 04:12:59 -0500","template":"default","status":"delivered","email":"praj@sailthru.com"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errormsg":"Unknown template: invalid","error":14}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"sent_count":2,"send_ids":{"example@example.com":"TT4YnGdj2RVrAASU","example3@example.com":"TT4YnGdj2RVrAAST"},"template":"default"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errormsg":"Unknown stat: lista","error":99}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"lists_signup_count":0,"active_count":0,"list":"","email_count":0,"passive_count":0,"optout_count":0,"optout_loss_count":0,"hardbounce_count":0,"day":20110125,"disengaged_count":0,"count_time":"Tue, 25 Jan 2011 05:40:50 -0500","lists_count":0,"lists_remove_count":0,"engaged_count":0,"dormant_count":0}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errormsg":"Unable to find stats for not-listed","error":99}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"lists_signup_count":0,"active_count":0,"list":"","email_count":0,"passive_count":0,"optout_count":0,"optout_loss_count":0,"hardbounce_count":0,"day":20110114,"disengaged_count":0,"count_time":"Fri, 14 Jan 2011 00:09:25 -0500","lists_count":0,"lists_remove_count":0,"engaged_count":0,"dormant_count":0}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"error":14, "errormsg": "Unknown template: my-template"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"template": "my-template", "ok": true}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errormsg":"Unknown template: invalid","error":14}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"name":"my-template-new","sample":"","verify_post_url":"","from_name":"prajwal tuladhar","is_google_analytics":false,"is_unviewable":false,"error_url":"","subject":"Hello world","content_html":"Hi {email} \n\n<p/>\n{beacon}\n<p><small>If you believe this has been sent to you in error, please safely <a href=\"{optout_confirm_url}\">unsubscribe</a>.</small></p>","is_disabled":false,"replyto_email":"","is_link_tracking":true,"from_email":"praj@sailthru.com","is_invite":false,"success_url":"","content_sms":"","content_text":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"name":"default","sample":"","verify_post_url":"","from_name":"","is_google_analytics":false,"is_unviewable":false,"error_url":"","subject":"Hello world","content_html":"Hi {email} \n\n<p/>\n{beacon}\n<p><small>If you believe this has been sent to you in error, please safely <a href=\"{optout_confirm_url}\">unsubscribe</a>.</small></p>","is_disabled":false,"replyto_email":"","is_link_tracking":true,"from_email":"praj@sailthru.com","is_invite":false,"success_url":"","content_sms":"","content_text":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"job_id" : "502c618ddd6a49b9200003c4", "name" : "Bulk Update", "update" : [], "status" : "pending"}
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BlastTest < Minitest::Test
|
4
|
+
describe "API Call: blast" do
|
5
|
+
before do
|
6
|
+
api_url = 'http://api.sailthru.com'
|
7
|
+
@secret = 'my_secret'
|
8
|
+
@api_key = 'my_api_key'
|
9
|
+
@sailthru_client = Sailthru::SailthruClient.new(@api_key, @secret, api_url)
|
10
|
+
@api_call_url = sailthru_api_call_url(api_url, 'blast')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can get the status of a blast when blast_id is valid" do
|
14
|
+
valid_blast_id = '665215'
|
15
|
+
params = {'blast_id' => valid_blast_id}
|
16
|
+
query_string = create_json_payload(@api_key, @secret, params)
|
17
|
+
stub_get(@api_call_url + '?' + query_string, 'blast_get_valid.json')
|
18
|
+
response = @sailthru_client.get_blast(valid_blast_id)
|
19
|
+
refute_nil response['name']
|
20
|
+
assert_equal valid_blast_id, response['blast_id'].to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
it "can get blast error message when blast_id is invalid" do
|
24
|
+
invalid_blast_id = '88787'
|
25
|
+
params = {'blast_id' => invalid_blast_id}
|
26
|
+
query_string = create_json_payload(@api_key, @secret, params)
|
27
|
+
stub_get(@api_call_url + '?' + query_string, 'blast_get_invalid.json')
|
28
|
+
response = @sailthru_client.get_blast(invalid_blast_id)
|
29
|
+
refute_nil response['error']
|
30
|
+
refute_nil response['errormsg']
|
31
|
+
end
|
32
|
+
|
33
|
+
it "can schedule blast with given blast name, list, schedule_time, from name, from email, subject, content html, content text" do
|
34
|
+
blast_name = 'Default Blast 222'
|
35
|
+
list = 'default-list'
|
36
|
+
schedule_time = '+3 hours'
|
37
|
+
from_name = 'Daily Newsletter'
|
38
|
+
from_email = 'praj@sailthru.com'
|
39
|
+
subject = 'Hello World!'
|
40
|
+
content_html = '<p>Hello World</p>'
|
41
|
+
content_text= 'Hello World'
|
42
|
+
stub_post(@api_call_url, 'blast_post_valid.json')
|
43
|
+
response = @sailthru_client.schedule_blast(blast_name, list, schedule_time, from_name, from_email, subject, content_html, content_text)
|
44
|
+
assert_equal blast_name, response['name']
|
45
|
+
assert_equal list, response['list']
|
46
|
+
assert_equal from_email, response['from_email']
|
47
|
+
assert_equal from_name, response['from_name']
|
48
|
+
end
|
49
|
+
|
50
|
+
it "cannot schedule blast with invalid email" do
|
51
|
+
blast_name = 'Default Blast 222'
|
52
|
+
list = 'default-list'
|
53
|
+
schedule_time = '+3 hours'
|
54
|
+
from_name = 'Daily Newsletter'
|
55
|
+
from_email_invalid = 'praj@'
|
56
|
+
subject = 'Hello World!'
|
57
|
+
content_html = '<p>Hello World</p>'
|
58
|
+
content_text= 'Hello World'
|
59
|
+
stub_post(@api_call_url, 'blast_post_invalid_email.json')
|
60
|
+
response = @sailthru_client.schedule_blast(blast_name, list, schedule_time, from_name, from_email_invalid, subject, content_html, content_text)
|
61
|
+
refute_nil response['error']
|
62
|
+
refute_nil response['errormsg']
|
63
|
+
end
|
64
|
+
|
65
|
+
it "cannot schedule blast with invalid list" do
|
66
|
+
blast_name = 'Default Blast 222'
|
67
|
+
list_invalid = 'this-list-does-not-exist'
|
68
|
+
schedule_time = '+3 hours'
|
69
|
+
from_name = 'Daily Newsletter'
|
70
|
+
from_email = 'praj@'
|
71
|
+
subject = 'Hello World!'
|
72
|
+
content_html = '<p>Hello World</p>'
|
73
|
+
content_text= 'Hello World'
|
74
|
+
stub_post(@api_call_url, 'blast_post_invalid_list.json')
|
75
|
+
response = @sailthru_client.schedule_blast(blast_name, list_invalid, schedule_time, from_name, from_email, subject, content_html, content_text)
|
76
|
+
refute_nil response['error']
|
77
|
+
refute_nil response['errormsg']
|
78
|
+
end
|
79
|
+
|
80
|
+
it "can update blast with valid blast_id" do
|
81
|
+
blast_id = 42499
|
82
|
+
name = 'blast name changed'
|
83
|
+
from_name = 'prajwal tuladhar'
|
84
|
+
stub_post(@api_call_url, 'blast_post_update_valid.json')
|
85
|
+
response = @sailthru_client.update_blast(blast_id = blast_id, from_name = from_name)
|
86
|
+
assert_equal(name, response['name'])
|
87
|
+
end
|
88
|
+
|
89
|
+
it "can delete valid blast" do
|
90
|
+
blast_id = 42499
|
91
|
+
params = {'blast_id' => blast_id}
|
92
|
+
query_string = create_json_payload(@api_key, @secret, params)
|
93
|
+
stub_delete(@api_call_url + '?' + query_string, 'blast_delete_valid.json')
|
94
|
+
response = @sailthru_client.delete_blast(blast_id)
|
95
|
+
assert_equal(blast_id, response['blast_id'])
|
96
|
+
end
|
97
|
+
|
98
|
+
it "cannot delete invalid blast" do
|
99
|
+
invalid_blast_id = '88787'
|
100
|
+
params = {'blast_id' => invalid_blast_id}
|
101
|
+
query_string = create_json_payload(@api_key, @secret, params)
|
102
|
+
stub_delete(@api_call_url + '?' + query_string, 'blast_delete_invalid.json')
|
103
|
+
response = @sailthru_client.delete_blast(invalid_blast_id)
|
104
|
+
refute_nil response['error']
|
105
|
+
refute_nil response['errormsg']
|
106
|
+
end
|
107
|
+
|
108
|
+
it "can cancel a valid blast" do
|
109
|
+
blast_id = 42499
|
110
|
+
stub_post(@api_call_url, 'blast_post_update_valid.json')
|
111
|
+
response = @sailthru_client.cancel_blast(blast_id)
|
112
|
+
assert_equal(blast_id, response['blast_id'])
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ContentTest < Minitest::Test
|
4
|
+
describe "API Call: content" do
|
5
|
+
before do
|
6
|
+
api_url = 'http://api.sailthru.com'
|
7
|
+
@secret = 'my_secret'
|
8
|
+
@api_key = 'my_api_key'
|
9
|
+
@sailthru_client = Sailthru::SailthruClient.new(@api_key, @secret, api_url)
|
10
|
+
@api_call_url = sailthru_api_call_url(api_url, 'content')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can push content with title, url, *array* tags and vars" do
|
14
|
+
title = 'unix is awesome'
|
15
|
+
url = 'http://example.com/hello-world'
|
16
|
+
date = nil
|
17
|
+
tags = ['unix', 'linux']
|
18
|
+
vars = {:price => 55, :description => 'Hello World'}
|
19
|
+
stub_post(@api_call_url, 'content_valid.json')
|
20
|
+
response = @sailthru_client.push_content(title, url, date = nil, tags = tags, vars = vars)
|
21
|
+
refute_nil response['content']
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can push content with title, url, *string* tags and vars" do
|
25
|
+
title = 'unix is awesome'
|
26
|
+
url = 'http://example.com/hello-world'
|
27
|
+
date = nil
|
28
|
+
tags = 'unix, linux'
|
29
|
+
vars = {:price => 55, :description => 'Hello World'}
|
30
|
+
stub_post(@api_call_url, 'content_valid.json')
|
31
|
+
response = @sailthru_client.push_content(title, url, date = nil, tags = tags, vars = vars)
|
32
|
+
refute_nil response['content']
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class EmailTest < Minitest::Test
|
4
|
+
describe "API Call: email" do
|
5
|
+
before do
|
6
|
+
api_url = 'http://api.sailthru.com'
|
7
|
+
@api_key = 'my_api_key'
|
8
|
+
@secret = 'my_secret'
|
9
|
+
@sailthru_client = Sailthru::SailthruClient.new(@api_key, @secret, api_url)
|
10
|
+
@api_call_url = sailthru_api_call_url(api_url, 'email')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can get email information for one of the client's user" do
|
14
|
+
email = 'praj@sailthru.com'
|
15
|
+
params = {'email' => email}
|
16
|
+
query_string = create_json_payload(@api_key, @secret, params)
|
17
|
+
stub_get(@api_call_url + '?' + query_string, 'email_get_listed_email.json')
|
18
|
+
response = @sailthru_client.get_email(email)
|
19
|
+
refute_nil response['verified']
|
20
|
+
assert_equal email, response['email']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ErrorTest < Minitest::Test
|
4
|
+
describe "Server is misbehaving" do
|
5
|
+
before do
|
6
|
+
api_url = 'http://api.sailthru.com'
|
7
|
+
@secret = 'my_secret'
|
8
|
+
@api_key = 'my_api_key'
|
9
|
+
@sailthru_client = Sailthru::SailthruClient.new(@api_key, @secret, api_url)
|
10
|
+
@api_call_url = sailthru_api_call_url(api_url, 'blast')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "raises an error when server misbehaves" do
|
14
|
+
stub_exception(@api_call_url, 'blast_post_update_valid.json')
|
15
|
+
assert_raises Sailthru::SailthruClientException do
|
16
|
+
@sailthru_client.cancel_blast(123)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "shows the true origin of the exception" do
|
21
|
+
stub_exception(@api_call_url, 'blast_post_update_valid.json')
|
22
|
+
begin
|
23
|
+
@sailthru_client.cancel_blast(123)
|
24
|
+
rescue Exception => e
|
25
|
+
assert(e.message =~ /Exception from FakeWeb/)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'mocha/setup'
|
3
|
+
|
4
|
+
class FileUploadTest < Minitest::Test
|
5
|
+
|
6
|
+
describe "API Call: blast" do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@secret = 'my_secret'
|
10
|
+
@api_key = 'my_api_key'
|
11
|
+
@sailthru_client = Sailthru::SailthruClient.new(
|
12
|
+
@api_key, @secret, 'http://api.sailthru.com'
|
13
|
+
)
|
14
|
+
@api_call_url = sailthru_api_call_url(
|
15
|
+
'http://api.sailthru.com', 'job'
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can upload a file of data" do
|
20
|
+
Net::HTTP::Post::Multipart.expects(:new).with(
|
21
|
+
instance_of(String),
|
22
|
+
has_entries({
|
23
|
+
"file" => instance_of(UploadIO)
|
24
|
+
})
|
25
|
+
)
|
26
|
+
Net::HTTP.stubs(:Proxy).returns(Net::HTTP)
|
27
|
+
Net::HTTP.any_instance.stubs(
|
28
|
+
:request => stub(
|
29
|
+
"body" => JSON.unparse({"job_id" => "123"})
|
30
|
+
)
|
31
|
+
)
|
32
|
+
|
33
|
+
data = {
|
34
|
+
"job" => "update",
|
35
|
+
"file" => fixture_file_path('user_update_post_valid.json')
|
36
|
+
}
|
37
|
+
response = @sailthru_client.api_post(
|
38
|
+
:job, data, 'file'
|
39
|
+
)
|
40
|
+
refute_nil response['job_id']
|
41
|
+
end
|
42
|
+
|
43
|
+
it "can upload a string of data" do
|
44
|
+
Net::HTTP::Post::Multipart.expects(:new).with(
|
45
|
+
instance_of(String),
|
46
|
+
has_entries({
|
47
|
+
"file" => instance_of(UploadIO)
|
48
|
+
})
|
49
|
+
)
|
50
|
+
Net::HTTP.stubs(:Proxy).returns(Net::HTTP)
|
51
|
+
Net::HTTP.any_instance.stubs(
|
52
|
+
:request => stub(
|
53
|
+
"body" => JSON.unparse({"job_id" => "123"})
|
54
|
+
)
|
55
|
+
)
|
56
|
+
|
57
|
+
email = {
|
58
|
+
"email" => "dan.langevin@lifebooker.com",
|
59
|
+
"vars" => {
|
60
|
+
"first_name" => "Dan"
|
61
|
+
}
|
62
|
+
}
|
63
|
+
data = {
|
64
|
+
"job" => "update",
|
65
|
+
"file" => StringIO.new(JSON.unparse(email))
|
66
|
+
}
|
67
|
+
|
68
|
+
response = @sailthru_client.api_post(
|
69
|
+
:job, data, 'file'
|
70
|
+
)
|
71
|
+
refute_nil response['job_id']
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|