This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app = ActionDispatch.test_app | |
session = ActionDispatch::Integration::Session.new(app) | |
session.get '/api/foo' | |
session.response.body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data: { | |
type: 'authors', | |
attributes: { first_name: 'Stephen', last_name: 'King' }, | |
relationships: { | |
books: { | |
:"added-data" => [ | |
{ | |
:"temp-id" => "abc123", | |
type: 'books', | |
attributes: { title: 'The Shining' }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data: { | |
type: 'authors', | |
attributes: { first_name: 'Stephen', last_name: 'King' }, | |
relationships: { | |
books: { | |
:"added-data" => [ | |
{ | |
:"temp-id" => "abc123", | |
type: 'books', | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ContractsController | |
jsonapi resource: ContractResource | |
end | |
class TransactionsController | |
jsonapi resource: TransactionResource | |
end | |
class ContractResource < JsonapiCompliable::Resource | |
type :contracts |
NewerOlder