examples/avvo_cli.rb in avvo_api-0.1.1 vs examples/avvo_cli.rb in avvo_api-0.2.0

- old
+ new

@@ -7,20 +7,17 @@ require 'avvo_api' professional_klass = nil professional_param = nil -opts = OptionParser.new("Usage: avvo_cli.rb [options] ID") -opts.on("-l", "--lawyer", "Get details about a lawyer") { professional_klass = AvvoApi::Lawyer; professional_param = :lawyer_id } -opts.on("-d", "--doctor", "Get details about a doctor") { professional_klass = AvvoApi::Doctor; professional_param = :doctor_id } +opts = OptionParser.new("Usage: avvo_cli.rb ID") rest = opts.parse ARGV -if !professional_klass - puts "You must specify either --lawyer or --doctor" - puts opts - exit(1) -elsif !rest.first +professional_klass = AvvoApi::Lawyer +professional_param = :lawyer_id + +if !rest.first puts "You must specify the ID of the professional you are looking for" puts opts exit(1) else begin @@ -30,12 +27,12 @@ email: email@domain.com password: your_avvo_password" exit(1) end AvvoApi.setup(config["email"], config["password"]) - AvvoApi::Base.site = 'http://localhost.local:3000' - + AvvoApi::Base.site = 'https://api.avvo.com/' + professional = professional_klass.find(rest.first) address = AvvoApi::Address.main(professional_param => professional.id) phones = address.phones specialties = professional.specialties @@ -53,22 +50,22 @@ printf format, "", address.city + ", " + address.state + " " + address.postal_code phones.each do |phone| printf format, "#{phone.phone_type}:", phone.phone_number end - + specialties.each_with_index do |specialty, i| header = i == 0 ? "Specialties:" : "" printf format, header, "#{specialty.specialty_name.strip} (#{specialty.specialty_percent}%)" end - + puts printf format, "Reviews ", '' reviews.each do |review| printf format, "Rating:", review.overall_rating printf format, "Title:", review.title printf format, "URL:", review.url printf format, "By:", review.posted_by - puts + puts end - + end