tokyo_api 0.6.1 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12d2d3a99c115528e680c6cad6fac2c2dd016ddf
4
- data.tar.gz: be23032d01f274d9639af99f419ed35b04e9a74f
3
+ metadata.gz: 79401acf7c96745e5ace0e9aee6cde215ab3872a
4
+ data.tar.gz: c785ce0ee3fe07bdb3797e89c66a858fa9ba88cf
5
5
  SHA512:
6
- metadata.gz: 639b6d88d3e5fc1db184da6cd35c1095c48626e207b1f769ce01a8ae44cf54e3cbb245db747b1b5833119a8b427ef96b05769e686bd1bb5d33852990f6e46809
7
- data.tar.gz: 60bb05952d75302a17e54293e603e316d121d40b8ad124d55254bda7ba75327a0a7c5f8fb5f3ea0d7da4cce76f17177f258d79084bae3424627b8d8fc8499d74
6
+ metadata.gz: 0dfb6516012f4917d445f6834741b1a404c5f1a594cfe753dd92d0d688c7372a8b444e4a46673e6b70572e5a1f5b8adcd3bf0e3348784e4946968b69d4a7c9ea
7
+ data.tar.gz: 990d1937b86831cb4b6e78a7cfd6a53ca65e215886ac20fb4d54a989e76c6fa038bc318f84e7cafc521f137bfafb31a5e811b5aaf767711b39ea9ae2f297d02b
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 1.0.1
@@ -5,11 +5,15 @@ module TokyoApi
5
5
  end
6
6
 
7
7
  def full_user(id)
8
- client.get_request("#{normalized_base_path}full_user/#{id}").body
8
+ client.get_request("#{normalized_base_path}full_user/#{url_escape(id)}").body
9
9
  end
10
10
 
11
- def user_path(id, phone_required)
12
- "/#{normalized_base_path}user/#{id}?phone_required=#{phone_required}"
11
+ 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
16
+ path
13
17
  end
14
18
  end
15
- end
19
+ end
@@ -3,5 +3,17 @@ module TokyoApi
3
3
  def normalized_base_path
4
4
  "#{base_path}/"
5
5
  end
6
+
7
+ def url_escape(string)
8
+ CGI.escape(string)
9
+ end
10
+
11
+ def required_fields_param(required_fields)
12
+ if required_fields.present?
13
+ "required_fields=#{required_fields.collect{|v| url_escape(v.to_s)}.join(',')}"
14
+ else
15
+ ''
16
+ end
17
+ end
6
18
  end
7
19
  end
@@ -5,11 +5,15 @@ module TokyoApi
5
5
  end
6
6
 
7
7
  def full_user(id)
8
- client.get_request("#{normalized_base_path}full_user/#{id}").body
8
+ client.get_request("#{normalized_base_path}full_user/#{url_escape(id)}").body
9
9
  end
10
10
 
11
- def tokyo_blue_state_digital_user_path(id, phone_required)
12
- "/#{normalized_base_path}constituent/#{id}?phone_required=#{phone_required}"
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
13
17
  end
14
18
  end
15
- end
19
+ end
@@ -5,7 +5,7 @@ module TokyoApi
5
5
  end
6
6
 
7
7
  def organisation(host)
8
- client.get_request("#{normalized_base_path}organisation/#{host}").body
8
+ client.get_request("#{normalized_base_path}organisation/#{url_escape(host)}").body
9
9
  end
10
10
  end
11
11
  end
@@ -5,11 +5,16 @@ module TokyoApi
5
5
  end
6
6
 
7
7
  def full_user(id)
8
- client.get_request("#{normalized_base_path}full_user/#{id}").body
8
+ client.get_request("#{normalized_base_path}full_user/#{url_escape(id)}").body
9
9
  end
10
10
 
11
- def tokyo_identity_user_path(id, phone_required)
12
- "/#{normalized_base_path}user/#{id}?phone_required=#{phone_required}"
11
+ def tokyo_identity_user_path(id, required_fields: nil)
12
+ path = "/#{normalized_base_path}user/#{url_escape(id)}"
13
+
14
+ unless required_fields.nil?
15
+ path << "?#{required_fields_param(required_fields)}"
16
+ end
17
+ path
13
18
  end
14
19
  end
15
20
  end
@@ -5,11 +5,11 @@ module TokyoApi
5
5
  end
6
6
 
7
7
  def full_user(session_id)
8
- client.get_request("#{normalized_base_path}full_user/#{session_id}").body
8
+ client.get_request("#{normalized_base_path}full_user/#{url_escape(session_id)}").body
9
9
  end
10
10
 
11
11
  def session_status(session_id)
12
- client.get_request("#{normalized_base_path}session_status/#{session_id}").body
12
+ client.get_request("#{normalized_base_path}session_status/#{url_escape(session_id)}").body
13
13
  end
14
14
 
15
15
  def subscription_status(token)
@@ -25,12 +25,16 @@ module TokyoApi
25
25
  end
26
26
  end
27
27
 
28
- def user_path(session_id, petition_id)
29
- "/#{normalized_base_path}user/#{session_id}?petition_id=#{petition_id}"
28
+ def user_path(session_id, petition_id:, required_fields: nil)
29
+ path = "/#{normalized_base_path}user/#{url_escape(session_id)}?petition_id=#{url_escape(petition_id)}"
30
+ unless required_fields.nil?
31
+ path << "&#{required_fields_param(required_fields)}"
32
+ end
33
+ path
30
34
  end
31
35
 
32
36
  def subscription_status_path(token)
33
- "/#{normalized_base_path}subscription_status/#{token}"
37
+ "/#{normalized_base_path}subscription_status/#{url_escape(token)}"
34
38
  end
35
39
  end
36
- end
40
+ end
@@ -38,15 +38,19 @@ describe TokyoApi::Actionkit do
38
38
  end
39
39
 
40
40
  describe 'user_path' do
41
- context 'phone not required' do
41
+ context 'without required_fields' do
42
42
  it "should return relative path to user API endpoint" do
43
- expect(subject.actionkit.user_path('abc.123.xyz', false)).to eq('/actionkit/user/abc.123.xyz?phone_required=false')
43
+ expect(subject.actionkit.user_path('abc.123.xyz')).to eq('/actionkit/user/abc.123.xyz')
44
44
  end
45
45
  end
46
46
 
47
- context 'phone required' do
47
+ context 'with required_fields' do
48
48
  it "should return relative path to user API endpoint" do
49
- expect(subject.actionkit.user_path('abc.123.xyz', true)).to eq('/actionkit/user/abc.123.xyz?phone_required=true')
49
+ expect(subject.actionkit.user_path('abc.123.xyz', required_fields: [:first_name, :last_name, :email, :postal, :phone])).to eq('/actionkit/user/abc.123.xyz?required_fields=first_name,last_name,email,postal,phone')
50
+ end
51
+
52
+ it 'should url-escape field names with weird characters' do
53
+ expect(subject.actionkit.user_path('abc.123.xyz', required_fields: ['email', 'fish & chips'])).to eq('/actionkit/user/abc.123.xyz?required_fields=email,fish+%26+chips')
50
54
  end
51
55
  end
52
56
  end
@@ -39,15 +39,19 @@ describe TokyoApi::Bluestatedigital do
39
39
  end
40
40
 
41
41
  describe 'tokyo_blue_state_digital_user_path' do
42
- context 'phone not required' do
42
+ context 'without required_fields' do
43
43
  it "should return rooted relative path to tokyo user API endpoint" do
44
- expect(subject.bluestatedigital.tokyo_blue_state_digital_user_path('-123456', false)).to eq('/bluestatedigital/constituent/-123456?phone_required=false')
44
+ expect(subject.bluestatedigital.tokyo_blue_state_digital_user_path('-123456')).to eq('/bluestatedigital/constituent/-123456')
45
45
  end
46
46
  end
47
47
 
48
- context 'phone required' do
48
+ context 'with required_fields' do
49
49
  it "should return rooted relative path to tokyo user API endpoint" do
50
- expect(subject.bluestatedigital.tokyo_blue_state_digital_user_path('-123456', true)).to eq('/bluestatedigital/constituent/-123456?phone_required=true')
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')
51
55
  end
52
56
  end
53
57
  end
@@ -38,15 +38,19 @@ describe TokyoApi::Identity do
38
38
  end
39
39
 
40
40
  describe 'tokyo_identity_user_path' do
41
- context 'phone not required' do
41
+ context 'without required_fields' do
42
42
  it 'should return rooted relative path to tokyo user API endpoint' do
43
- expect(subject.identity.tokyo_identity_user_path('-123456', false)).to eq('/identity/user/-123456?phone_required=false')
43
+ expect(subject.identity.tokyo_identity_user_path('-123456')).to eq('/identity/user/-123456')
44
44
  end
45
45
  end
46
46
 
47
- context 'phone required' do
47
+ context 'with required_fields' do
48
48
  it 'should return rooted relative path to tokyo user API endpoint' do
49
- expect(subject.identity.tokyo_identity_user_path('-123456', true)).to eq('/identity/user/-123456?phone_required=true')
49
+ expect(subject.identity.tokyo_identity_user_path('-123456', required_fields: [:first_name, :last_name, :email, :postal, :phone])).to eq('/identity/user/-123456?required_fields=first_name,last_name,email,postal,phone')
50
+ end
51
+
52
+ it 'should url-escape field names with weird characters' do
53
+ expect(subject.identity.tokyo_identity_user_path('-123456', required_fields: ['email', 'fish & chips'])).to eq('/identity/user/-123456?required_fields=email,fish+%26+chips')
50
54
  end
51
55
  end
52
56
  end
@@ -71,8 +71,20 @@ describe TokyoApi::Krautbuster do
71
71
  end
72
72
 
73
73
  describe '#user_path' do
74
- it "should return relative path to user API endpoint" do
75
- expect(subject.krautbuster.user_path('123abc456', 'save-the-trees')).to eq '/krautbuster/user/123abc456?petition_id=save-the-trees'
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
76
88
  end
77
89
  end
78
90
 
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 0.6.1 ruby lib
5
+ # stub: tokyo_api 1.0.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "tokyo_api".freeze
9
- s.version = "0.6.1"
9
+ s.version = "1.0.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 = "2017-08-21"
14
+ s.date = "2017-09-07"
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 = [
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: 0.6.1
4
+ version: 1.0.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: 2017-08-21 00:00:00.000000000 Z
11
+ date: 2017-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vertebrae