Skip to content

Commit

Permalink
Adding Contact.find_by_name. Also the authenticate method now returns…
Browse files Browse the repository at this point in the history
… true instead of your password.
  • Loading branch information
drcapulet committed Jun 2, 2010
1 parent f9fca6c commit 884e17f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -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"]
Expand Down
10 changes: 6 additions & 4 deletions lib/freeagent_api.rb
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/contact_test.rb
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/stubs/contacts/find_all
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion test/stubs/contacts/find_single
Expand Up @@ -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>
Expand Down

0 comments on commit 884e17f

Please sign in to comment.