diff --git a/Rakefile b/Rakefile
index 9d521dd..3b82828 100644
--- a/Rakefile
+++ b/Rakefile
@@ -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"]
diff --git a/lib/freeagent_api.rb b/lib/freeagent_api.rb
index f59f2cd..593f596 100644
--- a/lib/freeagent_api.rb
+++ b/lib/freeagent_api.rb
@@ -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
diff --git a/test/contact_test.rb b/test/contact_test.rb
index e966509..fe92d39 100644
--- a/test/contact_test.rb
+++ b/test/contact_test.rb
@@ -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
diff --git a/test/stubs/contacts/find_all b/test/stubs/contacts/find_all
index 2749ea4..5ba8521 100644
--- a/test/stubs/contacts/find_all
+++ b/test/stubs/contacts/find_all
@@ -18,7 +18,7 @@ Content-Type: application/xml; charset=utf-8
Bloggs
en
- Organisation Name
+ Organisation Name - Demo
01234 567890
BS1 2AW
diff --git a/test/stubs/contacts/find_single b/test/stubs/contacts/find_single
index 68f2361..50a933b 100644
--- a/test/stubs/contacts/find_single
+++ b/test/stubs/contacts/find_single
@@ -17,7 +17,7 @@ Content-Type: application/xml; charset=utf-8
Bloggs
en
- Organisation Name
+ Organisation Name - Demo
01234 567890
BS1 2AW