Skip to content

Instantly share code, notes, and snippets.

@moklett
Created September 1, 2010 20:51
Show Gist options
  • Save moklett/561348 to your computer and use it in GitHub Desktop.
Save moklett/561348 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'chargify_api_ares'
require 'cgi'
Chargify.configure do |c|
c.subdomain = 'acme'
c.api_key = 'x'
end
email = "[email protected]"
c = Chargify::Customer.create(
:first_name => "Foo",
:last_name => "Bar",
:email => email,
:reference => email
)
puts c.inspect
# => #<Chargify::Customer:0x101a899e8 @prefix_options={}, @attributes={"address"=>nil, "city"=>nil, "reference"=>"[email protected]", "zip"=>nil, "created_at"=>Wed Sep 01 20:45:37 UTC 2010, "country"=>nil, "updated_at"=>Wed Sep 01 20:45:37 UTC 2010, "id"=>104132, "address_2"=>nil, "phone"=>nil, "last_name"=>"Bar", "organization"=>nil, "state"=>nil, "email"=>"[email protected]", "first_name"=>"Foo"}>
begin
c = Chargify::Customer.find_by_reference(email).inspect
rescue ActiveResource::ResourceNotFound
c = "Not Found"
end
puts c
# => Not Found
begin
c = Chargify::Customer.find_by_reference(CGI.escape(email)).inspect
rescue ActiveResource::ResourceNotFound
c = "Not Found"
end
puts c
# => #<Chargify::Customer:0x10175a060 @prefix_options={}, @attributes={"reference"=>"[email protected]", "address"=>nil, "city"=>nil, "zip"=>nil, "created_at"=>Wed Sep 01 20:45:37 UTC 2010, "country"=>nil, "updated_at"=>Wed Sep 01 20:45:37 UTC 2010, "id"=>104132, "address_2"=>nil, "phone"=>nil, "last_name"=>"Bar", "organization"=>nil, "state"=>nil, "email"=>"[email protected]", "first_name"=>"Foo"}>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment