This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CustomersController < ApplicationController | |
| def index | |
| @customers = Customer.find(:all) | |
| respond_to do |format| | |
| format.xml { render :xml => @customers } | |
| format.html | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Customer < ActiveResource::Base | |
| self.site = "http://localhost:3000/" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >> 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Customer < ActiveResource::Base | |
| self.site = "http://localhost:3000/" | |
| self.user = "api" | |
| self.password = "kittens" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Customer < Service(:crm) | |
| # my custom methods here. | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Foo | |
| def bar | |
| blah | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/ruby | |
| require "rubygems" | |
| require "rake" | |
| require "erb" | |
| def ProcessTemplate(file) | |
| ERB.new(File.read(file)).result(binding) | |
| end |