Class: OpenCongress::OpenCongressObject
- Inherits:
-
Object
- Object
- OpenCongress::OpenCongressObject
show all
- Defined in:
- lib/opencongress_ruby.rb
Class Method Summary
collapse
Class Method Details
.construct_url(api_method, params) ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/opencongress_ruby.rb', line 14
def self.construct_url(api_method, params)
url = nil
if OpenCongress.api_key == nil || OpenCongress.api_key == ''
raise "Failed to provide OpenCongress API Key"
else
url = "#{API_URL}#{api_method}?key=#{OpenCongress.api_key}#{hash2get(params)}&format=json"
end
return url
end
|
.hash2get(h) ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/opencongress_ruby.rb', line 24
def self.hash2get(h)
get_string = ""
h.each_pair do |key, value|
get_string += "&#{key.to_s}=#{CGI::escape(value.to_s)}"
end
get_string
end
|
.make_call(this_url) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/opencongress_ruby.rb', line 77
def self.make_call(this_url)
result = nil
begin
result = JSON.parse(open(this_url).read)
rescue => e
puts e
end
return result
end
|
.parse_supporting_results(result) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/opencongress_ruby.rb', line 34
def self.parse_supporting_results(result)
working = result["opencongress_users_tracking"]
also_supporting_bills = []
working["also_supporting_bills"]["bill"].each do |bill|
also_supporting_bills << OCBill.new(bill)
end
also_opposing_bills = []
working["also_opposing_bills"]["bill"].each do |bill|
also_opposing_bills << OCBill.new(bill)
end
also_disapproved_senators = []
working["also_disapproved_senators"]["person"].each do |person|
also_disapproved_senators << OCPerson.new(person)
end
also_disapproved_representatives = []
working["also_disapproved_representatives"]["person"].each do |person|
also_disapproved_representatives << OCPerson.new(person)
end
also_approved_senators = []
working["also_approved_senators"]["person"].each do |person|
also_approved_senators << OCPerson.new(person)
end
also_approved_representatives = []
working["also_approved_representatives"]["person"].each do |person|
also_approved_representatives << OCPerson.new(person)
end
return {:also_supporting_bills => also_supporting_bills,
:also_opposing_bills => also_opposing_bills,
:also_disapproved_senators => also_disapproved_senators,
:also_disapproved_representatives => also_disapproved_representatives,
:also_approved_senators => also_approved_senators,
:also_approved_representatives => also_approved_representatives}
end
|