sanger-jsonapi-resources 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50c28dfc8e5e642688539a7cd8e5dcfff388be6f0b6bfd52aac37efb8faa81b8
4
- data.tar.gz: 4164c5253639dd7f04d3bd5f6ccc3a143fdc3f151ba45ef5d31d42c5a06a711e
3
+ metadata.gz: a55bda6cecda0ea196dec77943a8e2506af7bd15bd581cabcfbc996b3792aeb6
4
+ data.tar.gz: 84fe7e09db2944f6891037f838e751c7daf49ebd095bb08de43c1ab5a5010853
5
5
  SHA512:
6
- metadata.gz: a46064d85e7f5e4e19425c3e2f815f6d509901181bddb2024a3551abd532a831ec7b3feadf6c62787afbc6a4cb9d5974cb3e080709bba8eb2b879357dc83940d
7
- data.tar.gz: d302f0ca9f84734e207afd72d63101646bb1d5cf4380d5929483cdfa860728ccd26f00b30743a8ad744dfa20b3540186398f784f4a82cd0804dc6d4e9a6e3361
6
+ metadata.gz: '09651520c32728f3a6835aa77d83dc3b212426fc1154a7f49bc017f2f758aa8435c94954a6df5d3009fec99605fc8445ce4f636b6b2ce7f5b60d9758e061c1ed'
7
+ data.tar.gz: d7f53c0c0f23c6c1e6ec7e3f535e0e9481bf900682a93a5b1672ecfb5f53c642d74a4a754140b7daaf962a4cbe1c4eb2dc34e5b31763e0c631d0b7d0554c849c
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
- # JSONAPI::Resources [![Gem Version](https://badge.fury.io/rb/jsonapi-resources.svg)](https://badge.fury.io/rb/jsonapi-resources) [![Build Status](https://secure.travis-ci.org/cerebris/jsonapi-resources.svg?branch=beta)](http://travis-ci.org/cerebris/jsonapi-resources) [![Code Climate](https://codeclimate.com/github/cerebris/jsonapi-resources/badges/gpa.svg)](https://codeclimate.com/github/cerebris/jsonapi-resources)
2
-
3
- [![Join the chat at https://gitter.im/cerebris/jsonapi-resources](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cerebris/jsonapi-resources?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
1
+ # JSONAPI::Resources (Sanger fork)
4
2
 
5
3
  `JSONAPI::Resources`, or "JR", provides a framework for developing an API server that complies with the
6
4
  [JSON:API](http://jsonapi.org/) specification.
@@ -8,12 +6,12 @@
8
6
  Like JSON:API itself, JR's design is focused on the resources served by an API. JR needs little more than a definition
9
7
  of your resources, including their attributes and relationships, to make your server compliant with JSON API.
10
8
 
11
- JR is designed to work with Rails 4.2+, and provides custom routes, controllers, and serializers. JR's resources may be
9
+ JR is designed to work with Rails 5.1+, and provides custom routes, controllers, and serializers. JR's resources may be
12
10
  backed by ActiveRecord models or by custom objects.
13
11
 
14
12
  ## Documentation
15
13
 
16
- Full documentation can be found at [http://jsonapi-resources.com](http://jsonapi-resources.com), including the [v0.9 beta Guide](http://jsonapi-resources.com/v0.9/guide/) specific to this version.
14
+ Full documentation can be found at [http://jsonapi-resources.com](http://jsonapi-resources.com), including the [v0.10 alpha Guide](http://jsonapi-resources.com/v0.10/guide/) specific to this version.
17
15
 
18
16
  ## Demo App
19
17
 
@@ -22,32 +20,73 @@ We have a simple demo app, called [Peeps](https://github.com/cerebris/peeps), av
22
20
  ## Client Libraries
23
21
 
24
22
  JSON:API maintains a (non-verified) listing of [client libraries](http://jsonapi.org/implementations/#client-libraries)
25
- which *should* be compatible with JSON:API compliant server implementations such as JR.
23
+ which _should_ be compatible with JSON:API compliant server implementations such as JR.
26
24
 
27
25
  ## Installation
28
26
 
29
27
  Add JR to your application's `Gemfile`:
30
28
 
31
- gem 'sanger-jsonapi-resources'
29
+ ```
30
+ gem 'jsonapi-resources'
31
+ ```
32
32
 
33
33
  And then execute:
34
34
 
35
- $ bundle
35
+ ```bash
36
+ bundle
37
+ ```
36
38
 
37
39
  Or install it yourself as:
38
40
 
39
- $ gem install sanger-jsonapi-resources
41
+ ```bash
42
+ gem install jsonapi-resources
43
+ ```
44
+
45
+ **For further usage see the [v0.10 alpha Guide](http://jsonapi-resources.com/v0.10/guide/)**
46
+
47
+ ## Sanger-specific release process
48
+
49
+ There are two versions of the gem which we use for production. The version 1 series has unique customisations and is used by Sequencescape. The version 2 series is a more generic version which is used by Traction.
50
+
51
+ Check which versions we have published at https://rubygems.org/gems/sanger-jsonapi-resources
52
+
53
+ ### For version 1 series
54
+
55
+ - Create a branch from **develop**, apply fixes.
56
+ - Change version number in `lib/jsonapi/resources/version.rb` . This file is read by the gemspec during publication.
57
+ - Test Sequencescape with the gem from the branch.
58
+ - Merge the branch into develop.
59
+ - Create a release from the develop branch with the new version number as the tag. Set Release label to _None_.
60
+ <!-- list separator -->
61
+ - Checkout the newly-created tag on develop.
62
+ - Execute `bundle install` to ensure the gemspec is up to date.
63
+ - Execute `gem build jsonapi-resources.gemspec` which builds sanger-jsonapi-resources-0.1.x.gem in this case.
64
+ - Execute `gem push sanger-jsonapi-resources-0.1.x.gem` which publishes the gem.
65
+
66
+ ### For version 2 series
67
+
68
+ - Create a branch from **master**, apply fixes.
69
+ - Change version number in `lib/jsonapi/resources/version.rb` . This file is read by the gemspec during publication.
70
+ - Test Traction with the gem from the branch.
71
+ - Merge the branch into master.
72
+ - Create a release from the master branch with the new version number as the tag. Set Release label to _Latest_.
73
+ <!-- list separator -->
74
+ - Checkout the newly-created tag on master.
75
+ - Execute `bundle install` to ensure the gemspec is up to date.
76
+ - Execute `gem build jsonapi-resources.gemspec` which builds sanger-jsonapi-resources-0.2.x.gem in this case.
77
+ - Execute `gem push sanger-jsonapi-resources-0.2.x.gem` which publishes the gem.
78
+
79
+ ### Publication
80
+
81
+ You will be notified by email for each. You will also receive one email for API key setup. The first push will ask email and password for the account, which are in KeePass (search for "gem").
40
82
 
41
- **For further usage see the [v0.9 beta Guide](http://jsonapi-resources.com/v0.9/guide/)**
83
+ > [!NOTE]
84
+ > The email and password for gem publication is a recent addition to the credentials database. Pull latest changes in the credentials repo.
42
85
 
43
86
  ## Contributing
44
87
 
45
- 1. Fork it ( http://github.com/cerebris/jsonapi-resources/fork )
46
- 2. Create your feature branch (`git checkout -b my-new-feature`)
47
- 3. Commit your changes (`git commit -am 'Add some feature'`)
48
- 4. Push to the branch (`git push origin my-new-feature`)
49
- 5. Create a new Pull Request
88
+ See CONTRIBUTING.md for details.
50
89
 
51
90
  ## License
52
91
 
53
- Copyright 2014-2016 Cerebris Corporation. MIT License (see LICENSE for details).
92
+ Copyright 2014-2021 Cerebris Corporation. MIT License (see LICENSE for details).
data/lib/jsonapi/error.rb CHANGED
@@ -15,7 +15,7 @@ module JSONAPI
15
15
  @source = options[:source]
16
16
  @links = options[:links]
17
17
 
18
- @status = Rack::Utils.status_code(options[:status]).to_s
18
+ @status = status_code(options[:status]).to_s
19
19
  @meta = options[:meta]
20
20
  end
21
21
 
@@ -24,6 +24,21 @@ module JSONAPI
24
24
  instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) unless instance_variable_get(var).nil? }
25
25
  hash
26
26
  end
27
+
28
+ private
29
+
30
+ # Extracted from Rack 2
31
+ def status_code(status)
32
+ if status.nil?
33
+ raise ArgumentError, "Status code is required"
34
+ end
35
+
36
+ if status.is_a?(Symbol)
37
+ Rack::Utils::SYMBOL_TO_STATUS_CODE.fetch(status) { raise ArgumentError, "Unrecognized status code #{status.inspect}" }
38
+ else
39
+ status.to_i
40
+ end
41
+ end
27
42
  end
28
43
 
29
44
  class Warning
@@ -475,7 +475,7 @@ module JSONAPI
475
475
 
476
476
  def json_api_error(attr_key, message)
477
477
  create_error_object(code: JSONAPI::VALIDATION_ERROR,
478
- status: :unprocessable_entity,
478
+ status: :unprocessable_content,
479
479
  title: message,
480
480
  detail: "#{format_key(attr_key)} - #{message}",
481
481
  source: { pointer: pointer(attr_key) },
@@ -500,7 +500,7 @@ module JSONAPI
500
500
  class SaveFailed < Error
501
501
  def errors
502
502
  [create_error_object(code: JSONAPI::SAVE_FAILED,
503
- status: :unprocessable_entity,
503
+ status: :unprocessable_content,
504
504
  title: I18n.translate('jsonapi-resources.exceptions.save_failed.title',
505
505
  default: 'Save failed or was cancelled'),
506
506
  detail: I18n.translate('jsonapi-resources.exceptions.save_failed.detail',
@@ -1,5 +1,6 @@
1
1
  require 'jsonapi/operation'
2
2
  require 'jsonapi/paginator'
3
+ require 'cgi'
3
4
 
4
5
  module JSONAPI
5
6
  class RequestParser
@@ -272,7 +273,7 @@ module JSONAPI
272
273
 
273
274
  sorts = []
274
275
  begin
275
- raw = URI.unescape(sort_criteria)
276
+ raw = CGI.unescape(sort_criteria)
276
277
  sorts += CSV.parse_line(raw)
277
278
  rescue CSV::MalformedCSVError
278
279
  fail JSONAPI::Exceptions::InvalidSortCriteria.new(format_key(@resource_klass._type), raw)
@@ -511,7 +511,7 @@ module JSONAPI
511
511
  check_reserved_attribute_name(attr)
512
512
 
513
513
  if (attr.to_sym == :id) && (options[:format].nil?)
514
- ActiveSupport::Deprecation.warn('Id without format is no longer supported. Please remove ids from attributes, or specify a format.')
514
+ ActiveSupport::Deprecation.new(nil, 'JSONAPI').warn('Id without format is no longer supported. Please remove ids from attributes, or specify a format.')
515
515
  end
516
516
 
517
517
  check_duplicate_attribute_name(attr) if options[:format].nil?
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Resources
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.4'
4
4
  end
5
5
  end
@@ -38,28 +38,14 @@ module ActionDispatch
38
38
  options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy')
39
39
  end
40
40
 
41
- resource @resource_type, options do
42
- # :nocov:
43
- if @scope.respond_to? :[]=
44
- # Rails 4
45
- @scope[:jsonapi_resource] = @resource_type
46
-
41
+ resource @resource_type, **options do
42
+ jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], **options), @resource_type) do
47
43
  if block_given?
48
44
  yield
49
45
  else
50
46
  jsonapi_relationships
51
47
  end
52
- else
53
- # Rails 5
54
- jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do
55
- if block_given?
56
- yield
57
- else
58
- jsonapi_relationships
59
- end
60
- end
61
48
  end
62
- # :nocov:
63
49
  end
64
50
  end
65
51
 
@@ -107,27 +93,14 @@ module ActionDispatch
107
93
  options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy')
108
94
  end
109
95
 
110
- resources @resource_type, options do
111
- # :nocov:
112
- if @scope.respond_to? :[]=
113
- # Rails 4
114
- @scope[:jsonapi_resource] = @resource_type
96
+ resources @resource_type, **options do
97
+ jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], **options), @resource_type) do
115
98
  if block_given?
116
99
  yield
117
100
  else
118
101
  jsonapi_relationships
119
102
  end
120
- else
121
- # Rails 5
122
- jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do
123
- if block_given?
124
- yield
125
- else
126
- jsonapi_relationships
127
- end
128
- end
129
103
  end
130
- # :nocov:
131
104
  end
132
105
  end
133
106
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanger-jsonapi-resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - PSD Team - Wellcome Trust Sanger Institute
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-09-19 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
@@ -58,6 +57,20 @@ dependencies:
58
57
  - - ">="
59
58
  - !ruby/object:Gem::Version
60
59
  version: '0'
60
+ - !ruby/object:Gem::Dependency
61
+ name: minitest-mock
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
61
74
  - !ruby/object:Gem::Dependency
62
75
  name: minitest-spec-rails
63
76
  requirement: !ruby/object:Gem::Requirement
@@ -72,6 +85,20 @@ dependencies:
72
85
  - - ">="
73
86
  - !ruby/object:Gem::Version
74
87
  version: '0'
88
+ - !ruby/object:Gem::Dependency
89
+ name: minitest-reporters
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ type: :development
96
+ prerelease: false
97
+ version_requirements: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
75
102
  - !ruby/object:Gem::Dependency
76
103
  name: simplecov
77
104
  requirement: !ruby/object:Gem::Requirement
@@ -120,28 +147,54 @@ dependencies:
120
147
  requirements:
121
148
  - - ">="
122
149
  - !ruby/object:Gem::Version
123
- version: '4.1'
150
+ version: '7.2'
151
+ - - "<"
152
+ - !ruby/object:Gem::Version
153
+ version: '9.0'
124
154
  type: :runtime
125
155
  prerelease: false
126
156
  version_requirements: !ruby/object:Gem::Requirement
127
157
  requirements:
128
158
  - - ">="
129
159
  - !ruby/object:Gem::Version
130
- version: '4.1'
160
+ version: '7.2'
161
+ - - "<"
162
+ - !ruby/object:Gem::Version
163
+ version: '9.0'
131
164
  - !ruby/object:Gem::Dependency
132
165
  name: railties
133
166
  requirement: !ruby/object:Gem::Requirement
134
167
  requirements:
135
168
  - - ">="
136
169
  - !ruby/object:Gem::Version
137
- version: '4.1'
170
+ version: '7.2'
171
+ - - "<"
172
+ - !ruby/object:Gem::Version
173
+ version: '9.0'
138
174
  type: :runtime
139
175
  prerelease: false
140
176
  version_requirements: !ruby/object:Gem::Requirement
141
177
  requirements:
142
178
  - - ">="
143
179
  - !ruby/object:Gem::Version
144
- version: '4.1'
180
+ version: '7.2'
181
+ - - "<"
182
+ - !ruby/object:Gem::Version
183
+ version: '9.0'
184
+ - !ruby/object:Gem::Dependency
185
+ name: rack
186
+ requirement: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - "~>"
189
+ - !ruby/object:Gem::Version
190
+ version: '3.0'
191
+ type: :runtime
192
+ prerelease: false
193
+ version_requirements: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - "~>"
196
+ - !ruby/object:Gem::Version
197
+ version: '3.0'
145
198
  - !ruby/object:Gem::Dependency
146
199
  name: concurrent-ruby
147
200
  requirement: !ruby/object:Gem::Requirement
@@ -220,7 +273,6 @@ homepage: https://github.com/sanger/jsonapi-resources
220
273
  licenses:
221
274
  - MIT
222
275
  metadata: {}
223
- post_install_message:
224
276
  rdoc_options: []
225
277
  require_paths:
226
278
  - lib
@@ -228,15 +280,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
280
  requirements:
229
281
  - - ">="
230
282
  - !ruby/object:Gem::Version
231
- version: '2.1'
283
+ version: '3.2'
232
284
  required_rubygems_version: !ruby/object:Gem::Requirement
233
285
  requirements:
234
286
  - - ">="
235
287
  - !ruby/object:Gem::Version
236
288
  version: '0'
237
289
  requirements: []
238
- rubygems_version: 3.4.1
239
- signing_key:
290
+ rubygems_version: 3.6.9
240
291
  specification_version: 4
241
292
  summary: Easily support JSON API in Rails.
242
293
  test_files: []