Skip to content

Commit 96d868f

Browse files
author
Ben Fritsch
committed
use JSON in favor of MultiJson
1 parent d3ea555 commit 96d868f

15 files changed

Lines changed: 58 additions & 58 deletions

example/lib/example-client/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def list()
200200
end
201201
end
202202

203-
SCHEMA = Heroics::Schema.new(MultiJson.load(<<-'HEROICS_SCHEMA'))
203+
SCHEMA = Heroics::Schema.new(JSON.parse(<<-'HEROICS_SCHEMA'))
204204
{
205205
"description":"Sample schema for use in tests.",
206206
"definitions":{

heroics.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
3030
spec.add_dependency 'base64'
3131
spec.add_dependency 'erubis', '~> 2.0'
3232
spec.add_dependency 'excon'
33+
spec.add_dependency 'json'
3334
spec.add_dependency 'moneta'
34-
spec.add_dependency 'multi_json', '>= 1.9.2'
3535
spec.add_dependency 'webrick'
3636
end

lib/heroics.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'base64'
33
require 'erubis'
44
require 'excon'
5-
require 'multi_json'
5+
require 'json'
66
require 'uri'
77
require 'webrick'
88
require 'zlib'

lib/heroics/client_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def self.build_context(module_name, schema, base_url, options)
3737
default_headers: options.fetch(:default_headers, {}),
3838
cache: options.fetch(:cache, {}),
3939
description: schema.description,
40-
schema: MultiJson.dump(schema.schema, pretty:true),
40+
schema: JSON.pretty_generate(schema.schema),
4141
resources: resources
4242
}
4343
end

lib/heroics/command.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def usage
3838
#{description}
3939
USAGE
4040
if example_body
41-
example_body = MultiJson.dump(example_body, pretty: true)
41+
example_body = JSON.pretty_generate(example_body)
4242
example_body = example_body.lines.map do |line|
4343
" #{line}"
4444
end.join
@@ -60,7 +60,7 @@ def run(*parameters)
6060
result = @client.send(resource_name).send(name, *parameters)
6161
result = result.to_a if result.instance_of?(Enumerator)
6262
if result && !result.instance_of?(String)
63-
result = MultiJson.dump(result, pretty: true)
63+
result = JSON.pretty_generate(result)
6464
end
6565
@output.puts(result) unless result.nil?
6666
end

lib/heroics/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def schema=(schema)
4040
end
4141

4242
def schema_filepath=(schema_filepath)
43-
@schema = Heroics::Schema.new(MultiJson.decode(open(schema_filepath).read))
43+
@schema = Heroics::Schema.new(JSON.parse(open(schema_filepath).read))
4444
end
4545

4646
def module_name=(module_name)

lib/heroics/link.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def run(*parameters)
5858
if body.is_a?(Hash)
5959
query = body
6060
else
61-
query = MultiJson.load(body)
61+
query = JSON.parse(body)
6262
end
6363
body = nil
6464
end
@@ -71,7 +71,7 @@ def run(*parameters)
7171
expects: [200, 201, 202, 204, 206])
7272
content_type = response.headers['Content-Type']
7373
if content_type && content_type =~ /application\/.*json/
74-
body = MultiJson.load(response.body)
74+
body = JSON.parse(response.body)
7575
if response.status == 206
7676
next_range = response.headers['Next-Range']
7777
Enumerator.new do |yielder|
@@ -89,7 +89,7 @@ def run(*parameters)
8989
method: @link_schema.method,
9090
path: path, headers: headers,
9191
expects: [200, 201, 206])
92-
body = MultiJson.load(response.body)
92+
body = JSON.parse(response.body)
9393
next_range = response.headers['Next-Range']
9494
end
9595
end

lib/heroics/schema.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def encode(body)
150150
when 'application/x-www-form-urlencoded'
151151
URI.encode_www_form(body)
152152
when /application\/.*json/
153-
MultiJson.dump(body)
153+
JSON.generate(body)
154154
end
155155
end
156156

@@ -356,7 +356,7 @@ def iso_format(time)
356356
def self.download_schema(url, options={})
357357
default_headers = options.fetch(:default_headers, {})
358358
response = Excon.get(url, headers: default_headers, expects: [200, 201])
359-
Schema.new(MultiJson.load(response.body))
359+
Schema.new(JSON.parse(response.body))
360360
end
361361

362362
# A representation of a parameter.

lib/heroics/views/client.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ module <%= @module_name %>
132132
end
133133
<% end %>
134134

135-
SCHEMA = Heroics::Schema.new(MultiJson.load(<<-'HEROICS_SCHEMA'))
135+
SCHEMA = Heroics::Schema.new(JSON.parse(<<-'HEROICS_SCHEMA'))
136136
<%= @schema %>
137137
HEROICS_SCHEMA
138138
end

test/cli_test.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ def test_run_with_dashed_resource_name
131131
assert_equal("/another-resource", request[:path])
132132
Excon.stubs.pop
133133
{status: 200, headers: {'Content-Type' => 'application/json'},
134-
body: MultiJson.dump(result)}
134+
body: JSON.generate(result)}
135135
end
136136

137137
cli.run('another-resource:list')
138-
assert_equal(MultiJson.dump(result, pretty: true) + "\n", output.string)
138+
assert_equal(JSON.pretty_generate(result) + "\n", output.string)
139139
end
140140

141141
# CLI.run runs the command matching the specified name and passes parameters
@@ -154,14 +154,14 @@ def test_run_with_parameters
154154
Excon.stub(method: :patch) do |request|
155155
assert_equal("/resource/#{uuid}", request[:path])
156156
assert_equal('application/json', request[:headers]['Content-Type'])
157-
assert_equal(body, MultiJson.load(request[:body]))
157+
assert_equal(body, JSON.parse(request[:body]))
158158
Excon.stubs.pop
159159
{status: 200, headers: {'Content-Type' => 'application/json'},
160-
body: MultiJson.dump(result)}
160+
body: JSON.generate(result)}
161161
end
162162

163163
cli.run('resource:update', uuid, body)
164-
assert_equal(MultiJson.dump(result, pretty: true) + "\n", output.string)
164+
assert_equal(JSON.pretty_generate(result) + "\n", output.string)
165165
end
166166
end
167167

@@ -176,17 +176,17 @@ def test_cli_from_schema
176176
Excon.stub(method: :patch) do |request|
177177
assert_equal("/resource/#{uuid}", request[:path])
178178
assert_equal('application/json', request[:headers]['Content-Type'])
179-
assert_equal(body, MultiJson.load(request[:body]))
179+
assert_equal(body, JSON.parse(request[:body]))
180180
Excon.stubs.pop
181181
{status: 200, headers: {'Content-Type' => 'application/json'},
182-
body: MultiJson.dump(result)}
182+
body: JSON.generate(result)}
183183
end
184184

185185
schema = Heroics::Schema.new(SAMPLE_SCHEMA)
186186
output = StringIO.new
187187
cli = Heroics.cli_from_schema('cli', output, schema, 'https://example.com')
188188
cli.run('resource:update', uuid, body)
189-
assert_equal(MultiJson.dump(result, pretty: true) + "\n", output.string)
189+
assert_equal(JSON.pretty_generate(result) + "\n", output.string)
190190
end
191191

192192
# cli_from_schema returns a CLI that can make requests to APIs mounted under
@@ -198,18 +198,18 @@ def test_client_from_schema_with_url_prefix
198198
Excon.stub(method: :patch) do |request|
199199
assert_equal("/api/resource/#{uuid}", request[:path])
200200
assert_equal('application/json', request[:headers]['Content-Type'])
201-
assert_equal(body, MultiJson.load(request[:body]))
201+
assert_equal(body, JSON.parse(request[:body]))
202202
Excon.stubs.pop
203203
{status: 200, headers: {'Content-Type' => 'application/json'},
204-
body: MultiJson.dump(result)}
204+
body: JSON.generate(result)}
205205
end
206206

207207
schema = Heroics::Schema.new(SAMPLE_SCHEMA)
208208
output = StringIO.new
209209
cli = Heroics.cli_from_schema('cli', output, schema,
210210
'https://example.com/api')
211211
cli.run('resource:update', uuid, body)
212-
assert_equal(MultiJson.dump(result, pretty: true) + "\n", output.string)
212+
assert_equal(JSON.pretty_generate(result) + "\n", output.string)
213213
end
214214

215215
# cli_from_schema optionally accepts custom headers to pass with every
@@ -223,7 +223,7 @@ def test_cli_from_schema_with_custom_headers
223223
request[:headers]['Accept'])
224224
Excon.stubs.pop
225225
{status: 200, headers: {'Content-Type' => 'application/json'},
226-
body: MultiJson.dump(result)}
226+
body: JSON.generate(result)}
227227
end
228228

229229
schema = Heroics::Schema.new(SAMPLE_SCHEMA)
@@ -232,6 +232,6 @@ def test_cli_from_schema_with_custom_headers
232232
'cli', output, schema, 'https://example.com',
233233
default_headers: {'Accept' => 'application/vnd.heroku+json; version=3'})
234234
cli.run('resource:update', uuid, body)
235-
assert_equal(MultiJson.dump(result, pretty: true) + "\n", output.string)
235+
assert_equal(JSON.pretty_generate(result) + "\n", output.string)
236236
end
237237
end

0 commit comments

Comments
 (0)