cta_aggregator_client 0.1.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 +7 -0
- data/lib/cta_aggregator_client/advocacy_campaign.rb +17 -0
- data/lib/cta_aggregator_client/api/authenticator.rb +46 -0
- data/lib/cta_aggregator_client/api/client.rb +93 -0
- data/lib/cta_aggregator_client/api/utilities.rb +36 -0
- data/lib/cta_aggregator_client/configuration.rb +14 -0
- data/lib/cta_aggregator_client/cta_resource.rb +23 -0
- data/lib/cta_aggregator_client/event.rb +17 -0
- data/lib/cta_aggregator_client/location.rb +17 -0
- data/lib/cta_aggregator_client/response.rb +5 -0
- data/lib/cta_aggregator_client/target.rb +17 -0
- data/lib/cta_aggregator_client/version.rb +3 -0
- data/lib/cta_aggregator_client.rb +22 -0
- data/spec/factory.rb +32 -0
- data/spec/helpers/test_helpers.rb +26 -0
- data/spec/integration/advocacy_campaign_spec.rb +22 -0
- data/spec/integration/events_spec.rb +23 -0
- data/spec/integration/location_spec.rb +18 -0
- data/spec/integration/target_spec.rb +49 -0
- data/spec/shared_examples/creatable_resource.rb +108 -0
- data/spec/shared_examples/findable_resource.rb +15 -0
- data/spec/shared_examples/listable_resource.rb +26 -0
- data/spec/spec_helper.rb +24 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 409f45de3418b9c9b28d8658dba105cc036f1173
|
4
|
+
data.tar.gz: caff1471ad88c925a46d1ab2037613bd1f435eab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 611d21df72ce9c2c93aedf0aeb9aeb3fb210d7af405882b89c0abc0d69c592eb7a1802b0dc748f8bc768a83476324d48eb25ba4ed9120c37dedc5e5401f8a40f
|
7
|
+
data.tar.gz: eb92d66882035b642d7beba93572aad7607dff1c0175762686a83b4a9b0825c9ee1b8e4f2508dc77562711df19f88291ff751e78df294c23e0aab81d17ee8bc5
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'cta_aggregator_client/cta_resource'
|
2
|
+
|
3
|
+
module CTAAggregatorClient
|
4
|
+
module AdvocacyCampaign
|
5
|
+
extend CTAResource
|
6
|
+
|
7
|
+
RESOURCE_NAME = :advocacy_campaign
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def resource_name
|
12
|
+
RESOURCE_NAME
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'cta_aggregator_client/api/utilities'
|
2
|
+
|
3
|
+
module CTAAggregatorClient
|
4
|
+
module API
|
5
|
+
module Authenticator
|
6
|
+
extend Utilities
|
7
|
+
|
8
|
+
THREE_HOURS = 10800
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def headers_with_authentication
|
13
|
+
reset_auth unless Time.now < auth.expiration
|
14
|
+
default_headers.merge(authorization: "Bearer: #{auth.token}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def auth
|
18
|
+
@auth ||= generate_auth
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_auth
|
22
|
+
raw_response = RestClient.post(auth_url, nil, headers_with_auth_creds)
|
23
|
+
token = raw_response.code == 201 ? JSON.parse(raw_response.body)["jwt"] : nil
|
24
|
+
|
25
|
+
Auth.new(
|
26
|
+
token,
|
27
|
+
default_token_expiration
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def default_token_expiration
|
32
|
+
# API is more lenient on token expriation (way over 3 hours).
|
33
|
+
# We're keeping low expiration here to avoid dealing with expired tokens.
|
34
|
+
Time.now + THREE_HOURS
|
35
|
+
end
|
36
|
+
|
37
|
+
def reset_auth
|
38
|
+
@auth = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
class Auth < Struct.new(:token, :expiration) ; end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'cta_aggregator_client/response'
|
4
|
+
require 'cta_aggregator_client/api/utilities'
|
5
|
+
require 'cta_aggregator_client/api/authenticator'
|
6
|
+
|
7
|
+
module CTAAggregatorClient
|
8
|
+
module API
|
9
|
+
module Client
|
10
|
+
extend Utilities
|
11
|
+
|
12
|
+
class << self
|
13
|
+
|
14
|
+
def list(resource_name, filters)
|
15
|
+
url = "#{base_url}/#{api_version}/#{resource_name}s"
|
16
|
+
raw_response = RestClient.get(url, {headers: default_headers, params: {filter: filters} })
|
17
|
+
translate_response(raw_response)
|
18
|
+
end
|
19
|
+
|
20
|
+
def find(resource_name, uuid)
|
21
|
+
url = "#{base_url}/#{api_version}/#{resource_name}s/#{uuid}"
|
22
|
+
raw_response = RestClient.get(url, default_headers)
|
23
|
+
translate_response(raw_response)
|
24
|
+
end
|
25
|
+
|
26
|
+
def create(resource_name, attributes, relationships = {})
|
27
|
+
url = "#{base_url}/#{api_version}/#{resource_name}s"
|
28
|
+
payload = {
|
29
|
+
'data': {
|
30
|
+
'type': "#{resource_name}s",
|
31
|
+
'attributes': attributes,
|
32
|
+
'relationships': relationship_params(relationships)
|
33
|
+
}.reject{ |k,v| v.empty? }
|
34
|
+
}.to_json
|
35
|
+
|
36
|
+
perform_authenticated_request(:post, url, payload)
|
37
|
+
end
|
38
|
+
|
39
|
+
def relationship_params(relationships)
|
40
|
+
return {} unless relationships
|
41
|
+
|
42
|
+
relationships.each_with_object({}) do |(resource_name, uuid_data), obj|
|
43
|
+
if uuid_data.is_a? Array
|
44
|
+
obj[resource_name.to_sym] = {
|
45
|
+
data: uuid_data.map { |uuid| { type: resource_name, id: uuid } }
|
46
|
+
}
|
47
|
+
else
|
48
|
+
obj[resource_name.to_sym] = {
|
49
|
+
data: { type: "#{resource_name}s", id: uuid_data }
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_relationship(resource_name, uuid, related_resource_name, related_resource_uuids)
|
56
|
+
url = "#{base_url}/#{api_version}/#{resource_name}s/#{uuid}/relationships/#{related_resource_name}"
|
57
|
+
if related_resource_uuids.is_a? Array
|
58
|
+
|
59
|
+
resource_data = related_resource_uuids.map do |related_resource_uuid|
|
60
|
+
{ 'type': "#{related_resource_name}",
|
61
|
+
'id': related_resource_uuid }
|
62
|
+
end
|
63
|
+
|
64
|
+
elsif related_resource_uuids.is_a? String
|
65
|
+
resource_data = { 'type': "#{related_resource_name}",
|
66
|
+
'id': related_resource_uuids }
|
67
|
+
else
|
68
|
+
raise UnknownInputTypeError
|
69
|
+
end
|
70
|
+
|
71
|
+
payload = { data: resource_data }.to_json
|
72
|
+
|
73
|
+
perform_authenticated_request(:put, url, payload)
|
74
|
+
end
|
75
|
+
|
76
|
+
def perform_authenticated_request(http_method, url, payload)
|
77
|
+
raw_response = RestClient.send(http_method.to_sym, url, payload, headers_with_access_token)
|
78
|
+
translate_response(raw_response)
|
79
|
+
end
|
80
|
+
|
81
|
+
def headers_with_access_token
|
82
|
+
Authenticator.headers_with_authentication
|
83
|
+
end
|
84
|
+
|
85
|
+
def translate_response(response)
|
86
|
+
Response.new(response.code, response.body, response.headers)
|
87
|
+
end
|
88
|
+
|
89
|
+
class UnknownInputTypeError < StandardError ; end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module CTAAggregatorClient
|
2
|
+
module API
|
3
|
+
module Utilities
|
4
|
+
|
5
|
+
def default_headers
|
6
|
+
{ content_type: 'application/vnd.api+json',
|
7
|
+
accept: 'application/vnd.api+json'}
|
8
|
+
end
|
9
|
+
|
10
|
+
def headers_with_auth_creds
|
11
|
+
default_headers.merge(authorization: "#{api_key}:#{api_secret}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def base_url
|
15
|
+
CTAAggregatorClient.configuration.base_url
|
16
|
+
end
|
17
|
+
|
18
|
+
def api_version
|
19
|
+
CTAAggregatorClient.configuration.api_version
|
20
|
+
end
|
21
|
+
|
22
|
+
def auth_url
|
23
|
+
"#{base_url}/#{api_version}/authorize"
|
24
|
+
end
|
25
|
+
|
26
|
+
def api_key
|
27
|
+
CTAAggregatorClient.configuration.api_key
|
28
|
+
end
|
29
|
+
|
30
|
+
def api_secret
|
31
|
+
CTAAggregatorClient.configuration.api_secret
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'cta_aggregator_client/api/client'
|
2
|
+
|
3
|
+
module CTAAggregatorClient
|
4
|
+
module CTAResource
|
5
|
+
|
6
|
+
def list(filters = {})
|
7
|
+
API::Client.list(resource_name, filters)
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(uuid)
|
11
|
+
API::Client.find(resource_name, uuid)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create(attributes, relationships = {})
|
15
|
+
API::Client.create(resource_name, attributes, relationships)
|
16
|
+
end
|
17
|
+
|
18
|
+
def resource_name
|
19
|
+
raise NotImplementedError
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'cta_aggregator_client/configuration'
|
2
|
+
require 'cta_aggregator_client/api/client'
|
3
|
+
require 'cta_aggregator_client/advocacy_campaign'
|
4
|
+
require 'cta_aggregator_client/target'
|
5
|
+
require 'cta_aggregator_client/event'
|
6
|
+
require 'cta_aggregator_client/location'
|
7
|
+
|
8
|
+
module CTAAggregatorClient
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configuration
|
15
|
+
@configuration ||= Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/spec/factory.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
module Factory
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def response(code: 200, body: nil)
|
8
|
+
CTAAggregatorClient::Response.new(
|
9
|
+
code,
|
10
|
+
body,
|
11
|
+
{ content_type: 'application/vnd.api+json' }
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def auth_response
|
16
|
+
Factory.response(code: 201, body: {jwt: token}.to_json)
|
17
|
+
end
|
18
|
+
|
19
|
+
def bad_token_response
|
20
|
+
Factory.response(code: 401)
|
21
|
+
end
|
22
|
+
|
23
|
+
def bad_auth_response
|
24
|
+
Factory.response(code: 404)
|
25
|
+
end
|
26
|
+
|
27
|
+
def token
|
28
|
+
'as.df.gh'
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module TestHelpers
|
2
|
+
|
3
|
+
# Coerces a class name into pluralized resource name
|
4
|
+
# e.g. "CTAAggregatorClient::CallScript" to "call-scripts"
|
5
|
+
def formatted_resource_name(klass, hardcoded_klass_name)
|
6
|
+
resource_name = "#{(hardcoded_klass_name || klass.name.split("::")[1].split(/(?=[A-Z])/).map { |class_name_part| class_name_part.downcase }.join('_'))}s"
|
7
|
+
end
|
8
|
+
|
9
|
+
def api_url
|
10
|
+
"#{CTAAggregatorClient::configuration.base_url}/#{CTAAggregatorClient.configuration.api_version}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def auth_url
|
14
|
+
"#{api_url}/authorize"
|
15
|
+
end
|
16
|
+
|
17
|
+
def headers_with_auth_creds
|
18
|
+
CTAAggregatorClient::API::Authenticator.default_headers.merge(
|
19
|
+
authorization: auth_info
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def auth_info
|
24
|
+
"#{CTAAggregatorClient.configuration.api_key}:#{CTAAggregatorClient.configuration.api_secret}"
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CTAAggregatorClient::AdvocacyCampaign do
|
4
|
+
|
5
|
+
it_behaves_like 'listable resource'
|
6
|
+
it_behaves_like 'findable resource'
|
7
|
+
|
8
|
+
context 'creation' do
|
9
|
+
campaign_attrs = {
|
10
|
+
title: 'Email Congressman - 1',
|
11
|
+
description: 'Voluptas delectus distinctio maiores consequatur aspernatur.',
|
12
|
+
browser_url: 'http://example.com/nya.lang',
|
13
|
+
origin_system: '5Calls',
|
14
|
+
featured_image_url: 'http://lorempixel.com/300/300',
|
15
|
+
action_type: 'email',
|
16
|
+
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.',
|
17
|
+
}
|
18
|
+
relationship_attrs = { targets: ['a2f6f86b-a214-4892-8c06-8caece820fb0', '215ed993-3cd1-4fbc-b8af-7e2082813d06'] }
|
19
|
+
|
20
|
+
it_behaves_like 'creatable resource', campaign_attrs, relationship_attrs
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CTAAggregatorClient::Event do
|
4
|
+
|
5
|
+
it_behaves_like 'listable resource'
|
6
|
+
it_behaves_like 'findable resource'
|
7
|
+
context 'creation' do
|
8
|
+
event_attrs = {
|
9
|
+
title: 'March on Washington',
|
10
|
+
description: 'Illum molestiae aut ullam non qui consequatur magni.',
|
11
|
+
browser_url: 'http://example.com/marge',
|
12
|
+
origin_system: '5Calls',
|
13
|
+
featured_image_url: 'http://lorempixel.com/300/300',
|
14
|
+
start_date: '2017-07-08T03:58:25.098Z',
|
15
|
+
end_date: '2017-07-13T03:58:25.098Z',
|
16
|
+
free: false,
|
17
|
+
}
|
18
|
+
relationship_attrs = { location: '215ed993-3cd1-4fbc-b8af-7e2082813d06' }
|
19
|
+
|
20
|
+
it_behaves_like 'creatable resource', event_attrs, relationship_attrs
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CTAAggregatorClient::Location do
|
4
|
+
|
5
|
+
it_behaves_like 'listable resource'
|
6
|
+
it_behaves_like 'findable resource'
|
7
|
+
context 'creation' do
|
8
|
+
attributes = {
|
9
|
+
venue: 'Eastern Kemmer University',
|
10
|
+
address_lines: ['684 Schinner Trail', 'Apt. 512'],
|
11
|
+
locality: 'Rosenbaumville',
|
12
|
+
region: 'VA',
|
13
|
+
postal_code: '78183-3430'
|
14
|
+
}
|
15
|
+
it_behaves_like 'creatable resource', attributes
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CTAAggregatorClient::Target do
|
4
|
+
|
5
|
+
it_behaves_like 'listable resource'
|
6
|
+
it_behaves_like 'findable resource'
|
7
|
+
|
8
|
+
context 'creation' do
|
9
|
+
attributes = {
|
10
|
+
organization: 'Mohr Inc',
|
11
|
+
given_name: 'Pascale',
|
12
|
+
family_name: 'White',
|
13
|
+
ocdid: 'b4503418-6aab-451a-8e55-11ffd575bc85',
|
14
|
+
postal_addresses: [
|
15
|
+
{
|
16
|
+
primary: true,
|
17
|
+
address_type: 'Office',
|
18
|
+
venue: 'Southern Nitzsche',
|
19
|
+
address_lines: [
|
20
|
+
'36261 Kovacek Prairie',
|
21
|
+
'Apt. 760'
|
22
|
+
|
23
|
+
],
|
24
|
+
locality: 'West Brandynfort',
|
25
|
+
region: 'WV',
|
26
|
+
postal_code: '66900-1309',
|
27
|
+
country: 'US'
|
28
|
+
}
|
29
|
+
],
|
30
|
+
email_addresses: [
|
31
|
+
{
|
32
|
+
primary: true,
|
33
|
+
address: 'jeffry_durgan@rutherfordcarroll.net',
|
34
|
+
address_type: 'work'
|
35
|
+
}
|
36
|
+
|
37
|
+
],
|
38
|
+
phone_numbers: [
|
39
|
+
{
|
40
|
+
primary: true,
|
41
|
+
number: '(606) 087-8543 x254',
|
42
|
+
extension: '4594',
|
43
|
+
number_type: 'work'
|
44
|
+
}
|
45
|
+
]
|
46
|
+
}
|
47
|
+
it_behaves_like 'creatable resource', attributes
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
shared_examples_for "creatable resource" do |passed_attrs, passed_relationships, resource|
|
2
|
+
let(:response) { Factory.response }
|
3
|
+
let(:auth_response) { Factory.auth_response }
|
4
|
+
let(:token) { Factory.token }
|
5
|
+
|
6
|
+
def relationships(relationship_hash)
|
7
|
+
return {} unless relationship_hash
|
8
|
+
relationship_hash.each_with_object({}) do |(resource_name, uuid_data), obj|
|
9
|
+
if uuid_data.is_a? Array
|
10
|
+
obj[resource_name.to_sym] = {
|
11
|
+
data: uuid_data.map { |uuid| { type: resource_name, id: uuid } }
|
12
|
+
}
|
13
|
+
else
|
14
|
+
obj[resource_name.to_sym] = {
|
15
|
+
data: { type: "#{resource_name}s", id: uuid_data }
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with successful authentication' do
|
22
|
+
|
23
|
+
after do
|
24
|
+
CTAAggregatorClient::API::Authenticator.reset_auth
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'create new record' do
|
28
|
+
resource_name = formatted_resource_name(described_class, resource)
|
29
|
+
|
30
|
+
url = "#{api_url}/#{resource_name}"
|
31
|
+
|
32
|
+
payload = {
|
33
|
+
'data': {
|
34
|
+
'type': resource_name,
|
35
|
+
'attributes': passed_attrs,
|
36
|
+
'relationships': relationships(passed_relationships)
|
37
|
+
}.reject{ |k,v| v.empty? }
|
38
|
+
}
|
39
|
+
|
40
|
+
allow(RestClient).to receive(:post).with(
|
41
|
+
auth_url,
|
42
|
+
nil,
|
43
|
+
headers_with_auth_creds
|
44
|
+
).and_return(auth_response)
|
45
|
+
|
46
|
+
headers_with_auth_token = CTAAggregatorClient::API::Client.default_headers.merge(
|
47
|
+
authorization: "Bearer: #{token}"
|
48
|
+
)
|
49
|
+
|
50
|
+
expect(RestClient).to receive(:post).with(
|
51
|
+
url,
|
52
|
+
payload.to_json,
|
53
|
+
headers_with_auth_token
|
54
|
+
).and_return(response)
|
55
|
+
|
56
|
+
expect(described_class.create(passed_attrs, passed_relationships)).to eq response
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with unsuccessful authentication' do
|
61
|
+
before do
|
62
|
+
CTAAggregatorClient.configure do |config|
|
63
|
+
config.api_key = 'bad_key'
|
64
|
+
config.api_secret = 'bad_secret'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
after do
|
69
|
+
CTAAggregatorClient::API::Authenticator.reset_auth
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'fails when auth creds wrong' do
|
73
|
+
resource_name = formatted_resource_name(described_class, resource)
|
74
|
+
|
75
|
+
url = "#{api_url}/#{resource_name}"
|
76
|
+
payload = {
|
77
|
+
'data': {
|
78
|
+
'type': resource_name,
|
79
|
+
'attributes': passed_attrs,
|
80
|
+
'relationships': relationships(passed_relationships)
|
81
|
+
}.reject{ |k,v| v.empty? }
|
82
|
+
}
|
83
|
+
|
84
|
+
headers_with_auth_creds = CTAAggregatorClient::API::Client.default_headers.merge(
|
85
|
+
authorization: "#{'bad_key'}:#{'bad_secret'}"
|
86
|
+
)
|
87
|
+
|
88
|
+
allow(RestClient).to receive(:post).with(
|
89
|
+
auth_url,
|
90
|
+
nil,
|
91
|
+
headers_with_auth_creds
|
92
|
+
).and_return(Factory.bad_auth_response)
|
93
|
+
|
94
|
+
header_sans_auth_token = CTAAggregatorClient::API::Client.default_headers.merge(
|
95
|
+
authorization: "Bearer: #{nil}"
|
96
|
+
)
|
97
|
+
|
98
|
+
expect(RestClient).to receive(:post).with(
|
99
|
+
url,
|
100
|
+
payload.to_json,
|
101
|
+
header_sans_auth_token
|
102
|
+
).and_return(Factory.bad_token_response)
|
103
|
+
|
104
|
+
expect(described_class.create(passed_attrs, passed_relationships).code).to eq 401
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
shared_examples_for "findable resource" do |resource|
|
2
|
+
let(:response) { Factory.response }
|
3
|
+
|
4
|
+
it 'find record' do
|
5
|
+
uuid = '123'
|
6
|
+
|
7
|
+
url = "#{api_url}/#{formatted_resource_name(described_class, resource)}/#{uuid}"
|
8
|
+
expect(RestClient).to receive(:get).with(
|
9
|
+
url,
|
10
|
+
CTAAggregatorClient::API::Client.default_headers
|
11
|
+
).and_return(response)
|
12
|
+
|
13
|
+
expect(described_class.find(uuid)).to eq response
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
shared_examples_for "listable resource" do |resource|
|
2
|
+
let(:response) { Factory.response }
|
3
|
+
|
4
|
+
it 'with no filtering criterial' do
|
5
|
+
url = "#{api_url}/#{formatted_resource_name(described_class, resource)}"
|
6
|
+
|
7
|
+
expect(RestClient).to receive(:get).with(
|
8
|
+
url,
|
9
|
+
{headers: CTAAggregatorClient::API::Client.default_headers, params: {filter: {}}}
|
10
|
+
).and_return(response)
|
11
|
+
|
12
|
+
expect(described_class.list).to eq response
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'with filtering' do
|
16
|
+
url = "#{api_url}/#{formatted_resource_name(described_class, resource)}"
|
17
|
+
filters = {foo: :bar}
|
18
|
+
|
19
|
+
expect(RestClient).to receive(:get).with(
|
20
|
+
url,
|
21
|
+
{headers: CTAAggregatorClient::API::Client.default_headers, params: {filter: filters}}
|
22
|
+
).and_return(response)
|
23
|
+
|
24
|
+
expect(described_class.list(filters)).to eq response
|
25
|
+
end
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'cta_aggregator_client'
|
2
|
+
require 'shared_examples/listable_resource'
|
3
|
+
require 'shared_examples/findable_resource'
|
4
|
+
require 'shared_examples/creatable_resource'
|
5
|
+
require 'helpers/test_helpers'
|
6
|
+
require 'factory'
|
7
|
+
require 'pry'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.before(:all) do
|
11
|
+
CTAAggregatorClient.configure do |config|
|
12
|
+
config.base_url = 'localhost'
|
13
|
+
config.api_version = 'v1'
|
14
|
+
config.api_key = 'key'
|
15
|
+
config.api_secret = 'secret'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
config.raise_errors_for_deprecations!
|
20
|
+
|
21
|
+
config.order = 'random'
|
22
|
+
|
23
|
+
config.include TestHelpers
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cta_aggregator_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Downey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.12.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.12.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.5.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.5.0
|
55
|
+
description:
|
56
|
+
email: ben@buildingblocklabs.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- lib/cta_aggregator_client.rb
|
62
|
+
- lib/cta_aggregator_client/advocacy_campaign.rb
|
63
|
+
- lib/cta_aggregator_client/api/authenticator.rb
|
64
|
+
- lib/cta_aggregator_client/api/client.rb
|
65
|
+
- lib/cta_aggregator_client/api/utilities.rb
|
66
|
+
- lib/cta_aggregator_client/configuration.rb
|
67
|
+
- lib/cta_aggregator_client/cta_resource.rb
|
68
|
+
- lib/cta_aggregator_client/event.rb
|
69
|
+
- lib/cta_aggregator_client/location.rb
|
70
|
+
- lib/cta_aggregator_client/response.rb
|
71
|
+
- lib/cta_aggregator_client/target.rb
|
72
|
+
- lib/cta_aggregator_client/version.rb
|
73
|
+
- spec/factory.rb
|
74
|
+
- spec/helpers/test_helpers.rb
|
75
|
+
- spec/integration/advocacy_campaign_spec.rb
|
76
|
+
- spec/integration/events_spec.rb
|
77
|
+
- spec/integration/location_spec.rb
|
78
|
+
- spec/integration/target_spec.rb
|
79
|
+
- spec/shared_examples/creatable_resource.rb
|
80
|
+
- spec/shared_examples/findable_resource.rb
|
81
|
+
- spec/shared_examples/listable_resource.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
homepage: https://github.com/Ragtagteam/cta-aggregator-client-ruby
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.5.2
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Ruby Client for CTA Aggregator
|
107
|
+
test_files:
|
108
|
+
- spec/factory.rb
|
109
|
+
- spec/helpers/test_helpers.rb
|
110
|
+
- spec/integration/advocacy_campaign_spec.rb
|
111
|
+
- spec/integration/events_spec.rb
|
112
|
+
- spec/integration/location_spec.rb
|
113
|
+
- spec/integration/target_spec.rb
|
114
|
+
- spec/shared_examples/creatable_resource.rb
|
115
|
+
- spec/shared_examples/findable_resource.rb
|
116
|
+
- spec/shared_examples/listable_resource.rb
|
117
|
+
- spec/spec_helper.rb
|