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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -0
- data/README.md +117 -0
- data/lib/ngp_van.rb +47 -0
- data/lib/ngp_van/client.rb +41 -0
- data/lib/ngp_van/client/activist_codes.rb +15 -0
- data/lib/ngp_van/client/canvass_responses.rb +19 -0
- data/lib/ngp_van/client/codes.rb +31 -0
- data/lib/ngp_van/client/district_fields.rb +15 -0
- data/lib/ngp_van/client/event_types.rb +15 -0
- data/lib/ngp_van/client/events.rb +31 -0
- data/lib/ngp_van/client/locations.rb +27 -0
- data/lib/ngp_van/client/minivan_exports.rb +15 -0
- data/lib/ngp_van/client/notes.rb +19 -0
- data/lib/ngp_van/client/people.rb +31 -0
- data/lib/ngp_van/client/printed_lists.rb +15 -0
- data/lib/ngp_van/client/signups.rb +31 -0
- data/lib/ngp_van/client/survey_questions.rb +15 -0
- data/lib/ngp_van/client/users.rb +19 -0
- data/lib/ngp_van/configuration.rb +74 -0
- data/lib/ngp_van/connection.rb +32 -0
- data/lib/ngp_van/default.rb +41 -0
- data/lib/ngp_van/error.rb +124 -0
- data/lib/ngp_van/request.rb +39 -0
- data/lib/ngp_van/response.rb +15 -0
- data/lib/ngp_van/response/raise_error.rb +17 -0
- data/lib/ngp_van/version.rb +19 -0
- data/spec/ngp_van/client/activist_codes_spec.rb +88 -0
- data/spec/ngp_van/client/canvass_responses_spec.rb +126 -0
- data/spec/ngp_van/client/codes_spec.rb +197 -0
- data/spec/ngp_van/client/district_fields_spec.rb +79 -0
- data/spec/ngp_van/client/event_types_spec.rb +69 -0
- data/spec/ngp_van/client/events_spec.rb +205 -0
- data/spec/ngp_van/client/locations_spec.rb +172 -0
- data/spec/ngp_van/client/minivan_exports_spec.rb +82 -0
- data/spec/ngp_van/client/notes_spec.rb +107 -0
- data/spec/ngp_van/client/people_spec.rb +227 -0
- data/spec/ngp_van/client/printed_lists_spec.rb +91 -0
- data/spec/ngp_van/client/signups_spec.rb +209 -0
- data/spec/ngp_van/client/survey_questions_spec.rb +83 -0
- data/spec/ngp_van/client/users_spec.rb +122 -0
- data/spec/ngp_van/configuration_spec.rb +116 -0
- data/spec/ngp_van/request_spec.rb +137 -0
- data/spec/ngp_van_spec.rb +29 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/fixtures/activist_code.json +10 -0
- data/spec/support/fixtures/activist_codes.json +36 -0
- data/spec/support/fixtures/canvass_response.json +25 -0
- data/spec/support/fixtures/canvass_responses_contact_types.json +10 -0
- data/spec/support/fixtures/canvass_responses_input_types.json +26 -0
- data/spec/support/fixtures/canvass_responses_result_codes.json +26 -0
- data/spec/support/fixtures/code.json +18 -0
- data/spec/support/fixtures/code_supported_entities.json +5 -0
- data/spec/support/fixtures/codes.json +55 -0
- data/spec/support/fixtures/create_code.json +16 -0
- data/spec/support/fixtures/create_event.json +62 -0
- data/spec/support/fixtures/create_event_shift.json +5 -0
- data/spec/support/fixtures/create_location.json +9 -0
- data/spec/support/fixtures/create_signup.json +32 -0
- data/spec/support/fixtures/create_user_district_field_values.json +7 -0
- data/spec/support/fixtures/district_field.json +28 -0
- data/spec/support/fixtures/district_fields.json +22 -0
- data/spec/support/fixtures/event.json +139 -0
- data/spec/support/fixtures/event_type.json +75 -0
- data/spec/support/fixtures/event_types.json +77 -0
- data/spec/support/fixtures/events.json +86 -0
- data/spec/support/fixtures/location.json +19 -0
- data/spec/support/fixtures/locations.json +25 -0
- data/spec/support/fixtures/match_candidate.json +61 -0
- data/spec/support/fixtures/match_response.json +4 -0
- data/spec/support/fixtures/minivan_export.json +66 -0
- data/spec/support/fixtures/minivan_exports.json +72 -0
- data/spec/support/fixtures/note_categories.json +17 -0
- data/spec/support/fixtures/note_category.json +8 -0
- data/spec/support/fixtures/note_category_types.json +6 -0
- data/spec/support/fixtures/person.json +61 -0
- data/spec/support/fixtures/printed_list.json +52 -0
- data/spec/support/fixtures/printed_lists.json +58 -0
- data/spec/support/fixtures/signup.json +55 -0
- data/spec/support/fixtures/signup_statuses.json +26 -0
- data/spec/support/fixtures/signups.json +112 -0
- data/spec/support/fixtures/survey_question.json +36 -0
- data/spec/support/fixtures/survey_questions.json +85 -0
- data/spec/support/fixtures/update_code.json +22 -0
- data/spec/support/fixtures/update_event.json +61 -0
- data/spec/support/fixtures/update_signup.json +35 -0
- data/spec/support/fixtures/update_user_district_field_values.json +6 -0
- data/spec/support/fixtures/user_district_field_values.json +7 -0
- data/spec/support/path_helpers.rb +9 -0
- data/spec/support/rspec.rb +51 -0
- data/spec/support/url_helpers.rb +5 -0
- data/spec/support/webmock.rb +5 -0
- metadata +269 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module NgpVan
|
6
|
+
class Client
|
7
|
+
RSpec.describe SurveyQuestions do
|
8
|
+
let(:client) { NgpVan::Client.new }
|
9
|
+
|
10
|
+
describe '#survey_questions' do
|
11
|
+
let(:params) do
|
12
|
+
{
|
13
|
+
statuses: 'Active,Archived',
|
14
|
+
cycle: '2010',
|
15
|
+
type: 'Candidate'
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:response) { fixture('survey_questions.json') }
|
20
|
+
let(:url) { build_url(client: client, path: 'surveyQuestions') }
|
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.survey_questions(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
|
+
survey_questions = client.survey_questions(params: params)
|
40
|
+
expect(survey_questions['items']).to be_a(Array)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns the requested survey_questions' do
|
44
|
+
survey_questions = client.survey_questions(params: params)
|
45
|
+
expect(survey_questions['items'].first['surveyQuestionId'])
|
46
|
+
.to eq(54_945)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#survey_question' do
|
51
|
+
let(:params) { Hash.new }
|
52
|
+
let(:response) { fixture('survey_question.json') }
|
53
|
+
let(:url) { build_url(client: client, path: 'surveyQuestions/54949') }
|
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.survey_question(id: 54_949, params: params)
|
65
|
+
expect(
|
66
|
+
a_request(:get, url)
|
67
|
+
.with(query: params)
|
68
|
+
).to have_been_made
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns a survey_question object' do
|
72
|
+
survey_question = client.survey_question(id: 54_949, params: params)
|
73
|
+
expect(survey_question).to be_a(Hash)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'returns the requested survey_question' do
|
77
|
+
survey_question = client.survey_question(id: 54_949, params: params)
|
78
|
+
expect(survey_question['surveyQuestionId']).to eq(54_949)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module NgpVan
|
6
|
+
class Client
|
7
|
+
RSpec.describe Users do
|
8
|
+
let(:client) { NgpVan::Client.new }
|
9
|
+
|
10
|
+
describe '#user_district_field_values' do
|
11
|
+
let(:params) { Hash.new }
|
12
|
+
let(:response) { fixture('user_district_field_values.json') }
|
13
|
+
|
14
|
+
let(:url) do
|
15
|
+
build_url(client: client, path: 'users/1234/districtFieldValues')
|
16
|
+
end
|
17
|
+
|
18
|
+
before do
|
19
|
+
stub_request(:get, url)
|
20
|
+
.with(query: params)
|
21
|
+
.to_return(
|
22
|
+
body: response
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'requests the correct resource' do
|
27
|
+
client.user_district_field_values(id: 1234, params: params)
|
28
|
+
expect(
|
29
|
+
a_request(:get, url)
|
30
|
+
.with(query: params)
|
31
|
+
).to have_been_made
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns district field values for a user' do
|
35
|
+
results = client.user_district_field_values(id: 1234, params: params)
|
36
|
+
expect(results).to be_a(Hash)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns the requested district field values' do
|
40
|
+
results = client.user_district_field_values(id: 1234, params: params)
|
41
|
+
expect(results['districtFieldValues'].first).to eq('W1P2')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#create_user_district_field_values' do
|
46
|
+
let(:body) do
|
47
|
+
JSON.parse(
|
48
|
+
File.read(fixture_path + '/create_user_district_field_values.json')
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
let(:response) { fixture('user_district_field_values.json') }
|
53
|
+
|
54
|
+
let(:url) do
|
55
|
+
build_url(client: client, path: 'users/12345/districtFieldValues')
|
56
|
+
end
|
57
|
+
|
58
|
+
before do
|
59
|
+
stub_request(:post, url)
|
60
|
+
.with(body: JSON.generate(body))
|
61
|
+
.to_return(
|
62
|
+
body: response
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'requests the correct resource' do
|
67
|
+
client.create_user_district_field_values(id: 12_345, body: body)
|
68
|
+
expect(
|
69
|
+
a_request(:post, url)
|
70
|
+
.with(
|
71
|
+
body: body
|
72
|
+
)
|
73
|
+
).to have_been_made
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'returns the user district field value assignments' do
|
77
|
+
results = client.create_user_district_field_values(id: 12_345,
|
78
|
+
body: body)
|
79
|
+
expect(results['districtFieldValues'].first).to eq('W1P2')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#update_user_district_field_values' do
|
84
|
+
let(:body) do
|
85
|
+
JSON.parse(
|
86
|
+
File.read(fixture_path + '/update_user_district_field_values.json')
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
let(:response) { fixture('user_district_field_values.json') }
|
91
|
+
|
92
|
+
let(:url) do
|
93
|
+
build_url(client: client, path: 'users/12345/districtFieldValues')
|
94
|
+
end
|
95
|
+
|
96
|
+
before do
|
97
|
+
stub_request(:put, url)
|
98
|
+
.with(body: JSON.generate(body))
|
99
|
+
.to_return(
|
100
|
+
body: response
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'requests the correct resource' do
|
105
|
+
client.update_user_district_field_values(id: 12_345, body: body)
|
106
|
+
expect(
|
107
|
+
a_request(:put, url)
|
108
|
+
.with(
|
109
|
+
body: body
|
110
|
+
)
|
111
|
+
).to have_been_made
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'returns the user district field value assignments' do
|
115
|
+
results = client.update_user_district_field_values(id: 12_345,
|
116
|
+
body: body)
|
117
|
+
expect(results['districtFieldValues'].first).to eq('W1P2')
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module NgpVan
|
6
|
+
RSpec.describe Configuration do
|
7
|
+
before(:each) { NgpVan.configuration.reset! }
|
8
|
+
after(:each) { NgpVan.configuration.reset! }
|
9
|
+
|
10
|
+
describe '#api_endpoint' do
|
11
|
+
context 'when no api_endpoint is specified' do
|
12
|
+
it 'sets a default value' do
|
13
|
+
expect(NgpVan.configuration.api_endpoint)
|
14
|
+
.to eq(NgpVan::Default.api_endpoint)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when a custom value is specified' do
|
19
|
+
let(:url) { Faker::Internet.url }
|
20
|
+
|
21
|
+
before do
|
22
|
+
NgpVan.configure do |config|
|
23
|
+
config.api_endpoint = url
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns the custom value' do
|
28
|
+
expect(NgpVan.configuration.api_endpoint).to eq(url)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#api_key' do
|
34
|
+
context 'when no api_key is specified' do
|
35
|
+
it 'sets a default value' do
|
36
|
+
expect(NgpVan.configuration.api_key)
|
37
|
+
.to eq(NgpVan::Default.api_key)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when a custom value is specified' do
|
42
|
+
let(:key) { Faker::Internet.password }
|
43
|
+
|
44
|
+
before do
|
45
|
+
NgpVan.configure do |config|
|
46
|
+
config.api_key = key
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns the custom value' do
|
51
|
+
expect(NgpVan.configuration.api_key).to eq(key)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#application_name' do
|
57
|
+
context 'when no application name is specified' do
|
58
|
+
it 'sets a default value' do
|
59
|
+
expect(NgpVan.configuration.application_name)
|
60
|
+
.to eq(NgpVan::Default.application_name)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when a custom value is specified' do
|
65
|
+
let(:name) { Faker::Company.name }
|
66
|
+
|
67
|
+
before do
|
68
|
+
NgpVan.configure do |config|
|
69
|
+
config.application_name = name
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns the custom value' do
|
74
|
+
expect(NgpVan.configuration.application_name).to eq(name)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#inspect' do
|
80
|
+
it 'masks the application name' do
|
81
|
+
application_name = Faker::Company.name
|
82
|
+
NgpVan.configuration.application_name = application_name
|
83
|
+
expect(NgpVan.configuration.inspect).to_not include(application_name)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'masks the api key' do
|
87
|
+
api_key = Faker::Internet.password
|
88
|
+
NgpVan.configuration.api_key = api_key
|
89
|
+
expect(NgpVan.configuration.inspect).to_not include(api_key)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '#user_agent' do
|
94
|
+
context 'when no user_agent is specified' do
|
95
|
+
it 'sets a default value' do
|
96
|
+
expect(NgpVan.configuration.user_agent)
|
97
|
+
.to eq(NgpVan::Default.user_agent)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'when a custom value is specified' do
|
102
|
+
let(:agent) { 'Web Spider v123' }
|
103
|
+
|
104
|
+
before do
|
105
|
+
NgpVan.configure do |config|
|
106
|
+
config.user_agent = agent
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'returns the custom value' do
|
111
|
+
expect(NgpVan.configuration.user_agent).to eq(agent)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
# rubocop:disable Metrics/ModuleLength
|
6
|
+
module NgpVan
|
7
|
+
RSpec.describe Request do
|
8
|
+
let(:client) { NgpVan::Client.new }
|
9
|
+
let(:params) { { id: 2 } }
|
10
|
+
|
11
|
+
describe '#delete' do
|
12
|
+
let(:url) { build_url(client: client, path: '/some/resource') }
|
13
|
+
|
14
|
+
context 'when making a request' do
|
15
|
+
before do
|
16
|
+
stub_request(:delete, url)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'makes a DELETE request' do
|
20
|
+
NgpVan.delete(path: '/some/resource')
|
21
|
+
expect(a_request(:delete, url)).to have_been_made
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when passing parameters to the request' do
|
26
|
+
before do
|
27
|
+
stub_request(:delete, url).with(query: params)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'passes params to the request' do
|
31
|
+
NgpVan.delete(path: '/some/resource', params: params)
|
32
|
+
|
33
|
+
expect(a_request(:delete, url).with(query: params))
|
34
|
+
.to have_been_made
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#get' do
|
40
|
+
let(:url) { build_url(client: client, path: '/some/resource') }
|
41
|
+
|
42
|
+
context 'when making a request' do
|
43
|
+
before do
|
44
|
+
stub_request(:get, url)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'makes a get request' do
|
48
|
+
NgpVan.get(path: '/some/resource')
|
49
|
+
expect(a_request(:get, url)).to have_been_made
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when passing parameters to the request' do
|
54
|
+
before do
|
55
|
+
stub_request(:get, url).with(query: params)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'passes params to the request' do
|
59
|
+
NgpVan.get(path: '/some/resource', params: params)
|
60
|
+
|
61
|
+
expect(a_request(:get, url).with(query: params))
|
62
|
+
.to have_been_made
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#post' do
|
68
|
+
let(:url) { build_url(client: client, path: '/some/resource') }
|
69
|
+
let(:body) do
|
70
|
+
{
|
71
|
+
name: 'Neighbors Calling Neighbors',
|
72
|
+
shortName: 'NeighborCall',
|
73
|
+
description: 'Come help get the word out about our great campaign.'
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when making a request' do
|
78
|
+
before do
|
79
|
+
stub_request(:post, url)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'makes a post request' do
|
83
|
+
NgpVan.post(path: '/some/resource')
|
84
|
+
expect(a_request(:post, url)).to have_been_made
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'when passing a body to the request' do
|
89
|
+
before do
|
90
|
+
stub_request(:post, url).with(body: JSON.generate(body))
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'passes body to the request' do
|
94
|
+
NgpVan.post(path: '/some/resource', body: body)
|
95
|
+
|
96
|
+
expect(a_request(:post, url).with(body: JSON.generate(body)))
|
97
|
+
.to have_been_made
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#put' do
|
103
|
+
let(:url) { build_url(client: client, path: '/some/resource') }
|
104
|
+
let(:body) do
|
105
|
+
{
|
106
|
+
name: 'Neighbors Calling Neighbors',
|
107
|
+
shortName: 'NeighborCall',
|
108
|
+
description: 'Come help get the word out about our great campaign.'
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'when making a request' do
|
113
|
+
before do
|
114
|
+
stub_request(:put, url)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'makes a put request' do
|
118
|
+
NgpVan.put(path: '/some/resource')
|
119
|
+
expect(a_request(:put, url)).to have_been_made
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'when passing a body to the request' do
|
124
|
+
before do
|
125
|
+
stub_request(:put, url).with(body: JSON.generate(body))
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'passes body to the request' do
|
129
|
+
NgpVan.put(path: '/some/resource', body: body)
|
130
|
+
|
131
|
+
expect(a_request(:put, url).with(body: JSON.generate(body)))
|
132
|
+
.to have_been_made
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|