twfy 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/History.txt +6 -0
- data/LICENSE.txt +35 -0
- data/README.md +99 -0
- data/Rakefile +7 -19
- data/lib/twfy/api.rb +47 -0
- data/lib/twfy/client.rb +84 -0
- data/lib/twfy/commands.rb +73 -0
- data/lib/twfy/constituency.rb +15 -0
- data/lib/twfy/data_element.rb +62 -0
- data/lib/twfy/geometry.rb +17 -0
- data/lib/twfy/mp.rb +39 -0
- data/lib/twfy/validation.rb +88 -0
- data/lib/twfy/version.rb +3 -0
- data/lib/twfy.rb +12 -175
- data/test/fixtures/vcr_cassettes/client_test.yml +2723 -0
- data/test/fixtures/vcr_cassettes/data_element_test.yml +240 -0
- data/test/{test_twfy.rb → lib/twfy/client_test.rb} +13 -15
- data/test/{test_twfy_chain.rb → lib/twfy/data_element_test.rb} +12 -16
- data/test/test_helper.rb +38 -0
- data/twfy.gemspec +29 -0
- metadata +156 -76
- data/Manifest.txt +0 -9
- data/README.txt +0 -108
- data/lib/data_element.rb +0 -101
- data/test/api_key +0 -1
@@ -0,0 +1,240 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://www.theyworkforyou.com/api/getMP?key=<API_KEY>&postcode=IP6%209PN&version=1.0.0
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- '*/*'
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Last-Modified:
|
22
|
+
- Fri, 07 May 2010 02:51:26 +0100
|
23
|
+
Content-Type:
|
24
|
+
- text/javascript; charset=iso-8859-1
|
25
|
+
X-Url:
|
26
|
+
- /api/getMP?postcode=IP6+9PN&key=<API_KEY>&version=1.0.0
|
27
|
+
Content-Length:
|
28
|
+
- '506'
|
29
|
+
Accept-Ranges:
|
30
|
+
- bytes
|
31
|
+
Date:
|
32
|
+
- Wed, 13 Nov 2013 00:52:16 GMT
|
33
|
+
Age:
|
34
|
+
- '3'
|
35
|
+
Connection:
|
36
|
+
- keep-alive
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: '{"member_id":"40156","house":"1","first_name":"Daniel","last_name":"Poulter","constituency":"Central
|
40
|
+
Suffolk and North Ipswich","party":"Conservative","entered_house":"2010-05-06","left_house":"9999-12-31","entered_reason":"general_election","left_reason":"still_in_office","person_id":"24756","title":"","lastupdate":"2010-05-07
|
41
|
+
02:51:26","full_name":"Daniel Poulter","url":"/mp/24756/daniel_poulter/central_suffolk_and_north_ipswich","image":"/images/mpsL/24756.jpeg","image_height":118,"image_width":78}'
|
42
|
+
http_version:
|
43
|
+
recorded_at: Wed, 13 Nov 2013 00:52:16 GMT
|
44
|
+
- request:
|
45
|
+
method: get
|
46
|
+
uri: http://www.theyworkforyou.com/api/getGeometry?key=<API_KEY>&name=Central%20Suffolk%20and%20North%20Ipswich&version=1.0.0
|
47
|
+
body:
|
48
|
+
encoding: US-ASCII
|
49
|
+
string: ''
|
50
|
+
headers:
|
51
|
+
Accept-Encoding:
|
52
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
53
|
+
Accept:
|
54
|
+
- '*/*'
|
55
|
+
User-Agent:
|
56
|
+
- Ruby
|
57
|
+
response:
|
58
|
+
status:
|
59
|
+
code: 200
|
60
|
+
message: OK
|
61
|
+
headers:
|
62
|
+
Content-Type:
|
63
|
+
- text/javascript; charset=iso-8859-1
|
64
|
+
X-Url:
|
65
|
+
- /api/getGeometry?name=Central+Suffolk+and+North+Ipswich&key=<API_KEY>&version=1.0.0
|
66
|
+
Content-Length:
|
67
|
+
- '359'
|
68
|
+
Accept-Ranges:
|
69
|
+
- bytes
|
70
|
+
Date:
|
71
|
+
- Wed, 13 Nov 2013 00:52:16 GMT
|
72
|
+
Age:
|
73
|
+
- '4'
|
74
|
+
Connection:
|
75
|
+
- keep-alive
|
76
|
+
body:
|
77
|
+
encoding: UTF-8
|
78
|
+
string: '{"max_e":636672.1,"srid_en":27700,"area":796226596.18,"max_n":283760.6,"min_lat":52.0407410207,"max_lat":52.4044029233,"centre_n":263028.158509,"max_lon":1.46434493435,"centre_lon":1.22112407587,"min_n":242895.4,"parts":1,"centre_e":620106.539681,"min_e":602204.5,"min_lon":0.951515301231,"centre_lat":52.2215670245,"name":"Central
|
79
|
+
Suffolk and North Ipswich"}'
|
80
|
+
http_version:
|
81
|
+
recorded_at: Wed, 13 Nov 2013 00:52:17 GMT
|
82
|
+
- request:
|
83
|
+
method: get
|
84
|
+
uri: http://www.theyworkforyou.com/api/getMPInfo?id=24756&key=<API_KEY>&version=1.0.0
|
85
|
+
body:
|
86
|
+
encoding: US-ASCII
|
87
|
+
string: ''
|
88
|
+
headers:
|
89
|
+
Accept-Encoding:
|
90
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
91
|
+
Accept:
|
92
|
+
- '*/*'
|
93
|
+
User-Agent:
|
94
|
+
- Ruby
|
95
|
+
response:
|
96
|
+
status:
|
97
|
+
code: 200
|
98
|
+
message: OK
|
99
|
+
headers:
|
100
|
+
Last-Modified:
|
101
|
+
- Tue, 12 Nov 2013 03:38:59 +0000
|
102
|
+
Content-Type:
|
103
|
+
- text/javascript; charset=iso-8859-1
|
104
|
+
X-Url:
|
105
|
+
- /api/getMPInfo?id=24756&key=<API_KEY>&version=1.0.0
|
106
|
+
Content-Length:
|
107
|
+
- '6072'
|
108
|
+
Accept-Ranges:
|
109
|
+
- bytes
|
110
|
+
Date:
|
111
|
+
- Wed, 13 Nov 2013 00:52:16 GMT
|
112
|
+
Age:
|
113
|
+
- '4'
|
114
|
+
Connection:
|
115
|
+
- keep-alive
|
116
|
+
body:
|
117
|
+
encoding: UTF-8
|
118
|
+
string: '{"comments_on_speeches":"2","comments_on_speeches_quintile":"3","comments_on_speeches_rank":"450","comments_on_speeches_rank_joint":"48","comments_on_speeches_rank_outof":"650","debate_sectionsspoken_inlastyear":"32","debate_sectionsspoken_inlastyear_quintile":"2","debate_sectionsspoken_inlastyear_rank":"314","debate_sectionsspoken_inlastyear_rank_joint":"8","debate_sectionsspoken_inlastyear_rank_outof":"650","maiden_speech":"uk.org.publicwhip/debate/2010-06-22c.151.6","public_whip_dreammp1052_absent":"0","public_whip_dreammp1052_both_voted":"2","public_whip_dreammp1052_distance":"0","public_whip_dreammp1053_absent":"0","public_whip_dreammp1053_both_voted":"1","public_whip_dreammp1053_distance":"0","public_whip_dreammp1065_absent":"0","public_whip_dreammp1065_both_voted":"4","public_whip_dreammp1065_distance":"0.0833333","public_whip_dreammp1074_absent":"1","public_whip_dreammp1074_both_voted":"10","public_whip_dreammp1074_distance":"0.0641026","public_whip_dreammp1084_absent":"0","public_whip_dreammp1084_both_voted":"1","public_whip_dreammp1084_distance":"1","public_whip_dreammp1109_absent":"0","public_whip_dreammp1109_both_voted":"2","public_whip_dreammp1109_distance":"0","public_whip_dreammp1110_absent":"0","public_whip_dreammp1110_both_voted":"10","public_whip_dreammp1110_distance":"0","public_whip_dreammp1124_absent":"0","public_whip_dreammp1124_both_voted":"1","public_whip_dreammp1124_distance":"0","public_whip_dreammp1132_absent":"0","public_whip_dreammp1132_both_voted":"1","public_whip_dreammp1132_distance":"0","public_whip_dreammp811_absent":"0","public_whip_dreammp811_both_voted":"1","public_whip_dreammp811_distance":"0","public_whip_dreammp826_absent":"0","public_whip_dreammp826_both_voted":"4","public_whip_dreammp826_distance":"0","public_whip_dreammp984_absent":"0","public_whip_dreammp984_both_voted":"1","public_whip_dreammp984_distance":"0","reading_ease":"47.0414979003198","reading_ease_quintile":"4","reading_ease_rank":"534","reading_ease_rank_outof":"645","reading_year":"14.2795015913675","reading_year_quintile":"0","reading_year_rank":"81","reading_year_rank_outof":"645","register_member_interests_date":"2013-10-28","register_member_interests_html":"<div
|
119
|
+
class=\"regmemcategory\">2. Remunerated employment, office, profession etc</div>\n<div
|
120
|
+
class=\"regmemitem\"> Medical doctor</div>\n","select_committees":"0","select_committees_chair":"0","three_word_alliterations":"167","three_word_alliterations_quintile":"2","three_word_alliterations_rank":"363","three_word_alliterations_rank_joint":"2","three_word_alliterations_rank_outof":"650","three_word_alliteration_content":":to
|
121
|
+
take to:will work with:make my maiden:true that throughout:he has had:that
|
122
|
+
the treatment:it is important:that the true:the time that:the time to:and
|
123
|
+
about a:to trust them:it is impossible:think that there:should support such:to
|
124
|
+
tailor their:has he had:is invest in:it is important:to talk to:profit per
|
125
|
+
pig:it is important:onus on our:when we were:time to time:industry is in:be
|
126
|
+
bad because:should show some:after an ageing:through talking therapies:on
|
127
|
+
one of:bodies being bandied:it is important:important in improving:and alcohol
|
128
|
+
abuse:to try to:whereas\n\nwhat we:if it is:when we were:thanks to the:that
|
129
|
+
the two:all agree about:that they take:which we will:the train through:to
|
130
|
+
tackle the:think that there:important issue in:it is in:it is important:to
|
131
|
+
tackle these:to tackle this:it is important:tribute to the:it is important:investment
|
132
|
+
in increasing:support system should:women whom we:save social services:it
|
133
|
+
is important:the time that:specialist surgical services:it is important:it
|
134
|
+
is important:it is important:it is important:together to try:it is important:and
|
135
|
+
as a:work with women:way we would:at an average:has huge health:it is important:workers
|
136
|
+
who work:be brought back:party political points:not necessarily need:tribute
|
137
|
+
to the:it is important:why we would:trusts throughout the:interest in it:that
|
138
|
+
these things:also attracted attention:to travel to:important it is:the time
|
139
|
+
they:taking the time:turn to the:are available across:tribute to the:to talk
|
140
|
+
to:training thanks to:it is important:to tackle the:are already available:and
|
141
|
+
an ageing:reducing readmission rates:tribute to the:it is important:together
|
142
|
+
to talk:are at a:say something specifically:to try to:to take things:to their
|
143
|
+
task:to the trust:to talk through:operate out of:transfer times to:that the
|
144
|
+
trust:that the trust:thought that the:accrued as a:that trust to:that the
|
145
|
+
time:and accident and:to the table:to tackle that:it is irresponsible:the
|
146
|
+
talking therapies:it is important:and at a:it is important:testament to the:against
|
147
|
+
accident and:it is important:an accident and:it is ironic:that the trust:is
|
148
|
+
important in:it is important:to the task:tribute to the:funding formula for:formula
|
149
|
+
for funding:appointed as a:true that tariff:tribute to the:is implicit in:to
|
150
|
+
the topics:to their task:investing in integration:the trust to:that the trust:the
|
151
|
+
trust to:to talk through:tribute to the:are also amending:about as a:to talk
|
152
|
+
that:and are a:are anticipating a:and an ageing:issues in improving:tools
|
153
|
+
that the:to talk this:tribute to the:thanks to the:what went wrong:to try
|
154
|
+
to:thanks to the:to tackle them:it is important:and appropriate and:trying
|
155
|
+
to tighten","wikipedia_url":"http://en.wikipedia.org/wiki/Daniel_Poulter","wrans_answered_inlastyear":"1291","wrans_asked_inlastyear":"0","wrans_asked_inlastyear_quintile":"4","wrans_asked_inlastyear_rank":"525","wrans_asked_inlastyear_rank_joint":"126","wrans_asked_inlastyear_rank_outof":"650","wrans_departments":"Health,
|
156
|
+
Education, Environment Food and Rural Affairs, Energy and Climate Change,
|
157
|
+
Transport","wrans_subjects":"Poultry: Animal Welfare, General Practitioners,
|
158
|
+
NHS: Pensions, Ambulance Services: Standards, NHS: Drugs","by_member_id":{"40156":{"public_whip_division_attendance":"81.52%","public_whip_data_date":"2013-11-08","public_whip_rebellions":"1.92%","public_whip_rebelrank":"108","public_whip_attendrank":"163","public_whip_rebelrank_outof":"643","public_whip_attendrank_outof":"650"}}}'
|
159
|
+
http_version:
|
160
|
+
recorded_at: Wed, 13 Nov 2013 00:52:17 GMT
|
161
|
+
- request:
|
162
|
+
method: get
|
163
|
+
uri: http://www.theyworkforyou.com/api/getMPInfo?id=24756&key=<API_KEY>&version=1.0.0
|
164
|
+
body:
|
165
|
+
encoding: US-ASCII
|
166
|
+
string: ''
|
167
|
+
headers:
|
168
|
+
Accept-Encoding:
|
169
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
170
|
+
Accept:
|
171
|
+
- '*/*'
|
172
|
+
User-Agent:
|
173
|
+
- Ruby
|
174
|
+
response:
|
175
|
+
status:
|
176
|
+
code: 200
|
177
|
+
message: OK
|
178
|
+
headers:
|
179
|
+
Last-Modified:
|
180
|
+
- Tue, 12 Nov 2013 03:38:59 +0000
|
181
|
+
Content-Type:
|
182
|
+
- text/javascript; charset=iso-8859-1
|
183
|
+
X-Url:
|
184
|
+
- /api/getMPInfo?id=24756&key=<API_KEY>&version=1.0.0
|
185
|
+
Content-Length:
|
186
|
+
- '6072'
|
187
|
+
Accept-Ranges:
|
188
|
+
- bytes
|
189
|
+
Date:
|
190
|
+
- Wed, 13 Nov 2013 00:52:17 GMT
|
191
|
+
Age:
|
192
|
+
- '4'
|
193
|
+
Connection:
|
194
|
+
- keep-alive
|
195
|
+
body:
|
196
|
+
encoding: UTF-8
|
197
|
+
string: '{"comments_on_speeches":"2","comments_on_speeches_quintile":"3","comments_on_speeches_rank":"450","comments_on_speeches_rank_joint":"48","comments_on_speeches_rank_outof":"650","debate_sectionsspoken_inlastyear":"32","debate_sectionsspoken_inlastyear_quintile":"2","debate_sectionsspoken_inlastyear_rank":"314","debate_sectionsspoken_inlastyear_rank_joint":"8","debate_sectionsspoken_inlastyear_rank_outof":"650","maiden_speech":"uk.org.publicwhip/debate/2010-06-22c.151.6","public_whip_dreammp1052_absent":"0","public_whip_dreammp1052_both_voted":"2","public_whip_dreammp1052_distance":"0","public_whip_dreammp1053_absent":"0","public_whip_dreammp1053_both_voted":"1","public_whip_dreammp1053_distance":"0","public_whip_dreammp1065_absent":"0","public_whip_dreammp1065_both_voted":"4","public_whip_dreammp1065_distance":"0.0833333","public_whip_dreammp1074_absent":"1","public_whip_dreammp1074_both_voted":"10","public_whip_dreammp1074_distance":"0.0641026","public_whip_dreammp1084_absent":"0","public_whip_dreammp1084_both_voted":"1","public_whip_dreammp1084_distance":"1","public_whip_dreammp1109_absent":"0","public_whip_dreammp1109_both_voted":"2","public_whip_dreammp1109_distance":"0","public_whip_dreammp1110_absent":"0","public_whip_dreammp1110_both_voted":"10","public_whip_dreammp1110_distance":"0","public_whip_dreammp1124_absent":"0","public_whip_dreammp1124_both_voted":"1","public_whip_dreammp1124_distance":"0","public_whip_dreammp1132_absent":"0","public_whip_dreammp1132_both_voted":"1","public_whip_dreammp1132_distance":"0","public_whip_dreammp811_absent":"0","public_whip_dreammp811_both_voted":"1","public_whip_dreammp811_distance":"0","public_whip_dreammp826_absent":"0","public_whip_dreammp826_both_voted":"4","public_whip_dreammp826_distance":"0","public_whip_dreammp984_absent":"0","public_whip_dreammp984_both_voted":"1","public_whip_dreammp984_distance":"0","reading_ease":"47.0414979003198","reading_ease_quintile":"4","reading_ease_rank":"534","reading_ease_rank_outof":"645","reading_year":"14.2795015913675","reading_year_quintile":"0","reading_year_rank":"81","reading_year_rank_outof":"645","register_member_interests_date":"2013-10-28","register_member_interests_html":"<div
|
198
|
+
class=\"regmemcategory\">2. Remunerated employment, office, profession etc</div>\n<div
|
199
|
+
class=\"regmemitem\"> Medical doctor</div>\n","select_committees":"0","select_committees_chair":"0","three_word_alliterations":"167","three_word_alliterations_quintile":"2","three_word_alliterations_rank":"363","three_word_alliterations_rank_joint":"2","three_word_alliterations_rank_outof":"650","three_word_alliteration_content":":to
|
200
|
+
take to:will work with:make my maiden:true that throughout:he has had:that
|
201
|
+
the treatment:it is important:that the true:the time that:the time to:and
|
202
|
+
about a:to trust them:it is impossible:think that there:should support such:to
|
203
|
+
tailor their:has he had:is invest in:it is important:to talk to:profit per
|
204
|
+
pig:it is important:onus on our:when we were:time to time:industry is in:be
|
205
|
+
bad because:should show some:after an ageing:through talking therapies:on
|
206
|
+
one of:bodies being bandied:it is important:important in improving:and alcohol
|
207
|
+
abuse:to try to:whereas\n\nwhat we:if it is:when we were:thanks to the:that
|
208
|
+
the two:all agree about:that they take:which we will:the train through:to
|
209
|
+
tackle the:think that there:important issue in:it is in:it is important:to
|
210
|
+
tackle these:to tackle this:it is important:tribute to the:it is important:investment
|
211
|
+
in increasing:support system should:women whom we:save social services:it
|
212
|
+
is important:the time that:specialist surgical services:it is important:it
|
213
|
+
is important:it is important:it is important:together to try:it is important:and
|
214
|
+
as a:work with women:way we would:at an average:has huge health:it is important:workers
|
215
|
+
who work:be brought back:party political points:not necessarily need:tribute
|
216
|
+
to the:it is important:why we would:trusts throughout the:interest in it:that
|
217
|
+
these things:also attracted attention:to travel to:important it is:the time
|
218
|
+
they:taking the time:turn to the:are available across:tribute to the:to talk
|
219
|
+
to:training thanks to:it is important:to tackle the:are already available:and
|
220
|
+
an ageing:reducing readmission rates:tribute to the:it is important:together
|
221
|
+
to talk:are at a:say something specifically:to try to:to take things:to their
|
222
|
+
task:to the trust:to talk through:operate out of:transfer times to:that the
|
223
|
+
trust:that the trust:thought that the:accrued as a:that trust to:that the
|
224
|
+
time:and accident and:to the table:to tackle that:it is irresponsible:the
|
225
|
+
talking therapies:it is important:and at a:it is important:testament to the:against
|
226
|
+
accident and:it is important:an accident and:it is ironic:that the trust:is
|
227
|
+
important in:it is important:to the task:tribute to the:funding formula for:formula
|
228
|
+
for funding:appointed as a:true that tariff:tribute to the:is implicit in:to
|
229
|
+
the topics:to their task:investing in integration:the trust to:that the trust:the
|
230
|
+
trust to:to talk through:tribute to the:are also amending:about as a:to talk
|
231
|
+
that:and are a:are anticipating a:and an ageing:issues in improving:tools
|
232
|
+
that the:to talk this:tribute to the:thanks to the:what went wrong:to try
|
233
|
+
to:thanks to the:to tackle them:it is important:and appropriate and:trying
|
234
|
+
to tighten","wikipedia_url":"http://en.wikipedia.org/wiki/Daniel_Poulter","wrans_answered_inlastyear":"1291","wrans_asked_inlastyear":"0","wrans_asked_inlastyear_quintile":"4","wrans_asked_inlastyear_rank":"525","wrans_asked_inlastyear_rank_joint":"126","wrans_asked_inlastyear_rank_outof":"650","wrans_departments":"Health,
|
235
|
+
Education, Environment Food and Rural Affairs, Energy and Climate Change,
|
236
|
+
Transport","wrans_subjects":"Poultry: Animal Welfare, General Practitioners,
|
237
|
+
NHS: Pensions, Ambulance Services: Standards, NHS: Drugs","by_member_id":{"40156":{"public_whip_division_attendance":"81.52%","public_whip_data_date":"2013-11-08","public_whip_rebellions":"1.92%","public_whip_rebelrank":"108","public_whip_attendrank":"163","public_whip_rebelrank_outof":"643","public_whip_attendrank_outof":"650"}}}'
|
238
|
+
http_version:
|
239
|
+
recorded_at: Wed, 13 Nov 2013 00:52:18 GMT
|
240
|
+
recorded_with: VCR 2.5.0
|
@@ -1,27 +1,25 @@
|
|
1
|
-
require
|
2
|
-
require File.join(File.dirname(__FILE__), '../lib/twfy')
|
1
|
+
require "test_helper"
|
3
2
|
|
4
|
-
class
|
5
|
-
|
6
|
-
API_KEY_LOCATION = File.join(File.dirname(__FILE__), 'api_key')
|
3
|
+
class ClientTest < TwfyTest
|
7
4
|
|
8
5
|
def setup
|
9
|
-
|
6
|
+
super
|
10
7
|
@client = Twfy::Client.new(api_key)
|
11
8
|
end
|
12
|
-
|
9
|
+
|
13
10
|
def test_convert_url
|
14
|
-
uri = @client.convert_url(:
|
11
|
+
uri = @client.convert_url(url: 'http://www.publications.parliament.uk/pa/cm200506/cmhansrd/cm061018/debtext/61018-0002.htm#06101834000471')
|
15
12
|
assert_kind_of URI::HTTP, uri
|
16
13
|
assert_equal "www.theyworkforyou.com", uri.host
|
17
14
|
end
|
18
|
-
|
15
|
+
|
19
16
|
def test_mp_and_mp_info
|
20
|
-
mp = @client.mp(:
|
17
|
+
mp = @client.mp(postcode: 'IP6 9PN')
|
21
18
|
assert_kind_of Twfy::MP, mp
|
19
|
+
assert_kind_of Twfy::Constituency, mp.constituency
|
22
20
|
assert_kind_of OpenStruct, @client.mp_info(:id=>mp.person_id)
|
23
21
|
end
|
24
|
-
|
22
|
+
|
25
23
|
def test_mps
|
26
24
|
mps = @client.mps
|
27
25
|
assert_kind_of Array, mps
|
@@ -37,13 +35,13 @@ class BasicReturnedDataTest < Test::Unit::TestCase
|
|
37
35
|
assert_kind_of OpenStruct, msp
|
38
36
|
end
|
39
37
|
end
|
40
|
-
|
38
|
+
|
41
39
|
def test_constituency_and_geometry
|
42
|
-
c = @client.constituency(:
|
40
|
+
c = @client.constituency(postcode: 'IP6 9PN')
|
43
41
|
assert_kind_of Twfy::Constituency, c
|
44
42
|
assert_kind_of Twfy::Geometry, @client.geometry(:name=>c.name)
|
45
43
|
end
|
46
|
-
|
44
|
+
|
47
45
|
def test_constituencies
|
48
46
|
cs = @client.constituencies
|
49
47
|
assert_kind_of Array, cs
|
@@ -51,5 +49,5 @@ class BasicReturnedDataTest < Test::Unit::TestCase
|
|
51
49
|
assert_kind_of Twfy::Constituency, c
|
52
50
|
end
|
53
51
|
end
|
54
|
-
|
52
|
+
|
55
53
|
end
|
@@ -1,23 +1,20 @@
|
|
1
|
-
require
|
2
|
-
require File.join(File.dirname(__FILE__), '../lib/twfy')
|
1
|
+
require "test_helper.rb"
|
3
2
|
|
4
|
-
class
|
5
|
-
|
6
|
-
API_KEY_LOCATION = File.join(File.dirname(__FILE__), 'api_key')
|
3
|
+
class DataElementTest < TwfyTest
|
7
4
|
|
8
5
|
def setup
|
9
|
-
|
6
|
+
super
|
10
7
|
@client = Twfy::Client.new(api_key)
|
11
|
-
@mp = @client.mp(:
|
8
|
+
@mp = @client.mp(postcode: 'IP6 9PN')
|
12
9
|
end
|
13
|
-
|
10
|
+
|
14
11
|
def test_single_chain_class
|
15
12
|
assert_kind_of Twfy::Constituency, @mp.constituency
|
16
13
|
c = @mp.instance_eval{ @constituency }
|
17
14
|
assert c
|
18
15
|
assert_kind_of Twfy::Constituency, c
|
19
16
|
end
|
20
|
-
|
17
|
+
|
21
18
|
def test_reflexive_chain_class
|
22
19
|
c = @mp.constituency
|
23
20
|
assert_kind_of Twfy::Constituency, c
|
@@ -26,7 +23,7 @@ class ChainDataTest < Test::Unit::TestCase
|
|
26
23
|
assert c.instance_eval{ @mp }
|
27
24
|
assert_equal mp, c.instance_eval{ @mp }
|
28
25
|
end
|
29
|
-
|
26
|
+
|
30
27
|
def test_round_trip_chain_class
|
31
28
|
c = @mp.constituency
|
32
29
|
assert_kind_of Twfy::Constituency, c
|
@@ -37,16 +34,15 @@ class ChainDataTest < Test::Unit::TestCase
|
|
37
34
|
assert_kind_of Twfy::Constituency, c2
|
38
35
|
assert_equal c.name, c2.name
|
39
36
|
end
|
40
|
-
|
37
|
+
|
41
38
|
def test_overkill_chain_class
|
42
39
|
mp = @mp.constituency.mp.constituency.geometry.constituency.mp
|
43
40
|
assert_kind_of Twfy::MP, mp
|
44
|
-
assert_equal @mp.full_name, mp.full_name
|
41
|
+
assert_equal @mp.full_name, mp.full_name
|
45
42
|
end
|
46
|
-
|
43
|
+
|
47
44
|
def test_simple_chain_and_direct_call_are_equivalent
|
48
|
-
assert_equal @client.mp_info(:
|
45
|
+
assert_equal @client.mp_info(id: @mp.person_id), @mp.info
|
49
46
|
end
|
50
|
-
|
47
|
+
|
51
48
|
end
|
52
|
-
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path('../../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'twfy'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'vcr'
|
6
|
+
|
7
|
+
# If you need to record new episodes, run rake with:
|
8
|
+
#
|
9
|
+
# $ rake test API_KEY=YOUR-REAL-API-KEY
|
10
|
+
#
|
11
|
+
TEST_API_KEY = ENV['API_KEY'] || 'TEST_API_KEY'
|
12
|
+
|
13
|
+
VCR.configure do |c|
|
14
|
+
c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
|
15
|
+
c.hook_into :webmock
|
16
|
+
c.filter_sensitive_data("<API_KEY>") { TEST_API_KEY }
|
17
|
+
c.default_cassette_options = {record: :new_episodes}
|
18
|
+
end
|
19
|
+
|
20
|
+
class TwfyTest < Test::Unit::TestCase
|
21
|
+
|
22
|
+
def api_key
|
23
|
+
@api_key ||= TEST_API_KEY
|
24
|
+
end
|
25
|
+
|
26
|
+
def setup
|
27
|
+
VCR.insert_cassette self.class.name.gsub(/::/, '/').
|
28
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
29
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
30
|
+
tr("-", "_").
|
31
|
+
downcase
|
32
|
+
end
|
33
|
+
|
34
|
+
def teardown
|
35
|
+
VCR.eject_cassette
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/twfy.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'twfy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "twfy"
|
8
|
+
spec.version = Twfy::VERSION
|
9
|
+
spec.authors = ["Tom Hipkin", "Martin Owen", "Bruce Williams"]
|
10
|
+
spec.email = ["brwcodes@gmail.com", "tomhipkin@gmail.com"]
|
11
|
+
spec.description = "Ruby library to interface with the TheyWorkForYou API."
|
12
|
+
spec.summary = "Ruby library to interface with the TheyWorkForYou API. TheyWorkForYou.com is a non-partisan, volunteer-run website which aims to make it easy for people to keep tabs on their elected and unelected representatives in Parliament."
|
13
|
+
spec.homepage = "http://github.com/bruce/twfy"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "multi_json"
|
22
|
+
spec.add_dependency "paginator", "~> 1.2"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3.5"
|
24
|
+
spec.add_development_dependency "json"
|
25
|
+
spec.add_development_dependency "vcr"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "webmock"
|
28
|
+
|
29
|
+
end
|