tokyo_api 1.3.1 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81a96d89d04d1aff9f0a84ff9f33ca0764054d3173adfd8b4ba663964594540a
4
- data.tar.gz: 041b8d28402371b200e574470ed4389342f4cd6d62a7913dd2e775d433873fae
3
+ metadata.gz: 3b31314db88bda36022a686b1cf9e33bd95d870bbdfa3ca2fbefab8e0a36df72
4
+ data.tar.gz: 98a5e4540b99f31cdbb6d9abc05f1bb14c21451dcfccd9592c182ffb96ab2c28
5
5
  SHA512:
6
- metadata.gz: df589e1193bc8ec4563d0d98c3a5aeb0039cca8bb3029c34911fb39f7610b7a6b8e5791e324e59b9b13eb49951edbfc1069b50b842e6202fee26e0aa4574ced3
7
- data.tar.gz: 71baca71419c9901c9fe1d76cb2e71c65d346b57321cbb6203042df633a96db80d64d8d2789f8c8c7c752223f454d3c5e741033fa5f0053aba6e6c91c3ac6171
6
+ metadata.gz: 217d35539205c967954ecedcabe6bb52d9eba88405c36b877dffe828dec937e24c4cefccbf97fcdccb3ef00bcca73ab6e8cef53f5c683955b594ff25e7ead7ee
7
+ data.tar.gz: 4ff16723f4dc8d5ccfcf8e1c2e96f65f7071c60959fbee53a183806985757f975e9f4fcf4c1b02c12166396866ef31615c63810f4f3efc2c58474e830d32e7ab
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.1
1
+ 1.4.1
data/lib/tokyo_api.rb CHANGED
@@ -6,7 +6,6 @@ require 'tokyo_api/campact'
6
6
  require 'tokyo_api/client'
7
7
  require 'tokyo_api/expire'
8
8
  require 'tokyo_api/identity'
9
- require 'tokyo_api/krautbuster'
10
9
 
11
10
  module TokyoApi
12
11
  extend Vertebrae::Base
@@ -9,7 +9,11 @@ module TokyoApi
9
9
  end
10
10
 
11
11
  def session_status(session_id)
12
- client.get_request("#{normalized_base_path}session_status/#{url_escape(session_id)}").body
12
+ client.get_request("/#{normalized_base_path}session/#{url_escape(session_id)}/status").body
13
+ end
14
+
15
+ def destroy_session(session_id)
16
+ client.delete_request("/#{normalized_base_path}session/#{url_escape(session_id)}").status == 204
13
17
  end
14
18
 
15
19
  def subscription_status(token)
@@ -4,13 +4,13 @@ module TokyoApi
4
4
  @actionkit ||= TokyoApi::Actionkit.new(client: self)
5
5
  end
6
6
 
7
+ alias_method :action_kit, :actionkit
8
+
7
9
  def bluestatedigital
8
10
  @bluestatedigital ||= TokyoApi::Bluestatedigital.new(client: self)
9
11
  end
10
12
 
11
- def krautbuster
12
- @krautbuster ||= TokyoApi::Krautbuster.new(client: self)
13
- end
13
+ alias_method :blue_state_digital, :bluestatedigital
14
14
 
15
15
  def campact
16
16
  @campact ||= TokyoApi::Campact.new(client: self)
data/spec/campact_spec.rb CHANGED
@@ -109,4 +109,42 @@ describe TokyoApi::Campact do
109
109
  expect(subject.subscription_status_path('abc123')).to eq '/campact/subscription_status/abc123'
110
110
  end
111
111
  end
112
+
113
+ describe '#session_status' do
114
+ let(:client) { double }
115
+ let(:session_id) { '123456789abcdef' }
116
+
117
+ subject { TokyoApi::Campact.new(client: client) }
118
+
119
+ it 'should perform request on session status path' do
120
+ expect(client).to receive(:get_request).with("/campact/session/#{session_id}/status").and_return(double(body: { hard_login: false, soft_login: true }))
121
+
122
+ session_status = subject.session_status(session_id)
123
+
124
+ expect(session_status).to eq({ hard_login: false, soft_login: true })
125
+ end
126
+ end
127
+
128
+ describe '#destroy_session' 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(:delete_request).with("/campact/session/#{session_id}").and_return(double(status: 204))
136
+
137
+ result = subject.destroy_session(session_id)
138
+
139
+ expect(result).to be_truthy
140
+ end
141
+
142
+ it 'should return false if response status is 404' do
143
+ expect(client).to receive(:delete_request).with("/campact/session/#{session_id}").and_return(double(status: 404))
144
+
145
+ result = subject.destroy_session(session_id)
146
+
147
+ expect(result).to be_falsey
148
+ end
149
+ end
112
150
  end
data/tokyo_api.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: tokyo_api 1.3.1 ruby lib
5
+ # stub: tokyo_api 1.4.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "tokyo_api".freeze
9
- s.version = "1.3.1"
9
+ s.version = "1.4.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Nathan Woodhull".freeze]
14
- s.date = "2018-12-04"
14
+ s.date = "2019-05-23"
15
15
  s.description = "Tokyo is a CRM middleware, this gem helps apps talk to it.".freeze
16
16
  s.email = "nathan@controlshiftlabs.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -38,7 +38,6 @@ Gem::Specification.new do |s|
38
38
  "lib/tokyo_api/client.rb",
39
39
  "lib/tokyo_api/expire.rb",
40
40
  "lib/tokyo_api/identity.rb",
41
- "lib/tokyo_api/krautbuster.rb",
42
41
  "spec/actionkit_spec.rb",
43
42
  "spec/bluestatedigital_spec.rb",
44
43
  "spec/campact_spec.rb",
@@ -53,14 +52,13 @@ Gem::Specification.new do |s|
53
52
  "spec/fixtures/responses/identity/full_user_success",
54
53
  "spec/fixtures/responses/krautbuster/full_user_success",
55
54
  "spec/identity_spec.rb",
56
- "spec/krautbuster_spec.rb",
57
55
  "spec/spec_helper.rb",
58
56
  "spec/tokyo_api_spec.rb",
59
57
  "tokyo_api.gemspec"
60
58
  ]
61
59
  s.homepage = "http://github.com/controlshift/tokyo_api".freeze
62
60
  s.licenses = ["MIT".freeze]
63
- s.rubygems_version = "2.7.6".freeze
61
+ s.rubygems_version = "2.7.7".freeze
64
62
  s.summary = "Ruby API Wrapper for Tokyo CRM service".freeze
65
63
 
66
64
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tokyo_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Woodhull
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-04 00:00:00.000000000 Z
11
+ date: 2019-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vertebrae
@@ -121,7 +121,6 @@ files:
121
121
  - lib/tokyo_api/client.rb
122
122
  - lib/tokyo_api/expire.rb
123
123
  - lib/tokyo_api/identity.rb
124
- - lib/tokyo_api/krautbuster.rb
125
124
  - spec/actionkit_spec.rb
126
125
  - spec/bluestatedigital_spec.rb
127
126
  - spec/campact_spec.rb
@@ -136,7 +135,6 @@ files:
136
135
  - spec/fixtures/responses/identity/full_user_success
137
136
  - spec/fixtures/responses/krautbuster/full_user_success
138
137
  - spec/identity_spec.rb
139
- - spec/krautbuster_spec.rb
140
138
  - spec/spec_helper.rb
141
139
  - spec/tokyo_api_spec.rb
142
140
  - tokyo_api.gemspec
@@ -160,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
158
  version: '0'
161
159
  requirements: []
162
160
  rubyforge_project:
163
- rubygems_version: 2.7.6
161
+ rubygems_version: 2.7.7
164
162
  signing_key:
165
163
  specification_version: 4
166
164
  summary: Ruby API Wrapper for Tokyo CRM service
@@ -1,43 +0,0 @@
1
- module TokyoApi
2
- class Krautbuster < Base
3
- def base_path
4
- 'krautbuster'
5
- end
6
-
7
- def full_user(session_id)
8
- client.get_request("#{normalized_base_path}full_user/#{url_escape(session_id)}").body
9
- end
10
-
11
- def session_status(session_id)
12
- client.get_request("#{normalized_base_path}session_status/#{url_escape(session_id)}").body
13
- end
14
-
15
- def subscription_status(token)
16
- begin
17
- client.get_request(subscription_status_path(token)).body
18
- rescue Vertebrae::ResponseError => e
19
- # Status 404 is expected in these calls
20
- if e.status_code == 404
21
- return nil
22
- end
23
-
24
- raise
25
- end
26
- end
27
-
28
- 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
- path << '&with_subscription_status=true'
32
- end
33
- unless required_fields.nil?
34
- path << "&#{required_fields_param(required_fields)}"
35
- end
36
- path
37
- end
38
-
39
- def subscription_status_path(token)
40
- "/#{normalized_base_path}subscription_status/#{url_escape(token)}"
41
- end
42
- end
43
- end
@@ -1,112 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe TokyoApi::Krautbuster do
4
- subject { TokyoApi.new(host: 'test.com') }
5
-
6
- describe 'configuration' do
7
- it 'should propagate the host' do
8
- expect(subject.krautbuster.client.connection.configuration.host).to eq 'test.com'
9
- end
10
- end
11
-
12
- describe '#full_user' do
13
- let(:body) { fixture('responses/full_user_success') }
14
- let(:request_path) { '/krautbuster/full_user/123abc456' }
15
- let(:status) { 200 }
16
-
17
- before(:each) do
18
- stub_get(request_path).to_return(:body => body, :status => status,
19
- :headers => { content_type: "application/json; charset=utf-8"})
20
- end
21
-
22
- describe 'error' do
23
- let(:body) { fixture('responses/full_user_error') }
24
-
25
- it 'should return an error message' do
26
- expect(subject.krautbuster.full_user('123abc456')).to eq({'error' => 'Connection refused'})
27
- end
28
- end
29
-
30
- describe 'success' do
31
- let(:body) { fixture('responses/krautbuster/full_user_success') }
32
-
33
- it 'should find an organisation' do
34
- expect(subject.krautbuster.full_user('123abc456')).to eq({'first_name' => 'Homer', 'last_name' => 'Simpson',
35
- 'country' => 'DE', 'postal' => '12345', 'email' => 'foo@bar.com' })
36
- end
37
- end
38
- end
39
-
40
- describe '#subscription_status' do
41
- let(:client) { double }
42
- let(:token) { '2134567890abcdef' }
43
-
44
- subject { TokyoApi::Krautbuster.new(client: client) }
45
-
46
- before :each do
47
- expect(subject).to receive(:subscription_status_path).with(token).and_return("/krautbuster/subscription_status?token=#{token}")
48
- end
49
-
50
- it 'should perform request on subscription_status_path' do
51
- expect(client).to receive(:get_request).with("/krautbuster/subscription_status?token=#{token}").and_return(double(body: {subscribed: true}))
52
-
53
- subs_status = subject.subscription_status(token)
54
-
55
- expect(subs_status).to eq({subscribed: true})
56
- end
57
-
58
- it 'should return nil if tokyo responds with 404' do
59
- expect(client).to receive(:get_request).with("/krautbuster/subscription_status?token=#{token}").and_raise(Vertebrae::ResponseError.new(404, {method: 'get', url: "/krautbuster/subscription_status?token=#{token}", status: '404', body: 'Not Found'}))
60
-
61
- subs_status = subject.subscription_status(token)
62
-
63
- expect(subs_status).to be_nil
64
- end
65
-
66
- it 'should raise if tokyo responds with other error code' do
67
- expect(client).to receive(:get_request).with("/krautbuster/subscription_status?token=#{token}").and_raise(Vertebrae::ResponseError.new(500, {method: 'get', url: "/krautbuster/subscription_status?token=#{token}", status: '500', body: 'Something bad happened'}))
68
-
69
- expect { subject.subscription_status(token) }.to raise_error Vertebrae::ResponseError
70
- end
71
- end
72
-
73
- describe '#user_path' do
74
- context 'without required_fields' do
75
- it "should return relative path to user API endpoint" do
76
- expect(subject.krautbuster.user_path('123abc456', petition_id: 'save-the-trees')).to eq '/krautbuster/user/123abc456?petition_id=save-the-trees'
77
- end
78
- end
79
-
80
- context 'with required_fields' do
81
- it "should return relative path to user API endpoint" do
82
- expect(subject.krautbuster.user_path('123abc456', petition_id: 'save-the-trees', required_fields: [:first_name, :last_name, :email])).to eq '/krautbuster/user/123abc456?petition_id=save-the-trees&required_fields=first_name,last_name,email'
83
- end
84
-
85
- it 'should url-escape field names with weird characters' do
86
- expect(subject.krautbuster.user_path('123abc456', petition_id: 'save-the-trees', required_fields: ['email', 'fish & chips'])).to eq '/krautbuster/user/123abc456?petition_id=save-the-trees&required_fields=email,fish+%26+chips'
87
- end
88
- end
89
-
90
- context 'with_subscription_status argument' do
91
- it 'should not include query string parameter if argument is missing' do
92
- expect(subject.krautbuster.user_path('123abc456', petition_id: 'save-the-trees')).not_to match /.+with_subscription_status=.+/
93
- end
94
-
95
- it 'should not include query string parameter if argument is false' do
96
- expect(subject.krautbuster.user_path('123abc456', petition_id: 'save-the-trees', with_subscription_status: false)).not_to match /.+with_subscription_status=.+/
97
- end
98
-
99
- it 'should include query string parameter if argument is true' do
100
- expect(subject.krautbuster.user_path('123abc456', petition_id: 'save-the-trees', with_subscription_status: true)).to match /.+with_subscription_status=true.*/
101
- end
102
- end
103
- end
104
-
105
- describe '#subscription_status_path' do
106
- subject { TokyoApi::Krautbuster.new }
107
-
108
- it 'should return correct path' do
109
- expect(subject.subscription_status_path('abc123')).to eq '/krautbuster/subscription_status/abc123'
110
- end
111
- end
112
- end