Skip to content

Commit

Permalink
Adding json to wrap multi_json
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin French-Owen committed Feb 11, 2013
1 parent 0aeeaa6 commit 737bb36
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
5 changes: 5 additions & 0 deletions History.md
@@ -1,3 +1,8 @@
0.1.1 / 2013-2-11
===========
* Updating dependencies
* Adding actual support for MultiJson 1.0

0.1.0 / 2013-1-22
===========
* Updated docs to point at segment.io
Expand Down
2 changes: 1 addition & 1 deletion analytics-ruby.gemspec
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
spec.email = 'friends@segment.io'
spec.homepage = 'https://github.com/segmentio/analytics-ruby'

spec.add_dependency 'faraday', ['~> 0.8', '< 0.10']
spec.add_dependency 'faraday', ['>= 0.8', '< 0.10']
spec.add_dependency 'faraday_middleware', ['~> 0.9.0']
spec.add_dependency 'multi_json', ['~> 1.0']

Expand Down
28 changes: 28 additions & 0 deletions lib/analytics-ruby/json.rb
@@ -0,0 +1,28 @@
require 'multi_json'

module AnalyticsRuby

# JSON Wrapper module adapted from
# https://github.com/stripe/stripe-ruby/blob/master/lib/stripe/json.rb
#
# .dump was added in MultiJson 1.3
module JSON
if MultiJson.respond_to?(:dump)
def self.dump(*args)
MultiJson.dump(*args)
end

def self.load(*args)
MultiJson.load(*args)
end
else
def self.dump(*args)
MultiJson.encode(*args)
end

def self.load(*args)
MultiJson.decode(*args)
end
end
end
end
4 changes: 2 additions & 2 deletions lib/analytics-ruby/request.rb
@@ -1,7 +1,7 @@

require 'analytics-ruby/defaults'
require 'analytics-ruby/response'
require 'multi_json'
require 'analytics-ruby/json'
require 'faraday'
require 'faraday_middleware'

Expand Down Expand Up @@ -35,7 +35,7 @@ def post(secret, batch)
begin
res = @conn.post do |req|
req.url(@path)
req.body = MultiJson.dump(secret: secret, batch: batch)
req.body = AnalyticsRuby::JSON::dump(secret: secret, batch: batch)
end
status = res.status
error = res.body["error"]
Expand Down
2 changes: 1 addition & 1 deletion lib/analytics-ruby/version.rb
@@ -1,3 +1,3 @@
module AnalyticsRuby
VERSION = '0.1.0'
VERSION = '0.1.1'
end
2 changes: 2 additions & 0 deletions spec/module_spec.rb
Expand Up @@ -23,6 +23,7 @@

it 'should not error with the required options' do
Analytics.track AnalyticsHelpers::Queued::TRACK
sleep(1)
end
end

Expand All @@ -34,6 +35,7 @@

it 'should not error with the required options' do
Analytics.identify AnalyticsHelpers::Queued::IDENTIFY
sleep(1)
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -3,7 +3,7 @@ module AnalyticsHelpers

SECRET = 'testsecret'

TRACK = { event: 'Baked a cake',
TRACK = { event: 'Ruby Library test event',
properties: {
type: 'Chocolate',
is_a_lie: true,
Expand Down

0 comments on commit 737bb36

Please sign in to comment.