kontagent 0.0.1
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.
- data/Manifest +5 -0
- data/Rakefile +13 -0
- data/kontagent.gemspec +36 -0
- data/lib/kontagent.rb +143 -0
- data/spec/kontagent_spec.rb +323 -0
- metadata +106 -0
data/Manifest
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('kontagent', '0.0.1') do |p|
|
6
|
+
p.description = "A gem that provides basic integration with Kontagent's REST API"
|
7
|
+
p.url = "http://github.com/gamesthatgive/kontagent"
|
8
|
+
p.author = "Kristofer Goss"
|
9
|
+
p.email = "goss@gamesthatgive.net"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.runtime_dependencies = [["uuidtools", ">= 1.0.7"], ["rest-client", ">=1.1.0"]]
|
12
|
+
# p.development_dependencies = []
|
13
|
+
end
|
data/kontagent.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{kontagent}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Kristofer Goss"]
|
9
|
+
s.date = %q{2010-07-30}
|
10
|
+
s.description = %q{A gem that provides basic integration with Kontagent's REST API}
|
11
|
+
s.email = %q{goss@gamesthatgive.net}
|
12
|
+
s.extra_rdoc_files = ["lib/kontagent.rb"]
|
13
|
+
s.files = ["Manifest", "Rakefile", "kontagent.gemspec", "lib/kontagent.rb", "spec/kontagent_spec.rb"]
|
14
|
+
s.homepage = %q{http://github.com/gamesthatgive/kontagent}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Kontagent"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{kontagent}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{A gem that provides basic integration with Kontagent's REST API}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<uuidtools>, [">= 1.0.7"])
|
27
|
+
s.add_runtime_dependency(%q<rest-client>, [">= 1.1.0"])
|
28
|
+
else
|
29
|
+
s.add_dependency(%q<uuidtools>, [">= 1.0.7"])
|
30
|
+
s.add_dependency(%q<rest-client>, [">= 1.1.0"])
|
31
|
+
end
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<uuidtools>, [">= 1.0.7"])
|
34
|
+
s.add_dependency(%q<rest-client>, [">= 1.1.0"])
|
35
|
+
end
|
36
|
+
end
|
data/lib/kontagent.rb
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rest_client'
|
3
|
+
require 'uuidtools'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
module Kontagent
|
7
|
+
def self.config
|
8
|
+
@@config
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.base_url
|
12
|
+
@@base_url
|
13
|
+
end
|
14
|
+
|
15
|
+
PARAMS_MAP = {
|
16
|
+
:uid => :s,
|
17
|
+
:birth_year => :b,
|
18
|
+
:sex => [:g, :escape],
|
19
|
+
:city => [:ly, :escape],
|
20
|
+
:country => [:lc, :escape],
|
21
|
+
:zip => [:lp, :escape],
|
22
|
+
:state => [:ls, :escape],
|
23
|
+
:friend_count => :f,
|
24
|
+
:short_tag => :su,
|
25
|
+
:tag => :u,
|
26
|
+
:channel => :tu,
|
27
|
+
:link_type => :tu,
|
28
|
+
:st1 => [:st1, :escape],
|
29
|
+
:st2 => [:st2, :escape],
|
30
|
+
:st3 => [:st3, :escape],
|
31
|
+
:responder_uid => :r,
|
32
|
+
:recipient_uids => [:r, :escape],
|
33
|
+
:existing_install? => :i,
|
34
|
+
:timestamp => :ts,
|
35
|
+
}
|
36
|
+
|
37
|
+
def self.create_tracking_tag
|
38
|
+
tag = UUID.random_create.to_s.gsub("-", "")
|
39
|
+
yield tag if block_given?
|
40
|
+
tag
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.create_short_tag
|
44
|
+
create_tracking_tag
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.initialize!(options = {})
|
48
|
+
raise "Missing required api_url setting" unless options["api_url"]
|
49
|
+
raise "Missing required ab_url setting" unless options["ab_url"]
|
50
|
+
@@config = OpenStruct.new(options)
|
51
|
+
@@base_url = File.join(self.config.api_url, self.config.api_key)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.application_added(options = {})
|
55
|
+
assert_options(options, :uid)
|
56
|
+
call_method("apa", options)
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.application_removed(options = {})
|
60
|
+
assert_options(options, :uid)
|
61
|
+
call_method("apr", options)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.get_page_request_url(options = {})
|
65
|
+
assert_options(options, :uid)
|
66
|
+
options[:timestamp] ||= Time.now.strftime("%Y-%m-%dT%H:%M:%S")
|
67
|
+
build_url("pgr", options)
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.track_user(options = {})
|
71
|
+
assert_options(options, :uid)
|
72
|
+
options[:sex] = options[:sex].to_s[0,1]
|
73
|
+
call_method("cpu", options)
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.track_post(options = {})
|
77
|
+
assert_options(options, :uid, :tag, :channel)
|
78
|
+
assert_channel(options[:channel])
|
79
|
+
call_method("pst", options)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.track_post_response(options = {})
|
83
|
+
assert_options(options, :responder_uid, :tag, :channel, :existing_install?)
|
84
|
+
assert_channel(options[:channel])
|
85
|
+
options[:existing_install?] = options[:existing_install?] && 1 || 0
|
86
|
+
call_method("psr", options)
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.track_invite(options = {})
|
90
|
+
assert_options(options, :uid, :tag, :recipient_uids)
|
91
|
+
options[:recipient_uids] = options[:recipient_uids].join(",")
|
92
|
+
call_method("ins", options)
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.track_invite_response(options = {})
|
96
|
+
assert_options(options, :responder_uid, :tag, :existing_install?)
|
97
|
+
options[:existing_install?] = options[:existing_install?] && 1 || 0
|
98
|
+
call_method("inr", options)
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.build_url(method, options = {})
|
102
|
+
File.join(self.base_url, method, "?#{kontagent_params(options)}")
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.track_link(options)
|
106
|
+
assert_options(options, :link_type, :existing_install?, :short_tag)
|
107
|
+
options[:existing_install?] = options[:existing_install?] ? 1 : 0
|
108
|
+
call_method("ucc", options)
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def self.assert_options(options, *required_keys)
|
114
|
+
required_keys.each { |k| assert(options.key?(k), "#{k} is required") }
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.assert_channel(value)
|
118
|
+
assert([:stream, :feedpub, :feedstory, :multifeedstory].member?(value.to_sym), "channel type #{value} not supported")
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.assert(value, message = "Assertion failed")
|
122
|
+
raise Exception, message, caller unless value
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.call_method(method, options = {})
|
126
|
+
url = build_url(method, options)
|
127
|
+
RestClient.get(url)
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.kontagent_params(options)
|
131
|
+
opts = options.inject({}) do |rewritten_hash, (original_key, value)|
|
132
|
+
unless value.nil? || value.to_s.strip.empty?
|
133
|
+
if PARAMS_MAP[original_key].is_a? Array
|
134
|
+
rewritten_hash[PARAMS_MAP[original_key].first] = CGI.escape(value)
|
135
|
+
elsif PARAMS_MAP[original_key]
|
136
|
+
rewritten_hash[PARAMS_MAP[original_key]] = value
|
137
|
+
end
|
138
|
+
end
|
139
|
+
rewritten_hash
|
140
|
+
end
|
141
|
+
opts.map { |k,v| "#{k}=#{v}" }.sort.join("&")
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,323 @@
|
|
1
|
+
require "kontagent"
|
2
|
+
|
3
|
+
describe Kontagent do
|
4
|
+
before(:each) do
|
5
|
+
Kontagent.initialize!("api_url" => "http://kontagent.com/api/v1", "api_key" => "12345", "ab_url" => "http://kontagent.com")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should initialize" do
|
9
|
+
Kontagent.config.should_not be_nil
|
10
|
+
Kontagent.base_url.should == "http://kontagent.com/api/v1/12345"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not initialize without an API key" do
|
14
|
+
lambda { Kontagent.initialize!("api_url" => "http://kontagent.com/api/v1", "ab_url" => "http://kontagent.com") }.should raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should not initialize without an A/B url" do
|
18
|
+
lambda { Kontagent.initialize!("api_url" => "http://kontagent.com/api/v1", "api_key" => "12345") }.should raise_error
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when adding an application" do
|
22
|
+
before(:each) do
|
23
|
+
@tracking_tag = UUID.random_create.to_s.gsub("-", "")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should record the user id" do
|
27
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/apa/?s=1")
|
28
|
+
Kontagent.application_added :uid => 1
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should raise without user id" do
|
32
|
+
lambda { Kontagent.application_added }.should raise_error
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should record the tracking tag" do
|
36
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/apa/?s=1&u=#{@tracking_tag}")
|
37
|
+
Kontagent.application_added :uid => 1, :tag => @tracking_tag
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should record the short tracking tag" do
|
41
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/apa/?s=1&su=#{@tracking_tag}")
|
42
|
+
Kontagent.application_added :uid => 1, :short_tag => @tracking_tag
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when removing an application" do
|
47
|
+
it "should record the user id" do
|
48
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/apr/?s=1")
|
49
|
+
Kontagent.application_removed :uid => 1
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should raise without user id" do
|
53
|
+
lambda { Kontagent.application_removed }.should raise_error
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when tracking a page request" do
|
58
|
+
before(:each) do
|
59
|
+
@now = Time.now
|
60
|
+
Time.stub!(:now).and_return(@now)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should build the proper tracking url" do
|
64
|
+
expected_timestamp = @now.strftime("%Y-%m-%dT%H:%M:%S")
|
65
|
+
Kontagent.get_page_request_url(:uid => 1).should == "#{Kontagent.base_url}/pgr/?s=1&ts=#{expected_timestamp}"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should raise without user id" do
|
69
|
+
lambda { Kontagent.get_page_request_url }.should raise_error
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when tracking user demograpics" do
|
74
|
+
it "should record" do
|
75
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/cpu/?b=1955&f=3&g=f&lc=USA&lp=04103&ls=ME&ly=San+Francisco&s=1")
|
76
|
+
Kontagent.track_user(:uid => 1,
|
77
|
+
:birth_year => 1955,
|
78
|
+
:sex => "female",
|
79
|
+
:city => "San Francisco",
|
80
|
+
:country => "USA",
|
81
|
+
:state => "ME",
|
82
|
+
:zip => "04103",
|
83
|
+
:friend_count => 3)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should handle empty values" do
|
87
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/cpu/?b=1955&f=3&lc=USA&lp=04103&s=1")
|
88
|
+
Kontagent.track_user(:uid => 1,
|
89
|
+
:birth_year => 1955,
|
90
|
+
:sex => "",
|
91
|
+
:city => " ",
|
92
|
+
:country => "USA",
|
93
|
+
:state => "",
|
94
|
+
:zip => "04103",
|
95
|
+
:friend_count => 3)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should handle nil values" do
|
99
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/cpu/?b=1955&f=3&g=f&lc=USA&lp=04103&s=1")
|
100
|
+
Kontagent.track_user(:uid => 1,
|
101
|
+
:birth_year => 1955,
|
102
|
+
:sex => "female",
|
103
|
+
:city => nil,
|
104
|
+
:country => "USA",
|
105
|
+
:state => nil,
|
106
|
+
:zip => "04103",
|
107
|
+
:friend_count => 3)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "when tracking a post" do
|
112
|
+
it "should record a stream post" do
|
113
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/pst/?s=1&tu=stream&u=12345")
|
114
|
+
Kontagent.track_post(:channel => :stream, :uid => 1, :tag => "12345")
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should record a feed publication" do
|
118
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/pst/?s=1&tu=feedpub&u=12345")
|
119
|
+
Kontagent.track_post(:channel => :feedpub, :uid => 1, :tag => "12345")
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should record a feed story" do
|
123
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/pst/?s=1&tu=feedstory&u=12345")
|
124
|
+
Kontagent.track_post(:channel => :feedstory, :uid => 1, :tag => "12345")
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should record a multifeed story" do
|
128
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/pst/?s=1&tu=multifeedstory&u=12345")
|
129
|
+
Kontagent.track_post(:channel => :multifeedstory, :uid => 1, :tag => "12345")
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should record with subtypes" do
|
133
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/pst/?s=1&st1=subtype1&st2=subtype2&st3=subtype3&tu=multifeedstory&u=12345")
|
134
|
+
Kontagent.track_post(:channel => :multifeedstory,
|
135
|
+
:uid => 1,
|
136
|
+
:st1 => "subtype1",
|
137
|
+
:st2 => "subtype2",
|
138
|
+
:st3 => "subtype3",
|
139
|
+
:tag => "12345")
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should raise given unknown channel type" do
|
143
|
+
lambda { Kontagent.track_post(:channel => :bogus, :uid => 1, :tag => "12345") }.should raise_error
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should raise given missing uid" do
|
147
|
+
lambda { Kontagent.track_post(:channel => :stream, :tag => "12345") }.should raise_error
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should raise given missing tag" do
|
151
|
+
lambda { Kontagent.track_post(:channel => :stream, :uid => 1) }.should raise_error
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context "when tracking a post response" do
|
156
|
+
it "should record a stream response" do
|
157
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/psr/?i=0&r=2&tu=stream&u=12345")
|
158
|
+
Kontagent.track_post_response(:channel => :stream,
|
159
|
+
:responder_uid => 2,
|
160
|
+
:tag => 12345,
|
161
|
+
:existing_install? => false)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should record with subtypes" do
|
165
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/psr/?i=0&r=2&st1=subtype1&st2=subtype2&st3=subtype3&tu=stream&u=12345")
|
166
|
+
Kontagent.track_post_response(:channel => :stream,
|
167
|
+
:responder_uid => 2,
|
168
|
+
:st1 => "subtype1",
|
169
|
+
:st2 => "subtype2",
|
170
|
+
:st3 => "subtype3",
|
171
|
+
:tag => 12345,
|
172
|
+
:existing_install? => false)
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should record a feedpub post response" do
|
176
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/psr/?i=0&r=2&tu=feedpub&u=12345")
|
177
|
+
Kontagent.track_post_response(:channel => :feedpub,
|
178
|
+
:responder_uid => 2,
|
179
|
+
:tag => 12345,
|
180
|
+
:existing_install? => false)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should record a feedstory post response" do
|
184
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/psr/?i=1&r=2&tu=feedstory&u=12345")
|
185
|
+
Kontagent.track_post_response(:channel => :feedstory,
|
186
|
+
:responder_uid => 2,
|
187
|
+
:tag => 12345,
|
188
|
+
:existing_install? => true)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should record a multifeedstory post response" do
|
192
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/psr/?i=1&r=2&tu=multifeedstory&u=12345")
|
193
|
+
Kontagent.track_post_response(:channel => :multifeedstory,
|
194
|
+
:responder_uid => 2,
|
195
|
+
:tag => 12345,
|
196
|
+
:existing_install? => true)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should raise given missing recipient" do
|
200
|
+
lambda { Kontagent.track_post_response(:channel => :multifeedstory,
|
201
|
+
:tag => 12345,
|
202
|
+
:existing_install? => true) }.should raise_error
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should raise given missing channel" do
|
206
|
+
lambda { Kontagent.track_post_response(:responder_uid => 2,
|
207
|
+
:tag => 12345,
|
208
|
+
:existing_install? => true) }.should raise_error
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should raise given missing tag" do
|
212
|
+
lambda { Kontagent.track_post_response(:channel => :stream,
|
213
|
+
:responder_uid => 2,
|
214
|
+
:existing_install? => true) }.should raise_error
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should raise given missing install status" do
|
218
|
+
lambda { Kontagent.track_post_response(:channel => :stream,
|
219
|
+
:responder_uid => 2,
|
220
|
+
:tag => 12345) }.should raise_error
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should raise given invalid channel" do
|
224
|
+
lambda { Kontagent.track_post_response(:channel => :bogus,
|
225
|
+
:responder_uid => 2,
|
226
|
+
:tag => 12345,
|
227
|
+
:existing_install? => true) }.should raise_error
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context "creating tags" do
|
232
|
+
it "should be able to create a tracking tag" do
|
233
|
+
Kontagent.create_tracking_tag.should_not be_empty
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should be able to create a short tag" do
|
237
|
+
Kontagent.create_short_tag.should_not be_empty
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should yield when creating a tracking tag" do
|
241
|
+
yielded = false
|
242
|
+
|
243
|
+
Kontagent.create_tracking_tag do |tag|
|
244
|
+
tag.should_not be_nil
|
245
|
+
tag.should_not be_empty
|
246
|
+
yielded = true
|
247
|
+
end
|
248
|
+
|
249
|
+
yielded.should be_true
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
context "when tracking link traffic" do
|
254
|
+
it "should record an undirected communication click" do
|
255
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/ucc/?i=0&st1=Facebook&st2=GamePhun&st3=2&su=short_tag&tu=ad")
|
256
|
+
Kontagent.track_link(:link_type => 'ad', :st1 => 'Facebook', :st2 => 'GamePhun',
|
257
|
+
:st3 => '2', :existing_install? => false, :short_tag => 'short_tag')
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should encode its parameters" do
|
261
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/ucc/?i=0&st1=%2F&st2=%24&st3=%26&su=short_tag&tu=ad")
|
262
|
+
Kontagent.track_link(:link_type => 'ad', :st1 => '/', :st2 => '$', :st3 => '&',
|
263
|
+
:existing_install? => false, :short_tag => 'short_tag')
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
context "when tracking an invitation" do
|
268
|
+
before(:each) do
|
269
|
+
@tag = Kontagent.create_tracking_tag
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should record the invite" do
|
273
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/ins/?r=1%2C2%2C3%2C4%2C5&s=12345&u=#{@tag}")
|
274
|
+
Kontagent.track_invite :uid => 12345, :tag => @tag, :recipient_uids => [1,2,3,4,5]
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should require a uid" do
|
278
|
+
RestClient.should_not_receive(:get)
|
279
|
+
lambda { Kontagent.track_invite :tag => @tag, :recipient_uids => [1,2,3,4,5] }.should raise_error("uid is required")
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should require recipient identifiers" do
|
283
|
+
RestClient.should_not_receive(:get)
|
284
|
+
lambda { Kontagent.track_invite :uid => 12345, :tag => @tag }.should raise_error("recipient_uids is required")
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should require a tracking tag" do
|
288
|
+
RestClient.should_not_receive(:get)
|
289
|
+
lambda { Kontagent.track_invite :uid => 12345, :recipient_uids => [1,2,3,4,5] }.should raise_error("tag is required")
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should record with st1 param" do
|
293
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/ins/?r=1%2C2%2C3%2C4%2C5&s=12345&st1=st1&u=#{@tag}")
|
294
|
+
Kontagent.track_invite :uid => 12345, :tag => @tag, :recipient_uids => [1,2,3,4,5], :st1 => "st1"
|
295
|
+
end
|
296
|
+
|
297
|
+
it "should record with st2 param" do
|
298
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/ins/?r=1%2C2%2C3%2C4%2C5&s=12345&st2=st2&u=#{@tag}")
|
299
|
+
Kontagent.track_invite :uid => 12345, :tag => @tag, :recipient_uids => [1,2,3,4,5], :st2 => "st2"
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
context "when tracking an invitation response" do
|
304
|
+
before(:each) do
|
305
|
+
@tag = Kontagent.create_tracking_tag
|
306
|
+
end
|
307
|
+
|
308
|
+
it "should record the response" do
|
309
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/inr/?i=1&r=12345&u=#{@tag}")
|
310
|
+
Kontagent.track_invite_response(:responder_uid => 12345, :existing_install? => true, :tag => @tag)
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should record with st1 param" do
|
314
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/inr/?i=1&r=12345&st1=st1&u=#{@tag}")
|
315
|
+
Kontagent.track_invite_response(:responder_uid => 12345, :existing_install? => true, :tag => @tag, :st1 => "st1")
|
316
|
+
end
|
317
|
+
|
318
|
+
it "should record with st2 param" do
|
319
|
+
RestClient.should_receive(:get).with("#{Kontagent.base_url}/inr/?i=1&r=12345&st2=st2&u=#{@tag}")
|
320
|
+
Kontagent.track_invite_response(:responder_uid => 12345, :existing_install? => true, :tag => @tag, :st2 => "st2")
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kontagent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Kristofer Goss
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-30 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: uuidtools
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 25
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
- 7
|
34
|
+
version: 1.0.7
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rest-client
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 19
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 1
|
49
|
+
- 0
|
50
|
+
version: 1.1.0
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
description: A gem that provides basic integration with Kontagent's REST API
|
54
|
+
email: goss@gamesthatgive.net
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files:
|
60
|
+
- lib/kontagent.rb
|
61
|
+
files:
|
62
|
+
- Manifest
|
63
|
+
- Rakefile
|
64
|
+
- kontagent.gemspec
|
65
|
+
- lib/kontagent.rb
|
66
|
+
- spec/kontagent_spec.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://github.com/gamesthatgive/kontagent
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options:
|
73
|
+
- --line-numbers
|
74
|
+
- --inline-source
|
75
|
+
- --title
|
76
|
+
- Kontagent
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 11
|
94
|
+
segments:
|
95
|
+
- 1
|
96
|
+
- 2
|
97
|
+
version: "1.2"
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project: kontagent
|
101
|
+
rubygems_version: 1.3.7
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: A gem that provides basic integration with Kontagent's REST API
|
105
|
+
test_files: []
|
106
|
+
|