Permalink
Browse files

Adding Contact.find_by_name. Also the authenticate method now returns…

… true instead of your password.
  • Loading branch information...
drcapulet committed Jun 2, 2010
1 parent f9fca6c commit 884e17f4512223bc5636514e599cb342801f7813
Showing with 21 additions and 7 deletions.
  1. +1 −1 Rakefile
  2. +6 −4 lib/freeagent_api.rb
  3. +12 −0 test/contact_test.rb
  4. +1 −1 test/stubs/contacts/find_all
  5. +1 −1 test/stubs/contacts/find_single
View
@@ -6,7 +6,7 @@ begin
Jeweler::Tasks.new do |gem|
gem.name = "freeagent_api"
gem.summary = %Q{ActiveResource Ruby wrapper for the Freeagent Central API.}
- gem.description = %Q{This is an ActiveResource Ruby wrapper for the Freeagent API. Currently supports the following API resources: Company, Contacts, Projects, Tasks, Invoices, Invoice Items, Timeslips (more will follow).}
+ gem.description = %Q{This is an ActiveResource Ruby wrapper for the Freeagent API. Currently supports the following API resources: Company, Contacts, Projects, Tasks, Invoices, Invoice Items, Timeslips, Users (more will follow).}
gem.email = "aaron@gc4.co.uk"
gem.homepage = "http://github.com/aaronrussell/freeagent_api"
gem.authors = ["Aaron Russell"]
View
@@ -17,6 +17,7 @@ def self.authenticate(options)
self.site = "https://#{options[:domain]}"
self.user = options[:username]
self.password = options[:password]
+ return true
end
end
@@ -40,6 +41,10 @@ class TaxTimeline < Base
# Contacts
class Contact < Base
+ def self.find_by_name(name)
+ Contact.find(:all).each { |c| c.organisation_name == name ? (return c) : next }
+ raise Error, "No contact matches that name!"
+ end
end
# Projects
@@ -118,10 +123,7 @@ def self.find(*arguments)
class User < Base
self.prefix = '/company/'
def self.find_by_email(email)
- users = User.find :all
- users.each do |u|
- u.email == email ? (return u) : next
- end
+ User.find(:all).each { |u| u.email == email ? (return u) : next }
raise Error, "No user matches that email!"
end
end
View
@@ -43,6 +43,18 @@ class ContactTest < Test::Unit::TestCase
end
end
+ context "Finding Contact" do
+ setup do
+ @contact = Contact.find_by_name('Organisation Name - Demo')
+ end
+ should "return a Contact" do
+ assert @contact.is_a? Contact
+ end
+ should "return the correct User" do
+ assert_equal Contact.find(27309), @contact
+ end
+ end
+
#TODO - Add test for invalid resource
# Need support from fakeweb in order to achieve this
@@ -18,7 +18,7 @@ Content-Type: application/xml; charset=utf-8
<last-name>Bloggs</last-name>
<locale>en</locale>
<mobile nil="true"></mobile>
- <organisation-name>Organisation Name</organisation-name>
+ <organisation-name>Organisation Name - Demo</organisation-name>
<phone-number>01234 567890</phone-number>
<postcode>BS1 2AW</postcode>
<region></region>
@@ -17,7 +17,7 @@ Content-Type: application/xml; charset=utf-8
<last-name>Bloggs</last-name>
<locale>en</locale>
<mobile nil="true"></mobile>
- <organisation-name>Organisation Name</organisation-name>
+ <organisation-name>Organisation Name - Demo</organisation-name>
<phone-number>01234 567890</phone-number>
<postcode>BS1 2AW</postcode>
<region></region>

0 comments on commit 884e17f

Please sign in to comment.