Skip to content

Instantly share code, notes, and snippets.

View coderdan's full-sized avatar

Dan Draper coderdan

View GitHub Profile
class CustomerAPI < Grape::API
version 'v1', :using => :header
resource :users do
desc "Return all users"
get do
User.all
end
desc "Return a User with a given ID"
# In Rails config/routes.rb
mount Twitter::API => "/"
class CustomerAPI < Grape::API
version 'v1', :using => :header
resource :users do
desc "Create a user"
post :create do
User.create!(params[:user]).to_json
end
end
end
class CustomerAPI < Grape::API
version 'v1', :using => :header
resource :users do
desc "Will Error!"
post :silly do
error("You're silly", 500)
end
desc "Smarter version of all Users"
class CustomerAPI < Grape::API
version 'v1', :using => :header
rescue_from ActiveRecord::RecordInvalid do |e|
# Precondition Failed
error_response(:status => 412, :message => { :error => e.message }.to_json)
end
helpers do
def authenticate!
@coderdan
coderdan / gist:3747229
Created September 19, 2012 02:08
Codehire Cup Skeleton Code for Java
public class Challenge {
public static void main(String[] args) throws Exception {
Output.write(Input.read());
}
}
@coderdan
coderdan / gist:3747251
Created September 19, 2012 02:15
Codehire Cup Skeleton Code for Ruby
output << input
@coderdan
coderdan / gist:3747255
Created September 19, 2012 02:16
Codehire Cup Skeleton Code for C#
public class Challenge {
public static void Main() {
Output.Write(Input.Read());
}
}
@coderdan
coderdan / gist:3747258
Created September 19, 2012 02:17
Codehire Cup Skeleton Code for PHP
<?php
include 'support.php';
Output::Write(Input::Read());
@coderdan
coderdan / gist:3747268
Created September 19, 2012 02:19
Codehire Cup Skeleton Code for JavaScript
output += input;