avvo_api 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -1
- data/README.rdoc +6 -6
- data/avvo_api.gemspec +2 -1
- data/examples/avvo_cli.rb +11 -14
- data/lib/avvo_api.rb +1 -4
- data/lib/avvo_api/address.rb +3 -5
- data/lib/avvo_api/headshot.rb +3 -5
- data/lib/avvo_api/language.rb +4 -6
- data/lib/avvo_api/lawyer.rb +44 -3
- data/lib/avvo_api/phone.rb +4 -8
- data/lib/avvo_api/review.rb +5 -7
- data/lib/avvo_api/school.rb +6 -8
- data/lib/avvo_api/specialty.rb +6 -8
- data/lib/avvo_api/version.rb +1 -1
- data/test/unit/address_test.rb +5 -8
- data/test/unit/base_test.rb +38 -38
- data/test/unit/headshot_test.rb +1 -5
- data/test/unit/language_test.rb +0 -3
- data/test/unit/phone_test.rb +2 -2
- data/test/unit/review_test.rb +0 -3
- data/test/unit/school_test.rb +0 -3
- data/test/unit/specialty_test.rb +0 -3
- metadata +73 -73
- data/lib/avvo_api/advanced_training.rb +0 -35
- data/lib/avvo_api/doctor.rb +0 -22
- data/lib/avvo_api/professional_methods.rb +0 -52
- data/test/unit/advanced_training_test.rb +0 -11
- data/test/unit/doctor_test.rb +0 -46
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
This gem provides an
|
4
4
|
{ActiveResource}[http://api.rubyonrails.org/classes/ActiveResource/Base.html]-based
|
5
|
-
client to information on {Avvo}[http://www.avvo.com], a directory of lawyers
|
5
|
+
client to information on {Avvo}[http://www.avvo.com], a directory of lawyers.
|
6
6
|
|
7
7
|
== Requirements
|
8
8
|
|
@@ -50,14 +50,14 @@ or
|
|
50
50
|
|
51
51
|
AvvoApi::Headshot.find(:one, :params => {:lawyer_id => 28995}).headshot_url
|
52
52
|
|
53
|
-
=== Getting a list of addresses for a
|
53
|
+
=== Getting a list of addresses for a lawyer
|
54
54
|
|
55
|
-
addresses = AvvoApi::
|
55
|
+
addresses = AvvoApi::Lawyer.find(28995).addresses
|
56
56
|
|
57
57
|
or
|
58
58
|
|
59
|
-
addresses = AvvoApi::Address.find(:all, :params => {:
|
59
|
+
addresses = AvvoApi::Address.find(:all, :params => {:lawyer_id => lawyer.id})
|
60
60
|
|
61
|
-
=== Getting the main address for a
|
61
|
+
=== Getting the main address for a lawyer
|
62
62
|
|
63
|
-
main_address = AvvoApi::Address.main(:
|
63
|
+
main_address = AvvoApi::Address.main(:lawyer_id => lawyer.id)
|
data/avvo_api.gemspec
CHANGED
@@ -12,10 +12,11 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = %q{An ActiveResource client to the Avvo API}
|
13
13
|
s.description = %q{An ActiveResource client to the Avvo API}
|
14
14
|
|
15
|
+
s.add_dependency "activeresource", '~> 3.0.0'
|
15
16
|
s.add_dependency "reactive_resource", '~> 0.5'
|
16
17
|
s.add_development_dependency "shoulda", '~> 2.11.3'
|
17
18
|
s.add_development_dependency "webmock", '~> 1.6.1'
|
18
|
-
|
19
|
+
|
19
20
|
s.rubyforge_project = "avvo_api"
|
20
21
|
|
21
22
|
s.files = `git ls-files`.split("\n")
|
data/examples/avvo_cli.rb
CHANGED
@@ -9,16 +9,13 @@ require 'avvo_api'
|
|
9
9
|
professional_klass = nil
|
10
10
|
professional_param = nil
|
11
11
|
|
12
|
-
opts = OptionParser.new("Usage: avvo_cli.rb
|
13
|
-
opts.on("-l", "--lawyer", "Get details about a lawyer") { professional_klass = AvvoApi::Lawyer; professional_param = :lawyer_id }
|
14
|
-
opts.on("-d", "--doctor", "Get details about a doctor") { professional_klass = AvvoApi::Doctor; professional_param = :doctor_id }
|
12
|
+
opts = OptionParser.new("Usage: avvo_cli.rb ID")
|
15
13
|
rest = opts.parse ARGV
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
elsif !rest.first
|
15
|
+
professional_klass = AvvoApi::Lawyer
|
16
|
+
professional_param = :lawyer_id
|
17
|
+
|
18
|
+
if !rest.first
|
22
19
|
puts "You must specify the ID of the professional you are looking for"
|
23
20
|
puts opts
|
24
21
|
exit(1)
|
@@ -32,8 +29,8 @@ password: your_avvo_password"
|
|
32
29
|
exit(1)
|
33
30
|
end
|
34
31
|
AvvoApi.setup(config["email"], config["password"])
|
35
|
-
AvvoApi::Base.site = '
|
36
|
-
|
32
|
+
AvvoApi::Base.site = 'https://api.avvo.com/'
|
33
|
+
|
37
34
|
professional = professional_klass.find(rest.first)
|
38
35
|
|
39
36
|
address = AvvoApi::Address.main(professional_param => professional.id)
|
@@ -55,12 +52,12 @@ password: your_avvo_password"
|
|
55
52
|
phones.each do |phone|
|
56
53
|
printf format, "#{phone.phone_type}:", phone.phone_number
|
57
54
|
end
|
58
|
-
|
55
|
+
|
59
56
|
specialties.each_with_index do |specialty, i|
|
60
57
|
header = i == 0 ? "Specialties:" : ""
|
61
58
|
printf format, header, "#{specialty.specialty_name.strip} (#{specialty.specialty_percent}%)"
|
62
59
|
end
|
63
|
-
|
60
|
+
|
64
61
|
puts
|
65
62
|
printf format, "Reviews ", ''
|
66
63
|
reviews.each do |review|
|
@@ -68,7 +65,7 @@ password: your_avvo_password"
|
|
68
65
|
printf format, "Title:", review.title
|
69
66
|
printf format, "URL:", review.url
|
70
67
|
printf format, "By:", review.posted_by
|
71
|
-
puts
|
68
|
+
puts
|
72
69
|
end
|
73
|
-
|
70
|
+
|
74
71
|
end
|
data/lib/avvo_api.rb
CHANGED
@@ -1,20 +1,17 @@
|
|
1
1
|
require 'avvo_api/base'
|
2
|
-
require 'avvo_api/professional_methods'
|
3
2
|
|
4
3
|
# The Avvo API Client. All API models live in this module.
|
5
4
|
module AvvoApi
|
6
5
|
|
7
6
|
autoload :Lawyer, 'avvo_api/lawyer'
|
8
|
-
autoload :Doctor, 'avvo_api/doctor'
|
9
7
|
autoload :School, 'avvo_api/school'
|
10
8
|
autoload :Address, 'avvo_api/address'
|
11
9
|
autoload :Phone, 'avvo_api/phone'
|
12
10
|
autoload :Language, 'avvo_api/language'
|
13
11
|
autoload :Specialty, 'avvo_api/specialty'
|
14
12
|
autoload :Headshot, 'avvo_api/headshot'
|
15
|
-
autoload :AdvancedTraining, 'avvo_api/advanced_training'
|
16
13
|
autoload :Review, 'avvo_api/review'
|
17
|
-
|
14
|
+
|
18
15
|
# Tells this client to use +email+ and +password+ to authenticate to
|
19
16
|
# the Avvo API.
|
20
17
|
def self.setup(email, password)
|
data/lib/avvo_api/address.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
# Represents an address.
|
1
|
+
# Represents an address. The following attribute MUST
|
2
2
|
# be set when using this model:
|
3
|
-
#
|
4
|
-
# * doctor_id
|
3
|
+
#
|
5
4
|
# * lawyer_id
|
6
5
|
#
|
7
6
|
# This model has the following attributes:
|
@@ -14,10 +13,9 @@
|
|
14
13
|
# * postal_code
|
15
14
|
# * latitude
|
16
15
|
# * longitude
|
17
|
-
#
|
16
|
+
#
|
18
17
|
class AvvoApi::Address < AvvoApi::Base
|
19
18
|
belongs_to :lawyer
|
20
|
-
belongs_to :doctor
|
21
19
|
has_many :phones
|
22
20
|
|
23
21
|
# Returns the 'main' address associated with the passed in
|
data/lib/avvo_api/headshot.rb
CHANGED
@@ -3,18 +3,16 @@
|
|
3
3
|
#
|
4
4
|
# AvvoApi::Headshot.find(:one, :lawyer_id => l.id)
|
5
5
|
#
|
6
|
-
# When using this model,
|
7
|
-
#
|
8
|
-
# * doctor_id
|
6
|
+
# When using this model, The following attribute MUST be set:
|
7
|
+
#
|
9
8
|
# * lawyer_id
|
10
9
|
#
|
11
10
|
# This model has the following attribute:
|
12
11
|
#
|
13
12
|
# * headshot_url: The url to the standard-size headshot.
|
14
|
-
#
|
13
|
+
#
|
15
14
|
class AvvoApi::Headshot < AvvoApi::Base
|
16
15
|
singleton
|
17
16
|
|
18
17
|
belongs_to :lawyer
|
19
|
-
belongs_to :doctor
|
20
18
|
end
|
data/lib/avvo_api/language.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
# Represents a language.
|
1
|
+
# Represents a language. The following attribute MUST
|
2
2
|
# be set when using this model:
|
3
|
-
#
|
4
|
-
# * doctor_id
|
3
|
+
#
|
5
4
|
# * lawyer_id
|
6
5
|
#
|
7
6
|
# This model has the following attributes:
|
8
7
|
#
|
9
|
-
# * id
|
8
|
+
# * id
|
10
9
|
# * name: The language name.
|
11
10
|
# * specialty_id: The language id. 'name' takes priority over this if both are set.
|
12
|
-
#
|
11
|
+
#
|
13
12
|
class AvvoApi::Language < AvvoApi::Base
|
14
13
|
belongs_to :lawyer
|
15
|
-
belongs_to :doctor
|
16
14
|
end
|
data/lib/avvo_api/lawyer.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Represents a lawyer on Avvo. Attributes include:
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# * id: The id of this lawyer
|
4
4
|
# * firstname: the first name of this lawyer
|
5
5
|
# * middlename: the middle name of this lawyer
|
@@ -9,12 +9,53 @@
|
|
9
9
|
# * website_url
|
10
10
|
#
|
11
11
|
class AvvoApi::Lawyer < AvvoApi::Base
|
12
|
-
|
12
|
+
|
13
13
|
has_many :addresses
|
14
14
|
has_many :reviews
|
15
15
|
has_many :schools
|
16
16
|
has_many :languages
|
17
17
|
has_many :specialties
|
18
18
|
has_one :headshot
|
19
|
-
|
19
|
+
|
20
|
+
# Search avvo for a list of the top 10 professionals matching the
|
21
|
+
# passed-in parameters. Accepts the following parameters:
|
22
|
+
#
|
23
|
+
# [q] The search query
|
24
|
+
# [loc] The location to search in
|
25
|
+
#
|
26
|
+
# These parameters match the search boxes on the Avvo website.
|
27
|
+
#
|
28
|
+
# This method pre-dates the REST API, and thus returns a hash of
|
29
|
+
# data rather than API objects. Hopefully, we'll eventually come
|
30
|
+
# up with something better. To see an actual response, look at
|
31
|
+
# http://api.avvo.com/docs/get/lawyers/search.html
|
32
|
+
def self.search(params)
|
33
|
+
response = self.get(:search, params)
|
34
|
+
|
35
|
+
if response && response['num_results']
|
36
|
+
response
|
37
|
+
else
|
38
|
+
raise ActiveResource::ResourceNotFound.new(response)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Attempts to find a professional on Avvo that matches the
|
43
|
+
# passed-in params. Currently accepts the following params:
|
44
|
+
#
|
45
|
+
# [name] The full name of the lawyer you are trying to find
|
46
|
+
# [phone] The phone number of the lawyer, in the format XXX-XXX-XXXX
|
47
|
+
# [fax] The fax number of the lawyer, in the format XXX-XXX-XXXX
|
48
|
+
# [address] The full address of the lawyer
|
49
|
+
# [zip_code] The zip code of the lawyer
|
50
|
+
# [email_address] The e-mail address of the lawyer
|
51
|
+
def self.resolve(params)
|
52
|
+
response = self.get(:resolve, :params => params)
|
53
|
+
if response && response[collection_name]
|
54
|
+
response[collection_name].map do |params|
|
55
|
+
new(params.merge({"annotation" => response['annotation']}))
|
56
|
+
end
|
57
|
+
else
|
58
|
+
raise ActiveResource::ResourceNotFound.new(response)
|
59
|
+
end
|
60
|
+
end
|
20
61
|
end
|
data/lib/avvo_api/phone.rb
CHANGED
@@ -14,19 +14,15 @@ module AvvoApi::PhoneType
|
|
14
14
|
MOBILE = 4
|
15
15
|
end
|
16
16
|
|
17
|
-
# Represents a phone number tied to an address.
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# * doctor_id
|
21
|
-
# * lawyer_id
|
17
|
+
# Represents a phone number tied to an address. The following
|
18
|
+
# attributes MUST be set when using this model:
|
22
19
|
#
|
23
|
-
#
|
24
|
-
#
|
20
|
+
# * lawyer_id
|
25
21
|
# * address_id
|
26
22
|
#
|
27
23
|
# This model has the following attributes:
|
28
24
|
#
|
29
|
-
# * id
|
25
|
+
# * id
|
30
26
|
# * phone_number: The phone number. Will be normalized by Avvo.
|
31
27
|
# * phone_type_id: The type of the phone number, as an AvvoApi::PhoneType
|
32
28
|
# constant. (Only applicable when creating or updating records)
|
data/lib/avvo_api/review.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
# Represents a review for a professional.
|
2
|
-
#
|
3
|
-
#
|
4
|
-
# * doctor_id
|
1
|
+
# Represents a review for a professional. The following attribute
|
2
|
+
# MUST be set when using this model:
|
3
|
+
#
|
5
4
|
# * lawyer_id
|
6
5
|
#
|
7
6
|
# This model has the following attributes:
|
8
7
|
#
|
9
|
-
# * id
|
8
|
+
# * id
|
10
9
|
# * overall_rating: The overall rating (out of 5 stars) given by this review.
|
11
10
|
# * title: The review's title
|
12
11
|
# * body: The first 150 characters of the review's body
|
@@ -14,8 +13,7 @@
|
|
14
13
|
# * posted_by: The author of the review
|
15
14
|
# * posted_at: The date this review was posted
|
16
15
|
# * updated_at: The last time this review was updated
|
17
|
-
#
|
16
|
+
#
|
18
17
|
class AvvoApi::Review < AvvoApi::Base
|
19
18
|
belongs_to :lawyer
|
20
|
-
belongs_to :doctor
|
21
19
|
end
|
data/lib/avvo_api/school.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
|
-
# Represents a school attended by a professional.
|
2
|
-
#
|
3
|
-
#
|
4
|
-
# * doctor_id
|
1
|
+
# Represents a school attended by a professional. The following
|
2
|
+
# attribute MUST be set when using this model:
|
3
|
+
#
|
5
4
|
# * lawyer_id
|
6
5
|
#
|
7
6
|
# This model has the following attributes:
|
8
7
|
#
|
9
|
-
# * id
|
8
|
+
# * id
|
10
9
|
# * name: The name of the school. When set, this will be resolved by Avvo.
|
11
10
|
# * 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.
|
11
|
+
# * degree_area_name: Major or area of study. Will be resolved by Avvo.
|
13
12
|
# * graduation_date: The date the professional graduated from this school.
|
14
|
-
#
|
13
|
+
#
|
15
14
|
class AvvoApi::School < AvvoApi::Base
|
16
15
|
belongs_to :lawyer
|
17
|
-
belongs_to :doctor
|
18
16
|
end
|
data/lib/avvo_api/specialty.rb
CHANGED
@@ -1,19 +1,17 @@
|
|
1
|
-
# Represents a specialty.
|
2
|
-
#
|
3
|
-
#
|
4
|
-
# * doctor_id
|
1
|
+
# Represents a specialty. The following attribute MUST be set when
|
2
|
+
# using this model:
|
3
|
+
#
|
5
4
|
# * lawyer_id
|
6
5
|
#
|
7
6
|
# This model has the following attributes:
|
8
7
|
#
|
9
|
-
# * id
|
10
|
-
# * specialty_name: The name of this specialty.
|
8
|
+
# * id
|
9
|
+
# * specialty_name: The name of this specialty.
|
11
10
|
# * specialty_percent: The percent of time this professional spends in this specialty
|
12
11
|
# * specialty_start_date: When this professional started practicing this specialty.
|
13
12
|
# * number_cases_handled: The number of cases handled within this specialty
|
14
13
|
# * description: Additional information about this specialty.
|
15
|
-
#
|
14
|
+
#
|
16
15
|
class AvvoApi::Specialty < AvvoApi::Base
|
17
16
|
belongs_to :lawyer
|
18
|
-
belongs_to :doctor
|
19
17
|
end
|
data/lib/avvo_api/version.rb
CHANGED
data/test/unit/address_test.rb
CHANGED
@@ -6,23 +6,20 @@ class AvvoApi::AddressTest < Test::Unit::TestCase
|
|
6
6
|
should "belong_to :lawyer" do
|
7
7
|
assert_contains(AvvoApi::Address.belongs_to_associations.map(&:attribute), :lawyer)
|
8
8
|
end
|
9
|
-
should "belong_to :doctor" do
|
10
|
-
assert_contains(AvvoApi::Address.belongs_to_associations.map(&:attribute), :doctor)
|
11
|
-
end
|
12
9
|
end
|
13
10
|
|
14
|
-
context "AvvoApi::Address.main" do
|
15
|
-
|
16
|
-
setup do
|
11
|
+
context "AvvoApi::Address.main" do
|
12
|
+
|
13
|
+
setup do
|
17
14
|
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
15
|
@address = AvvoApi::Address.main(:lawyer_id => 1)
|
19
16
|
end
|
20
|
-
|
17
|
+
|
21
18
|
should "hit the correct url" do
|
22
19
|
assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/addresses/main.json")
|
23
20
|
end
|
24
21
|
|
25
|
-
should "setup the object correctly" do
|
22
|
+
should "setup the object correctly" do
|
26
23
|
assert_equal '98122', @address.postal_code
|
27
24
|
assert_equal 1, @address.prefix_options[:lawyer_id]
|
28
25
|
end
|
data/test/unit/base_test.rb
CHANGED
@@ -3,21 +3,21 @@ require 'test_helper'
|
|
3
3
|
class AvvoApi::BaseTest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
context "A resource that inherits from AvvoApi::Base" do
|
6
|
-
|
6
|
+
|
7
7
|
setup do
|
8
8
|
@object = AvvoApi::Lawyer.new
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
should "hit the Avvo API with the correct URL when saved" do
|
12
12
|
stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers.json")
|
13
13
|
@object.save
|
14
14
|
assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers.json")
|
15
15
|
end
|
16
16
|
|
17
|
-
should "hit the Avvo API with the correct URL when retrieved" do
|
17
|
+
should "hit the Avvo API with the correct URL when retrieved" do
|
18
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
19
|
AvvoApi::Lawyer.find(1)
|
20
|
-
assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1.json")
|
20
|
+
assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1.json")
|
21
21
|
end
|
22
22
|
|
23
23
|
context "with a has_many relationship to another object" do
|
@@ -39,26 +39,26 @@ class AvvoApi::BaseTest < Test::Unit::TestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
context "with a belongs_to association and correct parameters" do
|
42
|
-
setup do
|
42
|
+
setup do
|
43
43
|
@object = AvvoApi::Specialty.new(:lawyer_id => 2)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
should "hit the Avvo API with the correct URL when saved" do
|
47
47
|
stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties.json")
|
48
48
|
@object.save
|
49
49
|
assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties.json")
|
50
50
|
end
|
51
|
-
|
52
|
-
should "hit the Avvo API with the correct URL when retrieved" do
|
51
|
+
|
52
|
+
should "hit the Avvo API with the correct URL when retrieved" do
|
53
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
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")
|
55
|
+
assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties/3.json")
|
56
56
|
end
|
57
57
|
|
58
|
-
should "hit the Avvo API with the correct URL when updated" do
|
58
|
+
should "hit the Avvo API with the correct URL when updated" do
|
59
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
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")
|
61
|
+
assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties/3.json")
|
62
62
|
stub_request(:put, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties/3.json")
|
63
63
|
license.save
|
64
64
|
assert_requested(:put, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/specialties/3.json")
|
@@ -71,63 +71,63 @@ class AvvoApi::BaseTest < Test::Unit::TestCase
|
|
71
71
|
|
72
72
|
assert_equal "/api/1/lawyers/2/specialties/2.json", @object.send(:element_path)
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
end
|
76
76
|
|
77
|
-
context "with a belongs_to hierarchy and correct parameters" do
|
77
|
+
context "with a belongs_to hierarchy and correct parameters" do
|
78
78
|
|
79
|
-
setup do
|
80
|
-
@object = AvvoApi::Phone.new(:
|
79
|
+
setup do
|
80
|
+
@object = AvvoApi::Phone.new(:lawyer_id => 2, :address_id => 3)
|
81
81
|
end
|
82
82
|
|
83
83
|
should "allow setting the prefix options after creation" do
|
84
84
|
@object = AvvoApi::Phone.new
|
85
|
-
@object.
|
85
|
+
@object.lawyer_id = 2
|
86
86
|
@object.address_id = 3
|
87
|
-
stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/
|
87
|
+
stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/addresses/3/phones.json")
|
88
88
|
@object.save
|
89
|
-
assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/
|
89
|
+
assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/addresses/3/phones.json")
|
90
90
|
end
|
91
91
|
|
92
92
|
should "allow following +belongs_to+ associations" do
|
93
93
|
@object = AvvoApi::Phone.new
|
94
|
-
@object.
|
94
|
+
@object.lawyer_id = 2
|
95
95
|
@object.address_id = 3
|
96
96
|
assert_equal 3, @object.address_id
|
97
|
-
stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/
|
97
|
+
stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/addresses/3.json").to_return(:body => {:id => '3'}.to_json)
|
98
98
|
@object.address
|
99
99
|
@object.address
|
100
|
-
assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/
|
100
|
+
assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/addresses/3.json", :times => 1)
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
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/
|
104
|
+
stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/addresses/3/phones.json")
|
105
105
|
@object.save
|
106
|
-
assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/
|
106
|
+
assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/addresses/3/phones.json")
|
107
107
|
end
|
108
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/
|
111
|
-
phone = AvvoApi::Phone.find(4, :params => {:
|
112
|
-
assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/
|
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/lawyers/2/addresses/3/phones/4.json").to_return(:body => {:id => '4'}.to_json)
|
111
|
+
phone = AvvoApi::Phone.find(4, :params => {:lawyer_id => 2, :address_id => 3})
|
112
|
+
assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/addresses/3/phones/4.json")
|
113
113
|
|
114
|
-
stub_request(:put, "https://test_account%40avvo.com:password@api.avvo.com/api/1/
|
114
|
+
stub_request(:put, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/addresses/3/phones/4.json")
|
115
115
|
phone.save
|
116
|
-
assert_requested(:put, "https://test_account%40avvo.com:password@api.avvo.com/api/1/
|
116
|
+
assert_requested(:put, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/addresses/3/phones/4.json")
|
117
117
|
end
|
118
118
|
|
119
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/
|
120
|
+
stub_request(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/addresses/3/phones.json").to_return(:body => {:phone_type_id=>2, :id=>4, :phone_number=>"206-728-0588"}.to_json)
|
121
121
|
@object.save
|
122
|
-
assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/
|
122
|
+
assert_requested(:post, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/addresses/3/phones.json")
|
123
123
|
|
124
|
-
assert_equal "/api/1/
|
124
|
+
assert_equal "/api/1/lawyers/2/addresses/3/phones/4.json", @object.send(:element_path)
|
125
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/
|
129
|
-
AvvoApi::Phone.find(4, :params => {:
|
130
|
-
assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/
|
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/lawyers/2/addresses/3/phones/4.json").to_return(:body => {:id => '4'}.to_json)
|
129
|
+
AvvoApi::Phone.find(4, :params => {:lawyer_id => 2, :address_id => 3})
|
130
|
+
assert_requested(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/2/addresses/3/phones/4.json")
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
data/test/unit/headshot_test.rb
CHANGED
@@ -3,10 +3,6 @@ require 'test_helper'
|
|
3
3
|
class AvvoApi::HeadshotTest < Test::Unit::TestCase
|
4
4
|
|
5
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
6
|
|
11
7
|
should "belong_to :lawyer" do
|
12
8
|
assert_contains(AvvoApi::Headshot.belongs_to_associations.map(&:attribute), :lawyer)
|
@@ -38,7 +34,7 @@ class AvvoApi::HeadshotTest < Test::Unit::TestCase
|
|
38
34
|
@headshot = AvvoApi::Headshot.find(:one, :params => {:lawyer_id => 1})
|
39
35
|
stub_request(:delete, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/headshot.json")
|
40
36
|
@headshot.destroy
|
41
|
-
assert_requested(:delete, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/headshot.json")
|
37
|
+
assert_requested(:delete, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/headshot.json")
|
42
38
|
end
|
43
39
|
|
44
40
|
end
|
data/test/unit/language_test.rb
CHANGED
@@ -6,9 +6,6 @@ class AvvoApi::LanguageTest < Test::Unit::TestCase
|
|
6
6
|
should "belong_to :lawyer" do
|
7
7
|
assert_contains(AvvoApi::Language.belongs_to_associations.map(&:attribute), :lawyer)
|
8
8
|
end
|
9
|
-
should "belong_to :doctor" do
|
10
|
-
assert_contains(AvvoApi::Language.belongs_to_associations.map(&:attribute), :doctor)
|
11
|
-
end
|
12
9
|
end
|
13
10
|
|
14
11
|
end
|
data/test/unit/phone_test.rb
CHANGED
@@ -6,14 +6,14 @@ class AvvoApi::PhoneTest < Test::Unit::TestCase
|
|
6
6
|
should "belong_to :address" do
|
7
7
|
assert_contains(AvvoApi::Phone.belongs_to_associations.map(&:attribute), :address)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
should "build successfully with PhoneType constants" do
|
11
11
|
phone = AvvoApi::Phone.new(:phone_number => '2125551212', :phone_type_id => AvvoApi::PhoneType::OFFICE, :address_id => 1, :lawyer_id => 1)
|
12
12
|
assert_equal 2, phone.phone_type_id
|
13
13
|
end
|
14
14
|
|
15
15
|
should "be able to return a reasonable string for a phone type id" do
|
16
|
-
stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/addresses/1/phones/1.json").to_return(:body => {:id => 1, :phone_number => '212-555-1212', :phone_type => 'Office', :updated_at => Time.now}.to_json)
|
16
|
+
stub_request(:get, "https://test_account%40avvo.com:password@api.avvo.com/api/1/lawyers/1/addresses/1/phones/1.json").to_return(:body => {:id => 1, :phone_number => '212-555-1212', :phone_type => 'Office', :updated_at => Time.now.to_s}.to_json)
|
17
17
|
phone = AvvoApi::Phone.find(1, :params => {:lawyer_id => 1, :address_id => 1})
|
18
18
|
assert_equal "Office", phone.phone_type
|
19
19
|
end
|
data/test/unit/review_test.rb
CHANGED
@@ -6,9 +6,6 @@ class AvvoApi::ReviewTest < Test::Unit::TestCase
|
|
6
6
|
should "belong_to :lawyer" do
|
7
7
|
assert_contains(AvvoApi::Review.belongs_to_associations.map(&:attribute), :lawyer)
|
8
8
|
end
|
9
|
-
should "belong_to :doctor" do
|
10
|
-
assert_contains(AvvoApi::Review.belongs_to_associations.map(&:attribute), :doctor)
|
11
|
-
end
|
12
9
|
end
|
13
10
|
|
14
11
|
end
|
data/test/unit/school_test.rb
CHANGED
@@ -6,9 +6,6 @@ class AvvoApi::SchoolTest < Test::Unit::TestCase
|
|
6
6
|
should "belong_to :lawyer" do
|
7
7
|
assert_contains(AvvoApi::School.belongs_to_associations.map(&:attribute), :lawyer)
|
8
8
|
end
|
9
|
-
should "belong_to :doctor" do
|
10
|
-
assert_contains(AvvoApi::School.belongs_to_associations.map(&:attribute), :doctor)
|
11
|
-
end
|
12
9
|
end
|
13
10
|
|
14
11
|
end
|
data/test/unit/specialty_test.rb
CHANGED
@@ -6,9 +6,6 @@ class AvvoApi::SpecialtyTest < Test::Unit::TestCase
|
|
6
6
|
should "belong_to :lawyer" do
|
7
7
|
assert_contains(AvvoApi::Specialty.belongs_to_associations.map(&:attribute), :lawyer)
|
8
8
|
end
|
9
|
-
should "belong_to :doctor" do
|
10
|
-
assert_contains(AvvoApi::Specialty.belongs_to_associations.map(&:attribute), :doctor)
|
11
|
-
end
|
12
9
|
end
|
13
10
|
|
14
11
|
end
|
metadata
CHANGED
@@ -1,76 +1,87 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: avvo_api
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 1
|
9
|
-
version: 0.1.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Justin Weiss
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
date: 2012-11-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activeresource
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
21
31
|
name: reactive_resource
|
22
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
23
33
|
none: false
|
24
|
-
requirements:
|
34
|
+
requirements:
|
25
35
|
- - ~>
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
- 0
|
29
|
-
- 5
|
30
|
-
version: "0.5"
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.5'
|
31
38
|
type: :runtime
|
32
39
|
prerelease: false
|
33
|
-
version_requirements:
|
34
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.5'
|
46
|
+
- !ruby/object:Gem::Dependency
|
35
47
|
name: shoulda
|
36
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
37
49
|
none: false
|
38
|
-
requirements:
|
50
|
+
requirements:
|
39
51
|
- - ~>
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 2
|
43
|
-
- 11
|
44
|
-
- 3
|
52
|
+
- !ruby/object:Gem::Version
|
45
53
|
version: 2.11.3
|
46
54
|
type: :development
|
47
55
|
prerelease: false
|
48
|
-
version_requirements:
|
49
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.11.3
|
62
|
+
- !ruby/object:Gem::Dependency
|
50
63
|
name: webmock
|
51
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
52
65
|
none: false
|
53
|
-
requirements:
|
66
|
+
requirements:
|
54
67
|
- - ~>
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
segments:
|
57
|
-
- 1
|
58
|
-
- 6
|
59
|
-
- 1
|
68
|
+
- !ruby/object:Gem::Version
|
60
69
|
version: 1.6.1
|
61
70
|
type: :development
|
62
71
|
prerelease: false
|
63
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.6.1
|
64
78
|
description: An ActiveResource client to the Avvo API
|
65
|
-
email:
|
79
|
+
email:
|
66
80
|
- jweiss@avvo.com
|
67
81
|
executables: []
|
68
|
-
|
69
82
|
extensions: []
|
70
|
-
|
71
83
|
extra_rdoc_files: []
|
72
|
-
|
73
|
-
files:
|
84
|
+
files:
|
74
85
|
- .gitignore
|
75
86
|
- Gemfile
|
76
87
|
- Gemfile.lock
|
@@ -80,23 +91,18 @@ files:
|
|
80
91
|
- examples/avvo_cli.rb
|
81
92
|
- lib/avvo_api.rb
|
82
93
|
- lib/avvo_api/address.rb
|
83
|
-
- lib/avvo_api/advanced_training.rb
|
84
94
|
- lib/avvo_api/base.rb
|
85
|
-
- lib/avvo_api/doctor.rb
|
86
95
|
- lib/avvo_api/headshot.rb
|
87
96
|
- lib/avvo_api/language.rb
|
88
97
|
- lib/avvo_api/lawyer.rb
|
89
98
|
- lib/avvo_api/phone.rb
|
90
|
-
- lib/avvo_api/professional_methods.rb
|
91
99
|
- lib/avvo_api/review.rb
|
92
100
|
- lib/avvo_api/school.rb
|
93
101
|
- lib/avvo_api/specialty.rb
|
94
102
|
- lib/avvo_api/version.rb
|
95
103
|
- test/test_helper.rb
|
96
104
|
- test/unit/address_test.rb
|
97
|
-
- test/unit/advanced_training_test.rb
|
98
105
|
- test/unit/base_test.rb
|
99
|
-
- test/unit/doctor_test.rb
|
100
106
|
- test/unit/headshot_test.rb
|
101
107
|
- test/unit/language_test.rb
|
102
108
|
- test/unit/lawyer_test.rb
|
@@ -104,46 +110,40 @@ files:
|
|
104
110
|
- test/unit/review_test.rb
|
105
111
|
- test/unit/school_test.rb
|
106
112
|
- test/unit/specialty_test.rb
|
107
|
-
has_rdoc: true
|
108
113
|
homepage: http://api.avvo.com
|
109
114
|
licenses: []
|
110
|
-
|
111
115
|
post_install_message:
|
112
116
|
rdoc_options: []
|
113
|
-
|
114
|
-
require_paths:
|
117
|
+
require_paths:
|
115
118
|
- lib
|
116
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
120
|
none: false
|
118
|
-
requirements:
|
119
|
-
- -
|
120
|
-
- !ruby/object:Gem::Version
|
121
|
-
|
122
|
-
segments:
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
segments:
|
123
126
|
- 0
|
124
|
-
|
125
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
hash: -3858919658491321272
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
129
|
none: false
|
127
|
-
requirements:
|
128
|
-
- -
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
|
131
|
-
segments:
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
segments:
|
132
135
|
- 0
|
133
|
-
|
136
|
+
hash: -3858919658491321272
|
134
137
|
requirements: []
|
135
|
-
|
136
138
|
rubyforge_project: avvo_api
|
137
|
-
rubygems_version: 1.
|
139
|
+
rubygems_version: 1.8.24
|
138
140
|
signing_key:
|
139
141
|
specification_version: 3
|
140
142
|
summary: An ActiveResource client to the Avvo API
|
141
|
-
test_files:
|
143
|
+
test_files:
|
142
144
|
- test/test_helper.rb
|
143
145
|
- test/unit/address_test.rb
|
144
|
-
- test/unit/advanced_training_test.rb
|
145
146
|
- test/unit/base_test.rb
|
146
|
-
- test/unit/doctor_test.rb
|
147
147
|
- test/unit/headshot_test.rb
|
148
148
|
- test/unit/language_test.rb
|
149
149
|
- test/unit/lawyer_test.rb
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# Constants representing the possible values of the
|
2
|
-
# advanced_training_type_id parameter of AvvoApi::AdvancedTraining
|
3
|
-
module AvvoApi::AdvancedTrainingType
|
4
|
-
|
5
|
-
# Unknown training type
|
6
|
-
UNKNOWN = 1
|
7
|
-
|
8
|
-
# Represents an internship
|
9
|
-
INTERNSHIP = 2
|
10
|
-
|
11
|
-
# Represents a residency
|
12
|
-
RESIDENCY = 3
|
13
|
-
|
14
|
-
# Represents a fellowship
|
15
|
-
FELLOWSHIP = 4
|
16
|
-
end
|
17
|
-
|
18
|
-
# Represents advanced training, like residencies, for doctors. This
|
19
|
-
# model is only applicable to doctors. The following attributes MUST
|
20
|
-
# be set when using this model:
|
21
|
-
#
|
22
|
-
# * doctor_id
|
23
|
-
#
|
24
|
-
# This model has the following attributes:
|
25
|
-
#
|
26
|
-
# * id - The model's id
|
27
|
-
# * advanced_training_type_id - an AvvoApi::AdvancedTrainingType constant
|
28
|
-
# * specialty_name - The name of the specialty this advanced training is in
|
29
|
-
# * hospital_name - The normalized name of the hospital. This will be
|
30
|
-
# resolved by Avvo when it is set by this client.
|
31
|
-
# * graduation_date - The date this training was completed
|
32
|
-
#
|
33
|
-
class AvvoApi::AdvancedTraining < AvvoApi::Base
|
34
|
-
belongs_to :doctor
|
35
|
-
end
|
data/lib/avvo_api/doctor.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# Represents a doctor on Avvo. Attributes include:
|
2
|
-
#
|
3
|
-
# * id: The id of this doctor
|
4
|
-
# * firstname: the first name of this doctor
|
5
|
-
# * middlename: the middle name of this doctor
|
6
|
-
# * lastname: the last name of this doctor
|
7
|
-
# * suffix: the suffix of the doctor's name
|
8
|
-
# * avvo_rating: The doctor's Avvo Rating, from 0.0 to 10.0
|
9
|
-
# * email_address
|
10
|
-
# * website_url
|
11
|
-
# * profile_url
|
12
|
-
#
|
13
|
-
class AvvoApi::Doctor < AvvoApi::Base
|
14
|
-
has_many :addresses
|
15
|
-
has_many :reviews
|
16
|
-
has_many :schools
|
17
|
-
has_many :languages
|
18
|
-
has_many :specialties
|
19
|
-
has_many :advanced_trainings
|
20
|
-
has_one :headshot
|
21
|
-
include AvvoApi::ProfessionalMethods
|
22
|
-
end
|
@@ -1,52 +0,0 @@
|
|
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
|
@@ -1,11 +0,0 @@
|
|
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
|
data/test/unit/doctor_test.rb
DELETED
@@ -1,46 +0,0 @@
|
|
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¶ms%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¶ms%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
|