twfy 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
metadata
CHANGED
@@ -1,95 +1,175 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: twfy
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
-
|
6
|
+
authors:
|
7
|
+
- Tom Hipkin
|
8
8
|
- Martin Owen
|
9
|
+
- Bruce Williams
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
date: 2013-11-13 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: multi_json
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
18
22
|
type: :runtime
|
19
|
-
|
20
|
-
version_requirements: !ruby/object:Gem::Requirement
|
21
|
-
requirements:
|
22
|
-
- -
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version:
|
25
|
-
|
26
|
-
- !ruby/object:Gem::Dependency
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - '>='
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
27
30
|
name: paginator
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '1.2'
|
28
36
|
type: :runtime
|
29
|
-
|
30
|
-
version_requirements: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version:
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.2'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: bundler
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ~>
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.3.5
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.3.5
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: json
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
38
64
|
type: :development
|
39
|
-
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
requirements:
|
42
|
-
- -
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version:
|
45
|
-
|
46
|
-
|
47
|
-
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: vcr
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: rake
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: webmock
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
description: Ruby library to interface with the TheyWorkForYou API.
|
114
|
+
email:
|
115
|
+
- brwcodes@gmail.com
|
116
|
+
- tomhipkin@gmail.com
|
48
117
|
executables: []
|
49
|
-
|
50
118
|
extensions: []
|
51
|
-
|
52
|
-
|
53
|
-
-
|
54
|
-
-
|
55
|
-
-
|
56
|
-
files:
|
119
|
+
extra_rdoc_files: []
|
120
|
+
files:
|
121
|
+
- .gitignore
|
122
|
+
- .travis.yml
|
123
|
+
- Gemfile
|
57
124
|
- History.txt
|
58
|
-
-
|
59
|
-
- README.
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
60
127
|
- Rakefile
|
61
|
-
- lib/data_element.rb
|
62
128
|
- lib/twfy.rb
|
63
|
-
-
|
64
|
-
-
|
65
|
-
-
|
66
|
-
|
67
|
-
|
129
|
+
- lib/twfy/api.rb
|
130
|
+
- lib/twfy/client.rb
|
131
|
+
- lib/twfy/commands.rb
|
132
|
+
- lib/twfy/constituency.rb
|
133
|
+
- lib/twfy/data_element.rb
|
134
|
+
- lib/twfy/geometry.rb
|
135
|
+
- lib/twfy/mp.rb
|
136
|
+
- lib/twfy/validation.rb
|
137
|
+
- lib/twfy/version.rb
|
138
|
+
- test/fixtures/vcr_cassettes/client_test.yml
|
139
|
+
- test/fixtures/vcr_cassettes/data_element_test.yml
|
140
|
+
- test/lib/twfy/client_test.rb
|
141
|
+
- test/lib/twfy/data_element_test.rb
|
142
|
+
- test/test_helper.rb
|
143
|
+
- twfy.gemspec
|
144
|
+
homepage: http://github.com/bruce/twfy
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
metadata: {}
|
68
148
|
post_install_message:
|
69
|
-
rdoc_options:
|
70
|
-
|
71
|
-
- README.txt
|
72
|
-
require_paths:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
73
151
|
- lib
|
74
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
-
requirements:
|
76
|
-
- -
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version:
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
version: "0"
|
85
|
-
version:
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - '>='
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
86
162
|
requirements: []
|
87
|
-
|
88
|
-
|
89
|
-
rubygems_version: 1.2.0
|
163
|
+
rubyforge_project:
|
164
|
+
rubygems_version: 2.0.3
|
90
165
|
signing_key:
|
91
|
-
specification_version:
|
92
|
-
summary: Ruby library to interface with the TheyWorkForYou
|
93
|
-
|
94
|
-
|
95
|
-
|
166
|
+
specification_version: 4
|
167
|
+
summary: Ruby library to interface with the TheyWorkForYou API. TheyWorkForYou.com
|
168
|
+
is a non-partisan, volunteer-run website which aims to make it easy for people to
|
169
|
+
keep tabs on their elected and unelected representatives in Parliament.
|
170
|
+
test_files:
|
171
|
+
- test/fixtures/vcr_cassettes/client_test.yml
|
172
|
+
- test/fixtures/vcr_cassettes/data_element_test.yml
|
173
|
+
- test/lib/twfy/client_test.rb
|
174
|
+
- test/lib/twfy/data_element_test.rb
|
175
|
+
- test/test_helper.rb
|
data/Manifest.txt
DELETED
data/README.txt
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
twfy
|
2
|
-
by Bruce Williams (http://codefluency.com)
|
3
|
-
and Martin Owen (http://martinowen.net)
|
4
|
-
|
5
|
-
== DESCRIPTION:
|
6
|
-
|
7
|
-
Ruby library to interface with the TheyWorkForYou API.
|
8
|
-
|
9
|
-
From their website:
|
10
|
-
|
11
|
-
"TheyWorkForYou.com is a non-partisan, volunteer-run website which aims to make it easy
|
12
|
-
for people to keep tabs on their elected and unelected representatives in Parliament."
|
13
|
-
|
14
|
-
== FEATURES/PROBLEMS:
|
15
|
-
|
16
|
-
All services [currently] provided by the API are supported.
|
17
|
-
|
18
|
-
The Ruby API closely mirrors that of TWFY, with the exception that the client
|
19
|
-
methods are in lowercase and don't include the 'get' prefix.
|
20
|
-
|
21
|
-
Some examples:
|
22
|
-
|
23
|
-
getComments:: comments
|
24
|
-
getMPs:: mps
|
25
|
-
getMPInfo:: mp_info
|
26
|
-
|
27
|
-
Please submit bug reports to the RubyForge tracker via the project's homepage at
|
28
|
-
http://rubyforge.org/projects/twfy
|
29
|
-
|
30
|
-
== SYNOPSIS:
|
31
|
-
|
32
|
-
Use is very easy.
|
33
|
-
|
34
|
-
=== Get a Client
|
35
|
-
|
36
|
-
require 'twfy'
|
37
|
-
client = Twfy::Client.new(<YOUR API KEY HERE>)
|
38
|
-
|
39
|
-
Note that the Twfy::Client constructor in version 1.0.1 of the binding requires an API Key
|
40
|
-
string. If you don't have one they are available at http://www.theyworkforyou.com/api/key
|
41
|
-
|
42
|
-
=== Call API methods directly on client
|
43
|
-
|
44
|
-
puts client.constituency(:postcode=>'IP6 9PN').name
|
45
|
-
# => Central Suffolk & North Ipswich
|
46
|
-
|
47
|
-
mp = client.mp(:postcode=>'IP6 9PN')
|
48
|
-
puts mp.full_name
|
49
|
-
# => Michael Lord
|
50
|
-
|
51
|
-
# Get a *lot* of info about this MP
|
52
|
-
info = client.mp_info(:id=>mp.person_id)
|
53
|
-
|
54
|
-
# Get a sorted list of all the parties in the House of Lords
|
55
|
-
client.lords.map{|l| l.party}.uniq.sort
|
56
|
-
#=> ["Bishop", "Conservative", "Crossbench", "DUP", "Green", "Labour", "Liberal Democrat", "Other"]
|
57
|
-
|
58
|
-
# Get number of debates in the House of Commons mentioning 'Iraq'
|
59
|
-
number = client.debates(:type=>'commons',:search=>'Iraq').info['total_results']
|
60
|
-
|
61
|
-
=== Daisy chaining
|
62
|
-
|
63
|
-
A few methods on the client return non-OpenStruct instances that support daisy chaining. Using these to access related data more naturally (with caching).
|
64
|
-
|
65
|
-
Here are some examples
|
66
|
-
|
67
|
-
# Get the MP for the last constituency (if you sort them alphabetically)
|
68
|
-
mp = client.constituencies.sort_by{|c| c.name }.last.mp
|
69
|
-
# get the geometry information for that constituency (coming from the MP)
|
70
|
-
geometry = mp.constituency.geometry
|
71
|
-
|
72
|
-
# An overkill example showing caching (no services are called here, since
|
73
|
-
# the results have already been cached from above)
|
74
|
-
mp = mp.constituency.mp.constituency.geometry.constituency.mp
|
75
|
-
|
76
|
-
# These return equivalent results (Note how much easier the first is)
|
77
|
-
info1 = mp.info # this is cached for subsequent calls
|
78
|
-
info2 = client.mp_info(:id=>mp.person_id)
|
79
|
-
|
80
|
-
# Get pages of debates mentioning 'medicine'
|
81
|
-
debates1 = mp.debates(:search=>'medicine')
|
82
|
-
debates2 = mp.debates(:search=>'medicine', :page=>2)
|
83
|
-
|
84
|
-
See http://www.theyworkforyou.com/api/docs for API documentation.
|
85
|
-
|
86
|
-
Please note that data pulled from the API is licensed separately;
|
87
|
-
see the LICENSE portion of this README for further details.
|
88
|
-
|
89
|
-
== REQUIREMENTS:
|
90
|
-
|
91
|
-
+ json library (available as a gem)
|
92
|
-
|
93
|
-
== INSTALL:
|
94
|
-
|
95
|
-
No special instructions.
|
96
|
-
|
97
|
-
== LICENSE:
|
98
|
-
|
99
|
-
This library uses the MIT License
|
100
|
-
Copyright (c) 2006 Bruce Williams
|
101
|
-
|
102
|
-
Data is licensed separately:
|
103
|
-
|
104
|
-
The TheyWorkForYou license statement, from their website (http://www.theyworkforyou.com/api/), is:
|
105
|
-
|
106
|
-
To use parliamentary material yourself (that's data returned from getDebates, getWrans, and getWMS), you will need to get a Parliamentary Licence from the Office of Public Sector Information. Our own data - lists of MPs, Lords, constituencies and so on - is available under the Creative Commons Attribution-ShareAlike license version 2.5.
|
107
|
-
|
108
|
-
Non-commercial use is free, please contact us for commercial use.
|
data/lib/data_element.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'date'
|
3
|
-
|
4
|
-
module Twfy
|
5
|
-
|
6
|
-
class DataElement
|
7
|
-
@@conversions = {}
|
8
|
-
class << self
|
9
|
-
def convert(*fields,&block)
|
10
|
-
fields.each do |field|
|
11
|
-
@@conversions[field] = block
|
12
|
-
end
|
13
|
-
end
|
14
|
-
def convert_to_date(*fields)
|
15
|
-
fields.each do |field|
|
16
|
-
convert field do |d|
|
17
|
-
Date.parse(d)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
attr_reader :client
|
24
|
-
def initialize(client, data={})
|
25
|
-
@client = client
|
26
|
-
data.each do |field,value|
|
27
|
-
instance_variable_set("@#{field}", convert(field, value))
|
28
|
-
unless self.respond_to?(field)
|
29
|
-
self.class.send(:define_method, field) do
|
30
|
-
instance_variable_get("@#{field}")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def convert(field, value)
|
37
|
-
if conversion = @@conversions[field.to_sym]
|
38
|
-
args = [value]
|
39
|
-
args.unshift self if conversion.arity == 2
|
40
|
-
conversion.call(*args)
|
41
|
-
else
|
42
|
-
value
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
class MP < DataElement
|
49
|
-
|
50
|
-
convert_to_date :entered_house, :left_house
|
51
|
-
convert :image do |value|
|
52
|
-
URI.parse("http://theyworkforyou.com#{value}")
|
53
|
-
end
|
54
|
-
convert :constituency do |source,value|
|
55
|
-
Constituency.new(source.client, :name => value, :mp => source)
|
56
|
-
end
|
57
|
-
|
58
|
-
def in_office?
|
59
|
-
@left_reason == 'still_in_office'
|
60
|
-
end
|
61
|
-
|
62
|
-
def info
|
63
|
-
@info ||= @client.mp_info(:id => @person_id)
|
64
|
-
end
|
65
|
-
|
66
|
-
def debates(params={})
|
67
|
-
@debates ||= {}
|
68
|
-
@debates[params] ||= @client.debates(params.merge(:person=>@person_id, :type=>'commons'))
|
69
|
-
end
|
70
|
-
|
71
|
-
def comments(params={})
|
72
|
-
@comments ||= {}
|
73
|
-
@comments[params] ||= @client.comments(params.merge(:pid=>@person_id))
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
class Constituency < DataElement
|
79
|
-
|
80
|
-
def initialize(*args)
|
81
|
-
super
|
82
|
-
end
|
83
|
-
def geometry
|
84
|
-
@geometry ||= @client.geometry(:name=>@name)
|
85
|
-
end
|
86
|
-
|
87
|
-
def mp
|
88
|
-
@mp ||= @client.mp(:constituency=>@name)
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
class Geometry < DataElement
|
94
|
-
|
95
|
-
convert :constituency do |source,value|
|
96
|
-
Constituency.new(source.client, :name => value, :geometry => source)
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
data/test/api_key
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
B47i8vFYfgWvAa89eYErLWPF
|