avvo_api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ module AvvoApi::ProfessionalMethods # :nodoc:
2
+
3
+ # Methods that are shared between professionals.
4
+ module ClassMethods
5
+
6
+ # Search avvo for a list of the top 10 professionals matching the
7
+ # passed-in parameters. Accepts the following parameters:
8
+ #
9
+ # [q] The search query
10
+ # [loc] The location to search in
11
+ #
12
+ # These parameters match the search boxes on the Avvo website.
13
+ #
14
+ # This method pre-dates the REST API, and thus returns a hash of
15
+ # data rather than API objects. Hopefully, we'll eventually come
16
+ # up with something better. To see an actual response, look at
17
+ # http://api.avvo.com/docs/get/lawyers/search.html
18
+ def search(params)
19
+ response = self.get(:search, params)
20
+
21
+ if response && response['num_results']
22
+ response
23
+ else
24
+ raise ActiveResource::ResourceNotFound.new(response)
25
+ end
26
+ end
27
+
28
+ # Attempts to find a professional on Avvo that matches the
29
+ # passed-in params. Currently accepts the following params:
30
+ #
31
+ # [name] The full name of the lawyer you are trying to find
32
+ # [phone] The phone number of the lawyer, in the format XXX-XXX-XXXX
33
+ # [fax] The fax number of the lawyer, in the format XXX-XXX-XXXX
34
+ # [address] The full address of the lawyer
35
+ # [zip_code] The zip code of the lawyer
36
+ # [email_address] The e-mail address of the lawyer
37
+ def resolve(params)
38
+ response = self.get(:resolve, :params => params)
39
+ if response && response[collection_name]
40
+ response[collection_name].map do |params|
41
+ new(params.merge({"annotation" => response['annotation']}))
42
+ end
43
+ else
44
+ raise ActiveResource::ResourceNotFound.new(response)
45
+ end
46
+ end
47
+ end
48
+
49
+ def self.included(base)
50
+ base.send(:extend, ClassMethods)
51
+ end
52
+ end
@@ -0,0 +1,21 @@
1
+ # Represents a review for a professional. One of the following
2
+ # attributes MUST be set when using this model:
3
+ #
4
+ # * doctor_id
5
+ # * lawyer_id
6
+ #
7
+ # This model has the following attributes:
8
+ #
9
+ # * id
10
+ # * overall_rating: The overall rating (out of 5 stars) given by this review.
11
+ # * title: The review's title
12
+ # * body: The first 150 characters of the review's body
13
+ # * url: A link to the review on Avvo
14
+ # * posted_by: The author of the review
15
+ # * posted_at: The date this review was posted
16
+ # * updated_at: The last time this review was updated
17
+ #
18
+ class AvvoApi::Review < AvvoApi::Base
19
+ belongs_to :lawyer
20
+ belongs_to :doctor
21
+ end
@@ -0,0 +1,18 @@
1
+ # Represents a school attended by a professional. One of the following
2
+ # attributes MUST be set when using this model:
3
+ #
4
+ # * doctor_id
5
+ # * lawyer_id
6
+ #
7
+ # This model has the following attributes:
8
+ #
9
+ # * id
10
+ # * name: The name of the school. When set, this will be resolved by Avvo.
11
+ # * degree_level_name: The level of degree awarded at this school. BA, BS, JD, etc. Will be resolved by Avvo.
12
+ # * degree_area_name: Major or area of study. Will be resolved by Avvo.
13
+ # * graduation_date: The date the professional graduated from this school.
14
+ #
15
+ class AvvoApi::School < AvvoApi::Base
16
+ belongs_to :lawyer
17
+ belongs_to :doctor
18
+ end
@@ -0,0 +1,19 @@
1
+ # Represents a specialty. One of the following attributes MUST
2
+ # be set when using this model:
3
+ #
4
+ # * doctor_id
5
+ # * lawyer_id
6
+ #
7
+ # This model has the following attributes:
8
+ #
9
+ # * id
10
+ # * specialty_name: The name of this specialty.
11
+ # * specialty_percent: The percent of time this professional spends in this specialty
12
+ # * specialty_start_date: When this professional started practicing this specialty.
13
+ # * number_cases_handled: The number of cases handled within this specialty
14
+ # * description: Additional information about this specialty.
15
+ #
16
+ class AvvoApi::Specialty < AvvoApi::Base
17
+ belongs_to :lawyer
18
+ belongs_to :doctor
19
+ end
@@ -0,0 +1,3 @@
1
+ module AvvoApi
2
+ VERSION = "0.1.0" # :nodoc:
3
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'avvo_api'
4
+
5
+ require 'shoulda'
6
+
7
+ require 'webmock/test_unit'
8
+ class Test::Unit::TestCase
9
+ include WebMock::API
10
+ end
11
+
12
+ AvvoApi.setup('test_account@avvo.com', 'password')
13
+
14
+ WebMock.disable_net_connect!
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+
3
+ class AvvoApi::AddressTest < Test::Unit::TestCase
4
+
5
+ context "AvvoApi::Address" do
6
+ should "belong_to :lawyer" do
7
+ assert_contains(AvvoApi::Address.belongs_to_associations.map(&:attribute), :lawyer)
8
+ end
9
+ should "belong_to :doctor" do
10
+ assert_contains(AvvoApi::Address.belongs_to_associations.map(&:attribute), :doctor)
11
+ end
12
+ end
13
+
14
+ context "AvvoApi::Address.main" do
15
+
16
+ setup do
17
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/addresses/main.json").to_return(:body => {:id => '1', :postal_code => '98122'}.to_json)
18
+ @address = AvvoApi::Address.main(:lawyer_id => 1)
19
+ end
20
+
21
+ should "hit the correct url" do
22
+ assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/addresses/main.json")
23
+ end
24
+
25
+ should "setup the object correctly" do
26
+ assert_equal '98122', @address.postal_code
27
+ assert_equal 1, @address.prefix_options[:lawyer_id]
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class AvvoApi::AdvancedTrainingTest < Test::Unit::TestCase
4
+
5
+ context "AvvoApi::AdvancedTraining" do
6
+ should "belong_to :doctor" do
7
+ assert_contains(AvvoApi::AdvancedTraining.belongs_to_associations.map(&:attribute), :doctor)
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,135 @@
1
+ require 'test_helper'
2
+
3
+ class AvvoApi::BaseTest < Test::Unit::TestCase
4
+
5
+ context "A resource that inherits from AvvoApi::Base" do
6
+
7
+ setup do
8
+ @object = AvvoApi::Lawyer.new
9
+ end
10
+
11
+ should "hit the Avvo API with the correct URL when saved" do
12
+ stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers.json")
13
+ @object.save
14
+ assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers.json")
15
+ end
16
+
17
+ should "hit the Avvo API with the correct URL when retrieved" do
18
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1.json").to_return(:body => {:id => '1'}.to_json)
19
+ AvvoApi::Lawyer.find(1)
20
+ assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1.json")
21
+ end
22
+
23
+ context "with a has_many relationship to another object" do
24
+ should "hit the associated object's URL with the correct parameters when requested" do
25
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/addresses.json")
26
+ @object.id = 1
27
+ @object.addresses
28
+ assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/addresses.json")
29
+ end
30
+ end
31
+
32
+ context "with a has_one relationship to another object" do
33
+ should "hit the associated object's URL with the correct parameters when requested" do
34
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/headshot.json").to_return(:body => {:headshot_url => "blah"}.to_json)
35
+ @object.id = 1
36
+ @object.headshot
37
+ assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/headshot.json")
38
+ end
39
+ end
40
+
41
+ context "with a belongs_to association and correct parameters" do
42
+ setup do
43
+ @object = AvvoApi::Specialty.new(:lawyer_id => 2)
44
+ end
45
+
46
+ should "hit the Avvo API with the correct URL when saved" do
47
+ stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties.json")
48
+ @object.save
49
+ assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties.json")
50
+ end
51
+
52
+ should "hit the Avvo API with the correct URL when retrieved" do
53
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties/3.json").to_return(:body => {:id => '3'}.to_json)
54
+ AvvoApi::Specialty.find(3, :params => {:lawyer_id => 2})
55
+ assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties/3.json")
56
+ end
57
+
58
+ should "hit the Avvo API with the correct URL when updated" do
59
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties/3.json").to_return(:body => {:id => '3', :specialty_id => "88", :specialty_id => '88', :specialty_percent => '100'}.to_json)
60
+ license = AvvoApi::Specialty.find(3, :params => {:lawyer_id => 2})
61
+ assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties/3.json")
62
+ stub_request(:put, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties/3.json")
63
+ license.save
64
+ assert_requested(:put, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties/3.json")
65
+ end
66
+
67
+ should "set the prefix parameters correctly when saved" do
68
+ stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties.json").to_return(:body => {:id => '2', :specialty_id => "88", :specialty_id => '88', :specialty_percent => '100'}.to_json)
69
+ @object.save
70
+ assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties.json")
71
+
72
+ assert_equal "/api/1/lawyers/2/specialties/2.json", @object.send(:element_path)
73
+ end
74
+
75
+ end
76
+
77
+ context "with a belongs_to hierarchy and correct parameters" do
78
+
79
+ setup do
80
+ @object = AvvoApi::Phone.new(:doctor_id => 2, :address_id => 3)
81
+ end
82
+
83
+ should "allow setting the prefix options after creation" do
84
+ @object = AvvoApi::Phone.new
85
+ @object.doctor_id = 2
86
+ @object.address_id = 3
87
+ stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/2/addresses/3/phones.json")
88
+ @object.save
89
+ assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/2/addresses/3/phones.json")
90
+ end
91
+
92
+ should "allow following +belongs_to+ associations" do
93
+ @object = AvvoApi::Phone.new
94
+ @object.doctor_id = 2
95
+ @object.address_id = 3
96
+ assert_equal 3, @object.address_id
97
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/2/addresses/3.json").to_return(:body => {:id => '3'}.to_json)
98
+ @object.address
99
+ @object.address
100
+ assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/2/addresses/3.json", :times => 1)
101
+ end
102
+
103
+ should "hit the Avvo API with the correct URL when saved" do
104
+ stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/2/addresses/3/phones.json")
105
+ @object.save
106
+ assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/2/addresses/3/phones.json")
107
+ end
108
+
109
+ should "hit the Avvo API with the correct URL when updated" do
110
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/2/addresses/3/phones/4.json").to_return(:body => {:id => '4'}.to_json)
111
+ phone = AvvoApi::Phone.find(4, :params => {:doctor_id => 2, :address_id => 3})
112
+ assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/2/addresses/3/phones/4.json")
113
+
114
+ stub_request(:put, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/2/addresses/3/phones/4.json")
115
+ phone.save
116
+ assert_requested(:put, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/2/addresses/3/phones/4.json")
117
+ end
118
+
119
+ should "set the prefix parameters correctly when saved" do
120
+ stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/2/addresses/3/phones.json").to_return(:body => {:phone_type_id=>2, :id=>4, :phone_number=>"206-728-0588"}.to_json)
121
+ @object.save
122
+ assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/2/addresses/3/phones.json")
123
+
124
+ assert_equal "/api/1/doctors/2/addresses/3/phones/4.json", @object.send(:element_path)
125
+ end
126
+
127
+ should "hit the Avvo API with the correct URL when retrieved" do
128
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/2/addresses/3/phones/4.json").to_return(:body => {:id => '4'}.to_json)
129
+ AvvoApi::Phone.find(4, :params => {:doctor_id => 2, :address_id => 3})
130
+ assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/2/addresses/3/phones/4.json")
131
+ end
132
+ end
133
+
134
+ end
135
+ end
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+
3
+ class AvvoApi::DoctorTest < Test::Unit::TestCase
4
+
5
+ context "A valid doctor object" do
6
+ setup do
7
+ @doctor = AvvoApi::Doctor.new(valid_doctor_params)
8
+ stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors.json").to_return(:body => doctor_1.to_json)
9
+ end
10
+
11
+ should "#save successfully" do
12
+ assert @doctor.save, "doctor could not be saved"
13
+ assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors.json")
14
+ assert_equal "1", @doctor.id
15
+ end
16
+ end
17
+
18
+ context "AvvoApi::Doctor.resolve" do
19
+
20
+ should "return the appropriate doctors" do
21
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/resolve.json?params%5Bname%5D=Mark%20Britton&params%5Bzip_code%5D=98101").to_return(:body => {:doctors => [{:id => 1}]}.to_json)
22
+ doctors = AvvoApi::Doctor.resolve({:name => 'Mark Britton', :zip_code => 98101})
23
+ assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/doctors/resolve.json?params%5Bname%5D=Mark%20Britton&params%5Bzip_code%5D=98101")
24
+ assert_equal 1, doctors.length
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def valid_doctor_params
31
+ {
32
+ :firstname => 'Bob',
33
+ :lastname => 'Bobson',
34
+ :npi_number => '123456'
35
+ }
36
+ end
37
+
38
+ def doctor_1
39
+ {
40
+ :firstname => 'Bob',
41
+ :lastname => 'Bobson',
42
+ :id => '1'
43
+ }
44
+ end
45
+
46
+ end
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+
3
+ class AvvoApi::HeadshotTest < Test::Unit::TestCase
4
+
5
+ context "AvvoApi::Headshot" do
6
+
7
+ should "belong_to :doctor" do
8
+ assert_contains(AvvoApi::Headshot.belongs_to_associations.map(&:attribute), :doctor)
9
+ end
10
+
11
+ should "belong_to :lawyer" do
12
+ assert_contains(AvvoApi::Headshot.belongs_to_associations.map(&:attribute), :lawyer)
13
+ end
14
+
15
+ should "get the correct url" do
16
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/headshot.json").to_return(:body => {:headshot_url => "blah"}.to_json)
17
+ AvvoApi::Headshot.find(:one, :params => {:lawyer_id => 1})
18
+ assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/headshot.json")
19
+ end
20
+
21
+ should "be able to create a new headshot" do
22
+ @headshot = AvvoApi::Headshot.new(:lawyer_id => 1)
23
+ stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/headshot.json")
24
+ @headshot.save
25
+ assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/headshot.json")
26
+ end
27
+
28
+ should "be able to update an existing headshot" do
29
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/headshot.json").to_return(:body => {:headshot_url => "blah"}.to_json)
30
+ @headshot = AvvoApi::Headshot.find(:one, :params => {:lawyer_id => 1})
31
+ stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/headshot.json")
32
+ @headshot.save
33
+ assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/headshot.json")
34
+ end
35
+
36
+ should "be able to destroy a headshot" do
37
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/headshot.json").to_return(:body => {:headshot_url => "blah"}.to_json)
38
+ @headshot = AvvoApi::Headshot.find(:one, :params => {:lawyer_id => 1})
39
+ stub_request(:delete, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/headshot.json")
40
+ @headshot.destroy
41
+ assert_requested(:delete, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/headshot.json")
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class AvvoApi::LanguageTest < Test::Unit::TestCase
4
+
5
+ context "AvvoApi::Language" do
6
+ should "belong_to :lawyer" do
7
+ assert_contains(AvvoApi::Language.belongs_to_associations.map(&:attribute), :lawyer)
8
+ end
9
+ should "belong_to :doctor" do
10
+ assert_contains(AvvoApi::Language.belongs_to_associations.map(&:attribute), :doctor)
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,170 @@
1
+ require 'test_helper'
2
+
3
+ class AvvoApi::LawyerTest < Test::Unit::TestCase
4
+
5
+ context "A valid lawyer object" do
6
+ setup do
7
+ @lawyer = AvvoApi::Lawyer.new(valid_lawyer_params)
8
+ stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers.json").to_return(:body => lawyer_1.to_json)
9
+ end
10
+
11
+ should "#save successfully" do
12
+ assert @lawyer.save, "lawyer could not be saved"
13
+ assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers.json")
14
+ assert_equal "1", @lawyer.id
15
+ end
16
+ end
17
+
18
+ context "An invalid lawyer object" do
19
+ setup do
20
+ @lawyer = AvvoApi::Lawyer.new(invalid_lawyer_params)
21
+ stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers.json").to_return(:body => lawyer_errors.to_json, :status => 422)
22
+ @lawyer.save
23
+ end
24
+
25
+ should "not be created on the server when #save is called" do
26
+ assert_equal nil, @lawyer.id
27
+ end
28
+
29
+ should "have errors on the firstname attribute" do
30
+ assert_match "can't be blank", @lawyer.errors.on(:firstname)
31
+ end
32
+ end
33
+
34
+ context "AvvoApi::Lawyer.find" do
35
+ setup do
36
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1.json").to_return(:body => lawyer_1.to_json)
37
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2.json").to_return(:body => '', :status => 404)
38
+ end
39
+
40
+ should "return a lawyer when called with an existing id" do
41
+ @lawyer = AvvoApi::Lawyer.find(1)
42
+ assert_equal "Bob", @lawyer.firstname
43
+ assert_equal 'Mr.', @lawyer.prefix
44
+ end
45
+
46
+ should "raise an exception when called with a nonexistent id" do
47
+ assert_raises ActiveResource::ResourceNotFound do
48
+ @lawyer = AvvoApi::Lawyer.find(2)
49
+ end
50
+ end
51
+ end
52
+
53
+ context "AvvoApi::Lawyer.search" do
54
+ setup do
55
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/search.json?q=dui").to_return(:body => search_results.to_json)
56
+ end
57
+
58
+ should "return a hash of lawyer info" do
59
+ @results = AvvoApi::Lawyer.search(:q => 'dui')
60
+ assert_equal 2, @results["num_results"]
61
+ assert_equal "Bill T. Lawyer", @results["results"].last["name"]
62
+ assert_equal "DUI", @results["results"].first["specialties"].first["name"]
63
+ end
64
+ end
65
+
66
+ context "AvvoApi::Lawyer.resolve" do
67
+
68
+ should "return the appropriate lawyer" do
69
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/resolve.json?params%5Bname%5D=Mark%20Britton&params%5Bzip_code%5D=98101").to_return(:body => {:lawyers => [{:id => 1}]}.to_json)
70
+ lawyers = AvvoApi::Lawyer.resolve({:name => 'Mark Britton', :zip_code => 98101})
71
+ assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/resolve.json?params%5Bname%5D=Mark%20Britton&params%5Bzip_code%5D=98101")
72
+ assert_equal 1, lawyers.length
73
+ end
74
+
75
+ should "return an empty array if the lawyer can't be found" do
76
+ stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/resolve.json?params%5Bname%5D=Mark%20Britton&params%5Bzip_code%5D=98101").to_return(:body => {:lawyers => []}.to_json)
77
+ lawyers = AvvoApi::Lawyer.resolve({:name => 'Mark Britton', :zip_code => 98101})
78
+ assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/resolve.json?params%5Bname%5D=Mark%20Britton&params%5Bzip_code%5D=98101")
79
+ assert_equal 0, lawyers.length
80
+
81
+ end
82
+ end
83
+
84
+ private
85
+
86
+ def valid_lawyer_params
87
+ {
88
+ :firstname => 'Bob',
89
+ :lastname => 'Bobson',
90
+ }
91
+ end
92
+
93
+ def invalid_lawyer_params
94
+ valid_lawyer_params.tap {|p| p["firstname"] = ""}
95
+ end
96
+
97
+ def lawyer_1
98
+ {
99
+ :firstname => 'Bob',
100
+ :lastname => 'Bobson',
101
+ :prefix => 'Mr.',
102
+ :id => '1'
103
+ }
104
+ end
105
+
106
+ def lawyer_errors
107
+ {
108
+ :errors => [
109
+ "Firstname can't be blank"
110
+ ]
111
+ }
112
+ end
113
+
114
+ def search_results
115
+ {
116
+ "num_results" => 2,
117
+ "results" => [
118
+ {
119
+ "id" => 1,
120
+ "name" => "Bob the Lawyer",
121
+ "avvo_rating" => 5.0,
122
+ "client_rating" => 5.0,
123
+ "client_rating_count" => 10,
124
+ "specialties" => [
125
+ {
126
+ "name" => "DUI",
127
+ "percent" => 75
128
+ },
129
+ {
130
+ "name" => "Criminal Defense",
131
+ "percent" => 25
132
+ }
133
+ ],
134
+ "sponsored" => true,
135
+ "ad_details" => {
136
+ "tagline" => "I'm the best! Pick me!",
137
+ "website" => "http://www.avvo.com"
138
+ },
139
+ "phone" => "212-555-1212",
140
+ "address" => "123 Fake St., Seattle, WA 98121",
141
+ "tiny_image_url" => "http://media.avvo.com/ugc/images/head_shot/tinythumbnail_large/1.jpg",
142
+ "image_url" => "http://media.avvo.com/ugc/images/head_shot/thumbnail_large/1.jpg",
143
+ "profile_url" => "http://www.avvo.com/attorneys/1.html",
144
+ "client_reviews_url" => "http://www.avvo.com/attorneys/1/reviews.html"
145
+ },
146
+ {
147
+ "id" => 2,
148
+ "name" => "Bill T. Lawyer",
149
+ "avvo_rating" => 10.0,
150
+ "client_rating" => 0.0,
151
+ "client_rating_count" => 0,
152
+ "specialties" => [
153
+ {
154
+ "name" => "DUI",
155
+ "percent" => 100
156
+ }
157
+ ],
158
+ "sponsored" => false,
159
+ "phone" => "212-555-1213",
160
+ "address" => "123 Fake St., Suite 2B, Seattle, WA 98121",
161
+ "tiny_image_url" => "http://media.avvo.com/ugc/images/head_shot/tinythumbnail_large/2.jpg",
162
+ "image_url" => "http://media.avvo.com/ugc/images/head_shot/thumbnail_large/2.jpg",
163
+ "profile_url" => "http://www.avvo.com/attorneys/2.html",
164
+ "client_reviews_url" => "http://www.avvo.com/attorneys/2/reviews.html"
165
+ },
166
+ ],
167
+ }
168
+ end
169
+
170
+ end