keen 0.1.12 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 dorkitude
1
+ Copyright (c) 2012 Keen Labs
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  ---
2
- :minor: 1
3
- :build:
4
- :patch: 12
5
2
  :major: 0
3
+ :minor: 2
4
+ :patch: 0
5
+ :build:
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{keen}
8
- s.version = "0.1.12"
7
+ s.name = "keen"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["dorkitude"]
12
- s.date = %q{2012-06-22}
13
- s.description = %q{See the github repo or examples.rb for usage information.}
14
- s.email = %q{kyle@keen.io}
12
+ s.date = "2012-10-02"
13
+ s.description = "See the github repo or examples.rb for usage information."
14
+ s.email = "kyle@keen.io"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.md"
@@ -46,11 +46,11 @@ Gem::Specification.new do |s|
46
46
  "lib/keen/version.rb",
47
47
  "send.rb"
48
48
  ]
49
- s.homepage = %q{http://github.com/dorkitude/keen}
49
+ s.homepage = "http://github.com/dorkitude/keen"
50
50
  s.licenses = ["MIT"]
51
51
  s.require_paths = ["lib"]
52
- s.rubygems_version = %q{1.4.2}
53
- s.summary = %q{A library for batching and sending arbitrary events to the Keen API at http://keen.io}
52
+ s.rubygems_version = "1.8.19"
53
+ s.summary = "A library for batching and sending arbitrary events to the Keen API at http://keen.io"
54
54
 
55
55
  if s.respond_to? :specification_version then
56
56
  s.specification_version = 3
@@ -15,7 +15,7 @@ module Keen
15
15
  if @options[:base_url]
16
16
  @options[:base_url]
17
17
  else
18
- "https://api.keen.io/2.0"
18
+ "https://api.keen.io/3.0"
19
19
  end
20
20
  end
21
21
 
@@ -44,6 +44,8 @@ module Keen
44
44
  @cache_locally = options[:cache_locally]
45
45
 
46
46
  if @cache_locally
47
+ raise "Local caching not supported in this version."
48
+
47
49
  @storage_class = options[:storage_class]
48
50
  unless @storage_class and @storage_class < Keen::Async::Storage::BaseStorageHandler
49
51
  raise "The Storage Class you send must extend BaseStorageHandler. You sent: #{@storage_class}"
@@ -63,73 +65,64 @@ module Keen
63
65
  @storage_handler
64
66
  end
65
67
 
66
- def add_event(collection_name, event_body, timestamp=nil)
68
+ def add_event(event_collection, event_properties, timestamp=nil)
67
69
  #
68
- # `collection_name` should be a string
70
+ # `event_collection` should be a string
69
71
  #
70
- # `event_body` should be a JSON-serializable hash
72
+ # `event` should be a JSON-serializable hash
71
73
  #
72
74
  # `timestamp` is optional. If sent, it should be a Time instance.
73
75
  # If it's not sent, we'll use the current time.
74
76
 
75
- validate_collection_name(collection_name)
77
+ validate_event_collection(event_collection)
76
78
 
77
- unless timestamp
78
- timestamp = Time.now
79
+ if timestamp
80
+ timestamp = timestamp.utc.iso8601
79
81
  end
80
82
 
81
- timestamp = timestamp.utc.iso8601
83
+ event = Keen::Event.new(event_collection, event_properties)
82
84
 
83
- event = Keen::Event.new(timestamp, collection_name, event_body)
85
+ # build the request:
86
+ url = "#{base_url}/projects/#{project_id}/events/#{event_collection}"
87
+ uri = URI.parse(url)
88
+ http = Net::HTTP.new(uri.host, uri.port)
89
+ http.use_ssl = true
90
+ http.ca_file = Keen::Async::SSL_CA_FILE
91
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
92
+ http.verify_depth = 5
84
93
 
85
- if @cache_locally
86
- job = Keen::Async::Job.new(storage_handler, {
87
- :timestamp => event.timestamp,
88
- :project_id => @project_id,
89
- :auth_token => @auth_token,
90
- :collection_name => collection_name,
91
- :event_body => event.body,
92
- })
93
-
94
- job.save
95
- else
96
- # build the request:
97
- url = "#{base_url}/projects/#{project_id}/#{collection_name}"
98
- uri = URI.parse(url)
99
- http = Net::HTTP.new(uri.host, uri.port)
100
- http.use_ssl = true
101
- http.ca_file = Keen::Async::SSL_CA_FILE
102
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
103
- http.verify_depth = 5
104
-
105
- request = Net::HTTP::Post.new(uri.path)
106
- request.body = JSON.generate({
107
- :header => {
108
- :timestamp => event.timestamp,
109
- },
110
- :body => event.body
111
- })
112
-
113
- request["Content-Type"] = "application/json"
114
- request["Authorization"] = @auth_token
115
-
116
- response = http.request(request)
117
- JSON.parse response.body
94
+ request = Net::HTTP::Post.new(uri.path)
95
+
96
+ body = event.properties
97
+
98
+ if timestamp
99
+ request.body[:keen] = {
100
+ :timestamp => timestamp
101
+ }
118
102
  end
103
+
104
+ request.body = JSON.generate(body)
105
+
106
+ request["Content-Type"] = "application/json"
107
+ request["Authorization"] = @auth_token
108
+
109
+ response = http.request(request)
110
+ JSON.parse response.body
111
+
119
112
  end
120
113
 
121
114
  def send_batch(events)
122
115
  # make the request body:
123
116
  request_body = {}
124
117
  events.each { |event|
125
- unless request_body.has_key? event.collection_name
126
- request_body[event.collection_name] = []
118
+ unless request_body.has_key? event.event_collection
119
+ request_body[event.event_collection] = []
127
120
  end
128
121
 
129
122
  header = {"timestamp" => event.timestamp}
130
123
  body = event.body
131
124
  item = {"header" => header, "body" => body}
132
- request_body[event.collection_name].push(item)
125
+ request_body[event.event_collection].push(item)
133
126
  }
134
127
  request_body = request_body.to_json
135
128
 
@@ -154,10 +147,9 @@ module Keen
154
147
  end
155
148
 
156
149
  return JSON.parse resp.body
157
-
158
150
  end
159
151
 
160
- def validate_collection_name(collection_name)
152
+ def validate_event_collection(event_collection)
161
153
  # TODO
162
154
  end
163
155
 
@@ -1,12 +1,12 @@
1
1
  module Keen
2
2
  class Event
3
3
 
4
- attr_accessor :timestamp, :collection_name, :body
4
+ attr_accessor :event_collection, :properties, :timestamp
5
5
 
6
- def initialize(timestamp, collection_name, body)
6
+ def initialize(event_collection, properties, timestamp=nil)
7
+ @event_collection = event_collection
8
+ @properties = properties
7
9
  @timestamp = timestamp
8
- @collection_name = collection_name
9
- @body = body
10
10
  end
11
11
 
12
12
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keen
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 12
10
- version: 0.1.12
5
+ version: 0.2.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - dorkitude
@@ -15,132 +10,96 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2012-06-22 00:00:00 -07:00
19
- default_executable:
13
+ date: 2012-10-02 00:00:00 Z
20
14
  dependencies:
21
15
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
16
  name: json
24
- type: :runtime
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &id001 !ruby/object:Gem::Requirement
26
18
  none: false
27
19
  requirements:
28
20
  - - ">="
29
21
  - !ruby/object:Gem::Version
30
- hash: 5
31
- segments:
32
- - 1
33
- - 6
34
- - 5
35
22
  version: 1.6.5
36
- requirement: *id001
37
- - !ruby/object:Gem::Dependency
23
+ type: :runtime
38
24
  prerelease: false
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
39
27
  name: redis
40
- type: :runtime
41
- version_requirements: &id002 !ruby/object:Gem::Requirement
28
+ requirement: &id002 !ruby/object:Gem::Requirement
42
29
  none: false
43
30
  requirements:
44
31
  - - ">="
45
32
  - !ruby/object:Gem::Version
46
- hash: 3
47
- segments:
48
- - 0
49
33
  version: "0"
50
- requirement: *id002
51
- - !ruby/object:Gem::Dependency
34
+ type: :runtime
52
35
  prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
53
38
  name: shoulda
54
- type: :development
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
39
+ requirement: &id003 !ruby/object:Gem::Requirement
56
40
  none: false
57
41
  requirements:
58
42
  - - ">="
59
43
  - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 0
63
44
  version: "0"
64
- requirement: *id003
65
- - !ruby/object:Gem::Dependency
45
+ type: :development
66
46
  prerelease: false
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
67
49
  name: rdoc
68
- type: :development
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
50
+ requirement: &id004 !ruby/object:Gem::Requirement
70
51
  none: false
71
52
  requirements:
72
53
  - - ~>
73
54
  - !ruby/object:Gem::Version
74
- hash: 31
75
- segments:
76
- - 3
77
- - 12
78
55
  version: "3.12"
79
- requirement: *id004
80
- - !ruby/object:Gem::Dependency
56
+ type: :development
81
57
  prerelease: false
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
82
60
  name: bundler
83
- type: :development
84
- version_requirements: &id005 !ruby/object:Gem::Requirement
61
+ requirement: &id005 !ruby/object:Gem::Requirement
85
62
  none: false
86
63
  requirements:
87
64
  - - ">="
88
65
  - !ruby/object:Gem::Version
89
- hash: 27
90
- segments:
91
- - 1
92
- - 1
93
- - 4
94
66
  version: 1.1.4
95
- requirement: *id005
96
- - !ruby/object:Gem::Dependency
67
+ type: :development
97
68
  prerelease: false
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
98
71
  name: jeweler
99
- type: :development
100
- version_requirements: &id006 !ruby/object:Gem::Requirement
72
+ requirement: &id006 !ruby/object:Gem::Requirement
101
73
  none: false
102
74
  requirements:
103
75
  - - ~>
104
76
  - !ruby/object:Gem::Version
105
- hash: 49
106
- segments:
107
- - 1
108
- - 8
109
- - 3
110
77
  version: 1.8.3
111
- requirement: *id006
112
- - !ruby/object:Gem::Dependency
78
+ type: :development
113
79
  prerelease: false
80
+ version_requirements: *id006
81
+ - !ruby/object:Gem::Dependency
114
82
  name: rspec
115
- type: :development
116
- version_requirements: &id007 !ruby/object:Gem::Requirement
83
+ requirement: &id007 !ruby/object:Gem::Requirement
117
84
  none: false
118
85
  requirements:
119
86
  - - ">="
120
87
  - !ruby/object:Gem::Version
121
- hash: 43
122
- segments:
123
- - 2
124
- - 9
125
- - 0
126
88
  version: 2.9.0
127
- requirement: *id007
128
- - !ruby/object:Gem::Dependency
89
+ type: :development
129
90
  prerelease: false
91
+ version_requirements: *id007
92
+ - !ruby/object:Gem::Dependency
130
93
  name: cucumber
131
- type: :development
132
- version_requirements: &id008 !ruby/object:Gem::Requirement
94
+ requirement: &id008 !ruby/object:Gem::Requirement
133
95
  none: false
134
96
  requirements:
135
97
  - - ">="
136
98
  - !ruby/object:Gem::Version
137
- hash: 29
138
- segments:
139
- - 1
140
- - 2
141
- - 1
142
99
  version: 1.2.1
143
- requirement: *id008
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: *id008
144
103
  description: See the github repo or examples.rb for usage information.
145
104
  email: kyle@keen.io
146
105
  executables: []
@@ -179,7 +138,6 @@ files:
179
138
  - lib/keen/utils.rb
180
139
  - lib/keen/version.rb
181
140
  - send.rb
182
- has_rdoc: true
183
141
  homepage: http://github.com/dorkitude/keen
184
142
  licenses:
185
143
  - MIT
@@ -193,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
193
151
  requirements:
194
152
  - - ">="
195
153
  - !ruby/object:Gem::Version
196
- hash: 3
154
+ hash: 742359420627870706
197
155
  segments:
198
156
  - 0
199
157
  version: "0"
@@ -202,14 +160,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
160
  requirements:
203
161
  - - ">="
204
162
  - !ruby/object:Gem::Version
205
- hash: 3
206
- segments:
207
- - 0
208
163
  version: "0"
209
164
  requirements: []
210
165
 
211
166
  rubyforge_project:
212
- rubygems_version: 1.4.2
167
+ rubygems_version: 1.8.19
213
168
  signing_key:
214
169
  specification_version: 3
215
170
  summary: A library for batching and sending arbitrary events to the Keen API at http://keen.io