ngp_van 0.6.0 → 0.7.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
  SHA256:
3
- metadata.gz: ccb2039be63263fbefef7442a15d89a5a282955065e7f511b277f6568fcf93ec
4
- data.tar.gz: e50582b396dd4820e85edb297a384887f720742bea7803c9fd8468d47391751f
3
+ metadata.gz: 6605b07f76aa3dff12a6b31bbe049cc8a54096059c8b4df97542fb15505f9a8f
4
+ data.tar.gz: 117da358bf89bbad7d26376aa7290e7b3e6918d023920764a9b723a082f22f46
5
5
  SHA512:
6
- metadata.gz: d6879c125fe459db80cd6b349484b1440bb00b5de20939b54f63cd407f7a5d33f199dc7e5eb7baa4e513f6162e7dd81dbe9f93c2721cbba2f600e5d513d92fd9
7
- data.tar.gz: 1a6f0f9a61b96f852cffdc2ed8c745e4538a6b64618bae4bb6dcda69f0ab01d9534189a721ac452f2398b274dbb1ab843c2f847dff2161f1c773f20df40c8f4b
6
+ metadata.gz: 8a5b21a769638e6f4bc20aa4ceff7fff922ff3772863f689569fb678aa3f119daa7f04fbdd9fd249b62698922b61ffb32e6d46e54cebf4ae2ae111ae73f2e49f
7
+ data.tar.gz: 4f9ed158ae0ee2aa141f630d3d5911f9203c9a2a1e311a90f951570546e9a9e5bfccf38ce392189116b255e362399c43c1ba536cb7bc4af3dd1f95d858053e3f
Binary file
data.tar.gz.sig CHANGED
@@ -1,3 +1 @@
1
- �i�eOj��v�1T�WUM0���~�:�0qQ?r�s���J3z}׼�7]i'����h�Y���R�W�3w�_��M t�Z��)����� �3���]��%j��}Y�Ssh=�u<R=��`�7�DFҥ6y����}Ypw��%<M�]Y*
2
- ��qxsJq5C�;��C�� �}��ص������@E�n�خ �����Kt�a����gq���;������d*��i�C7�#�ۀc��|+)�w?�� �X�:g~ֳ*�蠯!��=����-L� ���+Rߦ��h��)h�(��3�o����9ΰw,��i�ks�S�0�l�X�C7�p��.� I��)F�)�׌t
3
- �>���*��PH� ��"�6{��_+
1
+ +��������X3!���>[�>$[_�����b/�K V�D�W K�<f�~�
@@ -5,11 +5,11 @@ require 'ngp_van/configuration'
5
5
  require 'ngp_van/version'
6
6
 
7
7
  module NgpVan
8
- class << self
9
- # The NgpVan configuration object.
10
- # @return [NgpVan::Configuration]
11
- attr_reader :configuration
8
+ class Invalid < StandardError; end
9
+
10
+ class InvalidID < Invalid; end
12
11
 
12
+ class << self
13
13
  def client
14
14
  @client ||= NgpVan::Client.new
15
15
  end
@@ -23,7 +23,6 @@ require 'ngp_van/client/users'
23
23
 
24
24
  module NgpVan
25
25
  class Client
26
-
27
26
  def initialize(configuration = nil)
28
27
  @config = configuration
29
28
  end
@@ -32,6 +31,18 @@ module NgpVan
32
31
  @config || NgpVan.configuration
33
32
  end
34
33
 
34
+ def valid_id?(id)
35
+ id.to_s =~ /\A[a-z0-9\-:]+\z/i ? true : false
36
+ end
37
+
38
+ def verify_id(*ids)
39
+ ids.each do |id|
40
+ raise NgpVan::InvalidID unless valid_id?(id)
41
+ end
42
+ nil
43
+ end
44
+ alias_method :verify_ids, :verify_id
45
+
35
46
  include NgpVan::Connection
36
47
  include NgpVan::Request
37
48
  include NgpVan::Response
@@ -8,6 +8,7 @@ module NgpVan
8
8
  end
9
9
 
10
10
  def activist_code(id:, params: {})
11
+ verify_id(id)
11
12
  get(path: "activistCodes/#{id}", params: params)
12
13
  end
13
14
  end
@@ -12,6 +12,7 @@ module NgpVan
12
12
  end
13
13
 
14
14
  def code(id:, params: {})
15
+ verify_id(id)
15
16
  get(path: "codes/#{id}", params: params)
16
17
  end
17
18
 
@@ -20,10 +21,12 @@ module NgpVan
20
21
  end
21
22
 
22
23
  def update_code(id:, body: {})
24
+ verify_id(id)
23
25
  put(path: "codes/#{id}", body: body)
24
26
  end
25
27
 
26
28
  def delete_code(id:)
29
+ verify_id(id)
27
30
  delete(path: "codes/#{id}")
28
31
  end
29
32
  end
@@ -8,6 +8,7 @@ module NgpVan
8
8
  end
9
9
 
10
10
  def district_field(id:)
11
+ verify_id(id)
11
12
  get(path: "districtFields/#{id}")
12
13
  end
13
14
  end
@@ -8,6 +8,7 @@ module NgpVan
8
8
  end
9
9
 
10
10
  def event_type(id:, params: {})
11
+ verify_id(id)
11
12
  get(path: "events/types/#{id}", params: params)
12
13
  end
13
14
  end
@@ -8,10 +8,12 @@ module NgpVan
8
8
  end
9
9
 
10
10
  def create_event_shift(id:, body: {})
11
+ verify_id(id)
11
12
  post(path: "events/#{id}/shifts", body: body)
12
13
  end
13
14
 
14
15
  def event(id:, params: {})
16
+ verify_id(id)
15
17
  get(path: "events/#{id}", params: params)
16
18
  end
17
19
 
@@ -20,10 +22,12 @@ module NgpVan
20
22
  end
21
23
 
22
24
  def update_event(id:, body: {})
25
+ verify_id(id)
23
26
  put(path: "events/#{id}", body: body)
24
27
  end
25
28
 
26
29
  def delete_event(id:)
30
+ verify_id(id)
27
31
  delete(path: "events/#{id}")
28
32
  end
29
33
  end
@@ -8,6 +8,7 @@ module NgpVan
8
8
  end
9
9
 
10
10
  def location(id:, params: {})
11
+ verify_id(id)
11
12
  get(path: "locations/#{id}", params: params)
12
13
  end
13
14
 
@@ -20,6 +21,7 @@ module NgpVan
20
21
  end
21
22
 
22
23
  def delete_location(id:)
24
+ verify_id(id)
23
25
  delete(path: "locations/#{id}")
24
26
  end
25
27
  end
@@ -8,6 +8,7 @@ module NgpVan
8
8
  end
9
9
 
10
10
  def minivan_export(id:, params: {})
11
+ verify_id(id)
11
12
  get(path: "minivanExports/#{id}", params: params)
12
13
  end
13
14
  end
@@ -12,6 +12,7 @@ module NgpVan
12
12
  end
13
13
 
14
14
  def note_category(id:, params: {})
15
+ verify_id(id)
15
16
  get(path: "notes/categories/#{id}", params: params)
16
17
  end
17
18
  end
@@ -12,18 +12,22 @@ module NgpVan
12
12
  end
13
13
 
14
14
  def person(id:, params: {})
15
+ verify_id(id)
15
16
  get(path: "people/#{id}", params: params)
16
17
  end
17
18
 
18
19
  def person_by_type(id:, type:, params: {})
20
+ verify_ids(id, type)
19
21
  get(path: "people/#{type}:#{id}", params: params)
20
22
  end
21
23
 
22
24
  def create_canvass_responses_for_person(id:, body: {})
25
+ verify_id(id)
23
26
  post(path: "people/#{id}/canvassResponses", body: body)
24
27
  end
25
28
 
26
29
  def create_canvass_responses_for_person_by_type(id:, type:, body: {})
30
+ verify_ids(id, type)
27
31
  post(path: "people/#{type}:#{id}/canvassResponses", body: body)
28
32
  end
29
33
  end
@@ -8,6 +8,7 @@ module NgpVan
8
8
  end
9
9
 
10
10
  def printed_list(id:, params: {})
11
+ verify_id(id)
11
12
  get(path: "printedLists/#{id}", params: params)
12
13
  end
13
14
  end
@@ -8,6 +8,7 @@ module NgpVan
8
8
  end
9
9
 
10
10
  def signup(id:, params: {})
11
+ verify_id(id)
11
12
  get(path: "signups/#{id}", params: params)
12
13
  end
13
14
 
@@ -20,10 +21,12 @@ module NgpVan
20
21
  end
21
22
 
22
23
  def update_signup(id:, body: {})
24
+ verify_id(id)
23
25
  put(path: "signups/#{id}", body: body)
24
26
  end
25
27
 
26
28
  def delete_signup(id:)
29
+ verify_id(id)
27
30
  delete(path: "signups/#{id}")
28
31
  end
29
32
  end
@@ -8,6 +8,7 @@ module NgpVan
8
8
  end
9
9
 
10
10
  def supporter_group(id:, params: {})
11
+ verify_id(id)
11
12
  get(path: "supporterGroups/#{id}", params: params)
12
13
  end
13
14
 
@@ -16,10 +17,12 @@ module NgpVan
16
17
  end
17
18
 
18
19
  def add_person_to_supporter_group(supporter_group_id:, id:)
20
+ verify_ids(id, supporter_group_id)
19
21
  put(path: "supporterGroups/#{supporter_group_id}/people/#{id}")
20
22
  end
21
23
 
22
24
  def remove_person_from_supporter_group(supporter_group_id:, id:)
25
+ verify_ids(id, supporter_group_id)
23
26
  delete(path: "supporterGroups/#{supporter_group_id}/people/#{id}")
24
27
  end
25
28
  end
@@ -8,6 +8,7 @@ module NgpVan
8
8
  end
9
9
 
10
10
  def survey_question(id:, params: {})
11
+ verify_id(id)
11
12
  get(path: "surveyQuestions/#{id}", params: params)
12
13
  end
13
14
  end
@@ -4,14 +4,17 @@ module NgpVan
4
4
  class Client
5
5
  module Users
6
6
  def user_district_field_values(id:, params: {})
7
+ verify_id(id)
7
8
  get(path: "users/#{id}/districtFieldValues", params: params)
8
9
  end
9
10
 
10
11
  def create_user_district_field_values(id:, body: {})
12
+ verify_id(id)
11
13
  post(path: "users/#{id}/districtFieldValues", body: body)
12
14
  end
13
15
 
14
16
  def update_user_district_field_values(id:, body: {})
17
+ verify_id(id)
15
18
  put(path: "users/#{id}/districtFieldValues", body: body)
16
19
  end
17
20
  end
@@ -28,7 +28,7 @@ module NgpVan
28
28
 
29
29
  def request(method:, path:, params: {}, body: {})
30
30
  response = connection.send(method) do |request|
31
- request.path = URI.encode(path)
31
+ request.path = path
32
32
  request.params = params
33
33
  request.body = ::JSON.generate(body) unless body.empty?
34
34
  end
@@ -7,7 +7,7 @@ module NgpVan
7
7
 
8
8
  # Current minor release.
9
9
  # @return [Integer]
10
- MINOR = 6
10
+ MINOR = 7
11
11
 
12
12
  # Current patch level.
13
13
  # @return [Integer]
@@ -30,5 +30,62 @@ module NgpVan
30
30
  expect(client.config.user_agent).to eq('test agent')
31
31
  end
32
32
  end
33
+
34
+ describe '#valid_id?' do
35
+ let(:client) { NgpVan::Client.new }
36
+
37
+ context 'with a valid id' do
38
+ it 'returns true' do
39
+ expect(client.valid_id?(123)).to eq(true)
40
+ expect(client.valid_id?('abc')).to eq(true)
41
+ expect(client.valid_id?('abc-123')).to eq(true)
42
+ expect(client.valid_id?('onlineReferenceNumber:123')).to eq(true)
43
+ end
44
+ end
45
+
46
+ context 'with an invalid id' do
47
+ it 'returns false' do
48
+ expect(client.valid_id?('fu?evil=mode')).to eq(false)
49
+ expect(client.valid_id?('fu/bar')).to eq(false)
50
+ expect(client.valid_id?('%20')).to eq(false)
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#verify_id' do
56
+ let(:client) { NgpVan::Client.new }
57
+
58
+ context 'with a single id' do
59
+ context 'when valid' do
60
+ it 'returns nil' do
61
+ expect(client.verify_id(123)).to eq(nil)
62
+ end
63
+ end
64
+
65
+ context 'when invalid' do
66
+ it 'raises an error' do
67
+ expect {
68
+ client.verify_id('fu?evil=mode')
69
+ }.to raise_error(NgpVan::InvalidID)
70
+ end
71
+ end
72
+ end
73
+
74
+ context 'with a list of ids' do
75
+ context 'when valid' do
76
+ it 'returns nil' do
77
+ expect(client.verify_id('abc', 123, 'abc-123')).to eq(nil)
78
+ end
79
+ end
80
+
81
+ context 'when invalid' do
82
+ it 'raises an error' do
83
+ expect {
84
+ client.verify_id('abc', 'fu?evil=mode', 'abc-123')
85
+ }.to raise_error(NgpVan::InvalidID)
86
+ end
87
+ end
88
+ end
89
+ end
33
90
  end
34
91
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ngp_van
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Styles
@@ -36,7 +36,7 @@ cert_chain:
36
36
  uZ9aI1c3Tt/pkw9HxXwDo1m/+BQOZkAhEZu6LQQgBPAX8hlUyDw54SoJtfnFp0FI
37
37
  Hje6PutFGypAA8f9kmLl8X2Eu74D8PI9ywc=
38
38
  -----END CERTIFICATE-----
39
- date: 2019-02-27 00:00:00.000000000 Z
39
+ date: 2019-03-29 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: faraday
metadata.gz.sig CHANGED
Binary file