Skip to content

Instantly share code, notes, and snippets.

View coreyjs's full-sized avatar

Corey Schaf coreyjs

View GitHub Profile
class App < ApplicationRecord
validates :name, uniqueness: true
validates :token, uniqueness: true
end
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root 'application#index', format: 'json'
namespace :v1 do
resource :apps
end
end
class V1::AppsController < ApplicationController
before_action :set_app, only: [:show, :update, :destroy]
# GET /v1/apps
def index
@apps = App.all
render json: @apps
end
http role route
GET Get an app /v1/apps/{int:id}
GET Get all apps /v1/apps/
POST Create an app /v1/apps/
PATCH Update an app /v1/apps/{int:id}
DELETE Delete an app /v1/apps/
class ApplicationController < ActionController::API
def index
render json: { status: 200, message: 'Hello World'}
end
end
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root 'application#index', format: 'json'
end
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
@coreyjs
coreyjs / ch-01-app.rb
Last active October 2, 2018 15:47
ch-01-app.rb
class CreateApps < ActiveRecord::Migration[5.2]
def change
create_table :apps do |t|
# Name of our app, used for visual readability.
t.string :name, unique: true
# Internal identifier of our app, for communication from the open api endpoint
t.string :token, unique: true
# Switch to determine if this app is currently accepting data.
@coreyjs
coreyjs / api_spec.rb
Created January 31, 2018 16:53
Rails API Spec Example
module ApiHelper
include Rack::Test::Methods
def app
Rails.application
end
end
RSpec.configure do |config|
config.include ApiHelper, api: true
select order_Id from [order] o where(
o.order_id in (
select osh.order_id
from order_status_history osh
join order_status os on os.status_id = osh.status_id
inner join (
select order_id, MAX(effective_date) as updated
from order_status_history
group by order_id) as status on osh.order_id = status.order_id and osh.effective_date = status.updated