Class: VoteSmartApi

Inherits:
GenericApi show all
Includes:
HTTParty
Defined in:
lib/apis/vote_smart_api.rb

Instance Method Summary collapse

Methods inherited from GenericApi

#initialized?

Instance Method Details

#candidate_find_for_office_and_state(office, state) ⇒ Object


65
66
67
# File 'lib/apis/vote_smart_api.rb', line 65

def candidate_find_for_office_and_state(office, state)
  get_votesmart_candidate("/Candidate.getByOfficeState", :query => {:officeId => office, :stateId => state})
end

#candidate_fuzzy_find(lastname) ⇒ Object


53
54
55
# File 'lib/apis/vote_smart_api.rb', line 53

def candidate_fuzzy_find(lastname)
  get_votesmart_candidate("/Candidates.getByLevenstein", :query => {:lastName => lastname})
end

#candidate_getBio(candidateId) ⇒ Object


61
62
63
# File 'lib/apis/vote_smart_api.rb', line 61

def candidate_getBio(candidateId)
  get_votesmart_candidate("/Candidate.getBio", :query => {:candidateId => candidateId})
end

#get_votesmart_candidate(method_name, query) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/apis/vote_smart_api.rb', line 38

def get_votesmart_candidate(method_name, query)
  begin
    result = VoteSmartApi.get(method_name, query)
  rescue Net::HTTPServerException => exception
    puts "\nEXCEPTION: from votesmart_api #{method_name}: #{exception.response.body}"
    return nil
  end
  if result.has_key?("error")
    puts "\nERROR: from votesmart_api #{method_name}: #{result["error"]["errorMessage"]}"
    return nil
  else
    result["candidateList"]["candidate"]
  end
end

#key=(key) ⇒ Object

Simply declare and remember the API Key


33
34
35
36
# File 'lib/apis/vote_smart_api.rb', line 33

def key=(key)
  @api_key = key
  VoteSmartApi.default_params :key => key
end

#officials_fuzzy_find(lastname) ⇒ Object


57
58
59
# File 'lib/apis/vote_smart_api.rb', line 57

def officials_fuzzy_find(lastname)
  get_votesmart_candidate("/Officials.getByLevenstein", :query => {:lastName => lastname})
end