keen 0.7.6 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ tmp
3
3
  .env
4
4
  log
5
5
  *.gem
6
+ Gemfile.lock
data/Gemfile CHANGED
@@ -1,6 +1,4 @@
1
- source "http://rubygems.org"
2
-
3
- gemspec
1
+ source "https://rubygems.org"
4
2
 
5
3
  group :development, :test do
6
4
  gem 'rake'
@@ -8,28 +6,6 @@ group :development, :test do
8
6
  gem 'em-http-request'
9
7
  gem 'em-synchrony', :require => false
10
8
  gem 'webmock'
11
- # ensure a reasonable json so multi_json doesn't complain
12
- gem 'json', '~> 1.7.7'
13
- end
14
-
15
- group :development do
16
- # guard cross-platform listener trick
17
- gem 'rb-inotify', :require => false
18
- gem 'rb-fsevent', :require => false
19
- gem 'rb-fchange', :require => false
20
-
21
- # guard notifications
22
- gem 'ruby_gntp'
23
-
24
- # fix guard prompt
25
- gem 'rb-readline' # or compile ruby w/ readline
26
-
27
- # guard
28
- gem 'guard'
29
- gem 'guard-rspec'
30
-
31
- # debuggers
32
- gem 'ruby-debug', :platforms => :mri_18
33
- gem 'debugger', :platforms => :mri_19
34
9
  end
35
10
 
11
+ gemspec
data/README.md CHANGED
@@ -226,6 +226,12 @@ To track email opens, simply add an image to your email template that points to
226
226
 
227
227
  ### Changelog
228
228
 
229
+ ##### 0.7.7
230
+ + Add support for HTTP and SOCKS proxies. Set `KEEN_PROXY_URL` to the proxy URL and `KEEN_PROXY_TYPE` to 'socks5' if you need to. These
231
+ properties can also be set on the client instances as `proxy_url` and `proxy_type`.
232
+
233
+ + Delegate the `master_key` fields from the Keen object.
234
+
229
235
  ##### 0.7.6
230
236
  + Explicitly require `CGI`.
231
237
 
data/keen.gemspec CHANGED
@@ -5,7 +5,6 @@ require "keen/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "keen"
7
7
  s.version = Keen::VERSION
8
- s.platform = Gem::Platform::RUBY
9
8
  s.authors = ["Kyle Wild", "Josh Dzielak", "Daniel Kador"]
10
9
  s.email = "josh@keen.io"
11
10
  s.homepage = "https://github.com/keenlabs/keen-gem"
@@ -15,6 +14,27 @@ Gem::Specification.new do |s|
15
14
  s.add_dependency "multi_json", "~> 1.0"
16
15
  s.add_dependency "jruby-openssl" if defined?(JRUBY_VERSION)
17
16
 
17
+ # guard
18
+ s.add_development_dependency 'guard'
19
+ s.add_development_dependency 'guard-rspec'
20
+
21
+ # guard cross-platform listener trick
22
+ s.add_development_dependency 'rb-inotify'
23
+ s.add_development_dependency 'rb-fsevent'
24
+ s.add_development_dependency 'rb-fchange'
25
+
26
+ # guard notifications
27
+ s.add_development_dependency 'ruby_gntp'
28
+
29
+ # fix guard prompt
30
+ s.add_development_dependency 'rb-readline' # or compile ruby w/ readline
31
+
32
+ # debuggers
33
+ if /\Aruby/ === RUBY_DESCRIPTION
34
+ s.add_development_dependency 'ruby-debug' if RUBY_VERSION.start_with? '1.8'
35
+ s.add_development_dependency 'debugger' if RUBY_VERSION.start_with? '1.9'
36
+ end
37
+
18
38
  s.files = `git ls-files`.split("\n")
19
39
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
40
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
data/lib/keen.rb CHANGED
@@ -29,8 +29,13 @@ module Keen
29
29
  :project_id, :project_id=,
30
30
  :write_key, :write_key=,
31
31
  :read_key, :read_key=,
32
+ :master_key, :master_key=,
32
33
  :api_url, :api_url=
33
34
 
35
+ def_delegators :default_client,
36
+ :proxy_url, :proxy_url=,
37
+ :proxy_type, :proxy_type=
38
+
34
39
  def_delegators :default_client,
35
40
  :publish, :publish_async, :publish_batch,
36
41
  :beacon_url
@@ -61,7 +66,9 @@ module Keen
61
66
  :write_key => ENV['KEEN_WRITE_KEY'],
62
67
  :read_key => ENV['KEEN_READ_KEY'],
63
68
  :master_key => ENV['KEEN_MASTER_KEY'],
64
- :api_url => ENV['KEEN_API_URL']
69
+ :api_url => ENV['KEEN_API_URL'],
70
+ :proxy_url => ENV['KEEN_PROXY_URL'],
71
+ :proxy_type => ENV['KEEN_PROXY_TYPE']
65
72
  )
66
73
  end
67
74
  end
data/lib/keen/client.rb CHANGED
@@ -15,7 +15,7 @@ module Keen
15
15
  include Keen::Client::QueryingMethods
16
16
  include Keen::Client::MaintenanceMethods
17
17
 
18
- attr_accessor :project_id, :write_key, :read_key, :master_key, :api_url
18
+ attr_accessor :project_id, :write_key, :read_key, :master_key, :api_url, :proxy_url, :proxy_type
19
19
 
20
20
  CONFIG = {
21
21
  :api_url => "https://api.keen.io",
@@ -47,6 +47,8 @@ module Keen
47
47
  :project_id, :write_key, :read_key, :master_key)
48
48
 
49
49
  self.api_url = options[:api_url] || CONFIG[:api_url]
50
+
51
+ self.proxy_url, self.proxy_type = options.values_at(:proxy_url, :proxy_type)
50
52
  end
51
53
 
52
54
  private
@@ -16,7 +16,7 @@ module Keen
16
16
  query_params = preprocess_params(params) if params != {}
17
17
 
18
18
  begin
19
- response = Keen::HTTP::Sync.new(self.api_url).delete(
19
+ response = Keen::HTTP::Sync.new(self.api_url, self.proxy_url).delete(
20
20
  :path => [api_event_collection_resource_path(event_collection), query_params].compact.join('?'),
21
21
  :headers => api_headers(self.master_key, "sync"))
22
22
  rescue Exception => http_error
@@ -63,7 +63,9 @@ module Keen
63
63
 
64
64
  deferrable = EventMachine::DefaultDeferrable.new
65
65
 
66
- http_client = Keen::HTTP::Async.new(self.api_url)
66
+ http_client = Keen::HTTP::Async.new(
67
+ self.api_url,
68
+ {:proxy_url => self.proxy_url, :proxy_type => self.proxy_type})
67
69
  http = http_client.post(
68
70
  :path => api_event_collection_resource_path(event_collection),
69
71
  :headers => api_headers(self.write_key, "async"),
@@ -116,7 +118,7 @@ module Keen
116
118
  def publish_body(path, body, error_method)
117
119
  begin
118
120
  response = Keen::HTTP::Sync.new(
119
- self.api_url).post(
121
+ self.api_url, self.proxy_url).post(
120
122
  :path => path,
121
123
  :headers => api_headers(self.write_key, "sync"),
122
124
  :body => body)
@@ -171,7 +171,7 @@ module Keen
171
171
  query_params = preprocess_params(params)
172
172
 
173
173
  begin
174
- response = Keen::HTTP::Sync.new(self.api_url).get(
174
+ response = Keen::HTTP::Sync.new(self.api_url, self.proxy_url).get(
175
175
  :path => "#{api_query_resource_path(query_name)}?#{query_params}",
176
176
  :headers => api_headers(self.read_key, "sync"))
177
177
  rescue Exception => http_error
data/lib/keen/http.rb CHANGED
@@ -1,12 +1,21 @@
1
1
  module Keen
2
2
  module HTTP
3
3
  class Sync
4
- def initialize(base_url)
4
+ def initialize(base_url, proxy_url=nil)
5
5
  require 'uri'
6
6
  require 'net/http'
7
7
 
8
8
  uri = URI.parse(base_url)
9
- @http = Net::HTTP.new(uri.host, uri.port)
9
+ if proxy_url
10
+ proxy_uri = URI.parse(proxy_url)
11
+ @http = Net::HTTP::Proxy(
12
+ proxy_uri.host,
13
+ proxy_uri.port,
14
+ proxy_uri.user,
15
+ proxy_uri.password).new(uri.host, uri.port)
16
+ else
17
+ @http = Net::HTTP.new(uri.host, uri.port)
18
+ end
10
19
 
11
20
  if uri.scheme == "https"
12
21
  require 'net/https'
@@ -37,7 +46,7 @@ module Keen
37
46
  end
38
47
 
39
48
  class Async
40
- def initialize(base_url)
49
+ def initialize(base_url, options={})
41
50
  if defined?(EventMachine) && EventMachine.reactor_running?
42
51
  require 'em-http-request'
43
52
  else
@@ -45,17 +54,29 @@ module Keen
45
54
  end
46
55
 
47
56
  @base_url = base_url
57
+ @proxy_url, @proxy_type = options.values_at(:proxy_url, :proxy_type)
48
58
  end
49
59
 
50
60
  def post(options)
51
61
  path, headers, body = options.values_at(
52
62
  :path, :headers, :body)
53
63
  uri = "#{@base_url}#{path}"
54
- http_client = EventMachine::HttpRequest.new(uri)
64
+ if @proxy_url
65
+ proxy_uri = URI.parse(@proxy_url)
66
+ connection_options = {:proxy =>
67
+ {:host => proxy_uri.host,
68
+ :port => proxy_uri.port,
69
+ :authorization => [proxy_uri.user, proxy_uri.password],
70
+ :type => @proxy_type || "http"}}
71
+ http_client = EventMachine::HttpRequest.new(uri, connection_options)
72
+ else
73
+ http_client = EventMachine::HttpRequest.new(uri)
74
+ end
55
75
  http_client.post(
56
76
  :body => body,
57
77
  :head => headers
58
78
  )
79
+
59
80
  end
60
81
  end
61
82
  end
data/lib/keen/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Keen
2
- VERSION = "0.7.6"
2
+ VERSION = "0.7.7"
3
3
  end
@@ -8,7 +8,10 @@ describe Keen do
8
8
  ENV["KEEN_PROJECT_ID"] = "12345"
9
9
  ENV["KEEN_WRITE_KEY"] = "abcdewrite"
10
10
  ENV["KEEN_READ_KEY"] = "abcderead"
11
+ ENV["KEEN_MASTER_KEY"] = "lalalala"
11
12
  ENV["KEEN_API_URL"] = "http://fake.keen.io:fakeport"
13
+ ENV["KEEN_PROXY_URL"] = "http://proxy.keen.io:proxyport"
14
+ ENV["KEEN_PROXY_TYPE"] = "http"
12
15
  end
13
16
 
14
17
  let(:client) { Keen.send(:default_client) }
@@ -25,9 +28,21 @@ describe Keen do
25
28
  client.read_key.should == "abcderead"
26
29
  end
27
30
 
31
+ it "should set a master key from the environment" do
32
+ client.master_key.should == "lalalala"
33
+ end
34
+
28
35
  it "should set an api host from the environment" do
29
36
  client.api_url.should == "http://fake.keen.io:fakeport"
30
37
  end
38
+
39
+ it "should set an proxy host from the environment" do
40
+ client.proxy_url.should == "http://proxy.keen.io:proxyport"
41
+ end
42
+
43
+ it "should set an proxy type from the environment" do
44
+ client.proxy_type.should == "http"
45
+ end
31
46
  end
32
47
  end
33
48
 
@@ -48,14 +63,21 @@ describe Keen do
48
63
  Keen.stub(:default_client).and_return(@default_client)
49
64
  end
50
65
 
51
- [:project_id, :write_key, :read_key, :api_url].each do |_method|
66
+ [:project_id, :write_key, :read_key, :api_url, :proxy_url, :proxy_type].each do |_method|
67
+ it "should forward the #{_method} method" do
68
+ @default_client.should_receive(_method)
69
+ Keen.send(_method)
70
+ end
71
+ end
72
+
73
+ [:project_id, :write_key, :read_key, :master_key, :api_url].each do |_method|
52
74
  it "should forward the #{_method} method" do
53
75
  @default_client.should_receive(_method)
54
76
  Keen.send(_method)
55
77
  end
56
78
  end
57
79
 
58
- [:project_id=, :write_key=, :read_key=, :api_url=].each do |_method|
80
+ [:project_id=, :write_key=, :read_key=, :master_key=, :api_url=].each do |_method|
59
81
  it "should forward the #{_method} method" do
60
82
  @default_client.should_receive(_method).with("12345")
61
83
  Keen.send(_method, "12345")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 0.7.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-07-02 00:00:00.000000000 Z
14
+ date: 2013-08-06 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: multi_json
@@ -29,6 +29,134 @@ dependencies:
29
29
  - - ~>
30
30
  - !ruby/object:Gem::Version
31
31
  version: '1.0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: guard
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: guard-rspec
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ - !ruby/object:Gem::Dependency
65
+ name: rb-inotify
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ - !ruby/object:Gem::Dependency
81
+ name: rb-fsevent
82
+ requirement: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: rb-fchange
98
+ requirement: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: ruby_gntp
114
+ requirement: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ - !ruby/object:Gem::Dependency
129
+ name: rb-readline
130
+ requirement: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ type: :development
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ - !ruby/object:Gem::Dependency
145
+ name: debugger
146
+ requirement: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
32
160
  description: Send events and build analytics features into your Ruby applications.
33
161
  email: josh@keen.io
34
162
  executables: []
@@ -39,7 +167,6 @@ files:
39
167
  - .rspec
40
168
  - .travis.yml
41
169
  - Gemfile
42
- - Gemfile.lock
43
170
  - Guardfile
44
171
  - LICENSE
45
172
  - README.md
data/Gemfile.lock DELETED
@@ -1,108 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- keen (0.7.5)
5
- multi_json (~> 1.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- addressable (2.3.4)
11
- coderay (1.0.9)
12
- columnize (0.3.6)
13
- cookiejar (0.3.0)
14
- crack (0.3.2)
15
- debugger (1.5.0)
16
- columnize (>= 0.3.1)
17
- debugger-linecache (~> 1.2.0)
18
- debugger-ruby_core_source (~> 1.2.0)
19
- debugger-linecache (1.2.0)
20
- debugger-ruby_core_source (1.2.0)
21
- diff-lcs (1.2.4)
22
- em-http-request (1.0.3)
23
- addressable (>= 2.2.3)
24
- cookiejar
25
- em-socksify
26
- eventmachine (>= 1.0.0.beta.4)
27
- http_parser.rb (>= 0.5.3)
28
- em-socksify (0.2.1)
29
- eventmachine (>= 1.0.0.beta.4)
30
- em-synchrony (1.0.3)
31
- eventmachine (>= 1.0.0.beta.1)
32
- eventmachine (1.0.3)
33
- ffi (1.8.1)
34
- formatador (0.2.4)
35
- guard (1.8.0)
36
- formatador (>= 0.2.4)
37
- listen (>= 1.0.0)
38
- lumberjack (>= 1.0.2)
39
- pry (>= 0.9.10)
40
- thor (>= 0.14.6)
41
- guard-rspec (2.6.0)
42
- guard (>= 1.8)
43
- rspec (~> 2.13)
44
- http_parser.rb (0.5.3)
45
- json (1.7.7)
46
- linecache (0.46)
47
- rbx-require-relative (> 0.0.4)
48
- listen (1.0.3)
49
- rb-fsevent (>= 0.9.3)
50
- rb-inotify (>= 0.9)
51
- rb-kqueue (>= 0.2)
52
- lumberjack (1.0.3)
53
- method_source (0.8.1)
54
- multi_json (1.7.4)
55
- pry (0.9.12.1)
56
- coderay (~> 1.0.5)
57
- method_source (~> 0.8)
58
- slop (~> 3.4)
59
- rake (10.0.4)
60
- rb-fchange (0.0.6)
61
- ffi
62
- rb-fsevent (0.9.3)
63
- rb-inotify (0.9.0)
64
- ffi (>= 0.5.0)
65
- rb-kqueue (0.2.0)
66
- ffi (>= 0.5.0)
67
- rb-readline (0.5.0)
68
- rbx-require-relative (0.0.9)
69
- rspec (2.13.0)
70
- rspec-core (~> 2.13.0)
71
- rspec-expectations (~> 2.13.0)
72
- rspec-mocks (~> 2.13.0)
73
- rspec-core (2.13.1)
74
- rspec-expectations (2.13.0)
75
- diff-lcs (>= 1.1.3, < 2.0)
76
- rspec-mocks (2.13.1)
77
- ruby-debug (0.10.4)
78
- columnize (>= 0.1)
79
- ruby-debug-base (~> 0.10.4.0)
80
- ruby-debug-base (0.10.4)
81
- linecache (>= 0.3)
82
- ruby_gntp (0.3.4)
83
- slop (3.4.4)
84
- thor (0.18.1)
85
- webmock (1.11.0)
86
- addressable (>= 2.2.7)
87
- crack (>= 0.3.2)
88
-
89
- PLATFORMS
90
- ruby
91
-
92
- DEPENDENCIES
93
- debugger
94
- em-http-request
95
- em-synchrony
96
- guard
97
- guard-rspec
98
- json (~> 1.7.7)
99
- keen!
100
- rake
101
- rb-fchange
102
- rb-fsevent
103
- rb-inotify
104
- rb-readline
105
- rspec
106
- ruby-debug
107
- ruby_gntp
108
- webmock