the_garage 2.4.4 → 2.7.0

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: 7c4e3dd92f5413a3042cd8e54590a5028ba27b6ec01ec2776bbe0d950693ccca
4
- data.tar.gz: f03ef645cf85bcfd54a416fb06f9d985d7515e8dfda1e2e445da5c4cf5d9239b
3
+ metadata.gz: 80169386da45b2a7fa5b98e3f855e9df7a49e9fac6357cd894bc26eb24d45a95
4
+ data.tar.gz: 0d7dd3a20e97a8aeeebdd79e52b99e8ddf4291b6eba0885b1d7a5cf453265792
5
5
  SHA512:
6
- metadata.gz: 834480a2f01fdbe73e607483b6faddae9cafecc29b6a18d617b7ad221c783b12e5c92471a52188bb54cdf056d8abbdf3f98f20c73dd34fbb6fc3cd3a511ca549
7
- data.tar.gz: d31177fc305961dd0dab978a71e0db3f51eef09460d18dfab0580ed07fd4704cd75888bfec0e2d86f215aa845ad3fd6acd8ac97a65e2023e89c1fb60bff06180
6
+ metadata.gz: a68873fd908fc82273b263f0234a852bf1537e3c6cce7a0ef957652ec773b711f2b7ee28cb1f183644e8f4bb9421c1c2a60fc5caf1ba567d5cf5e5c630fb00dc
7
+ data.tar.gz: 53ba2171e6f6b1c4eebd3bdc6158e932fea15780a2caecc2b19d5148dfe658c11fb0627cc8bd0c46ba232f29be6d287f9669f3da48a3e595d896df550d8f6aa1
data/README.md CHANGED
@@ -52,7 +52,7 @@ In your controller classes:
52
52
  ```ruby
53
53
  class ApplicationController < ActionController::Base
54
54
  include Garage::ControllerHelper
55
-
55
+
56
56
  # ...
57
57
  end
58
58
 
@@ -65,6 +65,18 @@ class EmployeesController < ApplicationController
65
65
  end
66
66
  ```
67
67
 
68
+ Resources are rendered with [respond_with (responders gem)](https://github.com/heartcombo/responders).
69
+ Additional options can be passed to respond_with by implementing `respond_with_resources_options` (index action)
70
+ and `respond_with_resource_options` (show, update destroy actions).
71
+
72
+ Available options
73
+ * `:paginate` - (Boolean) Enable pagination when `true`. Paginates with the `per_page` and `page` params
74
+ * `:per_page` - (Integer) value for default number of resources per page when paginating
75
+ * `:max_per_page` - (Integer) Maximum resources per page, irrespective of requested per_page
76
+ * `:hard_limit` - (Integer) Limit of retrievable records when paginating. Also hides total records.
77
+ * `:distinct_by` - (Symbol) Specify a property to count by for total page count
78
+ * `:to_resource_options` - (Hash) Options to pass as argument to `to_resource(options)`
79
+
68
80
  ## Create decorator for your AR models
69
81
  With not small application, you may add a presentation layer to build API responses.
70
82
  Define a decorator class with `Resource` suffix and define `#to_resource` in
@@ -141,7 +153,7 @@ Then configure auth server strategy:
141
153
 
142
154
  The OAuth server must response a json with following structure.
143
155
 
144
- - `token`(string) - OAuth access token value.
156
+ - `token` (string, null) - OAuth access token value.
145
157
  - `token_type` (string) - OAuth access token value. i.e. `bearer` type.
146
158
  - `scope` (string) - OAuth scopes separated by spaces. i.e. `public read_user`.
147
159
  - `application_id` (integer) - OAuth application id of the access token.
@@ -9,14 +9,6 @@ jQuery ()->
9
9
  $.colorbox.close()
10
10
  ev.preventDefault()
11
11
 
12
- buildAuthorizedUrl = (base, location, token) ->
13
- url = base + location
14
- if url.indexOf('?') > 0
15
- url += '&'
16
- else
17
- url += '?'
18
- url + 'access_token=' + token
19
-
20
12
  addNewParamField = (container) ->
21
13
  nextId = "parameter-" + $('.parameter', container).length
22
14
  copy = $('.template .parameter').clone().attr('id', nextId)
@@ -52,11 +44,11 @@ jQuery ()->
52
44
  $('#api-headers').text ''
53
45
  $('#api-response').text ''
54
46
 
55
- url = buildAuthorizedUrl $('#base').val(), $('#location').val(), $('#access_token').val()
56
47
  console.log buildData($('.parameters'))
57
48
  $.ajax
58
49
  type: $('#method').val(),
59
- url: url,
50
+ url: $('#base').val() + $('#location').val(),
51
+ headers: {'Authorization': 'Bearer ' + $('#access_token').val()},
60
52
  cache: false,
61
53
  data: buildData($('.parameters')),
62
54
  dataType: 'json',
@@ -86,7 +86,7 @@ class Garage::Docs::ResourcesController < Garage::ApplicationController
86
86
  def require_console_application
87
87
  @app = console_application
88
88
  if @app[:uid].blank? || @app[:secret].blank?
89
- render(text: 'Configuration for console application is missing.', status: :forbidden)
89
+ render(plain: 'Configuration for console application is missing.', status: :forbidden)
90
90
  end
91
91
  end
92
92
 
data/lib/garage/config.rb CHANGED
@@ -49,11 +49,13 @@ module Garage
49
49
  end
50
50
 
51
51
  def cast_resource
52
- @cast_resource ||= proc { |resource|
52
+ @cast_resource ||= proc { |resource, options|
53
+ options ||= {}
54
+ to_resource_args = [options[:to_resource_options]].compact
53
55
  if resource.respond_to?(:map) && resource.respond_to?(:to_a)
54
- resource.map(&:to_resource)
56
+ resource.map { |r| r.to_resource(*to_resource_args) }
55
57
  else
56
- resource.to_resource
58
+ resource.to_resource(*to_resource_args)
57
59
  end
58
60
  }
59
61
  end
@@ -90,7 +90,7 @@ module Garage
90
90
  links[:next] = rs.current_page + 1
91
91
  end
92
92
 
93
- unless rs.last_page? || hide_total?
93
+ unless rs.last_page? || hide_total? || rs.total_pages.zero?
94
94
  links[:last] = rs.total_pages
95
95
  end
96
96
  end
@@ -1,3 +1,5 @@
1
+ require 'active_support/time_with_zone'
2
+
1
3
  module Garage::Representer
2
4
  attr_accessor :params, :representer_attrs, :partial, :selector
3
5
 
@@ -51,7 +53,7 @@ module Garage::Representer
51
53
  self.class
52
54
  end
53
55
 
54
- def to_resource
56
+ def to_resource(options = {})
55
57
  self
56
58
  end
57
59
 
@@ -6,7 +6,7 @@ module Garage::ResourceCastingResponder
6
6
 
7
7
  def display(resource, given_options={})
8
8
  if @caster
9
- resource = @caster.call(resource)
9
+ resource = @caster.call(resource, @options)
10
10
  end
11
11
  super(resource, given_options)
12
12
  end
@@ -1,7 +1,8 @@
1
1
  module Garage
2
2
  module Strategy
3
3
  class AccessToken
4
- attr_reader :scope, :token, :token_type, :raw_response
4
+ attr_accessor :token
5
+ attr_reader :scope, :token_type, :raw_response
5
6
 
6
7
  def initialize(attrs)
7
8
  @raw_response = attrs
@@ -58,10 +58,8 @@ module Garage
58
58
 
59
59
  def fetch
60
60
  if has_any_valid_credentials?
61
- if has_cacheable_credentials?
62
- fetch_with_cache
63
- else
64
- fetch_without_cache
61
+ fetch_access_token&.tap do |access_token|
62
+ access_token.token ||= token_string
65
63
  end
66
64
  else
67
65
  nil
@@ -89,6 +87,8 @@ module Garage
89
87
  'Resource-Owner-Id' => @request.headers['Resource-Owner-Id'],
90
88
  'Scopes' => @request.headers['Scopes'],
91
89
  'User-Agent' => USER_AGENT,
90
+ # ActionDispatch::Request#request_id is only available in Rails 5.0 or later.
91
+ 'X-Request-Id' => @request.uuid,
92
92
  }.reject {|_, v| v.nil? }
93
93
  end
94
94
 
@@ -142,6 +142,14 @@ module Garage
142
142
  @bearer_token ||= @request.authorization.try {|o| o.slice(/\ABearer\s+(.+)\z/, 1) }
143
143
  end
144
144
 
145
+ def fetch_access_token
146
+ if has_cacheable_credentials?
147
+ fetch_with_cache
148
+ else
149
+ fetch_without_cache
150
+ end
151
+ end
152
+
145
153
  def fetch_with_cache
146
154
  Cache.with_cache("garage_gem/token_cache/#{Garage::VERSION}/#{bearer_token}") do
147
155
  fetch_without_cache
@@ -160,6 +168,12 @@ module Garage
160
168
  end
161
169
  end
162
170
  end
171
+
172
+ def token_string
173
+ bearer_token.presence ||
174
+ @request.params[:access_token].presence ||
175
+ @request.params[:bearer_token].presence
176
+ end
163
177
  end
164
178
 
165
179
  class Response
@@ -1,3 +1,3 @@
1
1
  module Garage
2
- VERSION = '2.4.4'
2
+ VERSION = '2.7.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_garage
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.4
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tatsuhiko Miyagawa
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-13 00:00:00.000000000 Z
11
+ date: 2021-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
19
+ version: 4.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.0.0
26
+ version: 4.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rack-accept-default
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -164,20 +164,6 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: 2.0.0
167
- - !ruby/object:Gem::Dependency
168
- name: appraisal
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: '0'
181
167
  description: Garage extends your RESTful, Hypermedia APIs as a Platform
182
168
  email:
183
169
  - miyagawa@bulknews.net
@@ -255,7 +241,7 @@ homepage: https://github.com/cookpad/garage
255
241
  licenses:
256
242
  - MIT
257
243
  metadata: {}
258
- post_install_message:
244
+ post_install_message:
259
245
  rdoc_options: []
260
246
  require_paths:
261
247
  - lib
@@ -270,8 +256,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
256
  - !ruby/object:Gem::Version
271
257
  version: '0'
272
258
  requirements: []
273
- rubygems_version: 3.0.3
274
- signing_key:
259
+ rubygems_version: 3.1.4
260
+ signing_key:
275
261
  specification_version: 4
276
262
  summary: Garage Platform Engine
277
263
  test_files: []