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
data/Gemfile.lock
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
activesupport (5.1.3)
|
5
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
6
|
-
i18n (~> 0.7)
|
7
|
-
minitest (~> 5.1)
|
8
|
-
tzinfo (~> 1.1)
|
9
|
-
addressable (2.4.0)
|
10
|
-
builder (3.2.3)
|
11
|
-
byebug (9.0.6)
|
12
|
-
concurrent-ruby (1.0.5)
|
13
|
-
crack (0.4.3)
|
14
|
-
safe_yaml (~> 1.0.0)
|
15
|
-
descendants_tracker (0.0.4)
|
16
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
17
|
-
diff-lcs (1.3)
|
18
|
-
faraday (0.9.2)
|
19
|
-
multipart-post (>= 1.2, < 3)
|
20
|
-
faraday_middleware (0.12.2)
|
21
|
-
faraday (>= 0.7.4, < 1.0)
|
22
|
-
git (1.3.0)
|
23
|
-
github_api (0.17.0)
|
24
|
-
addressable (~> 2.4.0)
|
25
|
-
descendants_tracker (~> 0.0.4)
|
26
|
-
faraday (~> 0.8, < 0.10)
|
27
|
-
hashie (>= 3.4)
|
28
|
-
mime-types (>= 1.16, < 3.0)
|
29
|
-
oauth2 (~> 1.0)
|
30
|
-
hashdiff (0.3.5)
|
31
|
-
hashie (3.5.6)
|
32
|
-
highline (1.7.8)
|
33
|
-
i18n (0.8.6)
|
34
|
-
juwelier (2.4.7)
|
35
|
-
builder
|
36
|
-
bundler
|
37
|
-
git
|
38
|
-
github_api
|
39
|
-
highline
|
40
|
-
kamelcase (~> 0)
|
41
|
-
nokogiri
|
42
|
-
psych
|
43
|
-
rake
|
44
|
-
rdoc
|
45
|
-
semver2
|
46
|
-
jwt (1.5.6)
|
47
|
-
kamelcase (0.0.1)
|
48
|
-
semver2 (~> 3)
|
49
|
-
mime-types (2.99.3)
|
50
|
-
mini_portile2 (2.3.0)
|
51
|
-
minitest (5.10.3)
|
52
|
-
multi_json (1.12.1)
|
53
|
-
multi_xml (0.6.0)
|
54
|
-
multipart-post (2.0.0)
|
55
|
-
nokogiri (1.8.2)
|
56
|
-
mini_portile2 (~> 2.3.0)
|
57
|
-
oauth2 (1.4.0)
|
58
|
-
faraday (>= 0.8, < 0.13)
|
59
|
-
jwt (~> 1.0)
|
60
|
-
multi_json (~> 1.3)
|
61
|
-
multi_xml (~> 0.5)
|
62
|
-
rack (>= 1.2, < 3)
|
63
|
-
psych (2.2.4)
|
64
|
-
rack (2.0.3)
|
65
|
-
rake (12.0.0)
|
66
|
-
rdoc (5.1.0)
|
67
|
-
rspec (3.6.0)
|
68
|
-
rspec-core (~> 3.6.0)
|
69
|
-
rspec-expectations (~> 3.6.0)
|
70
|
-
rspec-mocks (~> 3.6.0)
|
71
|
-
rspec-core (3.6.0)
|
72
|
-
rspec-support (~> 3.6.0)
|
73
|
-
rspec-expectations (3.6.0)
|
74
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
75
|
-
rspec-support (~> 3.6.0)
|
76
|
-
rspec-mocks (3.6.0)
|
77
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
78
|
-
rspec-support (~> 3.6.0)
|
79
|
-
rspec-support (3.6.0)
|
80
|
-
safe_yaml (1.0.4)
|
81
|
-
semver2 (3.4.2)
|
82
|
-
thread_safe (0.3.6)
|
83
|
-
tzinfo (1.2.3)
|
84
|
-
thread_safe (~> 0.1)
|
85
|
-
vertebrae (0.4.1)
|
86
|
-
activesupport
|
87
|
-
faraday (>= 0.9.2)
|
88
|
-
faraday_middleware
|
89
|
-
hashie
|
90
|
-
webmock (3.0.1)
|
91
|
-
addressable (>= 2.3.6)
|
92
|
-
crack (>= 0.3.2)
|
93
|
-
hashdiff
|
94
|
-
|
95
|
-
PLATFORMS
|
96
|
-
ruby
|
97
|
-
|
98
|
-
DEPENDENCIES
|
99
|
-
bundler
|
100
|
-
byebug
|
101
|
-
juwelier
|
102
|
-
rspec
|
103
|
-
vertebrae
|
104
|
-
webmock
|
105
|
-
|
106
|
-
BUNDLED WITH
|
107
|
-
1.16.1
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module TokyoApi
|
2
|
-
class Bluestatedigital < Base
|
3
|
-
def base_path
|
4
|
-
'bluestatedigital'
|
5
|
-
end
|
6
|
-
|
7
|
-
def full_user(id)
|
8
|
-
client.get_request("#{normalized_base_path}full_user/#{url_escape(id)}").body
|
9
|
-
end
|
10
|
-
|
11
|
-
def tokyo_blue_state_digital_user_path(id, required_fields: nil)
|
12
|
-
path = "/#{normalized_base_path}constituent/#{url_escape(id)}"
|
13
|
-
unless required_fields.nil?
|
14
|
-
path << "?#{required_fields_param(required_fields)}"
|
15
|
-
end
|
16
|
-
path
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -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,58 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe TokyoApi::Bluestatedigital do
|
4
|
-
subject { TokyoApi.new(host: 'test.com') }
|
5
|
-
|
6
|
-
describe 'configuration' do
|
7
|
-
it 'should propagate the host' do
|
8
|
-
expect(subject.bluestatedigital.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) { '/bluestatedigital/full_user/1' }
|
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.bluestatedigital.full_user('1')).to eq({'error' => 'Connection refused'})
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe 'success' do
|
31
|
-
let(:body) { fixture('responses/bluestatedigital/full_user_success') }
|
32
|
-
|
33
|
-
it 'should return a success hash' do
|
34
|
-
expect(subject.bluestatedigital.full_user('1')).to eq({ 'first_name' => 'Homer', 'last_name' => 'Simpson',
|
35
|
-
'city' => 'Springfield', 'state' => 'YZ', 'country' => 'US',
|
36
|
-
'postal' => '12345', 'email' => 'foo@bar.com' })
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe 'tokyo_blue_state_digital_user_path' do
|
42
|
-
context 'without required_fields' do
|
43
|
-
it "should return rooted relative path to tokyo user API endpoint" do
|
44
|
-
expect(subject.bluestatedigital.tokyo_blue_state_digital_user_path('-123456')).to eq('/bluestatedigital/constituent/-123456')
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'with required_fields' do
|
49
|
-
it "should return rooted relative path to tokyo user API endpoint" do
|
50
|
-
expect(subject.bluestatedigital.tokyo_blue_state_digital_user_path('-123456', required_fields: [:first_name, :last_name, :email, :postal, :phone])).to eq('/bluestatedigital/constituent/-123456?required_fields=first_name,last_name,email,postal,phone')
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should url-escape field names with weird characters' do
|
54
|
-
expect(subject.bluestatedigital.tokyo_blue_state_digital_user_path('-123456', required_fields: ['email', 'fish & chips'])).to eq('/bluestatedigital/constituent/-123456?required_fields=email,fish+%26+chips')
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
{"first_name":"Homer","last_name":"Simpson","city":"Springfield","state":"YZ","country":"US","postal":"12345","email":"foo@bar.com"}
|
data/spec/krautbuster_spec.rb
DELETED
@@ -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
|