governator 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/governator/civil_services.rb +44 -0
- data/lib/governator/version.rb +1 -1
- data/lib/governator.rb +24 -7
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a54cbc572f205a119acb57bf0546ff422bd4d430
|
4
|
+
data.tar.gz: 61f4feb76adf915a28131704f48054d9fde1e6c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cb65c51cc9394242e14744f5890f7552ef9426130a0a3da3ed3103a8e55e4edb21a314ef76e9bc428e2f0061753048ef939659ff87448e620b6b500efb29cc9
|
7
|
+
data.tar.gz: 56dc48561762376bd16672cebcb71cf6604df3a0226a48834292c1d64c2956c7161b937c972f115121cbdaf87f637a2c998f3314fdc405e80eb792d5eafd2c05
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Governator
|
4
|
+
class CivilServices
|
5
|
+
def self.json
|
6
|
+
@_json ||= JSON.parse Faraday.get(
|
7
|
+
'https://raw.githubusercontent.com/CivilServiceUSA/us-governors'\
|
8
|
+
'/master/us-governors/data/us-governors.json'
|
9
|
+
).body
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :governor
|
13
|
+
|
14
|
+
def initialize(governor)
|
15
|
+
@governor = governor
|
16
|
+
end
|
17
|
+
|
18
|
+
def twitter
|
19
|
+
record['twitter_handle'] if record
|
20
|
+
end
|
21
|
+
|
22
|
+
def facebook
|
23
|
+
if record && record['facebook_url']
|
24
|
+
@_facebook ||= record['facebook_url'].sub('https://www.facebook.com/', '')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def photo_url
|
29
|
+
record['photo_url'] if record
|
30
|
+
end
|
31
|
+
|
32
|
+
def contact_form
|
33
|
+
record['contact_page'] if record
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def record
|
39
|
+
@_record ||= self.class.json.detect do |record|
|
40
|
+
record['last_name'] == governor.last && record['state_name'] == governor.state_name
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/governator/version.rb
CHANGED
data/lib/governator.rb
CHANGED
@@ -5,6 +5,7 @@ require 'nokogiri'
|
|
5
5
|
require 'twitter'
|
6
6
|
|
7
7
|
require 'governator/bio_page'
|
8
|
+
require 'governator/civil_services'
|
8
9
|
require 'governator/name_parser'
|
9
10
|
require 'governator/panel'
|
10
11
|
require 'governator/twitter_client'
|
@@ -110,7 +111,15 @@ class Governator
|
|
110
111
|
end
|
111
112
|
|
112
113
|
def photo_url
|
113
|
-
|
114
|
+
civil_services.photo_url || BASE_URI + panel.image
|
115
|
+
end
|
116
|
+
|
117
|
+
def facebook
|
118
|
+
civil_services.facebook
|
119
|
+
end
|
120
|
+
|
121
|
+
def contact_form
|
122
|
+
civil_services.contact_form
|
114
123
|
end
|
115
124
|
|
116
125
|
private
|
@@ -124,18 +133,26 @@ class Governator
|
|
124
133
|
|
125
134
|
@first, @last, @middle, @nickname, @suffix = NameParser.new(official_full).parse
|
126
135
|
build_office_locations
|
127
|
-
fetch_twitter_handle
|
136
|
+
fetch_twitter_handle
|
128
137
|
self
|
129
138
|
end
|
130
139
|
|
140
|
+
def civil_services
|
141
|
+
@_civil_services ||= CivilServices.new(self)
|
142
|
+
end
|
143
|
+
|
131
144
|
def fetch_twitter_handle
|
132
|
-
|
133
|
-
|
134
|
-
tg[:
|
135
|
-
|
145
|
+
if self.class.use_twitter == true
|
146
|
+
twitter_governor = TwitterClient.governors.detect do |tg|
|
147
|
+
tg[:name].match?(last) && (
|
148
|
+
tg[:location].match?(state_name) || tg[:description].match?(state_name)
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
152
|
+
@twitter = twitter_governor[:screen_name] if twitter_governor
|
136
153
|
end
|
137
154
|
|
138
|
-
@twitter =
|
155
|
+
@twitter = civil_services.twitter if twitter.nil?
|
139
156
|
end
|
140
157
|
|
141
158
|
def build_office_locations
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: governator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- M. Simon Borg
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- governator.png
|
100
100
|
- lib/governator.rb
|
101
101
|
- lib/governator/bio_page.rb
|
102
|
+
- lib/governator/civil_services.rb
|
102
103
|
- lib/governator/name_parser.rb
|
103
104
|
- lib/governator/page_scraper.rb
|
104
105
|
- lib/governator/panel.rb
|