tokyo_api 1.3.0 → 1.6.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/.ruby-version +1 -1
- data/Gemfile +9 -6
- data/README.md +1 -1
- data/Rakefile +12 -12
- data/VERSION +1 -1
- data/example.rb +3 -2
- data/lib/tokyo_api.rb +2 -2
- data/lib/tokyo_api/actionkit.rb +4 -4
- data/lib/tokyo_api/base.rb +4 -2
- data/lib/tokyo_api/campact.rb +16 -18
- data/lib/tokyo_api/client.rb +21 -22
- data/lib/tokyo_api/expire.rb +3 -1
- data/lib/tokyo_api/identity.rb +18 -23
- data/spec/actionkit_spec.rb +14 -8
- data/spec/campact_spec.rb +73 -18
- data/spec/client_spec.rb +21 -9
- data/spec/expire_spec.rb +8 -6
- data/spec/identity_spec.rb +43 -29
- data/spec/spec_helper.rb +5 -3
- data/spec/tokyo_api_spec.rb +4 -4
- data/tokyo_api.gemspec +19 -22
- metadata +26 -19
- data/Gemfile.lock +0 -107
- data/lib/tokyo_api/bluestatedigital.rb +0 -19
- data/lib/tokyo_api/krautbuster.rb +0 -43
- data/spec/bluestatedigital_spec.rb +0 -58
- data/spec/fixtures/responses/bluestatedigital/full_user_success +0 -1
- data/spec/krautbuster_spec.rb +0 -112
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 608376ec5c22df615936ab9c5603877f983e3f1c36c93071f3e4e4195bc6012e
|
4
|
+
data.tar.gz: 48218037c0aa31d24ca5f708311677387172422adc63a1ee5a0f190b3f92bfd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5baf06d1f979d9efa535600046b02f384cc53ce3dc794be57e1e799a4cb1a9744b7202725656905940438b0a8081951f5545b9e46f463fa90f0c9ecf870d8a0b
|
7
|
+
data.tar.gz: 585fb0e20ce10d6aec74c764a8b43716dabed99e6c32605f8789837840e3ba80a0ae828dd5ed104fb604f2314e1c405242389bfcffe83b1467cba761b15256c3
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.6
|
data/Gemfile
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'http://rubygems.org'
|
4
|
+
|
5
|
+
gem 'vertebrae', '>= 0.6.0'
|
4
6
|
|
5
7
|
# Add dependencies to develop your gem here.
|
6
8
|
# Include everything needed to run rake, tests, features, etc.
|
7
9
|
group :development do
|
8
|
-
gem
|
9
|
-
gem 'webmock'
|
10
|
+
gem 'bundler'
|
10
11
|
gem 'byebug'
|
11
|
-
gem
|
12
|
-
gem
|
12
|
+
gem 'juwelier', git: 'https://github.com/flajann2/juwelier.git'
|
13
|
+
gem 'rspec'
|
14
|
+
gem 'rubocop'
|
15
|
+
gem 'webmock'
|
13
16
|
end
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ A ruby gem for communicating with ControlShift's Tokyo API.
|
|
7
7
|
## Usage
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
ta = TokyoApi.new(host: 'localhost:9000', username: 'tokyo', password: 'Passw0rd!', scheme: 'http')
|
10
|
+
ta = TokyoApi.new(host: 'localhost:9000', username: 'tokyo', password: 'Passw0rd!', scheme: 'http', timeout: 5)
|
11
11
|
ta.organisation.expire('foo.com')
|
12
12
|
```
|
13
13
|
|
data/Rakefile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'bundler'
|
5
5
|
begin
|
6
6
|
Bundler.setup(:default, :development)
|
7
7
|
rescue Bundler::BundlerError => e
|
8
|
-
|
9
|
-
|
8
|
+
warn e.message
|
9
|
+
warn 'Run `bundle install` to install missing gems'
|
10
10
|
exit e.status_code
|
11
11
|
end
|
12
12
|
require 'rake'
|
@@ -14,13 +14,13 @@ require 'rake'
|
|
14
14
|
require 'juwelier'
|
15
15
|
Juwelier::Tasks.new do |gem|
|
16
16
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name =
|
18
|
-
gem.homepage =
|
19
|
-
gem.license =
|
20
|
-
gem.summary =
|
21
|
-
gem.description =
|
22
|
-
gem.email =
|
23
|
-
gem.authors = [
|
17
|
+
gem.name = 'tokyo_api'
|
18
|
+
gem.homepage = 'http://github.com/controlshift/tokyo_api'
|
19
|
+
gem.license = 'MIT'
|
20
|
+
gem.summary = 'Ruby API Wrapper for Tokyo CRM service'
|
21
|
+
gem.description = 'Tokyo is a CRM middleware, this gem helps apps talk to it.'
|
22
|
+
gem.email = 'nathan@controlshiftlabs.com'
|
23
|
+
gem.authors = ['Nathan Woodhull']
|
24
24
|
# dependencies defined in Gemfile
|
25
25
|
end
|
26
26
|
Juwelier::RubygemsDotOrgTasks.new
|
@@ -36,11 +36,11 @@ RSpec::Core::RakeTask.new(:rcov) do |spec|
|
|
36
36
|
spec.rcov = true
|
37
37
|
end
|
38
38
|
|
39
|
-
task :
|
39
|
+
task default: :spec
|
40
40
|
|
41
41
|
require 'rdoc/task'
|
42
42
|
Rake::RDocTask.new do |rdoc|
|
43
|
-
version = File.exist?('VERSION') ? File.read('VERSION') :
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ''
|
44
44
|
|
45
45
|
rdoc.rdoc_dir = 'rdoc'
|
46
46
|
rdoc.title = "tokyo_api #{version}"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.6.0
|
data/example.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
|
2
4
|
|
3
5
|
require 'tokyo_api'
|
4
6
|
|
5
7
|
ta = TokyoApi.new(host: 'localhost:9000', username: 'tokyo', password: 'Passw0rd!', scheme: 'http')
|
6
8
|
|
7
|
-
|
8
9
|
require 'pry-debugger'
|
9
|
-
binding.pry
|
10
|
+
binding.pry
|
data/lib/tokyo_api.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'vertebrae'
|
2
4
|
require 'tokyo_api/base'
|
3
5
|
require 'tokyo_api/actionkit'
|
4
|
-
require 'tokyo_api/bluestatedigital'
|
5
6
|
require 'tokyo_api/campact'
|
6
7
|
require 'tokyo_api/client'
|
7
8
|
require 'tokyo_api/expire'
|
8
9
|
require 'tokyo_api/identity'
|
9
|
-
require 'tokyo_api/krautbuster'
|
10
10
|
|
11
11
|
module TokyoApi
|
12
12
|
extend Vertebrae::Base
|
data/lib/tokyo_api/actionkit.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module TokyoApi
|
2
4
|
class Actionkit < Base
|
3
5
|
def base_path
|
@@ -9,10 +11,8 @@ module TokyoApi
|
|
9
11
|
end
|
10
12
|
|
11
13
|
def user_path(id, required_fields: nil)
|
12
|
-
path = "/#{normalized_base_path}user/#{url_escape(id)}"
|
13
|
-
unless required_fields.nil?
|
14
|
-
path << "?#{required_fields_param(required_fields)}"
|
15
|
-
end
|
14
|
+
path = String.new("/#{normalized_base_path}user/#{url_escape(id)}")
|
15
|
+
path << "?#{required_fields_param(required_fields)}" unless required_fields.nil?
|
16
16
|
path
|
17
17
|
end
|
18
18
|
end
|
data/lib/tokyo_api/base.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module TokyoApi
|
2
4
|
class Base < Vertebrae::Model
|
3
5
|
def normalized_base_path
|
@@ -10,10 +12,10 @@ module TokyoApi
|
|
10
12
|
|
11
13
|
def required_fields_param(required_fields)
|
12
14
|
if required_fields.present?
|
13
|
-
"required_fields=#{required_fields.collect{|v| url_escape(v.to_s)}.join(',')}"
|
15
|
+
"required_fields=#{required_fields.collect { |v| url_escape(v.to_s) }.join(',')}"
|
14
16
|
else
|
15
17
|
''
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
19
|
-
end
|
21
|
+
end
|
data/lib/tokyo_api/campact.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module TokyoApi
|
2
4
|
class Campact < Base
|
3
5
|
def base_path
|
@@ -9,30 +11,26 @@ module TokyoApi
|
|
9
11
|
end
|
10
12
|
|
11
13
|
def session_status(session_id)
|
12
|
-
client.get_request("
|
14
|
+
client.get_request("/#{normalized_base_path}session/#{url_escape(session_id)}/status").body
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy_session(session_id)
|
18
|
+
client.delete_request("/#{normalized_base_path}session/#{url_escape(session_id)}").status == 204
|
13
19
|
end
|
14
20
|
|
15
21
|
def subscription_status(token)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
raise
|
25
|
-
end
|
22
|
+
client.get_request(subscription_status_path(token)).body
|
23
|
+
rescue Vertebrae::ResponseError => e
|
24
|
+
# Status 404 is expected in these calls
|
25
|
+
return nil if e.status_code == 404
|
26
|
+
|
27
|
+
raise
|
26
28
|
end
|
27
29
|
|
28
30
|
def user_path(session_id, petition_id:, with_subscription_status: false, required_fields: nil)
|
29
|
-
path = "/#{normalized_base_path}user/#{url_escape(session_id)}?petition_id=#{url_escape(petition_id)}"
|
30
|
-
if with_subscription_status
|
31
|
-
|
32
|
-
end
|
33
|
-
unless required_fields.nil?
|
34
|
-
path << "&#{required_fields_param(required_fields)}"
|
35
|
-
end
|
31
|
+
path = String.new("/#{normalized_base_path}user/#{url_escape(session_id)}?petition_id=#{url_escape(petition_id)}")
|
32
|
+
path << '&with_subscription_status=true' if with_subscription_status
|
33
|
+
path << "&#{required_fields_param(required_fields)}" unless required_fields.nil?
|
36
34
|
path
|
37
35
|
end
|
38
36
|
|
data/lib/tokyo_api/client.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module TokyoApi
|
2
4
|
class Client < Vertebrae::API
|
3
5
|
def actionkit
|
4
6
|
@actionkit ||= TokyoApi::Actionkit.new(client: self)
|
5
7
|
end
|
6
8
|
|
7
|
-
|
8
|
-
@bluestatedigital ||= TokyoApi::Bluestatedigital.new(client: self)
|
9
|
-
end
|
10
|
-
|
11
|
-
def krautbuster
|
12
|
-
@krautbuster ||= TokyoApi::Krautbuster.new(client: self)
|
13
|
-
end
|
9
|
+
alias action_kit actionkit
|
14
10
|
|
15
11
|
def campact
|
16
12
|
@campact ||= TokyoApi::Campact.new(client: self)
|
@@ -24,34 +20,34 @@ module TokyoApi
|
|
24
20
|
@expire ||= TokyoApi::Expire.new(client: self)
|
25
21
|
end
|
26
22
|
|
27
|
-
|
28
23
|
def default_options
|
29
|
-
{
|
24
|
+
opts = {
|
30
25
|
user_agent: 'TokyoApi Gem',
|
31
26
|
prefix: '',
|
32
27
|
content_type: 'application/json'
|
33
28
|
}
|
29
|
+
|
30
|
+
if initialisation_options.key?(:timeout)
|
31
|
+
opts[:connection_options] = { request: { timeout: initialisation_options[:timeout] } }
|
32
|
+
end
|
33
|
+
|
34
|
+
opts
|
34
35
|
end
|
35
36
|
|
36
37
|
def request(method, path, params, options) # :nodoc:
|
37
|
-
|
38
|
-
raise ArgumentError, "unknown http method: #{method}"
|
39
|
-
end
|
38
|
+
raise ArgumentError, "unknown http method: #{method}" unless ::Vertebrae::Request::METHODS.include?(method)
|
40
39
|
|
41
|
-
unless connection.configuration.prefix.blank?
|
42
|
-
path = connection.configuration.prefix + '/' + path
|
43
|
-
end
|
40
|
+
path = "#{connection.configuration.prefix}/#{path}" unless connection.configuration.prefix.blank?
|
44
41
|
|
45
42
|
::Vertebrae::Base.logger.debug "EXECUTED: #{method} - #{path} with #{params} and #{options}"
|
46
43
|
|
47
44
|
connection.connection.send(method) do |request|
|
48
|
-
|
49
45
|
case method.to_sym
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
46
|
+
when *(::Vertebrae::Request::METHODS - ::Vertebrae::Request::METHODS_WITH_BODIES)
|
47
|
+
request.url(path, params)
|
48
|
+
when *::Vertebrae::Request::METHODS_WITH_BODIES
|
49
|
+
request.path = path
|
50
|
+
request.body = extract_data_from_params(params) unless params.empty?
|
55
51
|
end
|
56
52
|
end
|
57
53
|
end
|
@@ -60,7 +56,10 @@ module TokyoApi
|
|
60
56
|
connection.stack do |builder|
|
61
57
|
builder.use Faraday::Request::Multipart
|
62
58
|
builder.use Faraday::Request::UrlEncoded
|
63
|
-
|
59
|
+
if connection.configuration.authenticated?
|
60
|
+
builder.use Faraday::Request::BasicAuthentication, connection.configuration.username,
|
61
|
+
connection.configuration.password
|
62
|
+
end
|
64
63
|
|
65
64
|
builder.use Faraday::Response::Logger if ENV['DEBUG']
|
66
65
|
|
data/lib/tokyo_api/expire.rb
CHANGED
data/lib/tokyo_api/identity.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module TokyoApi
|
2
4
|
class Identity < Base
|
3
5
|
def base_path
|
@@ -9,24 +11,19 @@ module TokyoApi
|
|
9
11
|
end
|
10
12
|
|
11
13
|
def tokyo_identity_user_path(id, with_subscription_status: false, required_fields: nil, opt_in_public_ids: nil, minimum_consent_level: nil, encrypted: nil)
|
12
|
-
path = "/#{normalized_base_path}user/#{url_escape(id)}"
|
14
|
+
path = String.new("/#{normalized_base_path}user/#{url_escape(id)}")
|
13
15
|
|
14
16
|
params = []
|
15
|
-
unless required_fields.nil?
|
16
|
-
params << required_fields_param(required_fields)
|
17
|
-
end
|
17
|
+
params << required_fields_param(required_fields) unless required_fields.nil?
|
18
18
|
|
19
19
|
if with_subscription_status
|
20
20
|
params << 'with_subscription_status=true'
|
21
|
-
additional_subscription_parameters = path_for_subscription_status_params(opt_in_public_ids,
|
22
|
-
|
23
|
-
|
24
|
-
end
|
21
|
+
additional_subscription_parameters = path_for_subscription_status_params(opt_in_public_ids,
|
22
|
+
minimum_consent_level, encrypted)
|
23
|
+
params << additional_subscription_parameters if additional_subscription_parameters.present?
|
25
24
|
end
|
26
25
|
|
27
|
-
if params.any?
|
28
|
-
path << "?#{params.join('&')}"
|
29
|
-
end
|
26
|
+
path << "?#{params.join('&')}" if params.any?
|
30
27
|
|
31
28
|
path
|
32
29
|
end
|
@@ -34,25 +31,23 @@ module TokyoApi
|
|
34
31
|
def subscription_status_path(id, opt_in_public_ids: nil, minimum_consent_level: nil, encrypted: nil)
|
35
32
|
raise 'must provide opt_in_public_ids' if opt_in_public_ids.nil?
|
36
33
|
|
37
|
-
"/#{normalized_base_path}subscription_status/#{url_escape(id)}?#{path_for_subscription_status_params(
|
34
|
+
"/#{normalized_base_path}subscription_status/#{url_escape(id)}?#{path_for_subscription_status_params(
|
35
|
+
opt_in_public_ids, minimum_consent_level, encrypted
|
36
|
+
)}"
|
38
37
|
end
|
39
38
|
|
40
39
|
private
|
41
40
|
|
42
41
|
def path_for_subscription_status_params(opt_in_public_ids, minimum_consent_level, encrypted = nil)
|
43
|
-
path =
|
42
|
+
path = if opt_in_public_ids.present?
|
43
|
+
String.new("opt_in_public_ids=#{url_escape(opt_in_public_ids.join(','))}")
|
44
|
+
else
|
45
|
+
String.new('')
|
46
|
+
end
|
44
47
|
|
45
|
-
if
|
46
|
-
path = "opt_in_public_ids=#{url_escape(opt_in_public_ids.join(','))}"
|
47
|
-
end
|
48
|
+
path << "&minimum_consent_level=#{url_escape(minimum_consent_level)}" if minimum_consent_level
|
48
49
|
|
49
|
-
if
|
50
|
-
path << "&minimum_consent_level=#{url_escape(minimum_consent_level)}"
|
51
|
-
end
|
52
|
-
|
53
|
-
if encrypted
|
54
|
-
path << "&encrypted=1"
|
55
|
-
end
|
50
|
+
path << '&encrypted=1' if encrypted
|
56
51
|
|
57
52
|
path
|
58
53
|
end
|
data/spec/actionkit_spec.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
|
2
4
|
|
3
5
|
describe TokyoApi::Actionkit do
|
4
6
|
subject { TokyoApi.new(host: 'test.com') }
|
@@ -15,15 +17,15 @@ describe TokyoApi::Actionkit do
|
|
15
17
|
let(:status) { 200 }
|
16
18
|
|
17
19
|
before(:each) do
|
18
|
-
|
19
|
-
|
20
|
+
stub_get(request_path).to_return(body: body, status: status,
|
21
|
+
headers: { content_type: 'application/json; charset=utf-8' })
|
20
22
|
end
|
21
23
|
|
22
24
|
describe 'error' do
|
23
25
|
let(:body) { fixture('responses/full_user_error') }
|
24
26
|
|
25
27
|
it 'should return an error hash' do
|
26
|
-
expect(subject.actionkit.full_user('1')).to eq({'error' => 'Connection refused'})
|
28
|
+
expect(subject.actionkit.full_user('1')).to eq({ 'error' => 'Connection refused' })
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
@@ -39,18 +41,22 @@ describe TokyoApi::Actionkit do
|
|
39
41
|
|
40
42
|
describe 'user_path' do
|
41
43
|
context 'without required_fields' do
|
42
|
-
it
|
44
|
+
it 'should return relative path to user API endpoint' do
|
43
45
|
expect(subject.actionkit.user_path('abc.123.xyz')).to eq('/actionkit/user/abc.123.xyz')
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
47
49
|
context 'with required_fields' do
|
48
|
-
it
|
49
|
-
expect(subject.actionkit.user_path('abc.123.xyz',
|
50
|
+
it 'should return relative path to user API endpoint' do
|
51
|
+
expect(subject.actionkit.user_path('abc.123.xyz',
|
52
|
+
required_fields: %i[first_name last_name email postal
|
53
|
+
phone])).to eq('/actionkit/user/abc.123.xyz?required_fields=first_name,last_name,email,postal,phone')
|
50
54
|
end
|
51
55
|
|
52
56
|
it 'should url-escape field names with weird characters' do
|
53
|
-
expect(subject.actionkit.user_path('abc.123.xyz',
|
57
|
+
expect(subject.actionkit.user_path('abc.123.xyz',
|
58
|
+
required_fields: ['email',
|
59
|
+
'fish & chips'])).to eq('/actionkit/user/abc.123.xyz?required_fields=email,fish+%26+chips')
|
54
60
|
end
|
55
61
|
end
|
56
62
|
end
|
data/spec/campact_spec.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
|
2
4
|
|
3
5
|
describe TokyoApi::Campact do
|
4
6
|
subject { TokyoApi.new(host: 'test.com') }
|
@@ -15,15 +17,15 @@ describe TokyoApi::Campact do
|
|
15
17
|
let(:status) { 200 }
|
16
18
|
|
17
19
|
before(:each) do
|
18
|
-
|
19
|
-
|
20
|
+
stub_get(request_path).to_return(body: body, status: status,
|
21
|
+
headers: { content_type: 'application/json; charset=utf-8' })
|
20
22
|
end
|
21
23
|
|
22
24
|
describe 'error' do
|
23
25
|
let(:body) { fixture('responses/full_user_error') }
|
24
26
|
|
25
27
|
it 'should return an error message' do
|
26
|
-
expect(subject.campact.full_user('123abc456')).to eq({'error' => 'Connection refused'})
|
28
|
+
expect(subject.campact.full_user('123abc456')).to eq({ 'error' => 'Connection refused' })
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
@@ -31,8 +33,8 @@ describe TokyoApi::Campact do
|
|
31
33
|
let(:body) { fixture('responses/campact/full_user_success') }
|
32
34
|
|
33
35
|
it 'should find an organisation' do
|
34
|
-
expect(subject.campact.full_user('123abc456')).to eq({'first_name' => 'Homer', 'last_name' => 'Simpson',
|
35
|
-
|
36
|
+
expect(subject.campact.full_user('123abc456')).to eq({ 'first_name' => 'Homer', 'last_name' => 'Simpson',
|
37
|
+
'country' => 'DE', 'postal' => '12345', 'email' => 'foo@bar.com' })
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
@@ -48,15 +50,19 @@ describe TokyoApi::Campact do
|
|
48
50
|
end
|
49
51
|
|
50
52
|
it 'should perform request on subscription_status_path' do
|
51
|
-
expect(client).to receive(:get_request).with("/campact/subscription_status?token=#{token}").and_return(double(body: {subscribed: true}))
|
53
|
+
expect(client).to receive(:get_request).with("/campact/subscription_status?token=#{token}").and_return(double(body: { subscribed: true }))
|
52
54
|
|
53
55
|
subs_status = subject.subscription_status(token)
|
54
56
|
|
55
|
-
expect(subs_status).to eq({subscribed: true})
|
57
|
+
expect(subs_status).to eq({ subscribed: true })
|
56
58
|
end
|
57
59
|
|
58
60
|
it 'should return nil if tokyo responds with 404' do
|
59
|
-
expect(client).to receive(:get_request).with("/campact/subscription_status?token=#{token}").and_raise(Vertebrae::ResponseError.new(
|
61
|
+
expect(client).to receive(:get_request).with("/campact/subscription_status?token=#{token}").and_raise(Vertebrae::ResponseError.new(
|
62
|
+
404, {
|
63
|
+
method: 'get', url: "/campact/subscription_status?token=#{token}", status: '404', body: 'Not Found'
|
64
|
+
}
|
65
|
+
))
|
60
66
|
|
61
67
|
subs_status = subject.subscription_status(token)
|
62
68
|
|
@@ -64,7 +70,10 @@ describe TokyoApi::Campact do
|
|
64
70
|
end
|
65
71
|
|
66
72
|
it 'should raise if tokyo responds with other error code' do
|
67
|
-
expect(client).to receive(:get_request).with("/campact/subscription_status?token=#{token}").and_raise(Vertebrae::ResponseError.new(
|
73
|
+
expect(client).to receive(:get_request).with("/campact/subscription_status?token=#{token}").and_raise(Vertebrae::ResponseError.new(
|
74
|
+
500, { method: 'get', url: "/campact/subscription_status?token=#{token}", status: '500',
|
75
|
+
body: 'Something bad happened' }
|
76
|
+
))
|
68
77
|
|
69
78
|
expect { subject.subscription_status(token) }.to raise_error Vertebrae::ResponseError
|
70
79
|
end
|
@@ -72,32 +81,38 @@ describe TokyoApi::Campact do
|
|
72
81
|
|
73
82
|
describe '#user_path' do
|
74
83
|
context 'without required_fields' do
|
75
|
-
it
|
76
|
-
expect(subject.campact.user_path('123abc456',
|
84
|
+
it 'should return relative path to user API endpoint' do
|
85
|
+
expect(subject.campact.user_path('123abc456',
|
86
|
+
petition_id: 'save-the-trees')).to eq '/campact/user/123abc456?petition_id=save-the-trees'
|
77
87
|
end
|
78
88
|
end
|
79
89
|
|
80
90
|
context 'with required_fields' do
|
81
|
-
it
|
82
|
-
expect(subject.campact.user_path('123abc456', petition_id: 'save-the-trees',
|
91
|
+
it 'should return relative path to user API endpoint' do
|
92
|
+
expect(subject.campact.user_path('123abc456', petition_id: 'save-the-trees',
|
93
|
+
required_fields: %i[first_name last_name email])).to eq '/campact/user/123abc456?petition_id=save-the-trees&required_fields=first_name,last_name,email'
|
83
94
|
end
|
84
95
|
|
85
96
|
it 'should url-escape field names with weird characters' do
|
86
|
-
expect(subject.campact.user_path('123abc456', petition_id: 'save-the-trees',
|
97
|
+
expect(subject.campact.user_path('123abc456', petition_id: 'save-the-trees',
|
98
|
+
required_fields: ['email', 'fish & chips'])).to eq '/campact/user/123abc456?petition_id=save-the-trees&required_fields=email,fish+%26+chips'
|
87
99
|
end
|
88
100
|
end
|
89
101
|
|
90
102
|
context 'with_subscription_status argument' do
|
91
103
|
it 'should not include query string parameter if argument is missing' do
|
92
|
-
expect(subject.campact.user_path('123abc456',
|
104
|
+
expect(subject.campact.user_path('123abc456',
|
105
|
+
petition_id: 'save-the-trees')).not_to match(/.+with_subscription_status=.+/)
|
93
106
|
end
|
94
107
|
|
95
108
|
it 'should not include query string parameter if argument is false' do
|
96
|
-
expect(subject.campact.user_path('123abc456', petition_id: 'save-the-trees',
|
109
|
+
expect(subject.campact.user_path('123abc456', petition_id: 'save-the-trees',
|
110
|
+
with_subscription_status: false)).not_to match(/.+with_subscription_status=.+/)
|
97
111
|
end
|
98
112
|
|
99
113
|
it 'should include query string parameter if argument is true' do
|
100
|
-
expect(subject.campact.user_path('123abc456', petition_id: 'save-the-trees',
|
114
|
+
expect(subject.campact.user_path('123abc456', petition_id: 'save-the-trees',
|
115
|
+
with_subscription_status: true)).to match(/.+with_subscription_status=true.*/)
|
101
116
|
end
|
102
117
|
end
|
103
118
|
end
|
@@ -109,4 +124,44 @@ describe TokyoApi::Campact do
|
|
109
124
|
expect(subject.subscription_status_path('abc123')).to eq '/campact/subscription_status/abc123'
|
110
125
|
end
|
111
126
|
end
|
127
|
+
|
128
|
+
describe '#session_status' do
|
129
|
+
let(:client) { double }
|
130
|
+
let(:session_id) { '123456789abcdef' }
|
131
|
+
|
132
|
+
subject { TokyoApi::Campact.new(client: client) }
|
133
|
+
|
134
|
+
it 'should perform request on session status path' do
|
135
|
+
expect(client).to receive(:get_request).with("/campact/session/#{session_id}/status").and_return(double(body: {
|
136
|
+
hard_login: false, soft_login: true
|
137
|
+
}))
|
138
|
+
|
139
|
+
session_status = subject.session_status(session_id)
|
140
|
+
|
141
|
+
expect(session_status).to eq({ hard_login: false, soft_login: true })
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe '#destroy_session' do
|
146
|
+
let(:client) { double }
|
147
|
+
let(:session_id) { '123456789abcdef' }
|
148
|
+
|
149
|
+
subject { TokyoApi::Campact.new(client: client) }
|
150
|
+
|
151
|
+
it 'should perform request on session status path' do
|
152
|
+
expect(client).to receive(:delete_request).with("/campact/session/#{session_id}").and_return(double(status: 204))
|
153
|
+
|
154
|
+
result = subject.destroy_session(session_id)
|
155
|
+
|
156
|
+
expect(result).to be_truthy
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should return false if response status is 404' do
|
160
|
+
expect(client).to receive(:delete_request).with("/campact/session/#{session_id}").and_return(double(status: 404))
|
161
|
+
|
162
|
+
result = subject.destroy_session(session_id)
|
163
|
+
|
164
|
+
expect(result).to be_falsey
|
165
|
+
end
|
166
|
+
end
|
112
167
|
end
|