open_parliament 0.0.1 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9de4e102a3a94c16f5d5f67ef60e162c1912c764
4
- data.tar.gz: 1f875edbdb4bdd1a1df019eb54f4d480450f2fb1
3
+ metadata.gz: 3c3aedb0b5ca2f066d7af2cd90f96b18ad392f8a
4
+ data.tar.gz: 5a6994212e32c030b8dd19102c5252af1ae783e8
5
5
  SHA512:
6
- metadata.gz: b711db89f02bbe026522ac11df413c2cb59d8ebcf9bac647ee2f4a2c4c9929e774a89831a7c15a7afffe0caa347a531998be5c62d3ded77cea7f4a6a40845283
7
- data.tar.gz: 7cb6bae102a1c716b5544551a978c565b0a108e19ede2ecb9da251120f7ec14031ece0e1072e7bd63648bec247412f807264a0660a5d6fe26fac55b60d451b20
6
+ metadata.gz: e4c10bbf28368847002d4fb8a2ce1099a69adcfbdcca977e03d173d8e2cee78b4751d1eb71a863269f2161b59513010142d165f4b83700a1d06a5fc0c61016f4
7
+ data.tar.gz: 0c32439aea2fb125d566c7d9d9d4525c03b888f9bba841d4c1104ba466ed0e365682a405ee19440ae808818d6134078963fdb91b05fe83b007855aad970ade5a
@@ -3,15 +3,15 @@ GEM
3
3
  specs:
4
4
  coderay (1.1.0)
5
5
  diff-lcs (1.2.5)
6
- domain_name (0.5.24)
6
+ domain_name (0.5.25)
7
7
  unf (>= 0.0.5, < 1.0.0)
8
8
  http-cookie (1.0.2)
9
9
  domain_name (~> 0.5)
10
10
  json (1.8.3)
11
11
  method_source (0.8.2)
12
- mime-types (2.6.1)
13
- netrc (0.10.3)
14
- pry (0.10.1)
12
+ mime-types (2.99)
13
+ netrc (0.11.0)
14
+ pry (0.10.3)
15
15
  coderay (~> 1.1.0)
16
16
  method_source (~> 0.8.1)
17
17
  slop (~> 3.4)
data/README.md CHANGED
@@ -6,7 +6,7 @@ A simple gem to interface with the api at https://openparliament.ca/api/
6
6
  Currently supports basic GETs of 5 endpoints: Bills, Committees, Debates, Politicians, and Votes. These endpoints return lists of OpenParliament objects (which are currently just OpenStructs).
7
7
 
8
8
  ##Usage
9
- ```
9
+ ```ruby
10
10
  gem install open_parliament
11
11
 
12
12
  require 'open_parliament'
@@ -22,4 +22,8 @@ OpenParliament.votes => [OpenParliament::Vote...]
22
22
  vote = OpenParliament.votes.first
23
23
  vote.result => "Passed"
24
24
  vote.description["en"] => "That the Bill be now read a third time and do pass."
25
+
26
+ # Pagination with limit/offset. Defaults to limit:20, offset:0
27
+ first_bill = OpenParliament.bills(limit: 1)
28
+ second_bill = OpenParliament.bills(limit: 1, offset: 1)
25
29
  ```
@@ -13,37 +13,37 @@ require 'open_parliament/request_service'
13
13
  module OpenParliament
14
14
  API_URL = 'http://api.openparliament.ca'
15
15
 
16
- def self.bills
16
+ def self.bills(params = {})
17
17
  url = "/bills/"
18
- json = RequestService.make_request(url: url, method: :get)
18
+ json = RequestService.make_request(url: url, method: :get, params: params)
19
19
  bills = json["objects"]
20
20
  bills.map { |bill_json| Bill.new(bill_json) }
21
21
  end
22
22
 
23
- def self.committees
23
+ def self.committees(params = {})
24
24
  url = "/committees/"
25
- json = RequestService.make_request(url: url, method: :get)
25
+ json = RequestService.make_request(url: url, method: :get, params: params)
26
26
  committees = json["objects"]
27
27
  committees.map { |committee_json| Committee.new(committee_json) }
28
28
  end
29
29
 
30
- def self.debates
30
+ def self.debates(params = {})
31
31
  url = "/debates/"
32
- json = RequestService.make_request(url: url, method: :get)
32
+ json = RequestService.make_request(url: url, method: :get, params: params)
33
33
  debates = json["objects"]
34
34
  debates.map { |debate_json| Debate.new(debate_json) }
35
35
  end
36
36
 
37
- def self.votes
37
+ def self.votes(params = {})
38
38
  url = "/votes/"
39
- json = RequestService.make_request(url: url, method: :get)
39
+ json = RequestService.make_request(url: url, method: :get, params: params)
40
40
  votes = json["objects"]
41
41
  votes.map { |vote_json| Vote.new(vote_json) }
42
42
  end
43
43
 
44
- def self.politicians
44
+ def self.politicians(params = {})
45
45
  url = "/politicians/"
46
- json = RequestService.make_request(url: url, method: :get)
46
+ json = RequestService.make_request(url: url, method: :get, params: params)
47
47
  politicians = json["objects"]
48
48
  politicians.map { |politician_json| Politician.new(politician_json) }
49
49
  end
@@ -1,16 +1,37 @@
1
1
  module OpenParliament
2
2
  module RequestService
3
3
 
4
+ VALID_PARAMS = [:limit, :offset]
5
+
4
6
  def self.make_request(url:, method:, params: {})
5
7
  full_url = "#{OpenParliament::API_URL}#{url}"
6
8
 
7
9
  resp = RestClient::Request.execute(method: method,
8
10
  url: full_url,
9
11
  timeout: 10,
10
- headers: { accept: :json }
12
+ headers: build_headers(params),
11
13
  )
12
14
  JSON.parse(resp)
13
15
  end
14
16
 
17
+ def self.build_headers(params)
18
+ {
19
+ "API-Version" => "v1",
20
+ accept: :json,
21
+ params: build_params(params),
22
+ }
23
+ end
24
+
25
+ def self.build_params(params)
26
+ allowed_params = params.select { |k| VALID_PARAMS.include?(k) }
27
+ default_params.merge(allowed_params)
28
+ end
29
+
30
+ def self.default_params
31
+ {
32
+ limit: 20,
33
+ offset: 0,
34
+ }
35
+ end
15
36
  end
16
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_parliament
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Runkel