Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
class Customer < Service(:crm)
# my custom methods here.
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 < ActiveResource::Base
self.site = "http://localhost:3000/"
self.user = "api"
self.password = "kittens"
end
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
>> 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)
class Customer < ActiveResource::Base
self.site = "http://localhost:3000/"
end
class CustomersController < ApplicationController
def index
@customers = Customer.find(:all)
respond_to do |format|
format.xml { render :xml => @customers }
format.html
end
end
create_table :customers do |t|
t.string :first_name
t.string :last_name
t.string :email
t.string :daytime_phone
t.string :evening_phone
t.timestamps
end
  • Introductions
  • Styling
  • Gravatar?
  • Gray BG for pre?
  • Scheduling
  • Calendar
  • Post to group?
  • Collaborators
  • Out of the box support or wait?
  • Licensing