tokyo_api 1.1.2 → 1.2.0

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: 5502304c73c869022683e520632e96fc836a552bfb98b876498476121bfb620e
4
- data.tar.gz: 517684ab971c1d9ed655991090a11c87688414cefee2df384b1d4e642dcbc627
3
+ metadata.gz: 2c13c06a403dbc3eeb297a65c97be04e9c6c4ecdc57faf3319fcaffc13a65752
4
+ data.tar.gz: b7809a0fbf2cb061a1d187727485dfa4486c8eb82e93f22fb4eca82a3d303fa3
5
5
  SHA512:
6
- metadata.gz: 0e0b6958e59a6fa7c3ede1d910b3a75fe002bd1741d999b7330bfa79d071590ef12bad60af9769fb9c4af43f3b06e05fbc271dc8996a4ee1bf8b60f713f3f1ce
7
- data.tar.gz: d10d735108fefa5a62bde79320e3a4184f62f108e878d813c2e7f0de3631aa0f6f91529298e701aacf0302f20bfe7967498a0dbea06dcc473973c7317897d115
6
+ metadata.gz: 6ba8f238329548d345363e5b7819172104559e6dda78cf8fd188978562e71e0578362091f57a5129862473e61b41f619bb737694eb61f05cce72aa35156becc7
7
+ data.tar.gz: a31540d25ae73fd9758d68b8e985a37f94defeacb2e833117927b6c8778d63226fc02c90127c0aed5969e94c85439aa58b400bf859039a427210a06db6208c41
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 1.2.0
@@ -0,0 +1,43 @@
1
+ module TokyoApi
2
+ class Campact < Base
3
+ def base_path
4
+ 'campact'
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
@@ -12,6 +12,10 @@ module TokyoApi
12
12
  @krautbuster ||= TokyoApi::Krautbuster.new(client: self)
13
13
  end
14
14
 
15
+ def campact
16
+ @campact ||= TokyoApi::Campact.new(client: self)
17
+ end
18
+
15
19
  def identity
16
20
  @identity ||= TokyoApi::Identity.new(client: self)
17
21
  end
data/lib/tokyo_api.rb CHANGED
@@ -2,10 +2,11 @@ require 'vertebrae'
2
2
  require 'tokyo_api/base'
3
3
  require 'tokyo_api/actionkit'
4
4
  require 'tokyo_api/bluestatedigital'
5
- require 'tokyo_api/krautbuster'
6
- require 'tokyo_api/identity'
7
- require 'tokyo_api/expire'
5
+ require 'tokyo_api/campact'
8
6
  require 'tokyo_api/client'
7
+ require 'tokyo_api/expire'
8
+ require 'tokyo_api/identity'
9
+ require 'tokyo_api/krautbuster'
9
10
 
10
11
  module TokyoApi
11
12
  extend Vertebrae::Base
@@ -0,0 +1,112 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe TokyoApi::Campact do
4
+ subject { TokyoApi.new(host: 'test.com') }
5
+
6
+ describe 'configuration' do
7
+ it 'should propagate the host' do
8
+ expect(subject.campact.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) { '/campact/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.campact.full_user('123abc456')).to eq({'error' => 'Connection refused'})
27
+ end
28
+ end
29
+
30
+ describe 'success' do
31
+ let(:body) { fixture('responses/campact/full_user_success') }
32
+
33
+ it 'should find an organisation' do
34
+ expect(subject.campact.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::Campact.new(client: client) }
45
+
46
+ before :each do
47
+ expect(subject).to receive(:subscription_status_path).with(token).and_return("/campact/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("/campact/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("/campact/subscription_status?token=#{token}").and_raise(Vertebrae::ResponseError.new(404, {method: 'get', url: "/campact/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("/campact/subscription_status?token=#{token}").and_raise(Vertebrae::ResponseError.new(500, {method: 'get', url: "/campact/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.campact.user_path('123abc456', petition_id: 'save-the-trees')).to eq '/campact/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.campact.user_path('123abc456', petition_id: 'save-the-trees', required_fields: [:first_name, :last_name, :email])).to eq '/campact/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.campact.user_path('123abc456', petition_id: 'save-the-trees', required_fields: ['email', 'fish & chips'])).to eq '/campact/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.campact.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.campact.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.campact.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::Campact.new }
107
+
108
+ it 'should return correct path' do
109
+ expect(subject.subscription_status_path('abc123')).to eq '/campact/subscription_status/abc123'
110
+ end
111
+ end
112
+ end
@@ -0,0 +1 @@
1
+ {"first_name":"Homer","last_name":"Simpson","country":"DE","postal":"12345","email":"foo@bar.com"}
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.1.2 ruby lib
5
+ # stub: tokyo_api 1.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "tokyo_api".freeze
9
- s.version = "1.1.2"
9
+ s.version = "1.2.0"
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-05-14"
14
+ s.date = "2018-08-31"
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 = [
@@ -35,17 +35,20 @@ Gem::Specification.new do |s|
35
35
  "lib/tokyo_api/actionkit.rb",
36
36
  "lib/tokyo_api/base.rb",
37
37
  "lib/tokyo_api/bluestatedigital.rb",
38
+ "lib/tokyo_api/campact.rb",
38
39
  "lib/tokyo_api/client.rb",
39
40
  "lib/tokyo_api/expire.rb",
40
41
  "lib/tokyo_api/identity.rb",
41
42
  "lib/tokyo_api/krautbuster.rb",
42
43
  "spec/actionkit_spec.rb",
43
44
  "spec/bluestatedigital_spec.rb",
45
+ "spec/campact_spec.rb",
44
46
  "spec/client_spec.rb",
45
47
  "spec/expire_spec.rb",
46
48
  "spec/fixtures/expire/success",
47
49
  "spec/fixtures/responses/actionkit/full_user_success",
48
50
  "spec/fixtures/responses/bluestatedigital/full_user_success",
51
+ "spec/fixtures/responses/campact/full_user_success",
49
52
  "spec/fixtures/responses/full_user_error",
50
53
  "spec/fixtures/responses/full_user_success",
51
54
  "spec/fixtures/responses/identity/full_user_success",
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.1.2
4
+ version: 1.2.0
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-05-14 00:00:00.000000000 Z
11
+ date: 2018-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vertebrae
@@ -118,17 +118,20 @@ files:
118
118
  - lib/tokyo_api/actionkit.rb
119
119
  - lib/tokyo_api/base.rb
120
120
  - lib/tokyo_api/bluestatedigital.rb
121
+ - lib/tokyo_api/campact.rb
121
122
  - lib/tokyo_api/client.rb
122
123
  - lib/tokyo_api/expire.rb
123
124
  - lib/tokyo_api/identity.rb
124
125
  - lib/tokyo_api/krautbuster.rb
125
126
  - spec/actionkit_spec.rb
126
127
  - spec/bluestatedigital_spec.rb
128
+ - spec/campact_spec.rb
127
129
  - spec/client_spec.rb
128
130
  - spec/expire_spec.rb
129
131
  - spec/fixtures/expire/success
130
132
  - spec/fixtures/responses/actionkit/full_user_success
131
133
  - spec/fixtures/responses/bluestatedigital/full_user_success
134
+ - spec/fixtures/responses/campact/full_user_success
132
135
  - spec/fixtures/responses/full_user_error
133
136
  - spec/fixtures/responses/full_user_success
134
137
  - spec/fixtures/responses/identity/full_user_success