get: http://gist.github.com/430863
post: http://gist.github.com/430865
controller: http://gist.github.com/430868
It’s a dead end!
What about evolution?
resource = Restfulie.at('http://localhost:3000/items').get | |
resource.items[0].name | |
resource.response.code | |
resource.response.body | |
resource = Restfulie.at('http://localhost:3000/items').accepts('application/xml').get | |
resource.items[0].name | |
resource.response.code | |
resource.response.body |
resource = Restfulie.at('http://localhost:3000/items').as("application/xml").post!(:item => { :name => "Robin costume", :price => 25.0}) | |
resource = Restfulie.at('http://localhost:3000/items').as("application/json").post!(:item => { :name => "Robin costume", :price => 25.0}) | |
resource = Restfulie.at('http://localhost:3000/items').as("application/atom+xml").post!(:item => { :name => "Robin costume", :price => 25.0}) | |
# already follows 201 |
get: http://gist.github.com/430863
post: http://gist.github.com/430865
controller: http://gist.github.com/430868
It’s a dead end!
What about evolution?
class ItemsController < ApplicationController | |
include Restfulie::Server::ActionController::Base | |
respond_to :xml, :json | |
def index | |
@items = Item.all | |
respond_with @items | |
end |
collection(@items) do |collection| | |
collection.link "basket", baskets_url | |
collection.members do |member, item| | |
partial "show", binding | |
end | |
end |
member(@basket) do |member, basket| | |
member.link "payment", basket_payments_url(@basket) | |
member.link "self", basket_url(@basket) | |
member.values { |values| | |
values.price @basket.price | |
} | |
end |
member.link :self, item_url(item) | |
member.values { |values| | |
values.id item.id | |
values.name item.name | |
values.price item.price | |
} |
require 'rubygems' | |
require 'restfulie' | |
# retrieves the list | |
resource = Restfulie.at("http://localhost:3000/items").accepts("application/xml").get | |
# picks the first item | |
basket = {"basket" => {"items" => [{"id" => resource.items.item.first["id"]}]}} | |
# creates the basket |
def i_want?(name) | |
@what.find { |desired| name[desired] } | |
end | |
When "there is a required item" do |resource| | |
if resource.keys.first == "items" | |
@desired = resource.items.item.find { |item| i_want?(item.name) } | |
else | |
false | |
end |
#!/usr/bin/env bash | |
for rvmrc in /etc/rvmrc $HOME/.rvmrc ; do | |
if [[ -f "$rvmrc" ]] ; then | |
if grep -q '^\s*rvm .*$' $rvmrc ; then | |
printf "\nError: $rvmrc is for rvm settings only.\nrvm CLI may NOT be called from within $rvmrc. \nSkipping the loading of $rvmrc" | |
exit 1 | |
else | |
source "$rvmrc" | |
fi |