Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
class CustomersController < ApplicationController
def index
@customers = Customer.find(:all)
respond_to do |format|
format.xml { render :xml => @customers }
format.html
end
end
class Customer < ActiveResource::Base
self.site = "http://localhost:3000/"
end
>> Customer.create(:first_name => "Gregory", :last_name => "Brown")
=> #<Customer:0x20d2120 @prefix_options={}, @attributes={"evening_phone"=>nil, "updated_at"=>Thu Apr 16 03:53:59 UTC 2009, "daytime_phone"=>nil, "id"=>1, "first_name"=>"Gregory", "last_name"=>"Brown", "created_at"=>Thu Apr 16 03:53:59 UTC 2009, "email"=>nil}>
>> Customer.find(:all)
=> [#<Customer:0x20a939c @prefix_options={}, @attributes={"evening_phone"=>nil, "updated_at"=>Thu Apr 16 03:53:59 UTC 2009, "daytime_phone"=>nil, "id"=>1, "first_name"=>"Gregory", "last_name"=>"Brown", "created_at"=>Thu Apr 16 03:53:59 UTC 2009, "email"=>nil}>]
>> Customer.find(1).first_name
=> "Gregory"
>> Customer.delete(1)
def basic_http_auth
authenticated = false
authenticate_with_http_basic do |login, password|
if login == "api" && password == API_KEY
authenticated = true
end
end
raise "Authentication failed" unless authenticated
end
class Customer < ActiveResource::Base
self.site = "http://localhost:3000/"
self.user = "api"
self.password = "kittens"
end
require 'yaml'
require 'activeresource'
class ServiceLocator
API_KEY = "kittens"
def self.services
return @services if @services
config_file = File.join(RAILS_ROOT, %w[config services.yml])
require 'yaml'
require 'activeresource'
class ServiceLocator
API_KEY = "kittens"
def self.services
return @services if @services
config_file = File.join(RAILS_ROOT, %w[config services.yml])
class Customer < Service(:crm)
# my custom methods here.
end
class Foo
def bar
blah
end
end
#!/usr/local/bin/ruby
require "rubygems"
require "rake"
require "erb"
def ProcessTemplate(file)
ERB.new(File.read(file)).result(binding)
end