This is just pseudo-code to give you a general idea:
# client code
class MyClient
def get(params)
RestClient.get '/some/api', params
end
end| # config/initializers/strong_resources.rb | |
| Parameters = ActionController::Parameters | |
| # first, define our custom type according to the stronger_parameters documentation | |
| custom_type = Parameters.array(Parameters.id) | |
| # then, register this custom type with strong resources. we need: | |
| # * a name for the type (:array_of_integers) | |
| # * since swagger only allows certain types, how should swagger handle this type? |
| require 'swagger/diff' | |
| require 'pp' | |
| def get_swagger(path) | |
| token = ENV['JSONAPI_TOKEN'] | |
| session = ActionDispatch::Integration::Session.new(Rails.application) | |
| session.get path, headers: { | |
| 'Authorization' => "Token token=\"#{token}\"" | |
| } | |
| session.response.body |
This is just pseudo-code to give you a general idea:
# client code
class MyClient
def get(params)
RestClient.get '/some/api', params
end
end| before_action :authenticate_user_from_token! | |
| before_action :authenticate_user! | |
| # Ripped from ember-simple-auth-devise | |
| def authenticate_user_from_token! | |
| if user = user_via_token | |
| sign_in(user, store: false) | |
| else | |
| raise NotAuthorized, 'Access is denied due to invalid token.' | |
| end |
| app = ActionDispatch.test_app | |
| session = ActionDispatch::Integration::Session.new(app) | |
| session.get '/api/foo' | |
| session.response.body |
| data: { | |
| type: 'authors', | |
| attributes: { first_name: 'Stephen', last_name: 'King' }, | |
| relationships: { | |
| books: { | |
| :"added-data" => [ | |
| { | |
| :"temp-id" => "abc123", | |
| type: 'books', | |
| attributes: { title: 'The Shining' }, |
| data: { | |
| type: 'authors', | |
| attributes: { first_name: 'Stephen', last_name: 'King' }, | |
| relationships: { | |
| books: { | |
| :"added-data" => [ | |
| { | |
| :"temp-id" => "abc123", | |
| type: 'books', | |
| } |
| class ContractsController | |
| jsonapi resource: ContractResource | |
| end | |
| class TransactionsController | |
| jsonapi resource: TransactionResource | |
| end | |
| class ContractResource < JsonapiCompliable::Resource | |
| type :contracts |