rughetto-sunlight 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,22 +1,6 @@
1
1
  module Sunlight
2
2
  class Legislator < SunlightObject
3
3
 
4
- attr_accessor :title, :firstname, :middlename, :lastname, :name_suffix, :nickname,
5
- :party, :state, :district, :gender, :phone, :fax, :website, :webform,
6
- :email, :congress_office, :bioguide_id, :votesmart_id, :fec_id,
7
- :govtrack_id, :crp_id, :event_id, :congresspedia_url, :youtube_url,
8
- :twitter_id
9
-
10
- # Takes in a hash where the keys are strings (the format passed in by the JSON parser)
11
- #
12
- def initialize(params)
13
- params.each do |key, value|
14
- instance_variable_set("@#{key}", value) if Legislator.instance_methods.include? key
15
- end
16
- end
17
-
18
-
19
-
20
4
  #
21
5
  # Useful for getting the exact Legislators for a given district.
22
6
  #
@@ -37,7 +21,6 @@ module Sunlight
37
21
  # Legislator.all_for(:address => "90210") # not recommended, but it'll work
38
22
  #
39
23
  def self.all_for(params)
40
-
41
24
  if (params[:latitude] and params[:longitude])
42
25
  Legislator.all_in_district(District.get(:latitude => params[:latitude], :longitude => params[:longitude]))
43
26
  elsif (params[:address])
@@ -45,7 +28,6 @@ module Sunlight
45
28
  else
46
29
  nil # appropriate params not found
47
30
  end
48
-
49
31
  end
50
32
 
51
33
 
@@ -58,13 +40,11 @@ module Sunlight
58
40
  # officials = Legislator.all_in_district(District.new("NJ", "7"))
59
41
  #
60
42
  def self.all_in_district(district)
61
-
62
43
  senior_senator = Legislator.all_where(:state => district.state, :district => "Senior Seat").first
63
44
  junior_senator = Legislator.all_where(:state => district.state, :district => "Junior Seat").first
64
45
  representative = Legislator.all_where(:state => district.state, :district => district.number).first
65
46
 
66
47
  {:senior_senator => senior_senator, :junior_senator => junior_senator, :representative => representative}
67
-
68
48
  end
69
49
 
70
50
 
@@ -85,26 +65,17 @@ module Sunlight
85
65
  # dudes = Legislator.all_where(:gender => "M")
86
66
  #
87
67
  def self.all_where(params)
88
-
89
68
  url = construct_url("legislators.getList", params)
90
-
91
69
  if (result = get_json_data(url))
92
-
93
70
  legislators = []
94
71
  result["response"]["legislators"].each do |legislator|
95
72
  legislators << Legislator.new(legislator["legislator"])
96
73
  end
97
-
98
74
  legislators
99
-
100
75
  else
101
76
  nil
102
- end # if response.class
103
-
77
+ end
104
78
  end
105
79
 
106
-
107
-
108
- end # class Legislator
109
-
110
- end # module Sunlight
80
+ end # Legislator
81
+ end # Sunlight
@@ -1,6 +1,27 @@
1
1
  module Sunlight
2
2
  # Houses general methods to work with the Sunlight and Google Maps APIs
3
3
  class SunlightObject
4
+
5
+ #
6
+ # Takes in a hash where the keys are strings (the format passed in by the JSON parser)
7
+ # if the class does not already have a attr_accessor one is created in the class
8
+ def initialize(params={})
9
+ params.each do |key, value|
10
+ unless self.class.instance_methods.include?(key)
11
+ add_accessor( key )
12
+ end
13
+ instance_variable_set("@#{key}", value)
14
+ end
15
+ end
16
+
17
+ private
18
+ def add_accessor( key )
19
+ self.class.class_eval do
20
+ attr_accessor key.to_sym
21
+ end
22
+ end
23
+ public
24
+
4
25
  def self.api_url
5
26
  "http://services.sunlightlabs.com/api/"
6
27
  end
data/sunlight.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "sunlight"
3
- s.version = "0.1.2"
3
+ s.version = "0.1.3"
4
4
  s.date = "2009-01-28"
5
5
  s.summary = "Library for accessing the Sunlight Labs API."
6
6
  s.email = "ru_ghetto@rubyghetto.com"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rughetto-sunlight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luigi Montanez