telephone_appointments 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a68c22ea72cc7042cdf4271298005e93f855402a
4
+ data.tar.gz: f48e156d0ef6ef3caac93fe09c890e5867f13cc0
5
+ SHA512:
6
+ metadata.gz: 19b546c5dd67b311a0e5fd1a70401c0588892bdef7ea68a290c10a0068db4f7bcbbda64dae2d049b184bc3e63c7ee2bc23aa07fd6f4bd6ea9a9a648d49b32883
7
+ data.tar.gz: 22f3719cb582b67139ddf9dc11f2ffff3094c02e8a9dd180ddfe873c3a6fdae946cf3bdd1b9bc542832efb195005423526b952ff598a45db82475c431a96cb30
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,33 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bin/*'
4
+ - 'db/**/*'
5
+ - 'vendor/**/*'
6
+ TargetRubyVersion: 2.3
7
+
8
+ Documentation:
9
+ Enabled: false
10
+
11
+ Lint/HandleExceptions:
12
+ Exclude:
13
+ - Rakefile
14
+
15
+ Metrics/LineLength:
16
+ Max: 120
17
+
18
+ Style/FrozenStringLiteralComment:
19
+ Enabled: false
20
+
21
+ Metrics/MethodLength:
22
+ Exclude:
23
+ - 'spec/features/*'
24
+ - 'spec/requests/*'
25
+
26
+ Metrics/AbcSize:
27
+ Exclude:
28
+ - 'spec/features/*'
29
+ - 'spec/requests/*'
30
+
31
+ Metrics/BlockLength:
32
+ Exclude:
33
+ - 'spec/**/*'
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.12.5
6
+ notifications:
7
+ slack:
8
+ secure: XecHmig/8T6A8kHE99V7GnXJJ6pDDH7QgjiI1gIcKXVOxsQEYDhfOgl0jZe+dn1t0rGR7JTClunI1vQCJPF/8W1iMLZHSS1oj0ow7W8Tdfo6UCKOscAsEp+5X1wxbvVEXuKwlkBQ7IcJeOeMglof6eUpOUCKm9j+NpvApXP8YYqIfBPKiMj1VQ7S/Bkckwe3DFomZxcIRKHM/TGe7A29ZauoWhXpYpy68BHMjDevmSPFXk5USigJXnBqdU/oH+uLUgBmEyc4396Yh5oQslPXxeXxavyvsIOFYIEmpjDez6JcQ7XgJy29lyZDQKYywP5yxisaXbeEpWjjqh5saaktukgRi8jLyTD2n6Zxq1udHg3TfWj+LccvF/NMu9cZGH4pvLB5jcGX5ZYlDAOddCujTsQu3mze/yb2XYSUp19bLBlA8TcnIPelAdzQS9vUGEcFfKIUvq1DQVYhsxfQ4rwyxBzbr8m4+FRum4HSDcb3HVSCCv/pusLISJS4kl+nLtk30hklRYZ/cz1CYj2WnhlsqYQOlrD/uZax0dthk+3v4cYW6tw2A3NNrEhUOUsTxH/+dPAstqmHrEKeSYJ3NTxw2Gfns2b0WB/alTFOe4S0c8/5h41G2d25wZTrUKcWyZYgdLMc9FY9CA2gvxTGKXde3UipEKwRs4GmsQ41RZsGXwg=
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.1.0
2
+
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in telephone_appointments.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ben Lovell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # TelephoneAppointments
2
+
3
+ Provides Telephone Appointment Planner API access.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'telephone_appointments'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install telephone_appointments
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+
25
+ summary_document = TelephoneAppointments::SummaryDocumentActivity.new(
26
+ appointment_id: id,
27
+ owner_uid: uid,
28
+ delivery_method: message # 'postal' or 'digital'
29
+ )
30
+ summary_document.save # returns true or false
31
+
32
+ summary_document.errors # returns a hash of errors if save is unsuccessful
33
+
34
+ ```
35
+
36
+ The library provides a stubbed adapter:
37
+
38
+ ```ruby
39
+
40
+ require 'telephone_appointments/stub_api'
41
+ TelephoneAppointments.api = TelephoneAppointments::StubApi.new
42
+
43
+ ```
44
+
45
+ This returns canned responses when creating a summary document.
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
50
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
51
+ prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To
54
+ release a new version, update the version number in `version.rb`, and then run
55
+ `bundle exec rake release`, which will create a git tag for the version, push
56
+ git commits and tags, and push the `.gem` file to
57
+ [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at
62
+ https://github.com/guidance-guarantee-programme/telephone_appointments.
63
+
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the
68
+ [MIT License](http://opensource.org/licenses/MIT).
69
+
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ default_tasks = [:spec]
7
+
8
+ begin
9
+ # Rubocop is not available in envs other than development and test.
10
+ require 'rubocop/rake_task'
11
+ RuboCop::RakeTask.new
12
+ default_tasks << :rubocop
13
+ rescue LoadError
14
+ end
15
+
16
+ task default: default_tasks
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "telephone_appointments"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ require 'open-uri'
2
+
3
+ module TelephoneAppointments
4
+ class Api
5
+ def post(path, form_data)
6
+ uri = URI.parse("#{api_uri}#{path}")
7
+ http = Net::HTTP.new(uri.host, uri.port)
8
+ http.read_timeout = read_timeout
9
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
10
+ request.set_form_data(form_data)
11
+
12
+ Response.new(http.request(request))
13
+ end
14
+
15
+ private
16
+
17
+ def headers
18
+ {}.tap do |hash|
19
+ hash['Authorization'] = "Bearer #{bearer_token}" if bearer_token
20
+ hash['Accept'] = 'application/json'
21
+ end
22
+ end
23
+
24
+ def bearer_token
25
+ ENV['TELEPHONE_APPOINTMENTS_API_BEARER_TOKEN']
26
+ end
27
+
28
+ def api_uri
29
+ ENV.fetch('TELEPHONE_APPOINTMENTS_API_URI', 'http://localhost:3001')
30
+ end
31
+
32
+ def read_timeout
33
+ ENV.fetch('TELEPHONE_APPOINTMENTS_API_READ_TIMEOUT', 5).to_i
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ module TelephoneAppointments
2
+ class Response
3
+ def initialize(response)
4
+ @response = response
5
+ end
6
+
7
+ def success?
8
+ response.is_a? Net::HTTPSuccess
9
+ end
10
+
11
+ def errors
12
+ return {} if success? || response.body.nil? || response.body == ''
13
+ JSON.parse(response.body)
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :response
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ module TelephoneAppointments
2
+ class StubApi
3
+ def post(*)
4
+ Response.new(Net::HTTPSuccess.new(nil, nil, nil))
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ module TelephoneAppointments
2
+ class SummaryDocumentActivity
3
+ class InvalidDeliveryMethod < StandardError; end
4
+
5
+ VALID_DELIVERY_METHODS = %w(postal digital).freeze
6
+ PATH = '/api/v1/summary_documents'.freeze
7
+
8
+ def initialize(appointment_id:, owner_uid:, delivery_method:)
9
+ raise(InvalidDeliveryMethod, delivery_method) unless VALID_DELIVERY_METHODS.include?(delivery_method)
10
+
11
+ @appointment_id = appointment_id
12
+ @owner_uid = owner_uid
13
+ @delivery_method = delivery_method
14
+ end
15
+
16
+ def save
17
+ @response = TelephoneAppointments.api.post(
18
+ PATH,
19
+ appointment_id: @appointment_id,
20
+ owner_uid: @owner_uid,
21
+ delivery_method: @delivery_method
22
+ )
23
+ @response.success?
24
+ end
25
+
26
+ def errors
27
+ @response || raise(TelephoneAppointments::UnsavedObject, 'Please save the object before accessing the errors')
28
+ @response.errors
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module TelephoneAppointments
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,17 @@
1
+ require 'telephone_appointments/version'
2
+ require 'telephone_appointments/api'
3
+
4
+ require 'telephone_appointments/response'
5
+ require 'telephone_appointments/summary_document_activity'
6
+
7
+ require 'active_support/core_ext/module/attribute_accessors'
8
+
9
+ module TelephoneAppointments
10
+ mattr_writer :api
11
+
12
+ def self.api
13
+ @api ||= TelephoneAppointments::Api.new
14
+ end
15
+
16
+ class UnsavedObject < StandardError; end
17
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'telephone_appointments/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'telephone_appointments'
8
+ spec.version = TelephoneAppointments::VERSION
9
+ spec.authors = ['David Henry']
10
+ spec.email = ['david@decoybecoy.com']
11
+
12
+ spec.summary = 'Pension Guidance Telephone Appointment Planner API adapter'
13
+ spec.homepage = 'https://github.com/guidance-guarantee-programme/telephone_appointments'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'activesupport', '>= 4', '< 5.1'
22
+
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'pry-byebug'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'rubocop'
28
+ spec.add_development_dependency 'vcr'
29
+ spec.add_development_dependency 'webmock'
30
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: telephone_appointments
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Henry
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: pry-byebug
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: vcr
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: webmock
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ description:
132
+ email:
133
+ - david@decoybecoy.com
134
+ executables: []
135
+ extensions: []
136
+ extra_rdoc_files: []
137
+ files:
138
+ - ".gitignore"
139
+ - ".rspec"
140
+ - ".rubocop.yml"
141
+ - ".travis.yml"
142
+ - CHANGELOG.md
143
+ - Gemfile
144
+ - LICENSE.txt
145
+ - README.md
146
+ - Rakefile
147
+ - bin/console
148
+ - bin/setup
149
+ - lib/telephone_appointments.rb
150
+ - lib/telephone_appointments/api.rb
151
+ - lib/telephone_appointments/response.rb
152
+ - lib/telephone_appointments/stub_api.rb
153
+ - lib/telephone_appointments/summary_document_activity.rb
154
+ - lib/telephone_appointments/version.rb
155
+ - telephone_appointments.gemspec
156
+ homepage: https://github.com/guidance-guarantee-programme/telephone_appointments
157
+ licenses:
158
+ - MIT
159
+ metadata: {}
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project:
176
+ rubygems_version: 2.5.1
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: Pension Guidance Telephone Appointment Planner API adapter
180
+ test_files: []