Skip to content

Commit

Permalink
Removed dependency on MultiJson.
Browse files Browse the repository at this point in the history
Closes #792
  • Loading branch information
trevorrowe committed May 8, 2015
1 parent d491987 commit 0b478fe
Show file tree
Hide file tree
Showing 32 changed files with 145 additions and 75 deletions.
1 change: 0 additions & 1 deletion aws-sdk-core/aws-sdk-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Gem::Specification.new do |spec|
spec.bindir = 'bin'
spec.executables << 'aws.rb'

spec.add_dependency('multi_json', '~> 1.0')
spec.add_dependency('jmespath', '~> 1.0')

end
5 changes: 3 additions & 2 deletions aws-sdk-core/features/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

require 'simplecov'
require 'aws-sdk-core'
require 'multi_json'

SimpleCov.command_name('test:integration:aws-sdk-core')

cfg = './integration-test-config.json'

if File.exist?(cfg)
Aws.config = MultiJson.load(File.read(cfg), symbolize_keys: true)
Aws.config = Aws::Json.load_file(cfg).inject({}) do |h, (k, v)|
h[k.to_sym] = v; h
end
elsif ENV['AWS_INTEGRATION']
# run integration tests, just don't read a configuration file from disk
else
Expand Down
18 changes: 1 addition & 17 deletions aws-sdk-core/lib/aws-sdk-core.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'jmespath'
require 'multi_json'
require 'seahorse'

Seahorse::Util.irregular_inflections({
Expand Down Expand Up @@ -86,6 +85,7 @@ module Aws
autoload :EndpointProvider, 'aws-sdk-core/endpoint_provider'
autoload :Errors, 'aws-sdk-core/errors'
autoload :InstanceProfileCredentials, 'aws-sdk-core/instance_profile_credentials'
autoload :Json, 'aws-sdk-core/json'
autoload :PageableResponse, 'aws-sdk-core/pageable_response'
autoload :ParamConverter, 'aws-sdk-core/param_converter'
autoload :ParamValidator, 'aws-sdk-core/param_validator'
Expand All @@ -110,17 +110,6 @@ module Api
autoload :ShapeMap, 'aws-sdk-core/api/shape_map'
end

# @api private
module Json
autoload :Builder, 'aws-sdk-core/json/builder'
autoload :ErrorHandler, 'aws-sdk-core/json/error_handler'
autoload :Parser, 'aws-sdk-core/json/parser'
autoload :RestHandler, 'aws-sdk-core/json/rest_handler'
autoload :RpcBodyHandler, 'aws-sdk-core/json/rpc_body_handler'
autoload :RpcHeadersHandler, 'aws-sdk-core/json/rpc_headers_handler'
autoload :SimpleBodyHandler, 'aws-sdk-core/json/simple_body_handler'
end

# @api private
module Paging
autoload :NullPager, 'aws-sdk-core/paging/null_pager'
Expand Down Expand Up @@ -237,11 +226,6 @@ def service_added(&block)
@service_added_callbacks << callback
end

# @api private
def load_json(path)
Seahorse::Util.load_json(path)
end

# Registers a new service.
#
# Aws.add_service('SvcName',
Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-core/lib/aws-sdk-core/api/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def load_definition(definition)
case definition
when nil then {}
when Hash then definition
when String, Pathname then Seahorse::Util.load_json(definition)
when String, Pathname then Json.load_file(definition)
else raise ArgumentError, "invalid api definition #{definition}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-core/lib/aws-sdk-core/api/docstrings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.apply(client_class, path)
return
api = client_class.api.definition
docs = File.open(path, 'r', encoding: 'UTF-8') { |f| f.read }
docs = MultiJson.load(docs)
docs = Json.load(docs)

api['documentation'] = docs['service']

Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-core/lib/aws-sdk-core/client_paging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def set_paginators(paginators)
@paginators = case paginators
when Paging::Provider then paginators
when Hash then Paging::Provider.new(paginators)
when String, Pathname then Paging::Provider.new(Aws.load_json(paginators))
when String, Pathname then Paging::Provider.new(Json.load_file(paginators))
when nil then Paging::NullProvider.new
else raise ArgumentError, 'invalid paginators'
end
Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-core/lib/aws-sdk-core/client_waiters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def set_waiters(waiters)
case waiters
when Waiters::Provider then waiters
when Hash then Waiters::Provider.new(waiters)
when String, Pathname then Waiters::Provider.new(Aws.load_json(waiters))
when String, Pathname then Waiters::Provider.new(Json.load_file(waiters))
when nil then Waiters::NullProvider.new
else raise ArgumentError, 'invalid waiters'
end
Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-core/lib/aws-sdk-core/endpoint_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class EndpointProvider
PATH = File.join(File.dirname(__FILE__), '..', '..', 'endpoints.json')

# @api private
RULES = MultiJson.load(File.read(PATH))['endpoints']
RULES = Json.load_file(PATH)['endpoints']

class << self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def backoff(backoff)
end

def refresh
credentials = MultiJson.load(get_credentials)
credentials = Json.load(get_credentials)
@access_key_id = credentials['AccessKeyId']
@secret_access_key = credentials['SecretAccessKey']
@session_token = credentials['Token']
Expand Down
59 changes: 59 additions & 0 deletions aws-sdk-core/lib/aws-sdk-core/json.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module Aws
# @api private
module Json

autoload :Builder, 'aws-sdk-core/json/builder'
autoload :ErrorHandler, 'aws-sdk-core/json/error_handler'
autoload :Parser, 'aws-sdk-core/json/parser'
autoload :RestHandler, 'aws-sdk-core/json/rest_handler'
autoload :RpcBodyHandler, 'aws-sdk-core/json/rpc_body_handler'
autoload :RpcHeadersHandler, 'aws-sdk-core/json/rpc_headers_handler'
autoload :SimpleBodyHandler, 'aws-sdk-core/json/simple_body_handler'

class ParseError < StandardError

def initialize(error)
@error = error
super(error.message)
end

attr_reader :error

end

class << self

def load(json)
ENGINE.load(json)
rescue ENGINE_ERROR => e
raise ParseError.new(e)
end

def load_file(path)
self.load(File.open(path, 'r', encoding: 'UTF-8') { |f| f.read })
end

def dump(value)
ENGINE.dump(value)
end

private

def oj_engine
require 'oj'
[Oj, Oj::ParseError]
rescue LoadError
false
end

def json_engine
require 'json'
[JSON, JSON::ParserError]
end

end

ENGINE, ENGINE_ERROR = oj_engine || json_engine

end
end
2 changes: 1 addition & 1 deletion aws-sdk-core/lib/aws-sdk-core/json/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(rules)
end

def to_json(params)
MultiJson.dump(format(@rules, params))
Json.dump(format(@rules, params))
end

private
Expand Down
4 changes: 2 additions & 2 deletions aws-sdk-core/lib/aws-sdk-core/json/error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def call(context)
private

def extract_error(body, context)
json = MultiJson.load(body)
json = Json.load(body)
code = error_code(json, context)
message = error_message(code, json)
[code, message]
rescue MultiJson::ParseError
rescue Json::ParseError
[http_status_error_code(context), '']
end

Expand Down
15 changes: 15 additions & 0 deletions aws-sdk-core/lib/aws-sdk-core/json/json_engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Aws
module Json
class OjEngine

def self.load(json)
Oj.load(json)
end

def self.dump(value)
Oj.dump(value)
end

end
end
end
15 changes: 15 additions & 0 deletions aws-sdk-core/lib/aws-sdk-core/json/oj_engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Aws
module Json
class JSONEngine

def self.load(json)
JSON.load(json)
end

def self.dump(value)
JSON.dump(value)
end

end
end
end
2 changes: 1 addition & 1 deletion aws-sdk-core/lib/aws-sdk-core/json/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(rules)

# @param [String<JSON>] json
def parse(json, target = nil)
parse_ref(@rules, MultiJson.load(json, max_nesting: false), target)
parse_ref(@rules, Json.load(json), target)
end

private
Expand Down
4 changes: 2 additions & 2 deletions aws-sdk-core/lib/aws-sdk-core/json/simple_body_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def call(context)
private

def build_json(context)
context.http_request.body = MultiJson.dump(context.params)
context.http_request.body = Json.dump(context.params)
end

def parse_json(context)
MultiJson.load(context.http_response.body_contents)
Json.load(context.http_response.body_contents)
end

end
Expand Down
7 changes: 6 additions & 1 deletion aws-sdk-core/lib/aws-sdk-core/xml/error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ def call(context)

def error(context)
body = context.http_response.body_contents
code, message = extract_error(body, context)
if body.empty?
code = http_status_error_code(context)
message = ''
else
code, message = extract_error(body, context)
end
svc = context.client.class.name.split('::')[1]
errors_module = Aws.const_get(svc).const_get(:Errors)
errors_module.error_class(code).new(context, message)
Expand Down
4 changes: 0 additions & 4 deletions aws-sdk-core/lib/seahorse/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ def uri_escape(string)
CGI::escape(string.encode('UTF-8')).gsub('+', '%20').gsub('%7E', '~')
end

def load_json(path)
MultiJson.load(File.open(path, 'r', encoding: 'UTF-8') { |f| f.read })
end

end

@irregular_inflections = {}
Expand Down
4 changes: 2 additions & 2 deletions aws-sdk-core/spec/aws_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ module Aws
end

it 'accpets hash values' do
Aws.add_service('DummyService', api: Aws.load_json(api_path))
Aws.add_service('DummyService', api: Json.load_file(api_path))
expect(DummyService::Client.api).to be_kind_of(Seahorse::Model::Api)
end

it 'accpets Seahorse::Model::Api values' do
api = Aws::Api::Builder.build(Aws.load_json(api_path))
api = Aws::Api::Builder.build(Json.load_file(api_path))
Aws.add_service('DummyService', api: api)
expect(DummyService::Client.api).to be(api)
end
Expand Down
11 changes: 5 additions & 6 deletions aws-sdk-core/spec/protocols_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'spec_helper'
require 'multi_json'
require 'rexml/document'

def fixtures
Expand All @@ -18,7 +17,7 @@ def fixtures

def each_test_case(context, fixture_path)
return unless fixture_path
MultiJson.load(File.read(fixture_path)).each do |suite|
Aws::Json.load_file(fixture_path).each do |suite|
describe(suite['description'].inspect) do
suite['cases'].each.with_index do |test_case,n|
describe("case: #{n}") do
Expand Down Expand Up @@ -118,12 +117,12 @@ def match_req_body(group, suite, test_case, http_req)
body = body.split('&').sort.join('&')
expected_body = expected_body.split('&').sort.join('&')
when 'json'
body = MultiJson.load(body) unless body == ''
expected_body = MultiJson.load(expected_body)
body = Aws::Json.load(body) unless body == ''
expected_body = Aws::Json.load(expected_body)
when 'rest-json'
if body[0] == '{'
body = MultiJson.load(body)
expected_body = MultiJson.load(expected_body)
body = Aws::Json.load(body)
expected_body = Aws::Json.load(expected_body)
end
when 'rest-xml'
body = normalize_xml(body)
Expand Down
4 changes: 3 additions & 1 deletion aws-sdk-resources/features/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
cfg = './integration-test-config.json'

if File.exist?(cfg)
Aws.config = MultiJson.load(File.read(cfg), symbolize_keys: true)
Aws.config = Aws::Json.load_file(cfg).inject({}) do |h, (k, v)|
h[k.to_sym] = v; h
end
elsif ENV['AWS_INTEGRATION']
# run integration tests, just don't read a configuration file from disk
else
Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-resources/lib/aws-sdk-resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Resources
when Resources::Definition then definition
when Hash then Resources::Definition.new(definition)
when String
Resources::Definition.new(Aws.load_json(definition), source_path: definition)
Resources::Definition.new(Json.load_file(definition), source_path: definition)
else raise ArgumentError, "invalid resource definition #{definition}"
end
definition.apply(svc_module)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ module S3
# @keys = keys
# @encryption_materials = Aws::S3::Encryption::Materials.new(
# key: @keys[default_key_name],
# description: MultiJson.dump(key: default_key_name),
# description: JSON.dump(key: default_key_name),
# )
# end
#
# attr_reader :encryption_materials
#
# def key_for(matdesc)
# key_name = MultiJson.load(matdesc)['key']
# key_name = JSON.load(matdesc)['key']
# if key = @keys[key_name]
# key
# else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def envelope_from_metadata(context)

def envelope_from_instr_file(context)
suffix = context[:encryption][:instruction_file_suffix]
MultiJson.load(context.client.get_object(
Json.load(context.client.get_object(
bucket: context.params[:bucket],
key: context.params[:key] + suffix
).body.read)
rescue S3::Errors::ServiceError, MultiJson::ParseError
rescue S3::Errors::ServiceError, Json::ParseError
nil
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def apply_encryption_envelope(context, envelope)
context.client.put_object(
bucket: context.params[:bucket],
key: context.params[:key] + suffix,
body: MultiJson.dump(envelope)
body: Json.dump(envelope)
)
end
end
Expand Down
Loading

0 comments on commit 0b478fe

Please sign in to comment.