keen 0.4.4 → 0.5.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 +7 -0
- data/Gemfile +1 -1
- data/README.md +12 -9
- data/lib/keen/client.rb +2 -3
- data/lib/keen/version.rb +1 -1
- data/spec/integration/api_spec.rb +1 -11
- data/spec/integration/spec_helper.rb +2 -2
- data/spec/keen/client_spec.rb +7 -16
- data/spec/spec_helper.rb +2 -3
- data/spec/synchrony/synchrony_spec.rb +2 -5
- metadata +7 -11
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b5661cff5eaa3017d59716166dc7b265519b95c9
|
4
|
+
data.tar.gz: 4644e32d886566a16b91bf3693bee6de1ba46c65
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7eeb6df1b69794c412f914a770da11addb9cbbddef4dfc17cab0cf96a27b44a9856c9eec5d654464c8f43d2c697510ba6386d16e203e954abb24bc81d0fc2f6f
|
7
|
+
data.tar.gz: 14e3bbf44cdc20227605e4452de88e4097f7d9081ab262ecd5fc5a2ce5c2d3072ead63ed1f25994953736eb0f74b0911f3076529ee46c1260223b0e7bdd962f9
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -23,18 +23,17 @@ keen is tested with Ruby 1.8 and 1.9 on:
|
|
23
23
|
|
24
24
|
### Usage
|
25
25
|
|
26
|
-
Before making any API calls, you must supply keen-gem with a Project ID
|
26
|
+
Before making any API calls, you must supply keen-gem with a Project ID.
|
27
27
|
(If you need a Keen IO account, [sign up here](https://keen.io/) - it's free.)
|
28
28
|
|
29
|
-
The recommended way to do this is to set `KEEN_PROJECT_ID`
|
29
|
+
The recommended way to do this is to set `KEEN_PROJECT_ID` in your
|
30
30
|
environment. If you're using [foreman](http://ddollar.github.com/foreman/), add this to your `.env` file:
|
31
31
|
|
32
32
|
KEEN_PROJECT_ID=your-project-id
|
33
|
-
KEEN_API_KEY=your-api-key
|
34
33
|
|
35
34
|
When you deploy, make sure your production environment variables are also set. For example,
|
36
35
|
set [config vars](https://devcenter.heroku.com/articles/config-vars) on Heroku. (We recommend this
|
37
|
-
environment-based approach because it keeps sensitive
|
36
|
+
environment-based approach because it keeps sensitive information out of the codebase. If you can't do this, see the alternatives below.)
|
38
37
|
|
39
38
|
If your environment is set up property, `Keen` is ready go immediately. Publish an event like this:
|
40
39
|
|
@@ -82,14 +81,13 @@ to resume processing immediately.
|
|
82
81
|
|
83
82
|
#### Authentication
|
84
83
|
|
85
|
-
To configure keen-gem
|
84
|
+
To configure keen-gem in code, do as follows:
|
86
85
|
|
87
86
|
Keen.project_id = 'your-project-id'
|
88
|
-
Keen.api_key = 'your-api-key'
|
89
87
|
|
90
88
|
You can also configure individual client instances as follows:
|
91
89
|
|
92
|
-
keen = Keen::Client.new(:project_id => 'your-project-id'
|
90
|
+
keen = Keen::Client.new(:project_id => 'your-project-id')
|
93
91
|
|
94
92
|
#### em-synchrony
|
95
93
|
keen-gem can be used with [em-synchrony](https://github.com/igrigorik/em-synchrony).
|
@@ -105,15 +103,20 @@ This is useful for situations like tracking email opens using [image beacons](ht
|
|
105
103
|
In this situation, the JSON event data is passed by encoding it base-64 and adding it as a request parameter called `data`.
|
106
104
|
The `beacon_url` method found on the `Keen::Client` does this for you. Here's an example:
|
107
105
|
|
108
|
-
keen = Keen::Client.new(:project_id => '12345'
|
106
|
+
keen = Keen::Client.new(:project_id => '12345')
|
109
107
|
|
110
108
|
keen.beacon_url("sign_ups", :recipient => "foo@foo.com")
|
111
|
-
# => "https://api.keen.io/3.0/projects/12345/events/email_opens?
|
109
|
+
# => "https://api.keen.io/3.0/projects/12345/events/email_opens?data=eyJyZWNpcGllbnQiOiJmb29AZm9vLmNvbSJ9"
|
112
110
|
|
113
111
|
To track email opens, simply add an image to your email template that points to this URL.
|
114
112
|
|
115
113
|
### Changelog
|
116
114
|
|
115
|
+
##### 0.5.0
|
116
|
+
+ Removed API Key as a required field on Keen::Client. Only the Project ID is required to publish events.
|
117
|
+
+ You can continue to provide the API Key. Future features planned for this gem will require it. But for now,
|
118
|
+
there is no keen-gem functionality that uses it.
|
119
|
+
|
117
120
|
##### 0.4.4
|
118
121
|
+ Event collections are URI escaped to account for spaces.
|
119
122
|
+ User agent of API calls made more granular to aid in support cases.
|
data/lib/keen/client.rb
CHANGED
@@ -33,7 +33,7 @@ module Keen
|
|
33
33
|
def beacon_url(event_collection, properties)
|
34
34
|
json = MultiJson.encode(properties)
|
35
35
|
data = [json].pack("m0").tr("+/", "-_").gsub("\n", "")
|
36
|
-
"https://#{api_host}#{api_path(event_collection)}?
|
36
|
+
"https://#{api_host}#{api_path(event_collection)}?data=#{data}"
|
37
37
|
end
|
38
38
|
|
39
39
|
def initialize(*args)
|
@@ -131,12 +131,11 @@ module Keen
|
|
131
131
|
end
|
132
132
|
|
133
133
|
def api_headers_with_auth(sync_or_async)
|
134
|
-
api_headers(sync_or_async)
|
134
|
+
api_headers(sync_or_async)
|
135
135
|
end
|
136
136
|
|
137
137
|
def check_configuration!
|
138
138
|
raise ConfigurationError, "Project ID must be set" unless project_id
|
139
|
-
raise ConfigurationError, "API Key must be set" unless api_key
|
140
139
|
end
|
141
140
|
|
142
141
|
def check_event_data!(event_collection, properties)
|
data/lib/keen/version.rb
CHANGED
@@ -2,7 +2,6 @@ require File.expand_path("../spec_helper", __FILE__)
|
|
2
2
|
|
3
3
|
describe "Keen IO API" do
|
4
4
|
let(:project_id) { ENV['KEEN_PROJECT_ID'] }
|
5
|
-
let(:api_key) { ENV['KEEN_API_KEY'] }
|
6
5
|
|
7
6
|
let(:collection) { "users" }
|
8
7
|
let(:event_properties) { { "name" => "Bob" } }
|
@@ -17,21 +16,12 @@ describe "Keen IO API" do
|
|
17
16
|
|
18
17
|
describe "failure" do
|
19
18
|
it "should raise a not found error if an invalid project id" do
|
20
|
-
client = Keen::Client.new(
|
21
|
-
:api_key => api_key, :project_id => "riker")
|
19
|
+
client = Keen::Client.new(:project_id => "riker")
|
22
20
|
expect {
|
23
21
|
client.publish(collection, event_properties)
|
24
22
|
}.to raise_error(Keen::NotFoundError)
|
25
23
|
end
|
26
24
|
|
27
|
-
it "should raise authentication error if invalid API Key" do
|
28
|
-
client = Keen::Client.new(
|
29
|
-
:api_key => "wrong", :project_id => project_id)
|
30
|
-
expect {
|
31
|
-
client.publish(collection, event_properties)
|
32
|
-
}.to raise_error(Keen::AuthenticationError)
|
33
|
-
end
|
34
|
-
|
35
25
|
it "should success if a non-url-safe event collection is specified" do
|
36
26
|
Keen.publish("infinite possibilities", event_properties).should == api_success
|
37
27
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.expand_path("../../spec_helper", __FILE__)
|
2
2
|
|
3
3
|
RSpec.configure do |config|
|
4
|
-
unless ENV['KEEN_PROJECT_ID']
|
5
|
-
raise "Please set a KEEN_PROJECT_ID
|
4
|
+
unless ENV['KEEN_PROJECT_ID']
|
5
|
+
raise "Please set a KEEN_PROJECT_ID on the environment
|
6
6
|
before running the integration specs."
|
7
7
|
end
|
8
8
|
end
|
data/spec/keen/client_spec.rb
CHANGED
@@ -34,29 +34,20 @@ describe Keen::Client do
|
|
34
34
|
send(_method, collection, event_properties)
|
35
35
|
}.to raise_error(Keen::ConfigurationError)
|
36
36
|
end
|
37
|
-
|
38
|
-
it "should raise an exception if no api_key" do
|
39
|
-
expect {
|
40
|
-
Keen::Client.new(:project_id => project_id).
|
41
|
-
send(_method, collection, event_properties)
|
42
|
-
}.to raise_error(Keen::ConfigurationError)
|
43
|
-
end
|
44
37
|
end
|
45
38
|
end
|
46
39
|
end
|
47
40
|
|
48
41
|
describe "with a configured client" do
|
49
42
|
before do
|
50
|
-
@client = Keen::Client.new(
|
51
|
-
:project_id => project_id,
|
52
|
-
:api_key => api_key)
|
43
|
+
@client = Keen::Client.new(:project_id => project_id)
|
53
44
|
end
|
54
45
|
|
55
46
|
describe "#publish" do
|
56
47
|
it "should post using the collection and properties" do
|
57
48
|
stub_api(api_url(collection), 201, "")
|
58
49
|
@client.publish(collection, event_properties)
|
59
|
-
expect_post(api_url(collection), event_properties,
|
50
|
+
expect_post(api_url(collection), event_properties, "sync")
|
60
51
|
end
|
61
52
|
|
62
53
|
it "should return the proper response" do
|
@@ -80,7 +71,7 @@ describe Keen::Client do
|
|
80
71
|
it "should url encode the event collection" do
|
81
72
|
stub_api(api_url("foo%20bar"), 201, "")
|
82
73
|
@client.publish("foo bar", event_properties)
|
83
|
-
expect_post(api_url("foo%20bar"), event_properties,
|
74
|
+
expect_post(api_url("foo%20bar"), event_properties, "sync")
|
84
75
|
end
|
85
76
|
|
86
77
|
it "should wrap exceptions" do
|
@@ -113,7 +104,7 @@ describe Keen::Client do
|
|
113
104
|
EM.run {
|
114
105
|
@client.publish_async(collection, event_properties).callback {
|
115
106
|
begin
|
116
|
-
expect_post(api_url(collection), event_properties,
|
107
|
+
expect_post(api_url(collection), event_properties, "async")
|
117
108
|
ensure
|
118
109
|
EM.stop
|
119
110
|
end
|
@@ -126,7 +117,7 @@ describe Keen::Client do
|
|
126
117
|
EM.run {
|
127
118
|
@client.publish_async("foo bar", event_properties).callback {
|
128
119
|
begin
|
129
|
-
expect_post(api_url("foo%20bar"), event_properties,
|
120
|
+
expect_post(api_url("foo%20bar"), event_properties, "async")
|
130
121
|
ensure
|
131
122
|
EM.stop
|
132
123
|
end
|
@@ -225,9 +216,9 @@ describe Keen::Client do
|
|
225
216
|
|
226
217
|
describe "beacon_url" do
|
227
218
|
it "should return a url with a base-64 encoded json param" do
|
228
|
-
client = Keen::Client.new(project_id
|
219
|
+
client = Keen::Client.new(project_id)
|
229
220
|
client.beacon_url("sign_ups", { :name => "Bob" }).should ==
|
230
|
-
"https://api.keen.io/3.0/projects/12345/events/sign_ups?
|
221
|
+
"https://api.keen.io/3.0/projects/12345/events/sign_ups?data=eyJuYW1lIjoiQm9iIn0="
|
231
222
|
end
|
232
223
|
end
|
233
224
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -17,7 +17,7 @@ module Keen::SpecHelpers
|
|
17
17
|
:body => MultiJson.encode(json_body))
|
18
18
|
end
|
19
19
|
|
20
|
-
def expect_post(url, event_properties,
|
20
|
+
def expect_post(url, event_properties, sync_or_async_ua)
|
21
21
|
user_agent = "keen-gem, v#{Keen::VERSION}, #{sync_or_async_ua}"
|
22
22
|
user_agent += ", #{RUBY_VERSION}, #{RUBY_PLATFORM}, #{RUBY_PATCHLEVEL}"
|
23
23
|
if defined?(RUBY_ENGINE)
|
@@ -27,8 +27,7 @@ module Keen::SpecHelpers
|
|
27
27
|
WebMock.should have_requested(:post, url).with(
|
28
28
|
:body => MultiJson.encode(event_properties),
|
29
29
|
:headers => { "Content-Type" => "application/json",
|
30
|
-
"User-Agent" => user_agent
|
31
|
-
"Authorization" => api_key })
|
30
|
+
"User-Agent" => user_agent })
|
32
31
|
end
|
33
32
|
|
34
33
|
def api_url(collection)
|
@@ -2,16 +2,13 @@ require File.expand_path("../spec_helper", __FILE__)
|
|
2
2
|
|
3
3
|
describe Keen::HTTP::Async do
|
4
4
|
let(:project_id) { "12345" }
|
5
|
-
let(:api_key) { "abcde" }
|
6
5
|
let(:collection) { "users" }
|
7
6
|
let(:event_properties) { { "name" => "Bob" } }
|
8
7
|
let(:api_success) { { "created" => true } }
|
9
8
|
|
10
9
|
describe "synchrony" do
|
11
10
|
before do
|
12
|
-
@client = Keen::Client.new(
|
13
|
-
:project_id => project_id,
|
14
|
-
:api_key => api_key)
|
11
|
+
@client = Keen::Client.new(:project_id => project_id)
|
15
12
|
end
|
16
13
|
|
17
14
|
describe "success" do
|
@@ -19,7 +16,7 @@ describe Keen::HTTP::Async do
|
|
19
16
|
stub_api(api_url(collection), 201, api_success)
|
20
17
|
EM.synchrony {
|
21
18
|
@client.publish_async(collection, event_properties)
|
22
|
-
expect_post(api_url(collection), event_properties,
|
19
|
+
expect_post(api_url(collection), event_properties, "async")
|
23
20
|
EM.stop
|
24
21
|
}
|
25
22
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Kyle Wild
|
@@ -10,12 +9,11 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2013-
|
12
|
+
date: 2013-02-24 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: multi_json
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
18
|
- - ~>
|
21
19
|
- !ruby/object:Gem::Version
|
@@ -23,7 +21,6 @@ dependencies:
|
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
25
|
- - ~>
|
29
26
|
- !ruby/object:Gem::Version
|
@@ -58,27 +55,26 @@ files:
|
|
58
55
|
- spec/synchrony/synchrony_spec.rb
|
59
56
|
homepage: https://github.com/keenlabs/keen-gem
|
60
57
|
licenses: []
|
58
|
+
metadata: {}
|
61
59
|
post_install_message:
|
62
60
|
rdoc_options: []
|
63
61
|
require_paths:
|
64
62
|
- lib
|
65
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
64
|
requirements:
|
68
|
-
- -
|
65
|
+
- - '>='
|
69
66
|
- !ruby/object:Gem::Version
|
70
67
|
version: '0'
|
71
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
69
|
requirements:
|
74
|
-
- -
|
70
|
+
- - '>='
|
75
71
|
- !ruby/object:Gem::Version
|
76
72
|
version: '0'
|
77
73
|
requirements: []
|
78
74
|
rubyforge_project:
|
79
|
-
rubygems_version:
|
75
|
+
rubygems_version: 2.0.0
|
80
76
|
signing_key:
|
81
|
-
specification_version:
|
77
|
+
specification_version: 4
|
82
78
|
summary: Keen IO API Client
|
83
79
|
test_files:
|
84
80
|
- spec/integration/api_spec.rb
|