keen 0.7.1 → 0.7.2

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/README.md CHANGED
@@ -177,6 +177,9 @@ To track email opens, simply add an image to your email template that points to
177
177
 
178
178
  ### Changelog
179
179
 
180
+ ##### 0.7.2
181
+ + Fix support for non-https API URL testing
182
+
180
183
  ##### 0.7.1
181
184
  + Allow configuration of the base API URL via the KEEN_API_URL environment variable. Useful for local testing and proxies.
182
185
 
data/lib/keen/client.rb CHANGED
@@ -17,12 +17,6 @@ module Keen
17
17
  CONFIG = {
18
18
  :api_url => "https://api.keen.io",
19
19
  :api_version => "3.0",
20
- :api_sync_http_options => {
21
- :use_ssl => true,
22
- :verify_mode => OpenSSL::SSL::VERIFY_PEER,
23
- :verify_depth => 5,
24
- :ca_file => File.expand_path("../../../config/cacert.pem", __FILE__) },
25
- :api_async_http_options => {},
26
20
  :api_headers => lambda { |authorization, sync_or_async|
27
21
  user_agent = "keen-gem, v#{Keen::VERSION}, #{sync_or_async}"
28
22
  user_agent += ", #{RUBY_VERSION}, #{RUBY_PLATFORM}, #{RUBY_PATCHLEVEL}"
@@ -28,7 +28,7 @@ module Keen
28
28
 
29
29
  begin
30
30
  response = Keen::HTTP::Sync.new(
31
- self.api_url, api_sync_http_options).post(
31
+ self.api_url).post(
32
32
  :path => api_event_resource_path(event_collection),
33
33
  :headers => api_headers(self.write_key, "sync"),
34
34
  :body => MultiJson.encode(properties))
@@ -53,7 +53,7 @@ module Keen
53
53
 
54
54
  deferrable = EventMachine::DefaultDeferrable.new
55
55
 
56
- http_client = Keen::HTTP::Async.new(self.api_url, api_async_http_options)
56
+ http_client = Keen::HTTP::Async.new(self.api_url)
57
57
  http = http_client.post(
58
58
  :path => api_event_resource_path(event_collection),
59
59
  :headers => api_headers(self.write_key, "async"),
@@ -171,8 +171,7 @@ module Keen
171
171
  query_params = preprocess_params(params)
172
172
 
173
173
  begin
174
- response = Keen::HTTP::Sync.new(
175
- self.api_url, api_sync_http_options).get(
174
+ response = Keen::HTTP::Sync.new(self.api_url).get(
176
175
  :path => "#{api_query_resource_path(query_name)}?#{query_params}",
177
176
  :headers => api_headers(self.read_key, "sync"))
178
177
  rescue Exception => http_error
data/lib/keen/http.rb CHANGED
@@ -1,13 +1,20 @@
1
1
  module Keen
2
2
  module HTTP
3
3
  class Sync
4
- def initialize(base_url, options={})
4
+ def initialize(base_url)
5
5
  require 'uri'
6
- require 'net/https'
6
+ require 'net/http'
7
7
 
8
8
  uri = URI.parse(base_url)
9
9
  @http = Net::HTTP.new(uri.host, uri.port)
10
- options.each_pair { |key, value| @http.send "#{key}=", value }
10
+
11
+ if uri.scheme == "https"
12
+ require 'net/https'
13
+ @http.use_ssl = true;
14
+ @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
15
+ @http.verify_depth = 5
16
+ @http.ca_file = File.expand_path("../../../config/cacert.pem", __FILE__)
17
+ end
11
18
  end
12
19
 
13
20
  def post(options)
@@ -24,21 +31,21 @@ module Keen
24
31
  end
25
32
 
26
33
  class Async
27
- def initialize(base_url, options={})
34
+ def initialize(base_url)
28
35
  if defined?(EventMachine) && EventMachine.reactor_running?
29
36
  require 'em-http-request'
30
37
  else
31
38
  raise Error, "An EventMachine loop must be running to use publish_async calls"
32
39
  end
33
40
 
34
- @base_url, @http_options = base_url, options
41
+ @base_url = base_url
35
42
  end
36
43
 
37
44
  def post(options)
38
45
  path, headers, body = options.values_at(
39
46
  :path, :headers, :body)
40
47
  uri = "#{@base_url}#{path}"
41
- http_client = EventMachine::HttpRequest.new(uri, @http_options)
48
+ http_client = EventMachine::HttpRequest.new(uri)
42
49
  http_client.post(
43
50
  :body => body,
44
51
  :head => headers
data/lib/keen/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Keen
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
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.1
4
+ version: 0.7.2
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-05-01 00:00:00.000000000 Z
14
+ date: 2013-05-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: multi_json