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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +15 -0
  4. data/Gemfile +3 -14
  5. data/Rakefile +4 -38
  6. data/action_kit_rest.gemspec +43 -105
  7. data/lib/action_kit_rest/api.rb +21 -10
  8. data/lib/action_kit_rest/response/raise_error.rb +1 -1
  9. data/lib/action_kit_rest/response/wrapper.rb +1 -1
  10. data/lib/action_kit_rest/user.rb +1 -1
  11. data/lib/action_kit_rest/version.rb +3 -3
  12. metadata +65 -47
  13. data/.document +0 -5
  14. data/.github/workflows/ci.yml +0 -24
  15. data/spec/fixtures/action/event_create_action.json +0 -24
  16. data/spec/fixtures/action/event_signup_action.json +0 -24
  17. data/spec/fixtures/allowed_user_field/get.json +0 -19
  18. data/spec/fixtures/allowed_user_field/list.json +0 -49
  19. data/spec/fixtures/allowed_user_field/list_filtered.json +0 -30
  20. data/spec/fixtures/error.json +0 -1
  21. data/spec/fixtures/page/campaign.json +0 -32
  22. data/spec/fixtures/page/collection.json +0 -984
  23. data/spec/fixtures/page/find_campaign.json +0 -43
  24. data/spec/fixtures/page/find_event_create.json +0 -42
  25. data/spec/fixtures/page/find_event_signup.json +0 -41
  26. data/spec/fixtures/page/object.json +0 -18
  27. data/spec/fixtures/phone/object.json +0 -33
  28. data/spec/fixtures/user/object_with_phones.json +0 -1
  29. data/spec/fixtures/user/object_without_phones.json +0 -1
  30. data/spec/lib/action_kit_rest/actions/event_create_action_spec.rb +0 -22
  31. data/spec/lib/action_kit_rest/actions/event_signup_action_spec.rb +0 -22
  32. data/spec/lib/action_kit_rest/allowed_user_field_spec.rb +0 -80
  33. data/spec/lib/action_kit_rest/api_spec.rb +0 -111
  34. data/spec/lib/action_kit_rest/logger_spec.rb +0 -22
  35. data/spec/lib/action_kit_rest/page_spec.rb +0 -112
  36. data/spec/lib/action_kit_rest/pages/event_campaign_page_spec.rb +0 -77
  37. data/spec/lib/action_kit_rest/pages/import_page_spec.rb +0 -53
  38. data/spec/lib/action_kit_rest/response/collection_spec.rb +0 -28
  39. data/spec/lib/action_kit_rest/response/validation_error_spec.rb +0 -39
  40. data/spec/lib/action_kit_rest/response/wrapper_spec.rb +0 -27
  41. data/spec/lib/action_kit_rest/user_spec.rb +0 -73
  42. data/spec/spec_helper.rb +0 -51
  43. data/spec/support/shared_contexts/stub_logger.rb +0 -11
@@ -1,43 +0,0 @@
1
- {
2
- "meta": {
3
- "limit": 20,
4
- "next": null,
5
- "offset": 0,
6
- "previous": null,
7
- "total_count": 1
8
- },
9
- "objects": [
10
- {
11
- "allow_private": true,
12
- "created_at": "2010-11-30T18:45:43",
13
- "default_event_size": 50,
14
- "default_title": "",
15
- "eventcreatepages": [],
16
- "events": "/rest/v1/event/?campaign=88",
17
- "eventsignuppages": [],
18
- "id": 88,
19
- "max_event_size": null,
20
- "name": "climate-change-paris-2015",
21
- "public_create_page": true,
22
- "public_search_page": true,
23
- "require_email_confirmation": true,
24
- "require_staff_approval": false,
25
- "resource_uri": "/rest/v1/campaign/88/",
26
- "show_address1": false,
27
- "show_attendee_count": false,
28
- "show_city": true,
29
- "show_directions": false,
30
- "show_public_description": true,
31
- "show_state": true,
32
- "show_title": true,
33
- "show_venue": true,
34
- "show_zip": true,
35
- "starts_at": null,
36
- "title": "Climate Change Paris 2015",
37
- "updated_at": "2015-06-19T01:39:09",
38
- "use_start_date": true,
39
- "use_start_time": true,
40
- "use_title": true
41
- }
42
- ]
43
- }
@@ -1,42 +0,0 @@
1
- {
2
- "meta": {
3
- "limit": 20,
4
- "next": null,
5
- "offset": 0,
6
- "previous": null,
7
- "total_count": 1
8
- },
9
- "objects": [
10
- {
11
- "actions": "/rest/v1/eventcreateaction/?page=818",
12
- "allow_multiple_responses": true,
13
- "campaign": "/rest/v1/campaign/88/",
14
- "campaign_title": "",
15
- "created_at": "2010-11-30T18:45:43",
16
- "eventcreateform": null,
17
- "fields": { },
18
- "followup": null,
19
- "goal": null,
20
- "goal_type": "actions",
21
- "hidden": false,
22
- "hosted_with": "/rest/v1/hostingplatform/1/",
23
- "id": 818,
24
- "language": "/rest/v1/language/100/",
25
- "list": "/rest/v1/list/66/",
26
- "multilingual_campaign": null,
27
- "name": "climate-change-paris-2015-event-create",
28
- "never_spam_check": false,
29
- "notes": "",
30
- "real_actions": true,
31
- "recognize": "once",
32
- "required_fields": [],
33
- "resource_uri": "/rest/v1/eventcreatepage/818/",
34
- "status": "active",
35
- "tags": [],
36
- "title": "Climate Change Paris 2015: event create",
37
- "type": "EventCreate",
38
- "updated_at": "2015-06-19T01:39:09",
39
- "url": ""
40
- }
41
- ]
42
- }
@@ -1,41 +0,0 @@
1
- {
2
- "meta": {
3
- "limit": 20,
4
- "next": null,
5
- "offset": 0,
6
- "previous": null,
7
- "total_count": 1
8
- },
9
- "objects": [
10
- {
11
- "actions": "/rest/v1/eventsignupaction/?page=819",
12
- "allow_multiple_responses": true,
13
- "campaign": "/rest/v1/campaign/88/",
14
- "created_at": "2017-09-01T14:49:50",
15
- "eventsignupform": null,
16
- "fields": {},
17
- "followup": null,
18
- "goal": null,
19
- "goal_type": "actions",
20
- "hidden": false,
21
- "hosted_with": "/rest/v1/hostingplatform/1/",
22
- "id": 819,
23
- "language": "/rest/v1/language/100/",
24
- "list": "/rest/v1/list/66/",
25
- "multilingual_campaign": null,
26
- "name": "climate-change-paris-2015-event-signup",
27
- "never_spam_check": false,
28
- "notes": "",
29
- "real_actions": true,
30
- "recognize": "once",
31
- "required_fields": [],
32
- "resource_uri": "/rest/v1/eventsignuppage/819/",
33
- "status": "active",
34
- "tags": [],
35
- "title": "Climate Change Paris 2015: event signup",
36
- "type": "EventSignup",
37
- "updated_at": "2017-09-01T14:49:50",
38
- "url": ""
39
- }
40
- ]
41
- }
@@ -1,18 +0,0 @@
1
- {"actions": "/rest/v1/petitionaction/?page=1", "allow_multiple_responses": false, "cms_form": "/rest/v1/petitionform/1/", "created_at": "2009-06-26T18:14:25", "delivery_template": "", "fields": {}, "followup": {
2
- "email_body": "<p>Dear {{user.first_name}},</p>\r\n<p>Thank you for signing!</p>\r\n<p>Best,</p>\r\n<p>Food Democracy Now</p>",
3
- "email_custom_from": "",
4
- "email_from_line": "/rest/v1/fromline/1/",
5
- "email_subject": "Thanks for demanding a sustainable USDA",
6
- "email_wrapper": "/rest/v1/emailwrapper/1/",
7
- "id": 1,
8
- "notifications": [],
9
- "page": "/rest/v1/petitionpage/1/",
10
- "resource_uri": "/rest/v1/pagefollowup/1/",
11
- "send_email": true,
12
- "send_notifications": false,
13
- "send_pushes": false,
14
- "send_taf": true,
15
- "taf_body": "Sample tellafriend content",
16
- "taf_subject": "Sample tellafriend message",
17
- "url": "/cms/thanks/usda/"
18
- }, "goal": 10, "goal_type": "actions", "hidden": false, "hosted_with": "/rest/v1/hostingplatform/1/", "id": 1, "immediate_email_subject": "", "language": "/rest/v1/language/100/", "list": "/rest/v1/list/1/", "multilingual_campaign": null, "name": "usda", "one_click": false, "recognize": "once", "required_fields": [], "resource_uri": "/rest/v1/petitionpage/1/", "send_immediate_email": false, "send_immediate_email_override_limit": false, "send_immediate_fax": false, "status": "active", "tags": [], "title": "Demand a Sustainable USDA", "type": "Petition", "updated_at": "2012-07-19T13:45:39", "url": ""}
@@ -1,33 +0,0 @@
1
- { "meta": { "limit": 20,
2
- "next": "None",
3
- "offset": 0,
4
- "previous": "None",
5
- "total_count": 3},
6
- "objects": [ { "created_at": "2015-09-29T04:15:50",
7
- "id": 1,
8
- "normalized_phone": "7755555555",
9
- "phone": "7755555555",
10
- "resource_uri": "/rest/v1/phone/1/",
11
- "source": "api",
12
- "type": "home",
13
- "updated_at": "2016-03-31T17:05:27",
14
- "user": "/rest/v1/user/1/"},
15
- { "created_at": "2012-05-12T23:49:44",
16
- "id": 2,
17
- "normalized_phone": "7755555577",
18
- "phone": "7755555577",
19
- "resource_uri": "/rest/v1/phone/2/",
20
- "source": "user",
21
- "type": "home",
22
- "updated_at": "2016-03-31T17:05:27",
23
- "user": "/rest/v1/user/1/"},
24
- { "created_at": "2012-05-12T23:49:44",
25
- "id": 3,
26
- "normalized_phone": "3103103310",
27
- "phone": "310-310-3310",
28
- "resource_uri": "/rest/v1/phone/3/",
29
- "source": "user",
30
- "type": "mobile",
31
- "updated_at": "2016-03-31T17:05:27",
32
- "user": "/rest/v1/user/1/"}]
33
- }
@@ -1 +0,0 @@
1
- {"actions": "/rest/v1/action/?user=1", "address1": "", "address2": "", "city": "Philadelphia", "country": "United States", "created_at": "2009-09-02T18:42:54", "email": "walkers@wawd.com", "events": "/rest/v1/event/?user=1", "eventsignups": "/rest/v1/eventsignup/?user=1", "fields": {"abc1": "2012-07-09 22:22:38", "abc2": "1", "abc4": "808003061", "abc5": "100", "abc6": "unsubscribed", "abc8": "roboticdogs", "color": ["blue", "yellow"], "food": "meatloaf", "test_custom": "\">la la la"}, "first_name": "", "id": 1, "lang": "/rest/v1/language/100/", "last_name": "", "location": "/rest/v1/location/1/", "middle_name": "", "orderrecurrings": "/rest/v1/orderrecurring/?user=1", "orders": "/rest/v1/order/?user=1", "phones": ["/rest/v1/phone/83/", "/rest/v1/phone/12/"], "plus4": "", "postal": "19130", "prefix": "", "rand_id": 382815937, "region": "PA", "resource_uri": "/rest/v1/user/1/", "source": "", "state": "PA", "subscription_status": "unsubscribed", "subscriptionhistory": "/rest/v1/subscriptionhistory/?user=1", "subscriptions": "/rest/v1/subscription/?user=1", "suffix": "", "token": ".1.9P66-W", "updated_at": "2013-10-02T00:56:36", "usergeofields": "/rest/v1/usergeofield/?user=1", "usermailings": "/rest/v1/usermailing/?user=1", "useroriginal": "/rest/v1/useroriginal/1/", "zip": "19130"}
@@ -1 +0,0 @@
1
- {"actions": "/rest/v1/action/?user=1", "address1": "", "address2": "", "city": "Philadelphia", "country": "United States", "created_at": "2009-09-02T18:42:54", "email": "walkers@wawd.com", "events": "/rest/v1/event/?user=1", "eventsignups": "/rest/v1/eventsignup/?user=1", "fields": {"abc1": "2012-07-09 22:22:38", "abc2": "1", "abc4": "808003061", "abc5": "100", "abc6": "unsubscribed", "abc8": "roboticdogs", "color": ["blue", "yellow"], "food": "meatloaf", "test_custom": "\">la la la"}, "first_name": "", "id": 1, "lang": "/rest/v1/language/100/", "last_name": "", "location": "/rest/v1/location/1/", "middle_name": "", "orderrecurrings": "/rest/v1/orderrecurring/?user=1", "orders": "/rest/v1/order/?user=1", "phones": [], "plus4": "", "postal": "19130", "prefix": "", "rand_id": 382815937, "region": "PA", "resource_uri": "/rest/v1/user/1/", "source": "", "state": "PA", "subscription_status": "unsubscribed", "subscriptionhistory": "/rest/v1/subscriptionhistory/?user=1", "subscriptions": "/rest/v1/subscription/?user=1", "suffix": "", "token": ".1.9P66-W", "updated_at": "2013-10-02T00:56:36", "usergeofields": "/rest/v1/usergeofield/?user=1", "usermailings": "/rest/v1/usermailing/?user=1", "useroriginal": "/rest/v1/useroriginal/1/", "zip": "19130"}
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe ActionKitRest::Actions::EventCreateAction do
6
- describe '#get' do
7
- let(:actionkit) { ActionKitRest.new(host: 'test.com') }
8
-
9
- before :each do
10
- stub_request(:get, 'https://test.com/rest/v1/eventcreateaction/123/')
11
- .to_return(body: fixture('action/event_create_action.json'), status: '200', headers: { content_type: 'application/json; charset=utf-8' })
12
- end
13
-
14
- it 'should retrieve eventcreateaction and aggregate parsed event and user IDs' do
15
- ak_event_create_action = actionkit.event_create_action.get('123')
16
-
17
- expect(ak_event_create_action.id).to eq(12_345)
18
- expect(ak_event_create_action.event_id).to eq('999')
19
- expect(ak_event_create_action.user_id).to eq('112233')
20
- end
21
- end
22
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe ActionKitRest::Actions::EventSignupAction do
6
- describe '#get' do
7
- let(:actionkit) { ActionKitRest.new(host: 'test.com') }
8
-
9
- before :each do
10
- stub_request(:get, 'https://test.com/rest/v1/eventsignupaction/54321/')
11
- .to_return(body: fixture('action/event_signup_action.json'), status: '200', headers: { content_type: 'application/json; charset=utf-8' })
12
- end
13
-
14
- it 'should retrieve eventsignupaction and aggregate parsed event sign-up and user IDs' do
15
- ak_event_signup_action = actionkit.event_signup_action.get('54321')
16
-
17
- expect(ak_event_signup_action.id).to eq(54_321)
18
- expect(ak_event_signup_action.event_signup_id).to eq('888')
19
- expect(ak_event_signup_action.user_id).to eq('111')
20
- end
21
- end
22
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe ActionKitRest::AllowedUserField do
6
- let(:status) { 200 }
7
- let(:standard_headers) { { content_type: 'application/json; charset=utf-8' } }
8
-
9
- subject { ActionKitRest.new(host: 'test.com', username: 'alice', password: 'somesecret') }
10
-
11
- before(:each) do
12
- logger = double
13
- logger.stub(:debug).and_return(true)
14
-
15
- ActionKitRest.stub(:logger).and_return(logger)
16
- Vertebrae::Base.stub(:logger).and_return(logger)
17
- end
18
-
19
- describe '#list' do
20
- let(:request_path) { 'alloweduserfield/' }
21
- let(:response_body) { fixture('allowed_user_field/list.json') }
22
-
23
- before :each do
24
- stub_get(request_path).with(basic_auth: %w[alice somesecret])
25
- .to_return(body: response_body,
26
- status: status,
27
- headers: standard_headers)
28
- end
29
-
30
- it 'should return a list of objects' do
31
- fields = subject.allowed_user_field.list
32
- fields.each do |field|
33
- expect(field).to respond_to(:name)
34
- end
35
- end
36
- end
37
-
38
- describe '#find' do
39
- let(:request_path) { 'alloweduserfield/?name=age' }
40
- let(:response_body) { fixture('allowed_user_field/list_filtered.json') }
41
-
42
- before :each do
43
- stub_get(request_path).with(basic_auth: %w[alice somesecret])
44
- .to_return(body: response_body,
45
- status: status,
46
- headers: standard_headers)
47
- end
48
-
49
- it 'should return a single object' do
50
- field = subject.allowed_user_field.find('age')
51
- expect(field.field_type).to eq 'integer'
52
- end
53
- end
54
-
55
- describe '#create' do
56
- let(:create_request_path) { 'alloweduserfield/' }
57
- let(:create_request_body) { { name: 'foo' }.to_json }
58
- let(:create_status) { 201 }
59
- let(:created_url) { 'https://test.com/rest/v1/alloweduserfield/foo/' }
60
- let(:get_request_path) { 'alloweduserfield/foo/' }
61
- let(:get_response_body) { fixture('allowed_user_field/get.json') }
62
-
63
- before :each do
64
- stub_post(create_request_path).with(basic_auth: %w[alice somesecret],
65
- body: create_request_body)
66
- .to_return(status: create_status,
67
- headers: standard_headers.merge(Location: created_url))
68
-
69
- stub_get(get_request_path).with(basic_auth: %w[alice somesecret])
70
- .to_return(body: get_response_body,
71
- status: status,
72
- headers: standard_headers)
73
- end
74
-
75
- it 'should POST to the endpoint, then do a GET on the created object' do
76
- field = subject.allowed_user_field.create({ name: 'foo' })
77
- expect(field.display_name).to eq 'Foo'
78
- end
79
- end
80
- end
@@ -1,111 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'support/shared_contexts/stub_logger'
5
-
6
- describe ActionKitRest::API do
7
- include_context 'stub_logger'
8
-
9
- subject { ActionKitRest::API.new(host: 'example.com', username: 'foo', password: 'bar') }
10
-
11
- describe 'error detection' do
12
- let(:request_body) { {some: 'data'} }
13
-
14
- before :each do
15
- stub_request(:post, 'https://example.com/rest/v1/something/')
16
- .to_return(status: response_status, body: response_body,
17
- headers: { content_type: 'application/json; charset=utf-8' })
18
- end
19
-
20
- context 'successful response' do
21
- let(:response_status) { 200 }
22
- let(:response_body) { '{"message": "good job!"}' }
23
-
24
- it 'should not raise' do
25
- subject.post_request('something/', request_body)
26
- end
27
- end
28
-
29
- context '400 response' do
30
- let(:response_status) { 400 }
31
-
32
- context 'unable to associate mailing ID' do
33
- let(:response_body) { '{"errors": {"mailing_id": ["Unable to associate this mailing ID with account."]}}' }
34
-
35
- it 'should raise an InvalidAkidError' do
36
- expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::InvalidAkidError)
37
- end
38
- end
39
-
40
- context 'unable to associate mailing ID error in Hebrew' do
41
- let(:response_body) { '{"errors": {"mailing_id": ["לא הצלחנו לקשר בין מספר הזיהוי של רשימת הדיוור הזו לבין החשבון."]}}' }
42
-
43
- it 'should raise an InvalidAkidError' do
44
- expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::InvalidAkidError)
45
- end
46
- end
47
-
48
- context 'other error' do
49
- let(:response_body) { '{"errors": {"zip": ["There is something wrong with your ZIP code!"]}}' }
50
-
51
- it 'sould raise a ValidationError' do
52
- expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::ValidationError)
53
- end
54
- end
55
-
56
- context 'no errors key in response' do
57
- let(:response_body) { '{"strange": "things are happening here"}' }
58
-
59
- it 'sould raise a ValidationError' do
60
- expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::ValidationError)
61
- end
62
- end
63
-
64
- context 'non-hash errors key in response' do
65
- let(:response_body) { '{"errors": "what is going on?"}' }
66
-
67
- it 'sould raise a ValidationError' do
68
- expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::ValidationError)
69
- end
70
- end
71
- end
72
-
73
- context '401 response' do
74
- let(:response_status) { 401 }
75
- let(:response_body) { '{"error": "Your API key is no good"}' }
76
-
77
- it 'should raise an Unauthorized exception' do
78
- expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::Unauthorized)
79
- end
80
- end
81
-
82
- context '404 response' do
83
- let(:response_status) { 404 }
84
- let(:response_body) { '{"error": "not found"}' }
85
-
86
- it 'should raise a NotFound exception' do
87
- expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::NotFound)
88
- end
89
- end
90
-
91
- context '500 response' do
92
- let(:response_status) { 500 }
93
-
94
- context 'Try Again Later message' do
95
- let(:response_body) { '{"error": "Sorry, this request could not be processed. Please try again later."}' }
96
-
97
- it 'should raise a TryAgainLater exception' do
98
- expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::TryAgainLater)
99
- end
100
- end
101
-
102
- context 'other error message' do
103
- let(:response_body) { '{"error": "Something is wrong, we will fix it!"}' }
104
-
105
- it 'should raise a StandardError' do
106
- expect{ subject.post_request('something/', request_body) }.to raise_error(StandardError)
107
- end
108
- end
109
- end
110
- end
111
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe ActionKitRest do
6
- describe 'logging' do
7
- it 'should have a logger' do
8
- ActionKitRest.respond_to?(:logger).should be_truthy
9
- end
10
-
11
- it 'should be able to log debug methods' do
12
- ActionKitRest.logger.respond_to?(:debug).should be_truthy
13
- end
14
-
15
- it 'should be settable' do
16
- ActionKitRest.respond_to?(:logger=).should be_truthy
17
- log = double
18
- ActionKitRest.logger = log
19
- ActionKitRest.logger.should == log
20
- end
21
- end
22
- end
@@ -1,112 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe ActionKitRest::Page do
6
- subject { ActionKitRest.new(host: 'test.com') }
7
-
8
- before(:each) do
9
- logger = double
10
- logger.stub(:debug).and_return(true)
11
-
12
- ActionKitRest.stub(:logger).and_return(logger)
13
- Vertebrae::Base.stub(:logger).and_return(logger)
14
- end
15
-
16
- describe 'configuration' do
17
- it 'should propagate the host to the page' do
18
- subject.connection.configuration.host.should == 'test.com'
19
- end
20
-
21
- it 'should have a client' do
22
- subject.page.client.should_not be_nil
23
- end
24
-
25
- describe 'adapter' do
26
- subject { ActionKitRest.new(host: 'test.com', adapter: :em_synchrony) }
27
-
28
- it 'should propagate the adapter' do
29
- subject.connection.configuration.adapter.should == :em_synchrony
30
- end
31
- end
32
- end
33
-
34
- describe 'retrieval' do
35
- before(:each) do
36
- stub_get(request_path).to_return(body: body, status: status,
37
- headers: { content_type: 'application/json; charset=utf-8' })
38
- end
39
-
40
- describe '.list' do
41
- let(:status) { 200 }
42
- let(:body) { fixture('page/collection.json') }
43
- let(:request_path) { 'page/' }
44
-
45
- it 'should allow listing the objects' do
46
- pages = subject.page.list
47
-
48
- pages.should be_an_instance_of(ActionKitRest::Response::Wrapper)
49
-
50
- pages.each do |obj|
51
- obj.should be_an_instance_of(Hashie::Mash)
52
- obj.should respond_to(:goal)
53
- end
54
- end
55
- end
56
-
57
- describe '.page' do
58
- let(:body) { fixture('page/object.json') }
59
- let(:request_path) { 'page/1/' }
60
-
61
- describe 'success' do
62
- let(:status) { 200 }
63
- it 'should return a single object' do
64
- page = subject.page.get(1)
65
- page.goal.should == 10
66
- end
67
- end
68
-
69
- describe 'not found' do
70
- let(:status) { 404 }
71
-
72
- it 'should return nil' do
73
- -> { subject.page.get(1).should.nil? }.should raise_exception(ActionKitRest::Response::NotFound)
74
- end
75
- end
76
-
77
- describe 'error' do
78
- let(:status) { 400 }
79
- let(:body) { fixture('error.json') }
80
-
81
- it 'should raise an ak validation response error' do
82
- -> { subject.page.get(1) }.should raise_exception(ActionKitRest::Response::ValidationError)
83
- end
84
- end
85
-
86
- describe 'mailing ID error' do
87
- let(:status) { 400 }
88
- let(:body) { '{"errors": {"mailing_id": ["Unable to associate this mailing ID with account."]}}' }
89
-
90
- it 'should raise an Invalid AKID response error' do
91
- -> { subject.page.get(1) }.should raise_exception(ActionKitRest::Response::InvalidAkidError)
92
- end
93
- end
94
-
95
- describe 'an error' do
96
- let(:status) { 500 }
97
-
98
- it 'should return nil' do
99
- -> { subject.page.get(1).should.nil? }.should raise_exception(StandardError)
100
- end
101
- end
102
-
103
- describe 'try again' do
104
- let(:status) { 500 }
105
- let(:body) { '{"error": "Sorry, this request could not be processed. Please try again later."}' }
106
- it 'should return nil' do
107
- -> { subject.page.get(1).should.nil? }.should raise_exception(ActionKitRest::Response::TryAgainLater)
108
- end
109
- end
110
- end
111
- end
112
- end
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'support/shared_contexts/stub_logger'
5
-
6
- describe ActionKitRest::Pages::EventCampaignPage do
7
- include_context 'stub_logger'
8
-
9
- describe 'create' do
10
- let(:actionkit) { ActionKitRest.new(host: 'test.com') }
11
-
12
- let(:event_campaign_title) { 'Climate Change Paris 2015' }
13
- let(:event_campaign_name) { 'climate-change-paris-2015' }
14
-
15
- before :each do
16
- stub_request(:post, 'https://test.com/rest/v1/campaign/')
17
- .with(body: "{\"title\":\"#{event_campaign_title}\",\"name\":\"#{event_campaign_name}\"}")
18
- .to_return({ status: '200', headers: { location: 'https://test.com/rest/v1/campaign/88/' } })
19
-
20
- stub_request(:get, 'https://test.com/rest/v1/campaign/88/')
21
- .to_return({ body: fixture('page/campaign.json'), status: '200',
22
- headers: { content_type: 'application/json; charset=utf-8' } })
23
-
24
- stub_request(:post, 'https://test.com/rest/v1/eventcreatepage/')
25
- .with(body: '{"campaign":"/rest/v1/campaign/88/","name":"climate-change-paris-2015-event-create","title":"Climate Change Paris 2015: event create","tags":["/rest/v1/tag/1/","/rest/v1/tag/5/"]}')
26
- .to_return({ status: '200', headers: { location: 'https://test.com/rest/v1/eventcreatepage/99/' } })
27
-
28
- stub_request(:post, 'https://test.com/rest/v1/eventsignuppage/')
29
- .with(body: '{"campaign":"/rest/v1/campaign/88/","name":"climate-change-paris-2015-event-signup","title":"Climate Change Paris 2015: event signup","tags":["/rest/v1/tag/1/","/rest/v1/tag/5/"]}')
30
- .to_return({ status: '200', headers: { location: 'https://test.com/rest/v1/eventsignuppage/111/' } })
31
- end
32
-
33
- it 'should create an event campaign' do
34
- resp = actionkit.event_campaign_page.create({ title: 'Climate Change Paris 2015',
35
- name: 'climate-change-paris-2015', event_pages_tags: ['/rest/v1/tag/1/', '/rest/v1/tag/5/'] })
36
- expect(resp.title).to eq event_campaign_title
37
- expect(resp.name).to eq event_campaign_name
38
-
39
- expect(a_request(:post, 'https://test.com/rest/v1/campaign/')).to have_been_made
40
- expect(a_request(:get, 'https://test.com/rest/v1/campaign/88/')).to have_been_made
41
- end
42
-
43
- it 'should create associated event and signup create pages' do
44
- resp = actionkit.event_campaign_page.create({ title: 'Climate Change Paris 2015',
45
- name: 'climate-change-paris-2015', event_pages_tags: ['/rest/v1/tag/1/', '/rest/v1/tag/5/'] })
46
- expect(resp.event_create_page_name).to eq 'climate-change-paris-2015-event-create'
47
- expect(resp.event_signup_page_name).to eq 'climate-change-paris-2015-event-signup'
48
-
49
- expect(a_request(:post, 'https://test.com/rest/v1/eventcreatepage/')).to have_been_made
50
- expect(a_request(:post, 'https://test.com/rest/v1/eventsignuppage/')).to have_been_made
51
- end
52
- end
53
-
54
- describe 'find' do
55
- let(:actionkit) { ActionKitRest.new(host: 'test.com') }
56
-
57
- let(:event_campaign_title) { 'Climate Change Paris 2015' }
58
- let(:event_campaign_name) { 'climate-change-paris-2015' }
59
-
60
- before :each do
61
- stub_request(:get, 'https://test.com/rest/v1/campaign/?name=climate-change-paris-2015')
62
- .to_return(body: fixture('page/find_campaign.json'), status: '200', headers: { content_type: 'application/json; charset=utf-8' })
63
- stub_request(:get, 'https://test.com/rest/v1/eventcreatepage/?name=climate-change-paris-2015-event-create')
64
- .to_return(body: fixture('page/find_event_create.json'), status: '200', headers: { content_type: 'application/json; charset=utf-8' })
65
- stub_request(:get, 'https://test.com/rest/v1/eventsignuppage/?name=climate-change-paris-2015-event-signup')
66
- .to_return(body: fixture('page/find_event_signup.json'), status: '200', headers: { content_type: 'application/json; charset=utf-8' })
67
- end
68
-
69
- it 'should retrieve event campaign by name' do
70
- resp = actionkit.event_campaign_page.find(event_campaign_name)
71
-
72
- expect(resp.name).to eq event_campaign_name
73
- expect(resp.event_create_page_name).to eq 'climate-change-paris-2015-event-create'
74
- expect(resp.event_signup_page_name).to eq 'climate-change-paris-2015-event-signup'
75
- end
76
- end
77
- end