open_civic_data 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8bb95989575453bc018f0019271ad66bad07f70f
4
- data.tar.gz: 359eeabd885b3f57e9938bd80ad1b4792b0a9e63
3
+ metadata.gz: 02afd451738c2eb01eb278856f0d930ed2768115
4
+ data.tar.gz: d27092afc718d564c6222ebabe946dc32b5592ef
5
5
  SHA512:
6
- metadata.gz: b29a0eff891f4ee80172e8e8479ab6bd42ca49f554903abf85f4910c0b415ba6b6f968163cc2315a1fba323754959fc6f7b168387dd43aab7f20c0db85c5987e
7
- data.tar.gz: cbf522dbd5e03d454b3c15c1c721f6887fe2cfaa043b9799fab75cadb45b033597a631a78699a0dcfd185f1525de9c12d4ee7bdc76eda9b9239a13ba2b2f1937
6
+ metadata.gz: c8c7d71d51c0c1b507cea00fdada8c535ef4147faf3389394c6c0d78e2bb591d7635f2998848621853decb5a3d49e243f886d6f7c2ccc3472e065a16abdb550d
7
+ data.tar.gz: 193021ea77469b93cdac34ae485c1d7b30942d9f42bce1101be0f2f266c825e85708b0ac8482c1a2735c6a2d414d3d922a165abcff65db2e630cf0af7e535fb8
data/README.md CHANGED
@@ -1,24 +1,20 @@
1
1
  # Ruby wrapper for the Open Civic Data API
2
2
 
3
- [![Build Status](https://travis-ci.org/whatasunnyday/open_civic_data.png?branch=master)](https://travis-ci.org/whatasunnyday/open_civic_data)
3
+ [![Build Status](https://travis-ci.org/whatasunnyday/open_civic_data.png?branch=master)][travis]
4
4
  [travis]: https://travis-ci.org/whatasunnyday/open_civic_data
5
5
 
6
6
  The Open Civic Data API is a JSON API that provides search and lookup across government organizations, people, legislation, and events, provided by the Sunlight Foundation.
7
7
 
8
- For more information, check the [API documentation][apidocs]
9
- [apidocs]: http://docs.opencivicdata.org/en/latest/index.html
8
+ For more information, check the [API documentation](http://docs.opencivicdata.org/en/latest/index.html).
10
9
 
11
10
  ## Installation
12
11
  gem install open_civic_data
13
12
 
14
- ## Documentation
15
- [http://rdoc.info/github/whatasunnyday/open_civic_data/][documentation]
16
- [documentation]: http://rdoc.info/github/whatasunnyday/open_civic_data/
17
-
18
13
  ## Authentication
19
14
 
20
15
  All requests to the Open Civic Data API require a Sunlight API key. An API key is
21
16
  [free to register][register] and has no usage limits.
17
+
22
18
  [register]: http://services.sunlightlabs.com/accounts/register/
23
19
 
24
20
  ## Usage Examples
@@ -29,57 +25,6 @@ require 'open_civic_data'
29
25
  OpenCivicData.key = YOUR_SUNLIGHT_API_KEY
30
26
  ```
31
27
 
32
- ###### Fetches governing bodies in a division.
33
- ```ruby
34
- OpenCivicData.jurisdictions
35
- ```
36
-
37
- ###### Fetches political geographies such as a state, county or congressional district.
38
- ```ruby
39
- OpenCivicData.divisions
40
- ```
41
-
42
- ###### Fetches people, typically politicians or gov officials.
43
- ```ruby
44
- OpenCivicData.people
45
- ```
46
-
47
- ###### Fetches groups of people, such as a city council, state senate or committee.
48
- ```ruby
49
- OpenCivicData.organizations
50
- ```
51
-
52
- ###### Fetches legislative event, such as a meeting or hearing.
53
- ```ruby
54
- OpenCivicData.events
55
- ```
56
-
57
- ###### Fetches legislative documents, resolutions, appointments, or contracts and its history.
58
- ```ruby
59
- OpenCivicData.bills
60
- ```
61
-
62
- ###### Fetches the record of vote taken on motions. May contain individual legilsator's yay/nay or outcome.
63
- ```ruby
64
- OpenCivicData.votes
65
- ```
66
-
67
- ###### All methods include an optional parameter to set search end points
68
- ```ruby
69
- # Returns legislators named 'Obama'
70
- OpenCivicData.people({'name' => 'Obama'})
71
-
72
- # Returns second page of results (results are paginated && 0 indexed)
73
- OpenCivicData.votes({'page' => 1 })
74
- ```
75
-
76
- ###### Use with Other APIs
77
- ```ruby
78
- # You can change the end point and disable key if necessary.
79
- OpenCivicData.key_required = false
80
- OpenCivicData.endpoint = 'http://imago-ca.herokuapp.com/'
81
- ```
82
-
83
28
  ## Supported Ruby Versions
84
29
  This library aims to support and is [tested against][travis] the following Ruby
85
30
  implementations:
@@ -106,10 +51,9 @@ timely fashion. If critical issues for a particular implementation exist at the
106
51
  time of a major release, support for that Ruby version may be dropped.
107
52
 
108
53
  ## Special Thanks to
109
- The [contributors][] of the [Congress gem][congress] where the ideas behind this gem were largely lifted from.
110
- [contributors]: https://github.com/codeforamerica/congress/graphs/contributors
111
- [congress]: https://github.com/codeforamerica/congress
54
+ The (contributors)[https://github.com/codeforamerica/congress/graphs/contributors] of the (Congress gem)[https://github.com/codeforamerica/congress] where the ideas behind this gem largely lifted from.
112
55
 
113
56
  ## Copyright
114
57
  Copyright (c) 2014, Sunny Juneja. See [LICENSE][] for details.
58
+
115
59
  [license]: https://github.com/whatasunnyday/open_civic_data/blob/master/LICENSE.md
data/Rakefile CHANGED
@@ -30,7 +30,7 @@ end
30
30
 
31
31
  require 'yardstick/rake/verify'
32
32
  Yardstick::Rake::Verify.new do |verify|
33
- verify.threshold = 72.6
33
+ verify.threshold = 60.0
34
34
  end
35
35
 
36
36
  task default: [:spec, :rubocop, :verify_measurements]
@@ -5,9 +5,7 @@ module OpenCivicData
5
5
  attr_accessor :key
6
6
 
7
7
  # Alias for OpenCivicData::Client.new
8
- # @api public
9
- # @example
10
- # OpenCivicData.new(SUNLIGHT_KEY)
8
+ #
11
9
  # @return [OpenCivicData::Client]
12
10
  def new(key = key)
13
11
  yield self if block_given?
@@ -16,17 +14,9 @@ module OpenCivicData
16
14
  end
17
15
 
18
16
  # Delegate to OpenCivicData::Client
19
- # @api public
20
- # @example
21
- # OpenCivicData.jurisdictions
22
17
  def method_missing(method, *args, &block)
23
- if OpenCivicData::Client.respond_to?(method)
24
- OpenCivicData::Client.send(method, *args, &block)
25
- elsif new.respond_to?(method)
26
- new.send(method, *args, &block)
27
- else
28
- super
29
- end
18
+ return super unless new.respond_to?(method)
19
+ new.send(method, *args, &block)
30
20
  end
31
21
 
32
22
  # return [Boolean]
@@ -8,112 +8,86 @@ module OpenCivicData
8
8
 
9
9
  attr_reader :key
10
10
 
11
- @@key_required = true # rubocop:disable ClassVars
12
- @@endpoint = 'http://api.opencivicdata.org' # rubocop:disable ClassVars
13
-
14
11
  def initialize(key)
15
- fail ArgumentError, 'API key required' if key.nil? && @@key_required
12
+ warn 'Warning: Your API key may not be set.' if key.nil?
16
13
  @key = key
17
14
  end
18
15
 
19
- # Fetches governing bodies that exist within a division
20
- # @return [Hashie::Rash] Jurisdiction's name, url, chambers, terms, and session details.
16
+ # Jurisdictions are governing bodies that exists within a division.
17
+ # Jurisdiction's name, url, chambers, terms, and session details.
18
+ #
19
+ # return [Hashie::Rash]
21
20
  # @example
22
21
  # OpenCivicData.key = YOUR_SUNLIGHT_API_KEY
23
22
  # OpenCivicData.jurisdictions
24
- # @api public
25
23
  def jurisdictions(options = {})
26
24
  get('/jurisdictions/', options)
27
25
  end
28
26
 
29
- # Fetches political geographies such as a state, county or congressional district
30
- # @return [Hashie::Rash] Division's geometries and list of child jurisdiction ids.
27
+ # Divisions are political geographies such as a state, county, or congressional district.
28
+ # Division's geometries and list of child jurisdiction ids.
29
+ #
30
+ # @return [Hashie::Rash]
31
31
  # @example
32
32
  # OpenCivicData.key = YOUR_SUNLIGHT_API_KEY
33
33
  # OpenCivicData.divisions
34
- # @api public
35
34
  def divisions(options = {})
36
35
  get('/divisions/', options)
37
36
  end
38
37
 
39
- # Fetches people, typically politicians or gov officials
40
- # @return [Hashie::Rash] Person's name, image, contact details, and links.
38
+ # People, typically a politician or gov official.
39
+ # Person's name, image, contact details, and links.
40
+ #
41
+ # @return [Hashie::Rash]
41
42
  # @example
42
43
  # OpenCivicData.key = YOUR_SUNLIGHT_API_KEY
43
44
  # OpenCivicData.people
44
- # @api public
45
45
  def people(options = {})
46
46
  get('/people/', options)
47
47
  end
48
48
 
49
- # Fetches groups of people, such as a city council, state senate or committee
50
- # @return [Hashie::Rash] Organization's name, classification, parent id, contact details, links and posts.
49
+ # A group of people, such as a city council, state senate, or committee.
50
+ # Organization's name, classification, parent id, contact details, links and posts.
51
+ #
52
+ # @return [Hashie::Rash]
51
53
  # @example
52
54
  # OpenCivicData.key = YOUR_SUNLIGHT_API_KEY
53
55
  # OpenCivicData.organizations
54
- # @api public
55
56
  def organizations(options = {})
56
57
  get('/organizations/', options)
57
58
  end
58
59
 
59
- # Fetches legislative event, such as a meeting or hearing
60
- # @return [Hashie::Rash] Event's type, name, description, when, end, status, location, and linked entities.
60
+ # A legislative event, such as a meeting or hearing.
61
+ # Event's type, name, description, when, end, status, location, and linked entities.
62
+ #
63
+ # @return [Hashie::Rash]
61
64
  # @example
62
65
  # OpenCivicData.key = YOUR_SUNLIGHT_API_KEY
63
66
  # OpenCivicData.events
64
- # @api public
65
67
  def events(options = {})
66
68
  get('/events/', options)
67
69
  end
68
70
 
69
- # Fetches legislative documents and their history
70
- # @return [Hashie::Rash] Bill's type, legislative body, session, name, chamber, title, type, subject and summary.
71
+ # Legislative documents, resolutions, appointments or contract and its history,
72
+ # Bill's type, legislative body, session, name, chamber, title, type, subject and summary.
73
+ #
74
+ # @return [Hashie::Rash]
71
75
  # @example
72
76
  # OpenCivicData.key = YOUR_SUNLIGHT_API_KEY
73
77
  # OpenCivicData.bills
74
- # @api public
75
78
  def bills(options = {})
76
79
  get('/bills/', options)
77
80
  end
78
81
 
79
- # Fetches the record of vote taken on motions
80
- # @return [Hashie::Rash] Vote's organization, session, chamber, date, motion, type and passed or not.
82
+ # The record of a vote taken on a motion. May contain individual legilsator's yay/nay or outcome.
83
+ # Vote's organization, session, chamber, date, motion, type and passed or not.
84
+ #
85
+ # @return [Hashie::Rash]
81
86
  # @example
82
87
  # OpenCivicData.key = YOUR_SUNLIGHT_API_KEY
83
88
  # OpenCivicData.votes
84
- # @api public
85
89
  def votes(options = {})
86
90
  get('/votes/', options)
87
91
  end
88
-
89
- class << self
90
- # Disable ArgumentError if no api key is provided. Useful for using different endpoints.
91
- # @param [Boolean]
92
- # @api public
93
- # @example
94
- # OpenCivicData.key_required(false)
95
- # OpenCivicData.jurisdictions
96
- def key_required=(bool)
97
- @@key_required = bool # rubocop:disable ClassVars
98
- end
99
-
100
- # Check if key is required.
101
- # @return [Boolean]
102
- # @api public
103
- # @example
104
- # if OpenCivicData.key_required
105
- # OpenCivicData.key = SUNLIGHT_KEY
106
- def key_required
107
- @@key_required
108
- end
109
-
110
- def endpoint=(endpoint)
111
- @@endpoint = endpoint
112
- end
113
-
114
- def endpoint
115
- @@endpoint
116
- end
117
- end
118
92
  end
119
93
  end
@@ -2,7 +2,7 @@ require 'faraday_middleware'
2
2
 
3
3
  module OpenCivicData
4
4
  module Connection
5
- # rubocop:disable EmptyLinesAroundBody
5
+ ENDPOINT = 'http://api.opencivicdata.org'.freeze
6
6
 
7
7
  private
8
8
 
@@ -11,7 +11,7 @@ module OpenCivicData
11
11
  end
12
12
 
13
13
  def create_connection
14
- Faraday.new(url: OpenCivicData.endpoint) do |connection|
14
+ Faraday.new(url: ENDPOINT) do |connection|
15
15
  middlewares.each { |middleware| connection.use(middleware) }
16
16
  connection.adapter(Faraday.default_adapter)
17
17
  end
@@ -8,7 +8,7 @@ module OpenCivicData
8
8
 
9
9
  def request(method, path, options)
10
10
  response = connection.send(method) do |request|
11
- request.params['apikey'] = @key if Client.key_required
11
+ request.params['apikey'] = @key
12
12
  request.url(path, options)
13
13
  end
14
14
  response.body
@@ -1,3 +1,3 @@
1
1
  module OpenCivicData
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -6,7 +6,7 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
6
 
7
7
  SimpleCov.start do
8
8
  add_filter '/spec/'
9
- minimum_coverage(98)
9
+ minimum_coverage(100)
10
10
  end
11
11
 
12
12
  require 'open_civic_data'
@@ -20,11 +20,11 @@ RSpec.configure do |config|
20
20
  end
21
21
 
22
22
  def a_get(path)
23
- a_request(:get, OpenCivicData.endpoint + path)
23
+ a_request(:get, OpenCivicData::Client::ENDPOINT + path)
24
24
  end
25
25
 
26
26
  def stub_get(path, options)
27
- stub_request(:get, OpenCivicData.endpoint + path).with(query: options)
27
+ stub_request(:get, OpenCivicData::Client::ENDPOINT + path).with(query: options)
28
28
  end
29
29
 
30
30
  def fixture_path
@@ -2,8 +2,9 @@ require 'helper'
2
2
 
3
3
  describe OpenCivicData::Client do
4
4
  before do
5
- @client = OpenCivicData::Client.new('abcd1234')
6
- @options = {'apikey' => 'abcd1234'}
5
+ apikey = 'abcd1234'
6
+ @client = OpenCivicData::Client.new(apikey)
7
+ @options = {'apikey' => apikey}
7
8
  end
8
9
 
9
10
  describe '#jurisdictions' do
@@ -1,12 +1,14 @@
1
1
  require 'helper'
2
2
 
3
3
  describe OpenCivicData do
4
+ before do
5
+ OpenCivicData.key = 'abcd1234'
6
+ end
7
+
4
8
  describe '.new' do
5
9
  it 'returns a OpenCivicData::Client' do
6
- OpenCivicData.key = 'abcd1234'
7
10
  expect(OpenCivicData.new).to be_a OpenCivicData::Client
8
11
  end
9
- # This test should fail even though it doesn't always
10
12
  it 'sets key with a block' do
11
13
  OpenCivicData.new do |ocd|
12
14
  ocd.key = '1234abcd'
@@ -15,49 +17,12 @@ describe OpenCivicData do
15
17
  end
16
18
  context 'with no api key' do
17
19
  it 'raises an arguement error' do
18
- expect(OpenCivicData.key_required).to eql(true)
19
- expect { OpenCivicData.new(nil) }.to raise_error
20
- end
21
- describe 'api key is disabled' do
22
- before do
23
- OpenCivicData.key_required = false
24
- end
25
- after do
26
- OpenCivicData.key_required = true
27
- end
28
- it 'does not raise an arguement error' do
29
- expect(OpenCivicData.key_required).to eql(false)
30
- expect { OpenCivicData.new(nil) }.not_to raise_error
31
- end
20
+ expect { OpenCivicData.new(nil) }.to raise_error ArgumentError
32
21
  end
33
22
  end
34
- describe '.endpoint' do
35
- it 'has a default endpoint' do
36
- expect(OpenCivicData.endpoint).to eq('http://api.opencivicdata.org')
37
- end
38
23
 
39
- describe 'setting a new endpoint' do
40
- before do
41
- OpenCivicData.key = 'ghapi'
42
- OpenCivicData.endpoint = 'http://github.com'
43
- stub_request(:get, 'http://github.com/jurisdictions/').
44
- with(query: {'apikey' => 'ghapi'}).
45
- to_return(status: 200, body: fixture('jurisdictions.json'))
46
- end
47
- after do
48
- OpenCivicData.endpoint = 'http://api.opencivicdata.org'
49
- OpenCivicData.key = 'abcd1234'
50
- end
51
- it 'changes the url queried' do
52
- OpenCivicData.jurisdictions
53
- expect(a_request(:get, 'http://github.com/jurisdictions/')
54
- .with(query: {'apikey' => 'ghapi'})).to have_been_made
55
- end
56
- end
57
- end
58
24
  describe '.method_missing' do
59
25
  before do
60
- OpenCivicData.key = 'abcd1234'
61
26
  stub_get('/jurisdictions/', 'apikey' => 'abcd1234').
62
27
  to_return(status: 200, body: fixture('jurisdictions.json'))
63
28
  end
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_civic_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunny Juneja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-03 00:00:00.000000000 Z
11
+ date: 2014-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.8.7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.8.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday_middleware
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.9.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.9.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: hashie
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.8'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.8'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rash
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.4'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.4'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
89
  version: '1.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.0'
97
97
  description: Ruby wrapper for the Sunlight Open Civic Data API, is an collaborative
@@ -102,12 +102,12 @@ executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
- - ".gemtest"
106
- - ".gitignore"
107
- - ".rspec"
108
- - ".rubocop.yml"
109
- - ".travis.yml"
110
- - ".yardopts"
105
+ - .gemtest
106
+ - .gitignore
107
+ - .rspec
108
+ - .rubocop.yml
109
+ - .travis.yml
110
+ - .yardopts
111
111
  - Gemfile
112
112
  - LICENSE.md
113
113
  - README.md
@@ -138,17 +138,17 @@ require_paths:
138
138
  - lib
139
139
  required_ruby_version: !ruby/object:Gem::Requirement
140
140
  requirements:
141
- - - ">="
141
+ - - '>='
142
142
  - !ruby/object:Gem::Version
143
143
  version: '0'
144
144
  required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  requirements:
146
- - - ">="
146
+ - - '>='
147
147
  - !ruby/object:Gem::Version
148
148
  version: '0'
149
149
  requirements: []
150
150
  rubyforge_project:
151
- rubygems_version: 2.2.1
151
+ rubygems_version: 2.0.3
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: Ruby wrapper for the Sunlight Open Civic Data API