tokyo_api 1.5.1 → 1.6.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: af1abab30e5fd562a76150009f4e942472e6a201ec92f28123a6cf3e4c5e1035
4
- data.tar.gz: 53965d4edd39431e61fc4024f9e0228a53c2753129645961856612adaa3a6ef5
3
+ metadata.gz: 608376ec5c22df615936ab9c5603877f983e3f1c36c93071f3e4e4195bc6012e
4
+ data.tar.gz: 48218037c0aa31d24ca5f708311677387172422adc63a1ee5a0f190b3f92bfd2
5
5
  SHA512:
6
- metadata.gz: f9cc2b5e986da3e50938638fcb014771dd22a9f95033625999a187e011c5140f44db98fb231a15859beb7318cc17a68be9ee757539c1c47a009b71fe564b7a3e
7
- data.tar.gz: a25c4dc8fb03616a16b1b7f08c2a8a79479c3630b05b5a5348af667b5ec3a527622da6c9f37063e65ff40f50f21c162f8445d891f79b1a2601d29363e33131ff
6
+ metadata.gz: 5baf06d1f979d9efa535600046b02f384cc53ce3dc794be57e1e799a4cb1a9744b7202725656905940438b0a8081951f5545b9e46f463fa90f0c9ecf870d8a0b
7
+ data.tar.gz: 585fb0e20ce10d6aec74c764a8b43716dabed99e6c32605f8789837840e3ba80a0ae828dd5ed104fb604f2314e1c405242389bfcffe83b1467cba761b15256c3
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.3
1
+ 2.6.6
data/Gemfile CHANGED
@@ -1,13 +1,16 @@
1
- source "http://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- gem 'vertebrae', '> 0.5.1'
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 "rspec"
9
- gem 'webmock'
10
+ gem 'bundler'
10
11
  gem 'byebug'
11
- gem "bundler"
12
- gem "juwelier"
12
+ gem 'juwelier', git: 'https://github.com/flajann2/juwelier.git'
13
+ gem 'rspec'
14
+ gem 'rubocop'
15
+ gem 'webmock'
13
16
  end
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
- # encoding: utf-8
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
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
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 = "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"]
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 :default => :spec
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.5.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,7 +1,8 @@
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'
@@ -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
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TokyoApi
2
4
  class Campact < Base
3
5
  def base_path
@@ -17,26 +19,18 @@ module TokyoApi
17
19
  end
18
20
 
19
21
  def subscription_status(token)
20
- begin
21
- client.get_request(subscription_status_path(token)).body
22
- rescue Vertebrae::ResponseError => e
23
- # Status 404 is expected in these calls
24
- if e.status_code == 404
25
- return nil
26
- end
27
-
28
- raise
29
- 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
30
28
  end
31
29
 
32
30
  def user_path(session_id, petition_id:, with_subscription_status: false, required_fields: nil)
33
- path = "/#{normalized_base_path}user/#{url_escape(session_id)}?petition_id=#{url_escape(petition_id)}"
34
- if with_subscription_status
35
- path << '&with_subscription_status=true'
36
- end
37
- unless required_fields.nil?
38
- path << "&#{required_fields_param(required_fields)}"
39
- 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?
40
34
  path
41
35
  end
42
36
 
@@ -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
- alias_method :action_kit, :actionkit
8
-
9
- def bluestatedigital
10
- @bluestatedigital ||= TokyoApi::Bluestatedigital.new(client: self)
11
- end
12
-
13
- alias_method :blue_state_digital, :bluestatedigital
9
+ alias action_kit actionkit
14
10
 
15
11
  def campact
16
12
  @campact ||= TokyoApi::Campact.new(client: self)
@@ -24,7 +20,6 @@ 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',
@@ -32,32 +27,27 @@ module TokyoApi
32
27
  content_type: 'application/json'
33
28
  }
34
29
 
35
- if initialisation_options.has_key?(:timeout)
36
- opts[:connection_options] = {request: {timeout: initialisation_options[:timeout]}}
30
+ if initialisation_options.key?(:timeout)
31
+ opts[:connection_options] = { request: { timeout: initialisation_options[:timeout] } }
37
32
  end
38
33
 
39
34
  opts
40
35
  end
41
36
 
42
37
  def request(method, path, params, options) # :nodoc:
43
- if !::Vertebrae::Request::METHODS.include?(method)
44
- raise ArgumentError, "unknown http method: #{method}"
45
- end
38
+ raise ArgumentError, "unknown http method: #{method}" unless ::Vertebrae::Request::METHODS.include?(method)
46
39
 
47
- unless connection.configuration.prefix.blank?
48
- path = connection.configuration.prefix + '/' + path
49
- end
40
+ path = "#{connection.configuration.prefix}/#{path}" unless connection.configuration.prefix.blank?
50
41
 
51
42
  ::Vertebrae::Base.logger.debug "EXECUTED: #{method} - #{path} with #{params} and #{options}"
52
43
 
53
44
  connection.connection.send(method) do |request|
54
-
55
45
  case method.to_sym
56
- when *(::Vertebrae::Request::METHODS - ::Vertebrae::Request::METHODS_WITH_BODIES)
57
- request.url(path, params)
58
- when *::Vertebrae::Request::METHODS_WITH_BODIES
59
- request.path = path
60
- request.body = extract_data_from_params(params) unless params.empty?
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?
61
51
  end
62
52
  end
63
53
  end
@@ -67,7 +57,8 @@ module TokyoApi
67
57
  builder.use Faraday::Request::Multipart
68
58
  builder.use Faraday::Request::UrlEncoded
69
59
  if connection.configuration.authenticated?
70
- builder.use Faraday::Request::BasicAuthentication, connection.configuration.username, connection.configuration.password
60
+ builder.use Faraday::Request::BasicAuthentication, connection.configuration.username,
61
+ connection.configuration.password
71
62
  end
72
63
 
73
64
  builder.use Faraday::Response::Logger if ENV['DEBUG']
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TokyoApi
2
4
  class Expire < Base
3
5
  def base_path
@@ -8,4 +10,4 @@ module TokyoApi
8
10
  client.get_request("#{normalized_base_path}organisation/#{url_escape(host)}").body
9
11
  end
10
12
  end
11
- end
13
+ end
@@ -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, minimum_consent_level, encrypted)
22
- unless additional_subscription_parameters.blank?
23
- params << additional_subscription_parameters
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(opt_in_public_ids, minimum_consent_level, encrypted)}"
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 opt_in_public_ids.present?
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 minimum_consent_level
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
@@ -1,4 +1,6 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
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
- stub_get(request_path).to_return(:body => body, :status => status,
19
- :headers => { content_type: "application/json; charset=utf-8"})
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 "should return relative path to user API endpoint" do
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 "should return relative path to user API endpoint" do
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
+ 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', required_fields: ['email', 'fish & chips'])).to eq('/actionkit/user/abc.123.xyz?required_fields=email,fish+%26+chips')
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
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
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
- stub_get(request_path).to_return(:body => body, :status => status,
19
- :headers => { content_type: "application/json; charset=utf-8"})
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
- 'country' => 'DE', 'postal' => '12345', 'email' => 'foo@bar.com' })
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(404, {method: 'get', url: "/campact/subscription_status?token=#{token}", status: '404', body: 'Not Found'}))
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(500, {method: 'get', url: "/campact/subscription_status?token=#{token}", status: '500', body: 'Something bad happened'}))
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 "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'
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 "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'
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', required_fields: ['email', 'fish & chips'])).to eq '/campact/user/123abc456?petition_id=save-the-trees&required_fields=email,fish+%26+chips'
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', petition_id: 'save-the-trees')).not_to match /.+with_subscription_status=.+/
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', with_subscription_status: false)).not_to match /.+with_subscription_status=.+/
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', with_subscription_status: true)).to match /.+with_subscription_status=true.*/
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
@@ -117,7 +132,9 @@ describe TokyoApi::Campact do
117
132
  subject { TokyoApi::Campact.new(client: client) }
118
133
 
119
134
  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 }))
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
+ }))
121
138
 
122
139
  session_status = subject.session_status(session_id)
123
140
 
data/spec/client_spec.rb CHANGED
@@ -1,11 +1,13 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
2
4
 
3
5
  describe TokyoApi::Client do
4
6
  describe 'initialisation' do
5
7
  subject { described_class.new(options) }
6
8
 
7
9
  context 'with a basic_auth string parameter' do
8
- let(:options) { {basic_auth: 'login:password'} }
10
+ let(:options) { { basic_auth: 'login:password' } }
9
11
 
10
12
  it 'should set username/password on the configuration' do
11
13
  config = subject.connection.configuration
@@ -15,7 +17,7 @@ describe TokyoApi::Client do
15
17
  end
16
18
 
17
19
  context 'with a timeout' do
18
- let(:options) { {timeout: 5} }
20
+ let(:options) { { timeout: 5 } }
19
21
 
20
22
  it 'should set the timeout on the faraday options' do
21
23
  config = subject.connection.configuration
data/spec/expire_spec.rb CHANGED
@@ -1,4 +1,6 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
2
4
 
3
5
  describe TokyoApi::Expire do
4
6
  subject { TokyoApi.new(host: 'test.com') }
@@ -8,16 +10,16 @@ describe TokyoApi::Expire do
8
10
  let(:request_path) { '/expire/organisation/foo.com' }
9
11
 
10
12
  before(:each) do
11
- stub_get(request_path).to_return(:body => body, :status => status,
12
- :headers => { content_type: "application/json; charset=utf-8"})
13
+ stub_get(request_path).to_return(body: body, status: status,
14
+ headers: { content_type: 'application/json; charset=utf-8' })
13
15
  end
14
16
 
15
17
  describe 'success' do
16
- let(:status) { 200 }
18
+ let(:status) { 200 }
17
19
 
18
20
  it 'should find an organisation' do
19
- expect(subject.expire.organisation('foo.com')).to eq({'status' => 'success'})
21
+ expect(subject.expire.organisation('foo.com')).to eq({ 'status' => 'success' })
20
22
  end
21
23
  end
22
24
  end
23
- end
25
+ end
@@ -1,4 +1,6 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
2
4
 
3
5
  describe TokyoApi::Identity do
4
6
  subject { TokyoApi.new(host: 'test.com') }
@@ -15,15 +17,15 @@ describe TokyoApi::Identity do
15
17
  let(:status) { 200 }
16
18
 
17
19
  before(:each) do
18
- stub_get(request_path).to_return(:body => body, :status => status,
19
- :headers => { content_type: "application/json; charset=utf-8"})
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.identity.full_user('1')).to eq({'error' => 'Connection refused'})
28
+ expect(subject.identity.full_user('1')).to eq({ 'error' => 'Connection refused' })
27
29
  end
28
30
  end
29
31
 
@@ -31,8 +33,8 @@ describe TokyoApi::Identity do
31
33
  let(:body) { fixture('responses/identity/full_user_success') }
32
34
 
33
35
  it 'should return a hash' do
34
- expect(subject.identity.full_user('1')).to eq({'first_name' => 'Homer', 'last_name' => 'Simpson',
35
- 'country' => 'GB', 'postal' => '12345', 'email' => 'foo@bar.com' })
36
+ expect(subject.identity.full_user('1')).to eq({ 'first_name' => 'Homer', 'last_name' => 'Simpson',
37
+ 'country' => 'GB', 'postal' => '12345', 'email' => 'foo@bar.com' })
36
38
  end
37
39
  end
38
40
  end
@@ -46,52 +48,60 @@ describe TokyoApi::Identity do
46
48
 
47
49
  context 'with required_fields' do
48
50
  it 'should return rooted relative path to tokyo user API endpoint' do
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')
51
+ expect(subject.identity.tokyo_identity_user_path('-123456',
52
+ required_fields: %i[first_name last_name email postal
53
+ phone])).to eq('/identity/user/-123456?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.identity.tokyo_identity_user_path('-123456', required_fields: ['email', 'fish & chips'])).to eq('/identity/user/-123456?required_fields=email,fish+%26+chips')
57
+ expect(subject.identity.tokyo_identity_user_path('-123456',
58
+ required_fields: ['email',
59
+ 'fish & chips'])).to eq('/identity/user/-123456?required_fields=email,fish+%26+chips')
54
60
  end
55
61
  end
56
62
 
57
63
  context 'with_subscription_status and associated arguments' do
58
64
  it 'should not include query string parameter if argument is missing' do
59
- expect(subject.identity.tokyo_identity_user_path('123abc456')).not_to match /.+with_subscription_status=.+/
65
+ expect(subject.identity.tokyo_identity_user_path('123abc456')).not_to match(/.+with_subscription_status=.+/)
60
66
  end
61
67
 
62
68
  it 'should not include query string parameter if argument is false' do
63
- expect(subject.identity.tokyo_identity_user_path('123abc456', with_subscription_status: false)).not_to match /.+with_subscription_status=.+/
69
+ expect(subject.identity.tokyo_identity_user_path('123abc456',
70
+ with_subscription_status: false)).not_to match(/.+with_subscription_status=.+/)
64
71
  end
65
72
 
66
73
  it 'should not include opt_in_public_ids and minimum_consent_level if with_subscription_status is false' do
67
74
  tokyo_path = subject.identity.tokyo_identity_user_path('123abc456',
68
- with_subscription_status: false,
69
- opt_in_public_ids: ['policy-1.5'],
70
- minimum_consent_level: 'explicit')
75
+ with_subscription_status: false,
76
+ opt_in_public_ids: ['policy-1.5'],
77
+ minimum_consent_level: 'explicit')
71
78
 
72
- expect(tokyo_path).not_to match /.+opt_in_public_ids=.+/
73
- expect(tokyo_path).not_to match /.+minimum_consent_level=.+/
79
+ expect(tokyo_path).not_to match(/.+opt_in_public_ids=.+/)
80
+ expect(tokyo_path).not_to match(/.+minimum_consent_level=.+/)
74
81
  end
75
82
 
76
83
  it 'should include query string parameter if argument is true' do
77
- expect(subject.identity.tokyo_identity_user_path('123abc456', with_subscription_status: true)).to match /.+with_subscription_status=.+/
84
+ expect(subject.identity.tokyo_identity_user_path('123abc456',
85
+ with_subscription_status: true)).to match(/.+with_subscription_status=.+/)
78
86
  end
79
87
 
80
88
  it 'should include encrypted parameter if argument is true' do
81
- expect(subject.identity.tokyo_identity_user_path('123abc456', with_subscription_status: true, encrypted: true)).to match /.+encrypted=.+/
89
+ expect(subject.identity.tokyo_identity_user_path('123abc456', with_subscription_status: true,
90
+ encrypted: true)).to match(/.+encrypted=.+/)
82
91
  end
83
92
 
84
93
  it 'should include opt_in_public_ids and minimum_consent_level if with_subscription_status is true' do
85
94
  tokyo_path = subject.identity.tokyo_identity_user_path('123abc456',
86
- required_fields: [:first_name, :last_name, :email, :postal, :phone],
87
- with_subscription_status: true,
88
- opt_in_public_ids: ['policy-1.5'],
89
- minimum_consent_level: 'explicit')
90
-
91
- expect(tokyo_path).to match /.+with_subscription_status=true.*/
92
- expect(tokyo_path).to match /.+opt_in_public_ids=.+/
93
- expect(tokyo_path).to match /.+minimum_consent_level=.+/
94
- expect { URI::parse(tokyo_path) }.not_to raise_error
95
+ required_fields: %i[first_name last_name email
96
+ postal phone],
97
+ with_subscription_status: true,
98
+ opt_in_public_ids: ['policy-1.5'],
99
+ minimum_consent_level: 'explicit')
100
+
101
+ expect(tokyo_path).to match(/.+with_subscription_status=true.*/)
102
+ expect(tokyo_path).to match(/.+opt_in_public_ids=.+/)
103
+ expect(tokyo_path).to match(/.+minimum_consent_level=.+/)
104
+ expect { URI.parse(tokyo_path) }.not_to raise_error
95
105
  end
96
106
  end
97
107
  end
@@ -103,17 +113,21 @@ describe TokyoApi::Identity do
103
113
 
104
114
  it 'should return correct path for a list of public ids' do
105
115
  expected_path = '/identity/subscription_status/abc123?opt_in_public_ids=policy-1.5%2Cpolicy-1.6'
106
- expect(subject.identity.subscription_status_path('abc123', opt_in_public_ids: ['policy-1.5', 'policy-1.6'])).to eq expected_path
116
+ expect(subject.identity.subscription_status_path('abc123',
117
+ opt_in_public_ids: ['policy-1.5',
118
+ 'policy-1.6'])).to eq expected_path
107
119
  end
108
120
 
109
121
  it 'should support minimum_consent_level' do
110
122
  expected_path = '/identity/subscription_status/abc123?opt_in_public_ids=policy-1.5&minimum_consent_level=explicit'
111
- expect(subject.identity.subscription_status_path('abc123', opt_in_public_ids: ['policy-1.5'], minimum_consent_level: 'explicit')).to eq expected_path
123
+ expect(subject.identity.subscription_status_path('abc123', opt_in_public_ids: ['policy-1.5'],
124
+ minimum_consent_level: 'explicit')).to eq expected_path
112
125
  end
113
126
 
114
127
  it 'should support encrypted param' do
115
128
  expected_path = '/identity/subscription_status/abc123?opt_in_public_ids=policy-1.5&minimum_consent_level=explicit&encrypted=1'
116
- expect(subject.identity.subscription_status_path('abc123', opt_in_public_ids: ['policy-1.5'], minimum_consent_level: 'explicit', encrypted: true)).to eq expected_path
129
+ expect(subject.identity.subscription_status_path('abc123', opt_in_public_ids: ['policy-1.5'],
130
+ minimum_consent_level: 'explicit', encrypted: true)).to eq expected_path
117
131
  end
118
132
  end
119
133
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
5
  require 'rspec'
@@ -6,12 +8,12 @@ require 'tokyo_api'
6
8
 
7
9
  # Requires supporting files with custom matchers and macros, etc,
8
10
  # in ./support/ and its subdirectories.
9
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
10
12
 
11
13
  RSpec.configure do |config|
12
14
  config.include WebMock::API
13
15
  config.color = true
14
- #config.raise_errors_for_deprecations!
16
+ # config.raise_errors_for_deprecations!
15
17
  end
16
18
 
17
19
  def stub_get(path)
@@ -29,7 +31,7 @@ def stub_tokyo_request(method, path)
29
31
  end
30
32
 
31
33
  def fixture_path
32
- File.expand_path("../fixtures", __FILE__)
34
+ File.expand_path('fixtures', __dir__)
33
35
  end
34
36
 
35
37
  def fixture(file)
@@ -1,11 +1,11 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
2
4
 
3
5
  describe TokyoApi do
4
6
  before(:each) do
5
7
  allow(TokyoApi::Client).to receive(:setup_client)
6
8
  end
7
9
  specify { expect(subject).to respond_to :actionkit }
8
- specify { expect(subject.new).to be_a(TokyoApi::Client)}
10
+ specify { expect(subject.new).to be_a(TokyoApi::Client) }
9
11
  end
10
-
11
-
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.5.1 ruby lib
5
+ # stub: tokyo_api 1.6.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "tokyo_api".freeze
9
- s.version = "1.5.1"
9
+ s.version = "1.6.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 = "2020-04-29"
14
+ s.date = "2021-03-24"
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 = [
@@ -33,19 +33,16 @@ Gem::Specification.new do |s|
33
33
  "lib/tokyo_api.rb",
34
34
  "lib/tokyo_api/actionkit.rb",
35
35
  "lib/tokyo_api/base.rb",
36
- "lib/tokyo_api/bluestatedigital.rb",
37
36
  "lib/tokyo_api/campact.rb",
38
37
  "lib/tokyo_api/client.rb",
39
38
  "lib/tokyo_api/expire.rb",
40
39
  "lib/tokyo_api/identity.rb",
41
40
  "spec/actionkit_spec.rb",
42
- "spec/bluestatedigital_spec.rb",
43
41
  "spec/campact_spec.rb",
44
42
  "spec/client_spec.rb",
45
43
  "spec/expire_spec.rb",
46
44
  "spec/fixtures/expire/success",
47
45
  "spec/fixtures/responses/actionkit/full_user_success",
48
- "spec/fixtures/responses/bluestatedigital/full_user_success",
49
46
  "spec/fixtures/responses/campact/full_user_success",
50
47
  "spec/fixtures/responses/full_user_error",
51
48
  "spec/fixtures/responses/full_user_success",
@@ -58,34 +55,37 @@ Gem::Specification.new do |s|
58
55
  ]
59
56
  s.homepage = "http://github.com/controlshift/tokyo_api".freeze
60
57
  s.licenses = ["MIT".freeze]
61
- s.rubygems_version = "3.0.4".freeze
58
+ s.rubygems_version = "3.0.8".freeze
62
59
  s.summary = "Ruby API Wrapper for Tokyo CRM service".freeze
63
60
 
64
61
  if s.respond_to? :specification_version then
65
62
  s.specification_version = 4
66
63
 
67
64
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
68
- s.add_runtime_dependency(%q<vertebrae>.freeze, ["> 0.5.1"])
69
- s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
70
- s.add_development_dependency(%q<webmock>.freeze, [">= 0"])
71
- s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
65
+ s.add_runtime_dependency(%q<vertebrae>.freeze, [">= 0.6.0"])
72
66
  s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
67
+ s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
73
68
  s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
69
+ s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
70
+ s.add_development_dependency(%q<rubocop>.freeze, [">= 0"])
71
+ s.add_development_dependency(%q<webmock>.freeze, [">= 0"])
74
72
  else
75
- s.add_dependency(%q<vertebrae>.freeze, ["> 0.5.1"])
76
- s.add_dependency(%q<rspec>.freeze, [">= 0"])
77
- s.add_dependency(%q<webmock>.freeze, [">= 0"])
78
- s.add_dependency(%q<byebug>.freeze, [">= 0"])
73
+ s.add_dependency(%q<vertebrae>.freeze, [">= 0.6.0"])
79
74
  s.add_dependency(%q<bundler>.freeze, [">= 0"])
75
+ s.add_dependency(%q<byebug>.freeze, [">= 0"])
80
76
  s.add_dependency(%q<juwelier>.freeze, [">= 0"])
77
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
78
+ s.add_dependency(%q<rubocop>.freeze, [">= 0"])
79
+ s.add_dependency(%q<webmock>.freeze, [">= 0"])
81
80
  end
82
81
  else
83
- s.add_dependency(%q<vertebrae>.freeze, ["> 0.5.1"])
84
- s.add_dependency(%q<rspec>.freeze, [">= 0"])
85
- s.add_dependency(%q<webmock>.freeze, [">= 0"])
86
- s.add_dependency(%q<byebug>.freeze, [">= 0"])
82
+ s.add_dependency(%q<vertebrae>.freeze, [">= 0.6.0"])
87
83
  s.add_dependency(%q<bundler>.freeze, [">= 0"])
84
+ s.add_dependency(%q<byebug>.freeze, [">= 0"])
88
85
  s.add_dependency(%q<juwelier>.freeze, [">= 0"])
86
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
87
+ s.add_dependency(%q<rubocop>.freeze, [">= 0"])
88
+ s.add_dependency(%q<webmock>.freeze, [">= 0"])
89
89
  end
90
90
  end
91
91
 
metadata CHANGED
@@ -1,31 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tokyo_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Woodhull
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-29 00:00:00.000000000 Z
11
+ date: 2021-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vertebrae
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.1
19
+ version: 0.6.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.1
26
+ version: 0.6.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: webmock
42
+ name: byebug
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: byebug
56
+ name: juwelier
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: bundler
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,21 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: juwelier
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
@@ -116,19 +130,16 @@ files:
116
130
  - lib/tokyo_api.rb
117
131
  - lib/tokyo_api/actionkit.rb
118
132
  - lib/tokyo_api/base.rb
119
- - lib/tokyo_api/bluestatedigital.rb
120
133
  - lib/tokyo_api/campact.rb
121
134
  - lib/tokyo_api/client.rb
122
135
  - lib/tokyo_api/expire.rb
123
136
  - lib/tokyo_api/identity.rb
124
137
  - spec/actionkit_spec.rb
125
- - spec/bluestatedigital_spec.rb
126
138
  - spec/campact_spec.rb
127
139
  - spec/client_spec.rb
128
140
  - spec/expire_spec.rb
129
141
  - spec/fixtures/expire/success
130
142
  - spec/fixtures/responses/actionkit/full_user_success
131
- - spec/fixtures/responses/bluestatedigital/full_user_success
132
143
  - spec/fixtures/responses/campact/full_user_success
133
144
  - spec/fixtures/responses/full_user_error
134
145
  - spec/fixtures/responses/full_user_success
@@ -142,7 +153,7 @@ homepage: http://github.com/controlshift/tokyo_api
142
153
  licenses:
143
154
  - MIT
144
155
  metadata: {}
145
- post_install_message:
156
+ post_install_message:
146
157
  rdoc_options: []
147
158
  require_paths:
148
159
  - lib
@@ -157,8 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
168
  - !ruby/object:Gem::Version
158
169
  version: '0'
159
170
  requirements: []
160
- rubygems_version: 3.0.4
161
- signing_key:
171
+ rubygems_version: 3.0.8
172
+ signing_key:
162
173
  specification_version: 4
163
174
  summary: Ruby API Wrapper for Tokyo CRM service
164
175
  test_files: []
@@ -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,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"}