Skip to content

Commit

Permalink
Use MultiJson to avoid object pollution by json_pure
Browse files Browse the repository at this point in the history
  • Loading branch information
rainux committed Nov 19, 2012
1 parent b9f123c commit 3657961
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion emailyak.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.add_dependency(%q<rest-client>, [">= 0"])
s.add_dependency('json_pure', '>= 0')
s.add_dependency('multi_json', '>= 1.3.7')
end
31 changes: 15 additions & 16 deletions lib/emailyak.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
require 'cgi'
require 'set'

require 'rubygems'
require 'json/pure'
require 'multi_json'
require 'openssl'
require 'rest_client'
require 'ostruct'

# A lot of the structure here is borrowed from the Stripe Ruby
# bindings (https://github.com/stripe/stripe-ruby).

# Further adapted from https://github.com/gdb/emailyak-ruby
# because I couldn't get it to install on heroku and
# Further adapted from https://github.com/gdb/emailyak-ruby
# because I couldn't get it to install on heroku and
# I wanted to add to it

module EmailYak
Expand All @@ -32,7 +31,7 @@ def self.file_readable(file)
end
end
end

def self.docs(url=self.api_docs_url)
begin
puts "opening api docs at #{self.api_docs_url} "
Expand All @@ -42,7 +41,7 @@ def self.docs(url=self.api_docs_url)
end
true
end

def self.api_docs_url
"http://docs.emailyak.com/"
end
Expand Down Expand Up @@ -72,40 +71,40 @@ module Email
def self.all(params={})
EmailYak.request(:get, 'get/all/email/', nil, params)
end

def self.get(params={})
EmailYak.request(:get, 'get/email/', nil, params)
end

def self.list(params={})
EmailYak.request(:get, 'get/email/list/', nil, params)
end

def self.new(params={})
EmailYak.request(:get, 'get/new/email/', nil, params)
end

def self.send(params={})
EmailYak.request(:post, 'send/email/', nil, params)
end

def self.delete(params={})
EmailYak.request(:post, 'delete/email/', nil, params)
end
end

module Address
def self.register(address, callback_url, push=true)
EmailYak.request(:post, 'register/address/', nil, {"PushEmail" => push, "Address" => address, "CallbackURL" => callback_url})
end
end

module Domain
def self.register(params={})
EmailYak.request(:post, 'register/domain/', nil, params)
end
end

def self.request(method, url, api_key, params=nil, headers={})
api_key ||= @@api_key
raise EmailYakError.new('No API key provided. (HINT: set your API key using "EmailYak.api_key = <API-KEY>".') unless api_key
Expand Down Expand Up @@ -136,7 +135,7 @@ def self.request(method, url, api_key, params=nil, headers={})
payload = nil
else
headers = {:content_type => 'application/json'}
payload = JSON.generate(params)
payload = MultiJson.dump(params)
end
opts = {
:method => method,
Expand Down Expand Up @@ -173,7 +172,7 @@ def self.request(method, url, api_key, params=nil, headers={})
rbody = response.body
rcode = response.code
begin
resp = JSON.parse(rbody)
resp = MultiJson.load(rbody)
rescue
raise APIError.new("Invalid response object from API: #{rbody.inspect} (HTTP response code was #{rcode})")
end
Expand Down

0 comments on commit 3657961

Please sign in to comment.