action_kit_rest 0.4.11 → 1.0.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 +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +15 -0
- data/Gemfile +3 -14
- data/Rakefile +4 -38
- data/action_kit_rest.gemspec +43 -105
- data/lib/action_kit_rest/api.rb +21 -10
- data/lib/action_kit_rest/response/raise_error.rb +1 -1
- data/lib/action_kit_rest/response/wrapper.rb +1 -1
- data/lib/action_kit_rest/user.rb +1 -1
- data/lib/action_kit_rest/version.rb +3 -3
- metadata +65 -47
- data/.document +0 -5
- data/.github/workflows/ci.yml +0 -24
- data/spec/fixtures/action/event_create_action.json +0 -24
- data/spec/fixtures/action/event_signup_action.json +0 -24
- data/spec/fixtures/allowed_user_field/get.json +0 -19
- data/spec/fixtures/allowed_user_field/list.json +0 -49
- data/spec/fixtures/allowed_user_field/list_filtered.json +0 -30
- data/spec/fixtures/error.json +0 -1
- data/spec/fixtures/page/campaign.json +0 -32
- data/spec/fixtures/page/collection.json +0 -984
- data/spec/fixtures/page/find_campaign.json +0 -43
- data/spec/fixtures/page/find_event_create.json +0 -42
- data/spec/fixtures/page/find_event_signup.json +0 -41
- data/spec/fixtures/page/object.json +0 -18
- data/spec/fixtures/phone/object.json +0 -33
- data/spec/fixtures/user/object_with_phones.json +0 -1
- data/spec/fixtures/user/object_without_phones.json +0 -1
- data/spec/lib/action_kit_rest/actions/event_create_action_spec.rb +0 -22
- data/spec/lib/action_kit_rest/actions/event_signup_action_spec.rb +0 -22
- data/spec/lib/action_kit_rest/allowed_user_field_spec.rb +0 -80
- data/spec/lib/action_kit_rest/api_spec.rb +0 -111
- data/spec/lib/action_kit_rest/logger_spec.rb +0 -22
- data/spec/lib/action_kit_rest/page_spec.rb +0 -112
- data/spec/lib/action_kit_rest/pages/event_campaign_page_spec.rb +0 -77
- data/spec/lib/action_kit_rest/pages/import_page_spec.rb +0 -53
- data/spec/lib/action_kit_rest/response/collection_spec.rb +0 -28
- data/spec/lib/action_kit_rest/response/validation_error_spec.rb +0 -39
- data/spec/lib/action_kit_rest/response/wrapper_spec.rb +0 -27
- data/spec/lib/action_kit_rest/user_spec.rb +0 -73
- data/spec/spec_helper.rb +0 -51
- data/spec/support/shared_contexts/stub_logger.rb +0 -11
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
require 'support/shared_contexts/stub_logger'
|
|
5
|
-
|
|
6
|
-
describe ActionKitRest::Pages::ImportPage do
|
|
7
|
-
include_context 'stub_logger'
|
|
8
|
-
|
|
9
|
-
let(:actionkit) { ActionKitRest.new(host: 'test.com') }
|
|
10
|
-
let(:status) { 200 }
|
|
11
|
-
|
|
12
|
-
describe 'create' do
|
|
13
|
-
let(:body) { '' }
|
|
14
|
-
let(:request_body) { { title: 'Title', name: 'name' }.to_json }
|
|
15
|
-
let(:request_path) { 'importpage/' }
|
|
16
|
-
|
|
17
|
-
before(:each) do
|
|
18
|
-
stub_post(request_path).with(body: request_body).to_return(body: body, status: status,
|
|
19
|
-
headers: { location: 'https://test.com/rest/v1/importpage/1093/', content_type: 'application/json; charset=utf-8' })
|
|
20
|
-
|
|
21
|
-
stub_request(:get, 'https://test.com/rest/v1/importpage/1093/').to_return(body: fixture('page/object.json'),
|
|
22
|
-
status: '200', headers: { content_type: 'application/json; charset=utf-8' })
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe '.create' do
|
|
26
|
-
it 'should allow creation' do
|
|
27
|
-
resp = actionkit.import_page.create(title: 'Title', name: 'name')
|
|
28
|
-
expect(resp.title).to eq 'Demand a Sustainable USDA'
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
describe 'update' do
|
|
34
|
-
let(:body) { '' }
|
|
35
|
-
let(:request_body) { { title: 'Title', name: 'name' }.to_json }
|
|
36
|
-
let(:request_path) { 'importpage/1093/' }
|
|
37
|
-
|
|
38
|
-
before(:each) do
|
|
39
|
-
stub_put(request_path).with(body: request_body).to_return(body: body, status: status,
|
|
40
|
-
headers: { content_type: 'application/json; charset=utf-8' })
|
|
41
|
-
|
|
42
|
-
stub_request(:get, 'https://test.com/rest/v1/importpage/1093/').to_return(body: fixture('page/object.json'),
|
|
43
|
-
status: '200', headers: { content_type: 'application/json; charset=utf-8' })
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
describe '.update' do
|
|
47
|
-
it 'should allow updates' do
|
|
48
|
-
resp = actionkit.import_page.update('1093', title: 'Title', name: 'name')
|
|
49
|
-
expect(resp.title).to eq 'Demand a Sustainable USDA'
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe ActionKitRest::Response::Collection do
|
|
6
|
-
let(:meta) { double }
|
|
7
|
-
let(:objects) { double }
|
|
8
|
-
subject { ActionKitRest::Response::Collection.new(meta, objects) }
|
|
9
|
-
|
|
10
|
-
describe 'initialization' do
|
|
11
|
-
it 'should set meta and objects' do
|
|
12
|
-
expect(subject.meta).to eq(meta)
|
|
13
|
-
expect(subject.objects).to eq(objects)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe 'each' do
|
|
18
|
-
let(:item1) { double }
|
|
19
|
-
let(:item2) { double }
|
|
20
|
-
let(:objects) { [item1, item2] }
|
|
21
|
-
|
|
22
|
-
it 'should return all collection items' do
|
|
23
|
-
expect(subject.count).to eq(2)
|
|
24
|
-
expect(subject.any? { |i| i == item1 }).to be_truthy
|
|
25
|
-
expect(subject.any? { |i| i == item2 }).to be_truthy
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe ActionKitRest::Response::ValidationError do
|
|
6
|
-
describe '#to_s' do
|
|
7
|
-
subject { ActionKitRest::Response::ValidationError.new(url: url, body: body) }
|
|
8
|
-
|
|
9
|
-
context 'with a normal URL and body' do
|
|
10
|
-
let(:url) { 'https://actionkit.example.com/rest/v1/page/1' }
|
|
11
|
-
let(:errors) { { 'zip' => 'invalid zip code' } }
|
|
12
|
-
let(:body) { { errors: errors }.to_json }
|
|
13
|
-
|
|
14
|
-
it 'should put information in the string' do
|
|
15
|
-
expect(subject.to_s).to eq "ActionKitRest::Response::ValidationError \n url: #{url} \n body: #{body} \n errors: #{errors.inspect}"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
context 'with special characters in the body' do
|
|
20
|
-
let(:url) { 'https://actionkit.example.com/rest/v1/page/1' }
|
|
21
|
-
let(:errors) { { 'zip' => '☃' } }
|
|
22
|
-
let(:body) { { errors: errors }.to_json }
|
|
23
|
-
|
|
24
|
-
it 'should put information in the string' do
|
|
25
|
-
expect(subject.to_s).to eq "ActionKitRest::Response::ValidationError \n url: #{url} \n body: #{body} \n errors: #{errors.inspect}"
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context 'with a body in ASCII-8BIT format' do
|
|
30
|
-
let(:url) { 'https://actionkit.example.com/rest/v1/page/1' }
|
|
31
|
-
let(:errors) { {'mailing_id' => ['לא הצלחנו לקשר בין מספר הזיהוי של רשימת הדיוור הזו לבין החשבון.']} }
|
|
32
|
-
let(:body) { { errors: errors }.to_json.b }
|
|
33
|
-
|
|
34
|
-
it 'should put information in the string' do
|
|
35
|
-
expect(subject.to_s).to eq "ActionKitRest::Response::ValidationError \n url: #{url} \n body: {\"errors\":#{errors.to_json}} \n errors: #{errors.inspect}"
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe ActionKitRest::Response::Wrapper do
|
|
6
|
-
describe 'initialization' do
|
|
7
|
-
it "should be kind 'object' for objects" do
|
|
8
|
-
body = double
|
|
9
|
-
response = double(body: body)
|
|
10
|
-
|
|
11
|
-
wrapper = ActionKitRest::Response::Wrapper.new(response)
|
|
12
|
-
|
|
13
|
-
wrapper.object?.should be_truthy
|
|
14
|
-
wrapper.collection?.should be_falsey
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "should be kind 'collection' for collections" do
|
|
18
|
-
body = double(meta: '', objects: [])
|
|
19
|
-
response = double(body: body)
|
|
20
|
-
|
|
21
|
-
wrapper = ActionKitRest::Response::Wrapper.new(response)
|
|
22
|
-
|
|
23
|
-
wrapper.object?.should be_falsey
|
|
24
|
-
wrapper.collection?.should be_truthy
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe ActionKitRest::User do
|
|
6
|
-
before :each do
|
|
7
|
-
logger = double
|
|
8
|
-
logger.stub(:debug).and_return(true)
|
|
9
|
-
|
|
10
|
-
ActionKitRest.stub(:logger).and_return(logger)
|
|
11
|
-
Vertebrae::Base.stub(:logger).and_return(logger)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
subject { ActionKitRest.new(host: 'test.com') }
|
|
15
|
-
|
|
16
|
-
describe 'retrieval' do
|
|
17
|
-
let(:request_path) { 'user/1/' }
|
|
18
|
-
|
|
19
|
-
context 'without basic auth' do
|
|
20
|
-
before(:each) do
|
|
21
|
-
stub_get(request_path).to_return(body: body, status: status,
|
|
22
|
-
headers: { content_type: 'application/json; charset=utf-8' })
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe '.get' do
|
|
26
|
-
let(:status) { 200 }
|
|
27
|
-
|
|
28
|
-
context 'without phones' do
|
|
29
|
-
let(:body) { fixture('user/object_without_phones.json') }
|
|
30
|
-
|
|
31
|
-
it 'should return a user object' do
|
|
32
|
-
expect(subject.user.get(1).email).to eq 'walkers@wawd.com'
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context 'with phones' do
|
|
37
|
-
let(:body) { fixture('user/object_with_phones.json') }
|
|
38
|
-
let(:phone_body) { fixture('phone/object.json') }
|
|
39
|
-
|
|
40
|
-
it 'should include phones' do
|
|
41
|
-
stub_get('phone/?user=1').to_return(body: phone_body, status: 200)
|
|
42
|
-
expect(subject.user.get(1).phones.count).to eq 3
|
|
43
|
-
expect(subject.user.get(1).phones.map(&:phone)).to match_array(%w[7755555555 7755555577 310-310-3310])
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
describe 'user not found' do
|
|
49
|
-
let(:body) { '' }
|
|
50
|
-
let(:status) { 404 }
|
|
51
|
-
|
|
52
|
-
it 'should raise an exception' do
|
|
53
|
-
expect { subject.user.get(1) }.to raise_error(ActionKitRest::Response::NotFound)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
context 'with basic auth' do
|
|
59
|
-
let(:body) { fixture('user/object_without_phones.json') }
|
|
60
|
-
|
|
61
|
-
subject { ActionKitRest.new(host: 'test.com', username: 'alice', password: 'somesecret') }
|
|
62
|
-
|
|
63
|
-
before(:each) do
|
|
64
|
-
stub_get(request_path).with(basic_auth: %w[alice somesecret])
|
|
65
|
-
.to_return(body: body, status: 200, headers: { content_type: 'application/json; charset=utf-8' })
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it 'should return a user object' do
|
|
69
|
-
expect(subject.user.get(1).email).to eq 'walkers@wawd.com'
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'rspec'
|
|
4
|
-
require 'webmock/rspec'
|
|
5
|
-
|
|
6
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
|
7
|
-
|
|
8
|
-
require 'action_kit_rest'
|
|
9
|
-
|
|
10
|
-
RSpec.configure do |config|
|
|
11
|
-
config.include WebMock::API
|
|
12
|
-
|
|
13
|
-
config.before(:each) do
|
|
14
|
-
WebMock.reset!
|
|
15
|
-
end
|
|
16
|
-
config.after(:each) do
|
|
17
|
-
WebMock.reset!
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
config.mock_with :rspec do |mocks|
|
|
21
|
-
mocks.syntax = %i[should expect]
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
config.expect_with :rspec do |c|
|
|
25
|
-
c.syntax = %i[should expect]
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def stub_get(path)
|
|
30
|
-
stub_action_kit_request(:get, path)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def stub_post(path)
|
|
34
|
-
stub_action_kit_request(:post, path)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def stub_put(path)
|
|
38
|
-
stub_action_kit_request(:put, path)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def stub_action_kit_request(method, path)
|
|
42
|
-
stub_request(method, "https://test.com/rest/v1/#{path}")
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def fixture_path
|
|
46
|
-
File.expand_path('fixtures', __dir__)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def fixture(file)
|
|
50
|
-
File.new(File.join(fixture_path, '/', file))
|
|
51
|
-
end
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
shared_context 'stub_logger' do
|
|
4
|
-
before(:each) do
|
|
5
|
-
logger = double
|
|
6
|
-
allow(logger).to receive(:debug).and_return(true)
|
|
7
|
-
|
|
8
|
-
allow(ActionKitRest).to receive(:logger).and_return(logger)
|
|
9
|
-
allow(Vertebrae::Base).to receive(:logger).and_return(logger)
|
|
10
|
-
end
|
|
11
|
-
end
|