notifications-ruby-client 2.4.0 → 2.5.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.
@@ -20,6 +20,8 @@ env_vars=(
20
20
  LETTER_TEMPLATE_ID
21
21
  EMAIL_REPLY_TO_ID
22
22
  SMS_SENDER_ID
23
+ API_SENDING_KEY
24
+ INBOUND_SMS_QUERY_KEY
23
25
  )
24
26
 
25
27
  for env_var in "${env_vars[@]}"; do
data/bin/test_client.rb CHANGED
@@ -15,6 +15,7 @@ def main
15
15
  test_get_notification_by_id_endpoint(client, sms_notification.id, 'sms')
16
16
  test_get_notification_by_id_endpoint(client, letter_notification.id, 'letter')
17
17
  test_get_all_notifications(client)
18
+ test_get_received_texts
18
19
  p 'ruby client integration tests pass'
19
20
  exit 0
20
21
  end
@@ -310,6 +311,15 @@ def expected_fields_in_template
310
311
  uri)
311
312
  end
312
313
 
314
+ def expected_fields_in_received_text_response
315
+ %w(id
316
+ created_at
317
+ content
318
+ notify_number
319
+ service_id
320
+ user_number)
321
+ end
322
+
313
323
  def test_get_all_notifications(client)
314
324
  notifications = client.get_notifications
315
325
  unless notifications.is_a?(Notifications::Client::NotificationsCollection)
@@ -319,6 +329,34 @@ def test_get_all_notifications(client)
319
329
  field_should_not_be_nil(expected_fields_for_get_all_notifications, notifications, 'get_notifications')
320
330
  end
321
331
 
332
+ def test_get_received_texts
333
+ client = Notifications::Client.new(ENV['INBOUND_SMS_QUERY_KEY'], ENV['NOTIFY_API_URL'])
334
+ response = client.get_received_texts
335
+ unless response.is_a?(Notifications::Client::ReceivedTextCollection)
336
+ p 'failed test_get_received_texts response is not a Notifications::Client::ReceivedTextCollection'
337
+ exit 1
338
+ end
339
+ unless response.collection.length >= 0
340
+ p 'failed test_get_received_texts, expected at least 1 received text returned.'
341
+ exit 1
342
+ end
343
+ test_received_text_response(response.collection[0], 'test_received_text_response')
344
+ test_received_text_response(response.collection[1], 'test_received_text_response')
345
+ test_received_text_response(response.collection[2], 'test_received_text_response')
346
+ end
347
+
348
+ def test_received_text_response(response, test_method)
349
+ unless response.is_a?(Notifications::Client::ReceivedText)
350
+ p 'failed test_get_received_texts response is not a Notifications::Client::ReceivedText'
351
+ exit 1
352
+ end
353
+ unless response.id.is_a?(String)
354
+ p 'failed received text id is not a String'
355
+ exit 1
356
+ end
357
+ field_should_not_be_nil(expected_fields_in_received_text_response, response, test_method)
358
+ end
359
+
322
360
  def expected_fields_for_get_all_notifications
323
361
  %W(links
324
362
  collection)
data/docker/Dockerfile CHANGED
@@ -9,6 +9,7 @@ RUN \
9
9
  && ([ -z "$HTTP_PROXY" ] || echo "Acquire::http::Proxy \"${HTTP_PROXY}\";" > /etc/apt/apt.conf.d/99HttpProxy) \
10
10
  && apt-get update \
11
11
  && apt-get install -y --no-install-recommends \
12
+ gcc \
12
13
  make \
13
14
  curl \
14
15
  git \
@@ -3,6 +3,8 @@ require_relative "client/speaker"
3
3
  require_relative "client/notification"
4
4
  require_relative "client/response_notification"
5
5
  require_relative "client/notifications_collection"
6
+ require_relative "client/received_text"
7
+ require_relative "client/received_text_collection"
6
8
  require_relative "client/response_template"
7
9
  require_relative "client/template_collection"
8
10
  require_relative "client/template_preview"
@@ -69,7 +71,7 @@ module Notifications
69
71
  # temporarily failed, or technical failure
70
72
  # @option options [String] :reference
71
73
  # your reference for the notification
72
- # @option options [String] :olderThanId
74
+ # @option options [String] :older_than
73
75
  # notification id to return notificaitons that are older than this id.
74
76
  # @see Notifications::Client::Speaker#get
75
77
  # @return [NotificationsCollection]
@@ -121,5 +123,16 @@ module Notifications
121
123
  speaker.post_with_url(path, options)
122
124
  )
123
125
  end
126
+
127
+ ##
128
+ # @option options [String] :older_than
129
+ # received text id to return received texts that are older than this id.
130
+ # @return [ReceivedTextCollection]
131
+ def get_received_texts(options = {})
132
+ path = "/v2/received-text-messages"
133
+ ReceivedTextCollection.new(
134
+ speaker.get_with_url(path, options)
135
+ )
136
+ end
124
137
  end
125
138
  end
@@ -1,3 +1,5 @@
1
+ require 'time'
2
+
1
3
  module Notifications
2
4
  class Client
3
5
  class Notification
@@ -40,7 +42,7 @@ module Notifications
40
42
  begin
41
43
  value = instance_variable_get(:"@#{field}")
42
44
  Time.parse value
43
- rescue
45
+ rescue StandardError
44
46
  value
45
47
  end
46
48
  end
@@ -0,0 +1,31 @@
1
+ require 'time'
2
+
3
+ module Notifications
4
+ class Client
5
+ class ReceivedText
6
+ FIELDS = %i(
7
+ id
8
+ created_at
9
+ content
10
+ notify_number
11
+ service_id
12
+ user_number
13
+ ).freeze
14
+
15
+ attr_reader(*FIELDS)
16
+
17
+ def initialize(received_text)
18
+ FIELDS.each do |field|
19
+ instance_variable_set(:"@#{field}", received_text.fetch(field.to_s, nil))
20
+ end
21
+ end
22
+
23
+ def created_at
24
+ value = instance_variable_get(:@created_at)
25
+ Time.parse(value)
26
+ rescue StandardError
27
+ value
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,18 @@
1
+ module Notifications
2
+ class Client
3
+ class ReceivedTextCollection
4
+ attr_reader :links, :collection
5
+
6
+ def initialize(response)
7
+ @links = response["links"]
8
+ @collection = collection_from(response["received_text_messages"])
9
+ end
10
+
11
+ def collection_from(received_texts)
12
+ received_texts.map do |received_text|
13
+ ReceivedText.new(received_text)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,5 @@
1
+ require 'time'
2
+
1
3
  module Notifications
2
4
  class Client
3
5
  class Template
@@ -28,7 +30,7 @@ module Notifications
28
30
  begin
29
31
  value = instance_variable_get(:"@#{field}")
30
32
  Time.parse value
31
- rescue
33
+ rescue StandardError
32
34
  value
33
35
  end
34
36
  end
@@ -9,6 +9,6 @@
9
9
 
10
10
  module Notifications
11
11
  class Client
12
- VERSION = "2.4.0".freeze
12
+ VERSION = "2.5.0".freeze
13
13
  end
14
14
  end
@@ -23,8 +23,9 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency "jwt", "~> 2.1"
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.13"
26
- spec.add_development_dependency "rake", "~> 12.1"
27
- spec.add_development_dependency "rspec", "~> 3.6"
26
+ spec.add_development_dependency "rake", "~> 12.3"
27
+ spec.add_development_dependency "rspec", "~> 3.7"
28
28
  spec.add_development_dependency "webmock", "~> 3.1"
29
29
  spec.add_development_dependency "factory_bot", "~> 4.8"
30
+ spec.add_development_dependency "govuk-lint", "~> 3.3"
30
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifications-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-06 00:00:00.000000000 Z
11
+ date: 2017-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '12.1'
47
+ version: '12.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '12.1'
54
+ version: '12.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.6'
61
+ version: '3.7'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.6'
68
+ version: '3.7'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: webmock
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '4.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: govuk-lint
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.3'
97
111
  description:
98
112
  email:
99
113
  - notify@digital.cabinet-office.gov.uk
@@ -104,6 +118,7 @@ files:
104
118
  - ".github/PULL_REQUEST_TEMPLATE.md"
105
119
  - ".gitignore"
106
120
  - ".rspec"
121
+ - ".rubocop.yml"
107
122
  - CHANGELOG.md
108
123
  - Gemfile
109
124
  - LICENSE
@@ -119,6 +134,8 @@ files:
119
134
  - lib/notifications/client.rb
120
135
  - lib/notifications/client/notification.rb
121
136
  - lib/notifications/client/notifications_collection.rb
137
+ - lib/notifications/client/received_text.rb
138
+ - lib/notifications/client/received_text_collection.rb
122
139
  - lib/notifications/client/request_error.rb
123
140
  - lib/notifications/client/response_notification.rb
124
141
  - lib/notifications/client/response_template.rb
@@ -146,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
163
  version: '0'
147
164
  requirements: []
148
165
  rubyforge_project:
149
- rubygems_version: 2.6.13
166
+ rubygems_version: 2.6.11
150
167
  signing_key:
151
168
  specification_version: 4
152
169
  summary: Ruby client for GOV.UK Notifications API