cta_aggregator_client 0.1.0 → 0.4.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 +4 -4
- data/lib/cta_aggregator_client/advocacy_campaign.rb +5 -1
- data/lib/cta_aggregator_client/api/client.rb +22 -2
- data/lib/cta_aggregator_client/api/utilities.rb +1 -1
- data/lib/cta_aggregator_client/cta_resource.rb +19 -2
- data/lib/cta_aggregator_client/event.rb +5 -0
- data/lib/cta_aggregator_client/version.rb +1 -1
- data/spec/helpers/test_helpers.rb +1 -1
- data/spec/integration/advocacy_campaign_spec.rb +4 -2
- data/spec/integration/events_spec.rb +5 -2
- data/spec/integration/location_spec.rb +3 -0
- data/spec/integration/target_spec.rb +2 -0
- data/spec/shared_examples/creatable_resource.rb +13 -7
- data/spec/shared_examples/deletable_resource.rb +31 -0
- data/spec/shared_examples/updatable_resource.rb +42 -0
- data/spec/spec_helper.rb +2 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0296b1a6b5e845c92ff5e651a0845f9e414ebc53'
|
4
|
+
data.tar.gz: ac44dbb3526e56a04b642a0fdfc298ab2af27f4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a323263b16f7661e6398968bcebdc945936807efb20bd30f71a60d24fea94bf529f2e63d73798ea6c49a9c69349881b4fa117f1ebbb023b563577cec4a30860
|
7
|
+
data.tar.gz: c32e4d4ce6caedcf35a50b50219215fc0739eabbd700980c1fe75fe412419473b354181dd09d406124c6a469110a2fef8dd6b7074384e772e40ad43dd0f7d72a
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'cta_aggregator_client/cta_resource'
|
2
|
-
|
3
2
|
module CTAAggregatorClient
|
4
3
|
module AdvocacyCampaign
|
5
4
|
extend CTAResource
|
6
5
|
|
7
6
|
RESOURCE_NAME = :advocacy_campaign
|
7
|
+
RELATIONSHIPS = :targets
|
8
8
|
|
9
9
|
class << self
|
10
10
|
|
@@ -12,6 +12,10 @@ module CTAAggregatorClient
|
|
12
12
|
RESOURCE_NAME
|
13
13
|
end
|
14
14
|
|
15
|
+
def relationships
|
16
|
+
RELATIONSHIPS
|
17
|
+
end
|
18
|
+
|
15
19
|
end
|
16
20
|
end
|
17
21
|
end
|
@@ -36,8 +36,28 @@ module CTAAggregatorClient
|
|
36
36
|
perform_authenticated_request(:post, url, payload)
|
37
37
|
end
|
38
38
|
|
39
|
+
def update(resource_name, uuid, attributes)
|
40
|
+
url = "#{base_url}/#{api_version}/#{resource_name}s/#{uuid}"
|
41
|
+
payload = {
|
42
|
+
'data': {
|
43
|
+
'type': "#{resource_name}s",
|
44
|
+
'id': uuid,
|
45
|
+
'attributes': attributes
|
46
|
+
}
|
47
|
+
}.to_json
|
48
|
+
|
49
|
+
perform_authenticated_request(:put, url, payload)
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete(resource_name, uuid)
|
53
|
+
url = "#{base_url}/#{api_version}/#{resource_name}s/#{uuid}"
|
54
|
+
|
55
|
+
raw_response = RestClient.delete(url, headers_with_access_token)
|
56
|
+
translate_response(raw_response)
|
57
|
+
end
|
58
|
+
|
39
59
|
def relationship_params(relationships)
|
40
|
-
return {} unless relationships
|
60
|
+
return {} unless relationships && relationships.reject { |k,v| v.nil? }.any?
|
41
61
|
|
42
62
|
relationships.each_with_object({}) do |(resource_name, uuid_data), obj|
|
43
63
|
if uuid_data.is_a? Array
|
@@ -73,7 +93,7 @@ module CTAAggregatorClient
|
|
73
93
|
perform_authenticated_request(:put, url, payload)
|
74
94
|
end
|
75
95
|
|
76
|
-
def perform_authenticated_request(http_method, url, payload)
|
96
|
+
def perform_authenticated_request(http_method, url, payload={})
|
77
97
|
raw_response = RestClient.send(http_method.to_sym, url, payload, headers_with_access_token)
|
78
98
|
translate_response(raw_response)
|
79
99
|
end
|
@@ -11,13 +11,30 @@ module CTAAggregatorClient
|
|
11
11
|
API::Client.find(resource_name, uuid)
|
12
12
|
end
|
13
13
|
|
14
|
-
def create(attributes
|
15
|
-
|
14
|
+
def create(attributes)
|
15
|
+
if relationships
|
16
|
+
relationship_data = { relationships => attributes.delete(relationships) }
|
17
|
+
end
|
18
|
+
|
19
|
+
API::Client.create(resource_name, attributes, relationship_data)
|
20
|
+
end
|
21
|
+
|
22
|
+
def update(attributes)
|
23
|
+
uuid = attributes.delete(:id)
|
24
|
+
API::Client.update(resource_name, uuid, attributes)
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete(uuid)
|
28
|
+
API::Client.delete(resource_name, uuid)
|
16
29
|
end
|
17
30
|
|
18
31
|
def resource_name
|
19
32
|
raise NotImplementedError
|
20
33
|
end
|
21
34
|
|
35
|
+
def relationships
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
22
39
|
end
|
23
40
|
end
|
@@ -5,6 +5,7 @@ module CTAAggregatorClient
|
|
5
5
|
extend CTAResource
|
6
6
|
|
7
7
|
RESOURCE_NAME = :event
|
8
|
+
RELATIONSHIPS = :location
|
8
9
|
|
9
10
|
class << self
|
10
11
|
|
@@ -12,6 +13,10 @@ module CTAAggregatorClient
|
|
12
13
|
RESOURCE_NAME
|
13
14
|
end
|
14
15
|
|
16
|
+
def relationships
|
17
|
+
RELATIONSHIPS
|
18
|
+
end
|
19
|
+
|
15
20
|
end
|
16
21
|
end
|
17
22
|
end
|
@@ -4,6 +4,8 @@ describe CTAAggregatorClient::AdvocacyCampaign do
|
|
4
4
|
|
5
5
|
it_behaves_like 'listable resource'
|
6
6
|
it_behaves_like 'findable resource'
|
7
|
+
it_behaves_like 'updatable resource'
|
8
|
+
it_behaves_like 'deletable resource'
|
7
9
|
|
8
10
|
context 'creation' do
|
9
11
|
campaign_attrs = {
|
@@ -14,9 +16,9 @@ describe CTAAggregatorClient::AdvocacyCampaign do
|
|
14
16
|
featured_image_url: 'http://lorempixel.com/300/300',
|
15
17
|
action_type: 'email',
|
16
18
|
template: 'Eum itaque et nisi dolores assumenda ipsum. Voluptates qui aut nobis veniam maxime qui. Illum saepe eum corporis vero qui soluta aliquam.\nTemporibus reiciendis velit fugiat. Facere laborum quia ea laboriosam necessitatibus quisquam eligendi. Et est dolorem eligendi id aut sint.\nAnimi qui totam voluptatem nesciunt iure et dolorem. Eos ut dolorum et quo illum fuga atque. Facere a ipsa corrupti assumenda provident commodi facilis. Eligendi officia est et.',
|
19
|
+
targets: ['a2f6f86b-a214-4892-8c06-8caece820fb0', '215ed993-3cd1-4fbc-b8af-7e2082813d06']
|
17
20
|
}
|
18
|
-
relationship_attrs = { targets: ['a2f6f86b-a214-4892-8c06-8caece820fb0', '215ed993-3cd1-4fbc-b8af-7e2082813d06'] }
|
19
21
|
|
20
|
-
it_behaves_like 'creatable resource', campaign_attrs,
|
22
|
+
it_behaves_like 'creatable resource', campaign_attrs, :targets
|
21
23
|
end
|
22
24
|
end
|
@@ -4,6 +4,9 @@ describe CTAAggregatorClient::Event do
|
|
4
4
|
|
5
5
|
it_behaves_like 'listable resource'
|
6
6
|
it_behaves_like 'findable resource'
|
7
|
+
it_behaves_like 'updatable resource'
|
8
|
+
it_behaves_like 'deletable resource'
|
9
|
+
|
7
10
|
context 'creation' do
|
8
11
|
event_attrs = {
|
9
12
|
title: 'March on Washington',
|
@@ -14,10 +17,10 @@ describe CTAAggregatorClient::Event do
|
|
14
17
|
start_date: '2017-07-08T03:58:25.098Z',
|
15
18
|
end_date: '2017-07-13T03:58:25.098Z',
|
16
19
|
free: false,
|
20
|
+
location: '215ed993-3cd1-4fbc-b8af-7e2082813d06'
|
17
21
|
}
|
18
|
-
relationship_attrs = { location: '215ed993-3cd1-4fbc-b8af-7e2082813d06' }
|
19
22
|
|
20
|
-
it_behaves_like 'creatable resource', event_attrs,
|
23
|
+
it_behaves_like 'creatable resource', event_attrs, :location
|
21
24
|
end
|
22
25
|
|
23
26
|
end
|
@@ -4,6 +4,9 @@ describe CTAAggregatorClient::Location do
|
|
4
4
|
|
5
5
|
it_behaves_like 'listable resource'
|
6
6
|
it_behaves_like 'findable resource'
|
7
|
+
it_behaves_like 'updatable resource'
|
8
|
+
it_behaves_like 'deletable resource'
|
9
|
+
|
7
10
|
context 'creation' do
|
8
11
|
attributes = {
|
9
12
|
venue: 'Eastern Kemmer University',
|
@@ -4,7 +4,8 @@ shared_examples_for "creatable resource" do |passed_attrs, passed_relationships,
|
|
4
4
|
let(:token) { Factory.token }
|
5
5
|
|
6
6
|
def relationships(relationship_hash)
|
7
|
-
return {} unless relationship_hash
|
7
|
+
return {} unless relationship_hash && relationship_hash.reject { |k,v| v.nil? }.any?
|
8
|
+
|
8
9
|
relationship_hash.each_with_object({}) do |(resource_name, uuid_data), obj|
|
9
10
|
if uuid_data.is_a? Array
|
10
11
|
obj[resource_name.to_sym] = {
|
@@ -28,12 +29,14 @@ shared_examples_for "creatable resource" do |passed_attrs, passed_relationships,
|
|
28
29
|
resource_name = formatted_resource_name(described_class, resource)
|
29
30
|
|
30
31
|
url = "#{api_url}/#{resource_name}"
|
32
|
+
payload_params = passed_attrs.clone
|
33
|
+
relationship_data = { passed_relationships => payload_params.delete(passed_relationships) }
|
31
34
|
|
32
35
|
payload = {
|
33
36
|
'data': {
|
34
37
|
'type': resource_name,
|
35
|
-
'attributes':
|
36
|
-
'relationships': relationships(
|
38
|
+
'attributes': payload_params,
|
39
|
+
'relationships': relationships(relationship_data)
|
37
40
|
}.reject{ |k,v| v.empty? }
|
38
41
|
}
|
39
42
|
|
@@ -53,7 +56,7 @@ shared_examples_for "creatable resource" do |passed_attrs, passed_relationships,
|
|
53
56
|
headers_with_auth_token
|
54
57
|
).and_return(response)
|
55
58
|
|
56
|
-
expect(described_class.create(passed_attrs
|
59
|
+
expect(described_class.create(passed_attrs)).to eq response
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
@@ -73,11 +76,14 @@ shared_examples_for "creatable resource" do |passed_attrs, passed_relationships,
|
|
73
76
|
resource_name = formatted_resource_name(described_class, resource)
|
74
77
|
|
75
78
|
url = "#{api_url}/#{resource_name}"
|
79
|
+
payload_params = passed_attrs.clone
|
80
|
+
relationship_data = { passed_relationships => payload_params.delete(passed_relationships) }
|
81
|
+
|
76
82
|
payload = {
|
77
83
|
'data': {
|
78
84
|
'type': resource_name,
|
79
|
-
'attributes':
|
80
|
-
'relationships': relationships(
|
85
|
+
'attributes': payload_params,
|
86
|
+
'relationships': relationships(relationship_data)
|
81
87
|
}.reject{ |k,v| v.empty? }
|
82
88
|
}
|
83
89
|
|
@@ -101,7 +107,7 @@ shared_examples_for "creatable resource" do |passed_attrs, passed_relationships,
|
|
101
107
|
header_sans_auth_token
|
102
108
|
).and_return(Factory.bad_token_response)
|
103
109
|
|
104
|
-
expect(described_class.create(passed_attrs
|
110
|
+
expect(described_class.create(passed_attrs).code).to eq 401
|
105
111
|
end
|
106
112
|
end
|
107
113
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
shared_examples_for "deletable resource" do |resource|
|
2
|
+
let(:response) { Factory.response }
|
3
|
+
let(:auth_response) { Factory.auth_response }
|
4
|
+
let(:token) { Factory.token }
|
5
|
+
let(:uuid) { '123' }
|
6
|
+
|
7
|
+
after do
|
8
|
+
CTAAggregatorClient::API::Authenticator.reset_auth
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'updates record' do
|
12
|
+
url = "#{api_url}/#{formatted_resource_name(described_class, resource)}/#{uuid}"
|
13
|
+
|
14
|
+
allow(RestClient).to receive(:post).with(
|
15
|
+
auth_url,
|
16
|
+
nil,
|
17
|
+
headers_with_auth_creds
|
18
|
+
).and_return(auth_response)
|
19
|
+
|
20
|
+
headers_with_auth_token = CTAAggregatorClient::API::Client.default_headers.merge(
|
21
|
+
authorization: "Bearer: #{token}"
|
22
|
+
)
|
23
|
+
|
24
|
+
expect(RestClient).to receive(:delete).with(
|
25
|
+
url,
|
26
|
+
headers_with_auth_token
|
27
|
+
).and_return(response)
|
28
|
+
|
29
|
+
expect(described_class.delete(uuid)).to eq response
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
shared_examples_for "updatable resource" do |resource|
|
2
|
+
let(:response) { Factory.response }
|
3
|
+
let(:auth_response) { Factory.auth_response }
|
4
|
+
let(:token) { Factory.token }
|
5
|
+
let(:uuid) { '123' }
|
6
|
+
let(:attrs_to_change) { {foo: :bar} }
|
7
|
+
let(:attrs) { {id: uuid}.merge(attrs_to_change) }
|
8
|
+
|
9
|
+
after do
|
10
|
+
CTAAggregatorClient::API::Authenticator.reset_auth
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'updates record' do
|
14
|
+
url = "#{api_url}/#{formatted_resource_name(described_class, resource)}/#{uuid}"
|
15
|
+
|
16
|
+
payload = {
|
17
|
+
'data': {
|
18
|
+
'type': formatted_resource_name(described_class, resource),
|
19
|
+
'id': uuid,
|
20
|
+
'attributes': attrs_to_change,
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
allow(RestClient).to receive(:post).with(
|
25
|
+
auth_url,
|
26
|
+
nil,
|
27
|
+
headers_with_auth_creds
|
28
|
+
).and_return(auth_response)
|
29
|
+
|
30
|
+
headers_with_auth_token = CTAAggregatorClient::API::Client.default_headers.merge(
|
31
|
+
authorization: "Bearer: #{token}"
|
32
|
+
)
|
33
|
+
|
34
|
+
expect(RestClient).to receive(:put).with(
|
35
|
+
url,
|
36
|
+
payload.to_json,
|
37
|
+
headers_with_auth_token
|
38
|
+
).and_return(response)
|
39
|
+
|
40
|
+
expect(described_class.update(attrs)).to eq response
|
41
|
+
end
|
42
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,8 @@ require 'cta_aggregator_client'
|
|
2
2
|
require 'shared_examples/listable_resource'
|
3
3
|
require 'shared_examples/findable_resource'
|
4
4
|
require 'shared_examples/creatable_resource'
|
5
|
+
require 'shared_examples/updatable_resource'
|
6
|
+
require 'shared_examples/deletable_resource'
|
5
7
|
require 'helpers/test_helpers'
|
6
8
|
require 'factory'
|
7
9
|
require 'pry'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cta_aggregator_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Downey
|
@@ -77,8 +77,10 @@ files:
|
|
77
77
|
- spec/integration/location_spec.rb
|
78
78
|
- spec/integration/target_spec.rb
|
79
79
|
- spec/shared_examples/creatable_resource.rb
|
80
|
+
- spec/shared_examples/deletable_resource.rb
|
80
81
|
- spec/shared_examples/findable_resource.rb
|
81
82
|
- spec/shared_examples/listable_resource.rb
|
83
|
+
- spec/shared_examples/updatable_resource.rb
|
82
84
|
- spec/spec_helper.rb
|
83
85
|
homepage: https://github.com/Ragtagteam/cta-aggregator-client-ruby
|
84
86
|
licenses:
|
@@ -112,6 +114,8 @@ test_files:
|
|
112
114
|
- spec/integration/location_spec.rb
|
113
115
|
- spec/integration/target_spec.rb
|
114
116
|
- spec/shared_examples/creatable_resource.rb
|
117
|
+
- spec/shared_examples/deletable_resource.rb
|
115
118
|
- spec/shared_examples/findable_resource.rb
|
116
119
|
- spec/shared_examples/listable_resource.rb
|
120
|
+
- spec/shared_examples/updatable_resource.rb
|
117
121
|
- spec/spec_helper.rb
|