ngp_van 0.1.1

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.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -0
  4. data/README.md +117 -0
  5. data/lib/ngp_van.rb +47 -0
  6. data/lib/ngp_van/client.rb +41 -0
  7. data/lib/ngp_van/client/activist_codes.rb +15 -0
  8. data/lib/ngp_van/client/canvass_responses.rb +19 -0
  9. data/lib/ngp_van/client/codes.rb +31 -0
  10. data/lib/ngp_van/client/district_fields.rb +15 -0
  11. data/lib/ngp_van/client/event_types.rb +15 -0
  12. data/lib/ngp_van/client/events.rb +31 -0
  13. data/lib/ngp_van/client/locations.rb +27 -0
  14. data/lib/ngp_van/client/minivan_exports.rb +15 -0
  15. data/lib/ngp_van/client/notes.rb +19 -0
  16. data/lib/ngp_van/client/people.rb +31 -0
  17. data/lib/ngp_van/client/printed_lists.rb +15 -0
  18. data/lib/ngp_van/client/signups.rb +31 -0
  19. data/lib/ngp_van/client/survey_questions.rb +15 -0
  20. data/lib/ngp_van/client/users.rb +19 -0
  21. data/lib/ngp_van/configuration.rb +74 -0
  22. data/lib/ngp_van/connection.rb +32 -0
  23. data/lib/ngp_van/default.rb +41 -0
  24. data/lib/ngp_van/error.rb +124 -0
  25. data/lib/ngp_van/request.rb +39 -0
  26. data/lib/ngp_van/response.rb +15 -0
  27. data/lib/ngp_van/response/raise_error.rb +17 -0
  28. data/lib/ngp_van/version.rb +19 -0
  29. data/spec/ngp_van/client/activist_codes_spec.rb +88 -0
  30. data/spec/ngp_van/client/canvass_responses_spec.rb +126 -0
  31. data/spec/ngp_van/client/codes_spec.rb +197 -0
  32. data/spec/ngp_van/client/district_fields_spec.rb +79 -0
  33. data/spec/ngp_van/client/event_types_spec.rb +69 -0
  34. data/spec/ngp_van/client/events_spec.rb +205 -0
  35. data/spec/ngp_van/client/locations_spec.rb +172 -0
  36. data/spec/ngp_van/client/minivan_exports_spec.rb +82 -0
  37. data/spec/ngp_van/client/notes_spec.rb +107 -0
  38. data/spec/ngp_van/client/people_spec.rb +227 -0
  39. data/spec/ngp_van/client/printed_lists_spec.rb +91 -0
  40. data/spec/ngp_van/client/signups_spec.rb +209 -0
  41. data/spec/ngp_van/client/survey_questions_spec.rb +83 -0
  42. data/spec/ngp_van/client/users_spec.rb +122 -0
  43. data/spec/ngp_van/configuration_spec.rb +116 -0
  44. data/spec/ngp_van/request_spec.rb +137 -0
  45. data/spec/ngp_van_spec.rb +29 -0
  46. data/spec/spec_helper.rb +11 -0
  47. data/spec/support/fixtures/activist_code.json +10 -0
  48. data/spec/support/fixtures/activist_codes.json +36 -0
  49. data/spec/support/fixtures/canvass_response.json +25 -0
  50. data/spec/support/fixtures/canvass_responses_contact_types.json +10 -0
  51. data/spec/support/fixtures/canvass_responses_input_types.json +26 -0
  52. data/spec/support/fixtures/canvass_responses_result_codes.json +26 -0
  53. data/spec/support/fixtures/code.json +18 -0
  54. data/spec/support/fixtures/code_supported_entities.json +5 -0
  55. data/spec/support/fixtures/codes.json +55 -0
  56. data/spec/support/fixtures/create_code.json +16 -0
  57. data/spec/support/fixtures/create_event.json +62 -0
  58. data/spec/support/fixtures/create_event_shift.json +5 -0
  59. data/spec/support/fixtures/create_location.json +9 -0
  60. data/spec/support/fixtures/create_signup.json +32 -0
  61. data/spec/support/fixtures/create_user_district_field_values.json +7 -0
  62. data/spec/support/fixtures/district_field.json +28 -0
  63. data/spec/support/fixtures/district_fields.json +22 -0
  64. data/spec/support/fixtures/event.json +139 -0
  65. data/spec/support/fixtures/event_type.json +75 -0
  66. data/spec/support/fixtures/event_types.json +77 -0
  67. data/spec/support/fixtures/events.json +86 -0
  68. data/spec/support/fixtures/location.json +19 -0
  69. data/spec/support/fixtures/locations.json +25 -0
  70. data/spec/support/fixtures/match_candidate.json +61 -0
  71. data/spec/support/fixtures/match_response.json +4 -0
  72. data/spec/support/fixtures/minivan_export.json +66 -0
  73. data/spec/support/fixtures/minivan_exports.json +72 -0
  74. data/spec/support/fixtures/note_categories.json +17 -0
  75. data/spec/support/fixtures/note_category.json +8 -0
  76. data/spec/support/fixtures/note_category_types.json +6 -0
  77. data/spec/support/fixtures/person.json +61 -0
  78. data/spec/support/fixtures/printed_list.json +52 -0
  79. data/spec/support/fixtures/printed_lists.json +58 -0
  80. data/spec/support/fixtures/signup.json +55 -0
  81. data/spec/support/fixtures/signup_statuses.json +26 -0
  82. data/spec/support/fixtures/signups.json +112 -0
  83. data/spec/support/fixtures/survey_question.json +36 -0
  84. data/spec/support/fixtures/survey_questions.json +85 -0
  85. data/spec/support/fixtures/update_code.json +22 -0
  86. data/spec/support/fixtures/update_event.json +61 -0
  87. data/spec/support/fixtures/update_signup.json +35 -0
  88. data/spec/support/fixtures/update_user_district_field_values.json +6 -0
  89. data/spec/support/fixtures/user_district_field_values.json +7 -0
  90. data/spec/support/path_helpers.rb +9 -0
  91. data/spec/support/rspec.rb +51 -0
  92. data/spec/support/url_helpers.rb +5 -0
  93. data/spec/support/webmock.rb +5 -0
  94. metadata +269 -0
  95. metadata.gz.sig +0 -0
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module NgpVan
6
+ class Client
7
+ RSpec.describe ActivistCodes do
8
+ let(:client) { NgpVan::Client.new }
9
+
10
+ describe '#activist_codes' do
11
+ let(:params) do
12
+ {
13
+ statuses: 'Active,Archived',
14
+ type: 'Volunteer'
15
+ }
16
+ end
17
+
18
+ let(:response) { fixture('activist_codes.json') }
19
+
20
+ let(:url) { build_url(client: client, path: 'activistCodes') }
21
+
22
+ before do
23
+ stub_request(:get, url)
24
+ .with(query: params)
25
+ .to_return(
26
+ body: response
27
+ )
28
+ end
29
+
30
+ it 'requests the correct resource' do
31
+ client.activist_codes(params: params)
32
+ expect(
33
+ a_request(:get, url)
34
+ .with(query: params)
35
+ ).to have_been_made
36
+ end
37
+
38
+ it 'returns an array of items' do
39
+ activist_codes = client.activist_codes(params: params)
40
+ expect(activist_codes['items']).to be_a(Array)
41
+ end
42
+
43
+ it 'returns the requested activist codes' do
44
+ activist_codes = client.activist_codes(params: params)
45
+ expect(activist_codes['items'].first['activistCodeId']).to eq(3214)
46
+ end
47
+ end
48
+
49
+ describe '#activist_code' do
50
+ let(:params) do
51
+ {
52
+ activistCodeId: 'EID28CG'
53
+ }
54
+ end
55
+
56
+ let(:response) { fixture('activist_code.json') }
57
+
58
+ before do
59
+ stub_request(:get, build_url(client: client,
60
+ path: 'activistCodes/3202'))
61
+ .with(query: params)
62
+ .to_return(
63
+ body: response
64
+ )
65
+ end
66
+
67
+ it 'requests the correct resource' do
68
+ client.activist_code(id: 3202, params: params)
69
+ expect(
70
+ a_request(:get, build_url(client: client,
71
+ path: 'activistCodes/3202'))
72
+ .with(query: params)
73
+ ).to have_been_made
74
+ end
75
+
76
+ it 'returns an activist code object' do
77
+ activist_code = client.activist_code(id: 3202, params: params)
78
+ expect(activist_code).to be_a Hash
79
+ end
80
+
81
+ it 'returns the requested activist code properties' do
82
+ activist_code = client.activist_code(id: 3202, params: params)
83
+ expect(activist_code['activistCodeId']).to eq(3202)
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module NgpVan
6
+ class Client
7
+ RSpec.describe CanvassResponses do
8
+ let(:client) { NgpVan::Client.new }
9
+
10
+ describe '#canvass_responses_contact_types' do
11
+ let(:params) do
12
+ {
13
+ inputTypeId: 11
14
+ }
15
+ end
16
+
17
+ let(:response) { fixture('canvass_responses_contact_types.json') }
18
+
19
+ let(:url) do
20
+ build_url(client: client, path: 'canvassResponses/contactTypes')
21
+ end
22
+
23
+ before do
24
+ stub_request(:get, url)
25
+ .with(query: params)
26
+ .to_return(
27
+ body: response
28
+ )
29
+ end
30
+
31
+ it 'requests the correct resource' do
32
+ client.canvass_responses_contact_types(params: params)
33
+ expect(
34
+ a_request(:get, url)
35
+ .with(query: params)
36
+ ).to have_been_made
37
+ end
38
+
39
+ it 'returns an array of contact types' do
40
+ contact_types = client.canvass_responses_contact_types(params: params)
41
+ expect(contact_types).to be_a(Array)
42
+ end
43
+
44
+ it 'returns the requested contact types' do
45
+ contact_types = client.canvass_responses_contact_types(params: params)
46
+ expect(contact_types.first['name']).to eq('Phone')
47
+ end
48
+ end
49
+
50
+ describe '#canvass_responses_input_types' do
51
+ let(:params) { Hash.new }
52
+ let(:response) { fixture('canvass_responses_input_types.json') }
53
+
54
+ let(:url) do
55
+ build_url(client: client, path: 'canvassResponses/inputTypes')
56
+ end
57
+
58
+ before do
59
+ stub_request(:get, url)
60
+ .to_return(
61
+ body: response
62
+ )
63
+ end
64
+
65
+ it 'requests the correct resource' do
66
+ client.canvass_responses_input_types(params: params)
67
+ expect(
68
+ a_request(:get, url)
69
+ .with(query: params)
70
+ ).to have_been_made
71
+ end
72
+
73
+ it 'returns an array of input types' do
74
+ input_types = client.canvass_responses_input_types(params: params)
75
+ expect(input_types).to be_a(Array)
76
+ end
77
+
78
+ it 'returns the requested input type' do
79
+ input_types = client.canvass_responses_input_types(params: params)
80
+ expect(input_types.first['name']).to eq('API')
81
+ end
82
+ end
83
+
84
+ describe '#canvass_responses_result_codes' do
85
+ let(:params) do
86
+ {
87
+ inputTypeId: 14,
88
+ contactTypeId: 1
89
+ }
90
+ end
91
+
92
+ let(:response) { fixture('canvass_responses_result_codes.json') }
93
+
94
+ let(:url) do
95
+ build_url(client: client, path: 'canvassResponses/resultCodes')
96
+ end
97
+
98
+ before do
99
+ stub_request(:get, url)
100
+ .with(query: params)
101
+ .to_return(
102
+ body: response
103
+ )
104
+ end
105
+
106
+ it 'requests the correct resource' do
107
+ client.canvass_responses_result_codes(params: params)
108
+ expect(
109
+ a_request(:get, url)
110
+ .with(query: params)
111
+ ).to have_been_made
112
+ end
113
+
114
+ it 'returns an array of result codes' do
115
+ result_codes = client.canvass_responses_result_codes(params: params)
116
+ expect(result_codes).to be_a(Array)
117
+ end
118
+
119
+ it 'returns the requested result codes' do
120
+ result_codes = client.canvass_responses_result_codes(params: params)
121
+ expect(result_codes.first['name']).to eq('Busy')
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,197 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module NgpVan
6
+ # rubocop:disable Metrics/ClassLength
7
+ class Client
8
+ RSpec.describe Codes do
9
+ let(:client) { NgpVan::Client.new }
10
+
11
+ describe '#code_supported_entities' do
12
+ let(:params) { Hash.new }
13
+ let(:response) { fixture('code_supported_entities.json') }
14
+ let(:url) { build_url(client: client, path: 'codes/supportedEntities') }
15
+
16
+ before do
17
+ stub_request(:get, url)
18
+ .with(query: params)
19
+ .to_return(
20
+ body: response
21
+ )
22
+ end
23
+
24
+ it 'requests the correct resource' do
25
+ client.code_supported_entities(params: params)
26
+ expect(
27
+ a_request(:get, url)
28
+ .with(query: params)
29
+ ).to have_been_made
30
+ end
31
+
32
+ it 'returns an array of items' do
33
+ code_supported_entities = client.code_supported_entities(
34
+ params: params)
35
+ expect(code_supported_entities).to be_a(Array)
36
+ end
37
+
38
+ it 'returns a collection of code supported entities' do
39
+ code_supported_entities = client.code_supported_entities(
40
+ params: params)
41
+ expect(code_supported_entities.first).to eq('Contacts')
42
+ end
43
+ end
44
+
45
+ describe '#codes' do
46
+ let(:params) do
47
+ {
48
+ parentCodeId: 20_513
49
+ }
50
+ end
51
+
52
+ let(:response) { fixture('codes.json') }
53
+ let(:url) { build_url(client: client, path: 'codes') }
54
+
55
+ before do
56
+ stub_request(:get, url)
57
+ .with(query: params)
58
+ .to_return(
59
+ body: response
60
+ )
61
+ end
62
+
63
+ it 'requests the correct resource' do
64
+ client.codes(params: params)
65
+ expect(
66
+ a_request(:get, url)
67
+ .with(query: params)
68
+ ).to have_been_made
69
+ end
70
+
71
+ it 'returns an array of items' do
72
+ codes = client.codes(params: params)
73
+ expect(codes['items']).to be_a(Array)
74
+ end
75
+
76
+ it 'returns the requested codes' do
77
+ codes = client.codes(params: params)
78
+ expect(codes['items'].first['codeId']).to eq(20_514)
79
+ end
80
+ end
81
+
82
+ describe '#code' do
83
+ let(:params) { Hash.new }
84
+ let(:response) { fixture('code.json') }
85
+ let(:url) { build_url(client: client, path: 'codes/20515') }
86
+
87
+ before do
88
+ stub_request(:get, url)
89
+ .with(query: params)
90
+ .to_return(
91
+ body: response
92
+ )
93
+ end
94
+
95
+ it 'requests the correct resource' do
96
+ client.code(id: 20_515, params: params)
97
+ expect(
98
+ a_request(:get, url)
99
+ .with(query: params)
100
+ ).to have_been_made
101
+ end
102
+
103
+ it 'returns a code object' do
104
+ code = client.code(id: 20_515, params: params)
105
+ expect(code).to be_a(Hash)
106
+ end
107
+
108
+ it 'returns the requested code' do
109
+ code = client.code(id: 20_515, params: params)
110
+ expect(code['codeId']).to eq(20_515)
111
+ end
112
+ end
113
+
114
+ describe '#create_code' do
115
+ let(:body) { JSON.parse(File.read(fixture_path + '/code.json')) }
116
+ let(:url) { build_url(client: client, path: 'codes') }
117
+
118
+ before do
119
+ stub_request(:post, url)
120
+ .with(body: JSON.generate(body))
121
+ .to_return(
122
+ body: '20516',
123
+ status: 201,
124
+ headers: {
125
+ 'Location' => build_url(client: client, path: '/codes/20516')
126
+ }
127
+ )
128
+ end
129
+
130
+ it 'requests the correct resource' do
131
+ client.create_code(body: body)
132
+ expect(
133
+ a_request(:post, url)
134
+ .with(
135
+ body: body
136
+ )
137
+ ).to have_been_made
138
+ end
139
+
140
+ it 'returns the created id' do
141
+ expect(client.create_code(body: body)).to eq(20516)
142
+ end
143
+ end
144
+
145
+ describe '#update_code' do
146
+ let(:body) { JSON.parse(File.read(fixture_path + '/update_code.json')) }
147
+ let(:url) { build_url(client: client, path: 'codes/20516') }
148
+
149
+ before do
150
+ stub_request(:put, url)
151
+ .with(body: JSON.generate(body))
152
+ .to_return(
153
+ body: '',
154
+ status: 204
155
+ )
156
+ end
157
+
158
+ it 'requests the correct resource' do
159
+ client.update_code(id: 20_516, body: body)
160
+ expect(
161
+ a_request(:put, url)
162
+ .with(
163
+ body: body
164
+ )
165
+ ).to have_been_made
166
+ end
167
+
168
+ it 'returns an empty response body' do
169
+ expect(client.update_code(id: 20_516, body: body)).to eq('')
170
+ end
171
+ end
172
+
173
+ describe '#delete_code' do
174
+ let(:url) { build_url(client: client, path: 'codes/20516') }
175
+
176
+ before do
177
+ stub_request(:delete, url)
178
+ .to_return(
179
+ body: '',
180
+ status: 204
181
+ )
182
+ end
183
+
184
+ it 'requests the correct resource' do
185
+ client.delete_code(id: 20_516)
186
+ expect(
187
+ a_request(:delete, url)
188
+ ).to have_been_made
189
+ end
190
+
191
+ it 'returns an empty response body' do
192
+ expect(client.delete_code(id: 20_516)).to eq('')
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module NgpVan
6
+ class Client
7
+ RSpec.describe DistrictFields do
8
+ let(:client) { NgpVan::Client.new }
9
+
10
+ describe '#district_fields' do
11
+ let(:params) do
12
+ {
13
+ custom: false,
14
+ organizeAt: false
15
+ }
16
+ end
17
+
18
+ let(:response) { fixture('district_fields.json') }
19
+ let(:url) { build_url(client: client, path: 'districtFields') }
20
+
21
+ before do
22
+ stub_request(:get, url)
23
+ .with(query: params)
24
+ .to_return(
25
+ body: response
26
+ )
27
+ end
28
+
29
+ it 'requests the correct resource' do
30
+ client.district_fields(params: params)
31
+ expect(
32
+ a_request(:get, url)
33
+ .with(query: params)
34
+ ).to have_been_made
35
+ end
36
+
37
+ it 'returns an array of districts' do
38
+ district_fields = client.district_fields(params: params)
39
+ expect(district_fields['districts']).to be_a(Array)
40
+ end
41
+
42
+ it 'returns the requested district fields' do
43
+ district_fields = client.district_fields(params: params)
44
+ expect(district_fields['districts'].first['name'])
45
+ .to eq('State Senate')
46
+ end
47
+ end
48
+
49
+ describe '#district_field' do
50
+ let(:response) { fixture('district_field.json') }
51
+ let(:url) { build_url(client: client, path: 'districtFields/999') }
52
+
53
+ before do
54
+ stub_request(:get, url)
55
+ .to_return(
56
+ body: response
57
+ )
58
+ end
59
+
60
+ it 'requests the correct resource' do
61
+ client.district_field(id: 999)
62
+ expect(
63
+ a_request(:get, url)
64
+ ).to have_been_made
65
+ end
66
+
67
+ it 'returns a district_field object' do
68
+ district_field = client.district_field(id: 999)
69
+ expect(district_field).to be_a(Hash)
70
+ end
71
+
72
+ it 'returns the requested district_field' do
73
+ district_field = client.district_field(id: 999)
74
+ expect(district_field['districtFieldId']).to eq(999)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end