sailthru_batching_client 0.0.1
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 +22 -0
- data/Gemfile.lock +84 -0
- data/Guardfile +30 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/lib/sailthru_batching_client.rb +140 -0
- data/sailthru_batching_client.gemspec +85 -0
- data/spec/sailthru_batching_client_spec.rb +97 -0
- data/spec/spec_helper.rb +58 -0
- metadata +195 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
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 "json"
|
7
|
+
gem "sailthru-client", :require => "sailthru"
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development, :test do
|
12
|
+
gem "bundler"
|
13
|
+
gem "guard-bundler"
|
14
|
+
gem "guard-rspec"
|
15
|
+
gem "guard-spork"
|
16
|
+
gem "jeweler", "~> 1.8.4"
|
17
|
+
gem "mocha"
|
18
|
+
gem "rdoc"
|
19
|
+
gem "rspec"
|
20
|
+
gem "ruby-debug19", :require => "ruby-debug"
|
21
|
+
gem "yard", "~> 0.7"
|
22
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
archive-tar-minitar (0.5.2)
|
5
|
+
columnize (0.3.6)
|
6
|
+
diff-lcs (1.1.3)
|
7
|
+
ffi (1.1.4)
|
8
|
+
git (1.2.5)
|
9
|
+
guard (1.3.0)
|
10
|
+
listen (>= 0.4.2)
|
11
|
+
thor (>= 0.14.6)
|
12
|
+
guard-bundler (1.0.0)
|
13
|
+
bundler (~> 1.0)
|
14
|
+
guard (~> 1.1)
|
15
|
+
guard-rspec (1.2.1)
|
16
|
+
guard (>= 1.1)
|
17
|
+
guard-spork (1.1.0)
|
18
|
+
guard (>= 1.1)
|
19
|
+
spork (>= 0.8.4)
|
20
|
+
jeweler (1.8.4)
|
21
|
+
bundler (~> 1.0)
|
22
|
+
git (>= 1.2.5)
|
23
|
+
rake
|
24
|
+
rdoc
|
25
|
+
json (1.7.4)
|
26
|
+
linecache19 (0.5.12)
|
27
|
+
ruby_core_source (>= 0.1.4)
|
28
|
+
listen (0.4.7)
|
29
|
+
rb-fchange (~> 0.0.5)
|
30
|
+
rb-fsevent (~> 0.9.1)
|
31
|
+
rb-inotify (~> 0.8.8)
|
32
|
+
metaclass (0.0.1)
|
33
|
+
mocha (0.12.3)
|
34
|
+
metaclass (~> 0.0.1)
|
35
|
+
multipart-post (1.1.5)
|
36
|
+
rake (0.9.2.2)
|
37
|
+
rb-fchange (0.0.5)
|
38
|
+
ffi
|
39
|
+
rb-fsevent (0.9.1)
|
40
|
+
rb-inotify (0.8.8)
|
41
|
+
ffi (>= 0.5.0)
|
42
|
+
rdoc (3.12)
|
43
|
+
json (~> 1.4)
|
44
|
+
rspec (2.11.0)
|
45
|
+
rspec-core (~> 2.11.0)
|
46
|
+
rspec-expectations (~> 2.11.0)
|
47
|
+
rspec-mocks (~> 2.11.0)
|
48
|
+
rspec-core (2.11.1)
|
49
|
+
rspec-expectations (2.11.1)
|
50
|
+
diff-lcs (~> 1.1.3)
|
51
|
+
rspec-mocks (2.11.1)
|
52
|
+
ruby-debug-base19 (0.11.25)
|
53
|
+
columnize (>= 0.3.1)
|
54
|
+
linecache19 (>= 0.5.11)
|
55
|
+
ruby_core_source (>= 0.1.4)
|
56
|
+
ruby-debug19 (0.11.6)
|
57
|
+
columnize (>= 0.3.1)
|
58
|
+
linecache19 (>= 0.5.11)
|
59
|
+
ruby-debug-base19 (>= 0.11.19)
|
60
|
+
ruby_core_source (0.1.5)
|
61
|
+
archive-tar-minitar (>= 0.5.2)
|
62
|
+
sailthru-client (1.15)
|
63
|
+
json
|
64
|
+
multipart-post
|
65
|
+
spork (0.9.2)
|
66
|
+
thor (0.15.4)
|
67
|
+
yard (0.8.2.1)
|
68
|
+
|
69
|
+
PLATFORMS
|
70
|
+
ruby
|
71
|
+
|
72
|
+
DEPENDENCIES
|
73
|
+
bundler
|
74
|
+
guard-bundler
|
75
|
+
guard-rspec
|
76
|
+
guard-spork
|
77
|
+
jeweler (~> 1.8.4)
|
78
|
+
json
|
79
|
+
mocha
|
80
|
+
rdoc
|
81
|
+
rspec
|
82
|
+
ruby-debug19
|
83
|
+
sailthru-client
|
84
|
+
yard (~> 0.7)
|
data/Guardfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'bundler' do
|
5
|
+
watch('Gemfile')
|
6
|
+
# Uncomment next line if Gemfile contain `gemspec' command
|
7
|
+
# watch(/^.+\.gemspec/)
|
8
|
+
end
|
9
|
+
|
10
|
+
guard 'rspec', :version => 2 do
|
11
|
+
watch(%r{^spec/.+_spec\.rb$})
|
12
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
13
|
+
watch('spec/spec_helper.rb') { "spec" }
|
14
|
+
|
15
|
+
# Rails example
|
16
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
17
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
18
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
19
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
20
|
+
watch('config/routes.rb') { "spec/routing" }
|
21
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
22
|
+
|
23
|
+
# Capybara request specs
|
24
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
25
|
+
|
26
|
+
# Turnip features and steps
|
27
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
28
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
29
|
+
end
|
30
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Dan Langevin
|
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,19 @@
|
|
1
|
+
= sailthru_batching_client
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to sailthru_batching_client
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* 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.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Dan Langevin. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
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 = "sailthru_batching_client"
|
18
|
+
gem.homepage = "http://github.com/LifebookerInc/sailthru_batching_client"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Sailthru Client with Batching}
|
21
|
+
gem.description = %Q{Sailthru Client with Batching}
|
22
|
+
gem.email = "dan.langevin@lifebooker.com"
|
23
|
+
gem.authors = ["Dan Langevin"]
|
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 'yard'
|
42
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'sailthru'
|
2
|
+
|
3
|
+
class SailthruBatchingClient
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :api_key, :api_secret
|
7
|
+
attr_writer :file_root, :batch_size
|
8
|
+
end
|
9
|
+
|
10
|
+
# where we store our temp files
|
11
|
+
def self.base_file_name
|
12
|
+
"#{self.file_root}/#{Process.pid}-sailthru-list"
|
13
|
+
end
|
14
|
+
|
15
|
+
# max size that Sailthru can support
|
16
|
+
def self.batch_size
|
17
|
+
@batch_size ||= 10000000
|
18
|
+
end
|
19
|
+
|
20
|
+
# clear the files we created to push data to Sailthru
|
21
|
+
def self.clear_tmp_files
|
22
|
+
FileUtils.rm_rf("#{self.base_file_name}*")
|
23
|
+
end
|
24
|
+
|
25
|
+
# instance of sailthru client
|
26
|
+
def self.client
|
27
|
+
@client ||= ::Sailthru::SailthruClient.new(
|
28
|
+
self.api_key,
|
29
|
+
self.api_secret,
|
30
|
+
"https://api.sailthru.com"
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
# We are connected if a client is present
|
35
|
+
def self.connected?
|
36
|
+
@client.present?
|
37
|
+
end
|
38
|
+
|
39
|
+
# get an instance of sailthru client
|
40
|
+
def self.establish_connection
|
41
|
+
self.client
|
42
|
+
end
|
43
|
+
|
44
|
+
# root at which we are going to write our temp files
|
45
|
+
def self.file_root
|
46
|
+
@file_root ||= "/tmp"
|
47
|
+
end
|
48
|
+
|
49
|
+
# override respond_to? to also include methods of our
|
50
|
+
# instance of SailthruClient
|
51
|
+
def self.respond_to?(m)
|
52
|
+
return true if super(m)
|
53
|
+
return self.client.respond_to?(m)
|
54
|
+
end
|
55
|
+
|
56
|
+
# update rows of email data
|
57
|
+
def self.update_users(user_data_array, clear_tmp = true)
|
58
|
+
# make sure we have the dir
|
59
|
+
FileUtils.mkdir_p(File.dirname(self.base_file_name))
|
60
|
+
self.clear_tmp_files if clear_tmp
|
61
|
+
|
62
|
+
begin
|
63
|
+
self.batch_data_as_json(user_data_array).each_with_index do |rows, i|
|
64
|
+
# write to the file system
|
65
|
+
file = self.write_temp_file(rows, i)
|
66
|
+
# send our file
|
67
|
+
self.send_file(file)
|
68
|
+
end
|
69
|
+
return true
|
70
|
+
ensure
|
71
|
+
self.clear_tmp_files if clear_tmp
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
protected
|
76
|
+
|
77
|
+
def self.batch_data_as_json(data)
|
78
|
+
# convert to strings so we can count bytes
|
79
|
+
data = data.collect{|r| JSON.unparse(r)}
|
80
|
+
ret = []
|
81
|
+
# start off 0 size and empty batch
|
82
|
+
size = 0
|
83
|
+
batch = []
|
84
|
+
# iterate, breaking into batches
|
85
|
+
data.each do |row, i|
|
86
|
+
# get the number of bytes in our string
|
87
|
+
size += row.bytes.to_a.inject{|sum,x| sum + x}
|
88
|
+
# if we've gone over the limit with this row, we
|
89
|
+
# create a new batch and reset the size to 0
|
90
|
+
if size > self.batch_size
|
91
|
+
ret << batch
|
92
|
+
batch = []
|
93
|
+
size = 0
|
94
|
+
end
|
95
|
+
# add our row to the current batch
|
96
|
+
batch << row
|
97
|
+
end
|
98
|
+
# if we have leftover records, put them here
|
99
|
+
ret << batch unless batch.empty?
|
100
|
+
ret
|
101
|
+
end
|
102
|
+
|
103
|
+
# proxy everything else to the client
|
104
|
+
def self.method_missing(m, *args, &block)
|
105
|
+
self.establish_connection
|
106
|
+
# why Sailthru, would you override "send"
|
107
|
+
@client.__send__(m, *args, &block)
|
108
|
+
end
|
109
|
+
|
110
|
+
# send a file to sailthru
|
111
|
+
def self.send_file(file)
|
112
|
+
i = 0
|
113
|
+
begin
|
114
|
+
SailthruBatchingClient.api_post(
|
115
|
+
:job,
|
116
|
+
{"job" => "update", "file" => file},
|
117
|
+
"file"
|
118
|
+
)
|
119
|
+
rescue Exception => e
|
120
|
+
if i < 5
|
121
|
+
i += 1
|
122
|
+
retry
|
123
|
+
else
|
124
|
+
raise e
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# write a temp filte for a given group so that we
|
130
|
+
# can push the file to sailthru
|
131
|
+
def self.write_temp_file(group, i)
|
132
|
+
name = "#{self.base_file_name}.#{i}"
|
133
|
+
File.open(name, 'wb') do |f|
|
134
|
+
group.compact.each do |row|
|
135
|
+
f.puts(row)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
name
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,85 @@
|
|
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 = "sailthru_batching_client"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Dan Langevin"]
|
12
|
+
s.date = "2012-08-09"
|
13
|
+
s.description = "Sailthru Client with Batching"
|
14
|
+
s.email = "dan.langevin@lifebooker.com"
|
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
|
+
"Guardfile",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"lib/sailthru_batching_client.rb",
|
30
|
+
"sailthru_batching_client.gemspec",
|
31
|
+
"spec/sailthru_batching_client_spec.rb",
|
32
|
+
"spec/spec_helper.rb"
|
33
|
+
]
|
34
|
+
s.homepage = "http://github.com/LifebookerInc/sailthru_batching_client"
|
35
|
+
s.licenses = ["MIT"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = "1.8.11"
|
38
|
+
s.summary = "Sailthru Client with Batching"
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
45
|
+
s.add_runtime_dependency(%q<sailthru-client>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<guard-bundler>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<guard-rspec>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<guard-spork>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
51
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<yard>, ["~> 0.7"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<json>, [">= 0"])
|
58
|
+
s.add_dependency(%q<sailthru-client>, [">= 0"])
|
59
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
60
|
+
s.add_dependency(%q<guard-bundler>, [">= 0"])
|
61
|
+
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
62
|
+
s.add_dependency(%q<guard-spork>, [">= 0"])
|
63
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
64
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
66
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
67
|
+
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|
68
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
69
|
+
end
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<json>, [">= 0"])
|
72
|
+
s.add_dependency(%q<sailthru-client>, [">= 0"])
|
73
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
74
|
+
s.add_dependency(%q<guard-bundler>, [">= 0"])
|
75
|
+
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
76
|
+
s.add_dependency(%q<guard-spork>, [">= 0"])
|
77
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
78
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
79
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
80
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
81
|
+
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|
82
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "SailthruBatchingClient" do
|
4
|
+
|
5
|
+
|
6
|
+
context ".api_key" do
|
7
|
+
it "sets its api_key" do
|
8
|
+
SailthruBatchingClient.api_key = "test"
|
9
|
+
SailthruBatchingClient.api_key.should eql("test")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context ".api_secret" do
|
14
|
+
it "sets its api_secret" do
|
15
|
+
SailthruBatchingClient.api_secret = "test"
|
16
|
+
SailthruBatchingClient.api_secret.should eql("test")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context ".base_file_name" do
|
21
|
+
it "should be configurable and based on the process id" do
|
22
|
+
SailthruBatchingClient.file_root = "/tmp"
|
23
|
+
SailthruBatchingClient.base_file_name.should eql(
|
24
|
+
"/tmp/#{Process.pid}-sailthru-list"
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context ".batch_size" do
|
30
|
+
it "should default to 10_000_000" do
|
31
|
+
SailthruBatchingClient.batch_size.should eql(10000000)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be configurable" do
|
35
|
+
SailthruBatchingClient.batch_size = 1
|
36
|
+
SailthruBatchingClient.batch_size.should eql(1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context ".client" do
|
41
|
+
it "initializes a new SailthruClient" do
|
42
|
+
SailthruBatchingClient.api_key = "key"
|
43
|
+
SailthruBatchingClient.api_secret = "secret"
|
44
|
+
|
45
|
+
Sailthru::SailthruClient.expects(:new).with(
|
46
|
+
"key", "secret", "https://api.sailthru.com"
|
47
|
+
)
|
48
|
+
|
49
|
+
SailthruBatchingClient.client
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context ".method_missing" do
|
54
|
+
|
55
|
+
it "should proxy all other methods to method_missing" do
|
56
|
+
SailthruBatchingClient.client.expects(:api_post).with("abc")
|
57
|
+
SailthruBatchingClient.api_post("abc")
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context ".update_users" do
|
63
|
+
|
64
|
+
before(:each) do
|
65
|
+
SailthruBatchingClient.batch_size = 10000000
|
66
|
+
end
|
67
|
+
|
68
|
+
after(:each) do
|
69
|
+
SailthruBatchingClient.clear_tmp_files
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should write a file to sailthru" do
|
73
|
+
|
74
|
+
args = [
|
75
|
+
:job,
|
76
|
+
{"job" => "update", "file" => "/tmp/#{Process.pid}-sailthru-list.0"},
|
77
|
+
"file"
|
78
|
+
]
|
79
|
+
|
80
|
+
SailthruBatchingClient.expects(:api_post)
|
81
|
+
.with(*args)
|
82
|
+
.returns({"job_id" => "213"})
|
83
|
+
|
84
|
+
SailthruBatchingClient.update_users(
|
85
|
+
[{"email" => "dan.langevin@gmail.com"}],
|
86
|
+
false
|
87
|
+
)
|
88
|
+
|
89
|
+
File.read("/tmp/#{Process.pid}-sailthru-list.0").should eql(
|
90
|
+
JSON.unparse({"email" => "dan.langevin@gmail.com"}) + "\n"
|
91
|
+
)
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spork'
|
3
|
+
#uncomment the following line to use spork with the debugger
|
4
|
+
#require 'spork/ext/ruby-debug'
|
5
|
+
|
6
|
+
Spork.prefork do
|
7
|
+
# Loading more in this block will cause your tests to run faster. However,
|
8
|
+
# if you change any configuration or code from libraries loaded here, you'll
|
9
|
+
# need to restart spork for it take effect.
|
10
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
11
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
12
|
+
require 'rspec'
|
13
|
+
require 'sailthru_batching_client'
|
14
|
+
require "ruby-debug"
|
15
|
+
Debugger.start
|
16
|
+
|
17
|
+
# Requires supporting files with custom matchers and macros, etc,
|
18
|
+
# in ./support/ and its subdirectories.
|
19
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
config.mock_with :mocha
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Spork.each_run do
|
27
|
+
# This code will be run each time you run your specs.
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
# --- Instructions ---
|
32
|
+
# Sort the contents of this file into a Spork.prefork and a Spork.each_run
|
33
|
+
# block.
|
34
|
+
#
|
35
|
+
# The Spork.prefork block is run only once when the spork server is started.
|
36
|
+
# You typically want to place most of your (slow) initializer code in here, in
|
37
|
+
# particular, require'ing any 3rd-party gems that you don't normally modify
|
38
|
+
# during development.
|
39
|
+
#
|
40
|
+
# The Spork.each_run block is run each time you run your specs. In case you
|
41
|
+
# need to load files that tend to change during development, require them here.
|
42
|
+
# With Rails, your application modules are loaded automatically, so sometimes
|
43
|
+
# this block can remain empty.
|
44
|
+
#
|
45
|
+
# Note: You can modify files loaded *from* the Spork.each_run block without
|
46
|
+
# restarting the spork server. However, this file itself will not be reloaded,
|
47
|
+
# so if you change any of the code inside the each_run block, you still need to
|
48
|
+
# restart the server. In general, if you have non-trivial code in this file,
|
49
|
+
# it's advisable to move it into a separate file so you can easily edit it
|
50
|
+
# without restarting spork. (For example, with RSpec, you could move
|
51
|
+
# non-trivial code into a file spec/support/my_helper.rb, making sure that the
|
52
|
+
# spec/support/* files are require'd from inside the each_run block.)
|
53
|
+
#
|
54
|
+
# Any code that is left outside the two blocks will be run during preforking
|
55
|
+
# *and* during each_run -- that's probably not what you want.
|
56
|
+
#
|
57
|
+
# These instructions should self-destruct in 10 seconds. If they don't, feel
|
58
|
+
# free to delete them.
|
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sailthru_batching_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Langevin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: &2168519620 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2168519620
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sailthru-client
|
27
|
+
requirement: &2168513860 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2168513860
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
requirement: &2168497900 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2168497900
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: guard-bundler
|
49
|
+
requirement: &2168495200 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2168495200
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: guard-rspec
|
60
|
+
requirement: &2168491980 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2168491980
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-spork
|
71
|
+
requirement: &2168487900 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2168487900
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: jeweler
|
82
|
+
requirement: &2168484120 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.8.4
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2168484120
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: mocha
|
93
|
+
requirement: &2165406360 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *2165406360
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: rdoc
|
104
|
+
requirement: &2165405620 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *2165405620
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: rspec
|
115
|
+
requirement: &2165404700 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: *2165404700
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: ruby-debug19
|
126
|
+
requirement: &2165404000 !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: *2165404000
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: yard
|
137
|
+
requirement: &2165403460 !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ~>
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0.7'
|
143
|
+
type: :development
|
144
|
+
prerelease: false
|
145
|
+
version_requirements: *2165403460
|
146
|
+
description: Sailthru Client with Batching
|
147
|
+
email: dan.langevin@lifebooker.com
|
148
|
+
executables: []
|
149
|
+
extensions: []
|
150
|
+
extra_rdoc_files:
|
151
|
+
- LICENSE.txt
|
152
|
+
- README.rdoc
|
153
|
+
files:
|
154
|
+
- .document
|
155
|
+
- .rspec
|
156
|
+
- Gemfile
|
157
|
+
- Gemfile.lock
|
158
|
+
- Guardfile
|
159
|
+
- LICENSE.txt
|
160
|
+
- README.rdoc
|
161
|
+
- Rakefile
|
162
|
+
- VERSION
|
163
|
+
- lib/sailthru_batching_client.rb
|
164
|
+
- sailthru_batching_client.gemspec
|
165
|
+
- spec/sailthru_batching_client_spec.rb
|
166
|
+
- spec/spec_helper.rb
|
167
|
+
homepage: http://github.com/LifebookerInc/sailthru_batching_client
|
168
|
+
licenses:
|
169
|
+
- MIT
|
170
|
+
post_install_message:
|
171
|
+
rdoc_options: []
|
172
|
+
require_paths:
|
173
|
+
- lib
|
174
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
+
none: false
|
176
|
+
requirements:
|
177
|
+
- - ! '>='
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
segments:
|
181
|
+
- 0
|
182
|
+
hash: 3030402115352125693
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
none: false
|
185
|
+
requirements:
|
186
|
+
- - ! '>='
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
requirements: []
|
190
|
+
rubyforge_project:
|
191
|
+
rubygems_version: 1.8.11
|
192
|
+
signing_key:
|
193
|
+
specification_version: 3
|
194
|
+
summary: Sailthru Client with Batching
|
195
|
+
test_files: []
|