Skip to content

Instantly share code, notes, and snippets.

View stravid's full-sized avatar

David Strauß stravid

View GitHub Profile
Possible tasks I have a hard time mapping to resources.
- Issuing an invoice
- Completing some kind of sports match
- Advancing an item in a defined process
- Lock/Release an item (to prevent tampering by others)
- Move an upload from temporary to permanent storage
module BaseCommand
module ClassMethods
def schema(&block)
@schema = Dry::Validation.Form(&block)
end
def build(data)
result = schema.call(data)
if result.success?
@stravid
stravid / README.md
Last active June 21, 2016 07:24
Ruby JSON API Stack

Ruby JSON API Stack

What is this? I'm a little bugged out by all current approaches that are available to build JSON API APIs. I'm writing all this down to help me figure out what I want and how to accomplish it.

There are basically two sides, reading data and writing data. There are also a few parts of the stack that can be generalized. On the other side there are also parts where I think generalization is harmful.

Things like transforming parameters from dasherized to snake case, and serializing an object graph to JSON can be kept pretty generic. The thing I'm not so sure about on the read side is handling query parameters like included, fields, sort, filter, page and so on. For example using JSONAPI::Resources gives you the query parameter handling out of the box. On the other side I think it's impossible to deal with associations if you don't use the Active Record pattern and/or have 1:1 mapping between API resources and models.

On the write

@stravid
stravid / application.controller.js
Last active December 20, 2015 10:31
Ember Data Auto-Update Test Case
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
@stravid
stravid / cURL request
Last active October 16, 2015 08:39
Lotus JSON Body Parsing
curl 'http://localhost:2300/api/players' --data-binary '{"data":{"attributes":{"name":"David"},"type":"players"}}' --compressed
{"data":null}
require 'rubygems'
require 'bundler/setup'
require 'rom'
require 'rom-sql'
ROM.setup(:sql, 'postgres://localhost/datsu_development')
class Players < ROM::Relation[:sql]
register_as :players
dataset :players
require 'rubygems'
require 'bundler/setup'
require 'rom'
require 'rom-sql'
ROM.setup(:sql, 'postgres://localhost/datsu_development')
class Players < ROM::Relation[:sql]
register_as :players
dataset :players
require 'rubygems'
require 'bundler/setup'
require 'rom'
require 'rom-sql'
ROM.setup(:sql, 'postgres://localhost/datsu_development')
class Players < ROM::Relation[:sql]
register_as :players
dataset :players
@stravid
stravid / Brocfile.js
Last active August 29, 2015 14:06
Creating a Datepicker Ember Addon
// Rest of the file
app.import('bower_components/momentjs/moment.js');
app.import('bower_components/pikaday/pikaday.js');
app.import('bower_components/pikaday/css/pikaday.css');
module.exports = app.toTree();
---
- name: apply common configuration to all servers
hosts: all
remote_user: deployer
sudo_user: deployer
sudo: yes
vars:
- ansible_sudo_pass: secret
tasks:
- debug: msg={{ansible_sudo_pass}}