pliny 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0737c4e1c61ecef9881625ff6bb0d2afeacc63977f239b7e2562d4aec3c3609a
4
- data.tar.gz: f8db4293037c673ff3e33e025c75e86664f19cd207f3e36a2934e47eb981e942
3
+ metadata.gz: 53b08362a2511749050f3ca5ea9690d2adeefec8662f0a74cf391c896b119fd8
4
+ data.tar.gz: 23da2c0e15bdb3bf93f719e440bf0c2ac2a093fc1de3e500850c47ce5b8d6851
5
5
  SHA512:
6
- metadata.gz: bad71b767121811048ca67857644d74d6b7e565461e96cc6f52fa3b8207a41cb6f5fa8b4d32d14fc49894709a7959c55ddd7a6c8972f1555f6d5b6108c160978
7
- data.tar.gz: d0e2adac5319670b3c12344f6b4d40a989e74770f4ffdbffdbf7082941ed7f2590802babf478966a63c475638f4736961855a449cf9629779baf696f98f2eb28
6
+ metadata.gz: fc1e1a5d4fda88d1a181e06e7aefb300d1cf6ee516ca8e6018173dfd5dcf079885ebfb8c74643db317aa889a82cd38b95ce9101a592b3126fd7039f4aa7b029c
7
+ data.tar.gz: 1120021ef6ade5c1470cb280504e9abad2f672610be35546d3ea2521164841e973cef2b1be2f2e1b9dd0614ac1c493e6dae818ab35cb8dff242fdd115228524c
data/lib/pliny/errors.rb CHANGED
@@ -6,7 +6,7 @@ module Pliny
6
6
  def self.render(error)
7
7
  headers = { "content-type" => "application/json; charset=utf-8" }
8
8
  data = { id: error.id, message: error.message }
9
- [error.status, headers, [MultiJson.encode(data)]]
9
+ [error.status, headers, [JSON.generate(data)]]
10
10
  end
11
11
 
12
12
  def initialize(message, id)
@@ -2,7 +2,11 @@ module Pliny::Helpers
2
2
  module Encode
3
3
  def encode(object)
4
4
  content_type :json, charset: 'utf-8'
5
- MultiJson.encode(object, pretty: params[:pretty] == 'true' || Config.pretty_json)
5
+ if params[:pretty] == 'true' || Config.pretty_json
6
+ JSON.pretty_generate(object)
7
+ else
8
+ JSON.generate(object)
9
+ end
6
10
  end
7
11
  end
8
12
  end
@@ -9,8 +9,8 @@ module Pliny::Helpers
9
9
  def parse_body_params
10
10
  if request.media_type == "application/json"
11
11
  begin
12
- decoded = MultiJson.decode(request.body.read)
13
- rescue MultiJson::ParseError => e
12
+ decoded = JSON.parse(request.body.read)
13
+ rescue JSON::ParserError => e
14
14
  raise Pliny::Errors::BadRequest, e.message
15
15
  end
16
16
  request.body.rewind
@@ -27,7 +27,7 @@ module Pliny::Middleware
27
27
  Please specify a version along with the MIME type. For example, `Accept: application/vnd.#{@app_name}+json; version=1`.
28
28
  eos
29
29
  return [400, { "content-type" => "application/json; charset=utf-8" },
30
- [MultiJson.encode(error)]]
30
+ [JSON.generate(error)]]
31
31
  end
32
32
 
33
33
  unless version
@@ -23,7 +23,7 @@ RSpec.describe Endpoints::<%= plural_class_name %> do
23
23
  describe 'POST <%= url_path %>' do
24
24
  it 'returns correct status code and conforms to schema' do
25
25
  header "Content-Type", "application/json"
26
- post '<%= url_path %>', MultiJson.encode({})
26
+ post '<%= url_path %>', JSON.generate({})
27
27
  assert_equal 201, last_response.status
28
28
  assert_schema_conform
29
29
  end
@@ -40,7 +40,7 @@ RSpec.describe Endpoints::<%= plural_class_name %> do
40
40
  describe 'PATCH <%= url_path %>/:id' do
41
41
  it 'returns correct status code and conforms to schema' do
42
42
  header "Content-Type", "application/json"
43
- patch '<%= url_path %>/123', MultiJson.encode({})
43
+ patch '<%= url_path %>/123', JSON.generate({})
44
44
  assert_equal 200, last_response.status
45
45
  assert_schema_conform
46
46
  end
@@ -32,7 +32,7 @@ RSpec.describe Endpoints::<%= plural_class_name %> do
32
32
  describe 'POST <%= url_path %>' do
33
33
  it 'returns correct status code and conforms to schema' do
34
34
  header "Content-Type", "application/json"
35
- post '<%= url_path %>', MultiJson.encode({})
35
+ post '<%= url_path %>', JSON.generate({})
36
36
  assert_equal 201, last_response.status
37
37
  assert_schema_conform
38
38
  end
@@ -50,7 +50,7 @@ RSpec.describe Endpoints::<%= plural_class_name %> do
50
50
  describe 'PATCH <%= url_path %>/:id' do
51
51
  it 'returns correct status code and conforms to schema' do
52
52
  header "Content-Type", "application/json"
53
- patch "<%= url_path %>/#{@<%= field_name %>.id}", MultiJson.encode({})
53
+ patch "<%= url_path %>/#{@<%= field_name %>.id}", JSON.generate({})
54
54
  assert_equal 200, last_response.status
55
55
  assert_schema_conform
56
56
  end
data/lib/pliny/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pliny
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
data/lib/pliny.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "multi_json"
1
+ require "json"
2
2
  require "sinatra/base"
3
3
 
4
4
  require_relative "pliny/version"
data/lib/template/Gemfile CHANGED
@@ -1,8 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
  ruby "2.4.0"
3
3
 
4
- gem "multi_json"
5
- gem "oj"
6
4
  gem "pg"
7
5
  gem "pliny", "~> 0.32"
8
6
  gem "pry"
@@ -13,7 +13,7 @@ RSpec.describe Endpoints::Health do
13
13
  assert_equal(200, last_response.status)
14
14
  assert_equal("application/json;charset=utf-8", last_response.headers["Content-Type"])
15
15
  assert_equal(2, last_response.headers["Content-Length"].to_i)
16
- assert_equal({}, MultiJson.decode(last_response.body))
16
+ assert_equal({}, JSON.parse(last_response.body))
17
17
  end
18
18
  end
19
19
 
@@ -49,7 +49,7 @@ RSpec.describe Endpoints::Health do
49
49
  assert_equal(200, last_response.status)
50
50
  assert_equal("application/json;charset=utf-8", last_response.headers["Content-Type"])
51
51
  assert_equal(2, last_response.headers["Content-Length"].to_i)
52
- assert_equal({}, MultiJson.decode(last_response.body))
52
+ assert_equal({}, JSON.parse(last_response.body))
53
53
  end
54
54
  end
55
55
  end
@@ -26,31 +26,31 @@ describe Pliny::Commands::Generator::Endpoint do
26
26
  it "defines a stub GET /" do
27
27
  get "/artists"
28
28
  assert_equal 200, last_response.status
29
- assert_equal [], MultiJson.decode(last_response.body)
29
+ assert_equal [], JSON.parse(last_response.body)
30
30
  end
31
31
 
32
32
  it "defines a stub POST /" do
33
33
  post "/artists"
34
34
  assert_equal 201, last_response.status
35
- assert_equal Hash.new, MultiJson.decode(last_response.body)
35
+ assert_equal Hash.new, JSON.parse(last_response.body)
36
36
  end
37
37
 
38
38
  it "defines a stub GET /:id" do
39
39
  get "/artists/123"
40
40
  assert_equal 200, last_response.status
41
- assert_equal Hash.new, MultiJson.decode(last_response.body)
41
+ assert_equal Hash.new, JSON.parse(last_response.body)
42
42
  end
43
43
 
44
44
  it "defines a stub PATCH /:id" do
45
45
  patch "/artists/123"
46
46
  assert_equal 200, last_response.status
47
- assert_equal Hash.new, MultiJson.decode(last_response.body)
47
+ assert_equal Hash.new, JSON.parse(last_response.body)
48
48
  end
49
49
 
50
50
  it "defines a stub DELETE /:id" do
51
51
  delete "/artists/123"
52
52
  assert_equal 200, last_response.status
53
- assert_equal Hash.new, MultiJson.decode(last_response.body)
53
+ assert_equal Hash.new, JSON.parse(last_response.body)
54
54
  end
55
55
 
56
56
  end
@@ -23,19 +23,19 @@ describe Pliny::Helpers::Encode do
23
23
  it "encodes as json" do
24
24
  payload = { "foo" => "bar" }
25
25
  post "/", payload
26
- assert_equal MultiJson.encode(payload), last_response.body
26
+ assert_equal JSON.generate(payload), last_response.body
27
27
  end
28
28
 
29
29
  it "encodes in pretty mode when pretty=true" do
30
30
  payload = { "foo" => "bar", "pretty" => "true" }
31
31
  post "/", payload
32
- assert_equal MultiJson.encode(payload, pretty: true), last_response.body
32
+ assert_equal JSON.pretty_generate(payload), last_response.body
33
33
  end
34
34
 
35
35
  it "encodes in pretty mode when set by config" do
36
36
  allow(Config).to receive(:pretty_json) { true }
37
37
  payload = { "foo" => "bar" }
38
38
  post "/", payload
39
- assert_equal MultiJson.encode(payload, pretty: true), last_response.body
39
+ assert_equal JSON.pretty_generate(payload), last_response.body
40
40
  end
41
41
  end
@@ -7,7 +7,7 @@ describe Pliny::Helpers::Serialize do
7
7
  register Pliny::Helpers::Serialize
8
8
 
9
9
  get "/" do
10
- MultiJson.encode(serialize([]))
10
+ JSON.generate(serialize([]))
11
11
  end
12
12
  end
13
13
  end
@@ -34,11 +34,11 @@ describe Pliny::Helpers::Serialize do
34
34
  serializer Serializer
35
35
 
36
36
  get "/" do
37
- MultiJson.encode(serialize([]))
37
+ JSON.generate(serialize([]))
38
38
  end
39
39
 
40
40
  get "/env" do
41
- MultiJson.encode(serialize(env))
41
+ JSON.generate(serialize(env))
42
42
  end
43
43
  end
44
44
  end
@@ -46,13 +46,13 @@ describe Pliny::Helpers::Serialize do
46
46
  it "encodes as json" do
47
47
  get "/"
48
48
  assert_equal 200, last_response.status
49
- assert_equal MultiJson.encode([]), last_response.body
49
+ assert_equal JSON.generate([]), last_response.body
50
50
  end
51
51
 
52
52
  it "emits information for canonical log lines" do
53
53
  get "/env"
54
54
  assert_equal 200, last_response.status
55
- body = MultiJson.decode(last_response.body)
55
+ body = JSON.parse(last_response.body)
56
56
  assert body["pliny.serializer_arity"] > 1
57
57
  assert body["pliny.serializer_timing"] > 0
58
58
  end
@@ -21,7 +21,7 @@ describe Pliny::Middleware::RescueErrors do
21
21
  @app = new_rack_app
22
22
  get "/api-error"
23
23
  assert_equal 503, last_response.status
24
- error_json = MultiJson.decode(last_response.body)
24
+ error_json = JSON.parse(last_response.body)
25
25
  assert_equal "service_unavailable", error_json["id"]
26
26
  assert_equal "Service unavailable.", error_json["message"]
27
27
  end
@@ -31,7 +31,7 @@ describe Pliny::Middleware::RescueErrors do
31
31
  expect(Pliny::ErrorReporters).to receive(:notify)
32
32
  get "/"
33
33
  assert_equal 500, last_response.status
34
- error_json = MultiJson.decode(last_response.body)
34
+ error_json = JSON.parse(last_response.body)
35
35
  assert_equal "internal_server_error", error_json["id"]
36
36
  assert_equal "Internal server error.", error_json["message"]
37
37
  end
@@ -48,7 +48,7 @@ describe Pliny::Middleware::RescueErrors do
48
48
  allow(Pliny::ErrorReporters).to receive(:notify)
49
49
  get "/"
50
50
  assert_equal 500, last_response.status
51
- error_json = MultiJson.decode(last_response.body)
51
+ error_json = JSON.parse(last_response.body)
52
52
  assert_equal "internal_server_error", error_json["id"]
53
53
  assert_equal "Please stand by", error_json["message"]
54
54
  end
@@ -13,7 +13,7 @@ describe Pliny::Middleware::Versioning do
13
13
  use Pliny::Middleware::Versioning, default: '2', app_name: 'pliny'
14
14
  run Sinatra.new {
15
15
  get "/" do
16
- MultiJson.encode env
16
+ JSON.generate env
17
17
  end
18
18
  }
19
19
  end
@@ -21,7 +21,7 @@ describe Pliny::Middleware::Versioning do
21
21
 
22
22
  it "produces default version on application/json" do
23
23
  get '/', {}, {'HTTP_ACCEPT' => 'application/json'}
24
- json = MultiJson.decode(last_response.body)
24
+ json = JSON.parse(last_response.body)
25
25
  assert_equal 'application/json', json['HTTP_ACCEPT']
26
26
  assert_equal '2', json['HTTP_X_API_VERSION']
27
27
  end
@@ -33,19 +33,19 @@ Please specify a version along with the MIME type. For example, `Accept: applica
33
33
  eos
34
34
 
35
35
  assert_equal 400, last_response.status
36
- assert_equal MultiJson.encode(error), last_response.body
36
+ assert_equal JSON.generate(error), last_response.body
37
37
  end
38
38
 
39
39
  it "ignores a wrong app name" do
40
40
  get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.chuck_norris+json'}
41
- json = MultiJson.decode(last_response.body)
41
+ json = JSON.parse(last_response.body)
42
42
  assert_equal 'application/vnd.chuck_norris+json', json['HTTP_ACCEPT']
43
43
  assert_equal '2', json['HTTP_X_API_VERSION']
44
44
  end
45
45
 
46
46
  it "produces a version on application/vnd.pliny+json; version=3" do
47
47
  get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.pliny+json; version=3'}
48
- json = MultiJson.decode(last_response.body)
48
+ json = JSON.parse(last_response.body)
49
49
  assert_equal 'application/json', json['HTTP_ACCEPT']
50
50
  assert_equal '3', json['HTTP_X_API_VERSION']
51
51
  end
@@ -53,14 +53,14 @@ Please specify a version along with the MIME type. For example, `Accept: applica
53
53
  # this behavior is pretty sketchy, but a pretty extreme edge case
54
54
  it "handles multiple MIME types" do
55
55
  get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.pliny+json; version=3; q=0.5, text/xml'}
56
- json = MultiJson.decode(last_response.body)
56
+ json = JSON.parse(last_response.body)
57
57
  assert_equal 'text/xml, application/json; q=0.5', json['HTTP_ACCEPT']
58
58
  assert_equal '3', json['HTTP_X_API_VERSION']
59
59
  end
60
60
 
61
61
  it "produces the priority version on multiple types" do
62
62
  get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.pliny+json; version=4; q=0.5, application/vnd.pliny+json; version=3'}
63
- json = MultiJson.decode(last_response.body)
63
+ json = JSON.parse(last_response.body)
64
64
  assert_equal 'application/json, application/json; q=0.5', json['HTTP_ACCEPT']
65
65
  assert_equal '3', json['HTTP_X_API_VERSION']
66
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pliny
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandur Leach
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-02-13 00:00:00.000000000 Z
12
+ date: 2025-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -17,40 +17,20 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '6.0'
20
+ version: '7.0'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '8.0'
23
+ version: '9.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
- version: '6.0'
30
+ version: '7.0'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '8.0'
34
- - !ruby/object:Gem::Dependency
35
- name: multi_json
36
- requirement: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.9'
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: 1.9.3
44
- type: :runtime
45
- prerelease: false
46
- version_requirements: !ruby/object:Gem::Requirement
47
- requirements:
48
- - - "~>"
49
- - !ruby/object:Gem::Version
50
- version: '1.9'
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: 1.9.3
33
+ version: '9.0'
54
34
  - !ruby/object:Gem::Dependency
55
35
  name: prmd
56
36
  requirement: !ruby/object:Gem::Requirement
@@ -505,14 +485,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
505
485
  requirements:
506
486
  - - ">="
507
487
  - !ruby/object:Gem::Version
508
- version: '0'
488
+ version: '3.2'
509
489
  required_rubygems_version: !ruby/object:Gem::Requirement
510
490
  requirements:
511
491
  - - ">="
512
492
  - !ruby/object:Gem::Version
513
493
  version: '0'
514
494
  requirements: []
515
- rubygems_version: 3.5.3
495
+ rubygems_version: 3.5.22
516
496
  signing_key:
517
497
  specification_version: 4
518
498
  summary: Basic tooling to support API apps in Sinatra