ncco 0.1.0 → 0.1.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
  SHA256:
3
- metadata.gz: a216f5030e69381a0ca46d99de4a863b516db4fd66f22064355e67cdb046d54c
4
- data.tar.gz: e1b6caab15abf000193c4f8710b9b50522ce00cd15dd7e576c41547f8e5e77e2
3
+ metadata.gz: 83ee03788109717640e74920bb21cc2fbc07dd2d27ec8850bde4ad0002ae94a7
4
+ data.tar.gz: 625ca24611c7640f53e7bdfbae9758a7a13f74df4f61248977d8f44363baa49b
5
5
  SHA512:
6
- metadata.gz: 674f045c36ab386af75256ac35ada221181eb5e342cff6e136fa307c5d5e2d21e9f829d8bac21da767d24e1e43aeb2ea9a4ee63d9ed6282e0c140cf0d3e06aff
7
- data.tar.gz: f6cc04a4edbf5de4a22fdee12a5950416cb450d9dfeb82b25a6dcbfc1a0d32d58b83788b453efed44cd6d0612b574f86bff214046fcc43c91354dccf3d8f2c53
6
+ metadata.gz: e31008d689272f5ef55f293670fc160f7dd466288ea57bca7b38bc92cb39c0b69cb9259b2104154de5ba722ed938485566d0e9ee73d9d303b6ade9772ffe3969
7
+ data.tar.gz: 17b0a41431b94d9840972d06ec6792f0325f66645162946e86a02eb1831ed899f0226ac9fb6715ec5914dac5348155b3630f2c3756ac0b247723cd439e53f651
data/.circleci/config.yml CHANGED
@@ -7,6 +7,7 @@ jobs:
7
7
  - image: circleci/ruby:2.5.1
8
8
  steps:
9
9
  - checkout
10
+ - run: gem install bundler --pre
10
11
  - type: cache-restore
11
12
  name: Restore Bundler cache
12
13
  key: ncco-{{ checksum "Gemfile.lock" }}
data/Gemfile.lock CHANGED
@@ -1,17 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ncco (0.1.0)
4
+ ncco (0.1.1)
5
5
  dry-validation (~> 0.12.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (5.2.1)
11
- concurrent-ruby (~> 1.0, >= 1.0.2)
12
- i18n (>= 0.7, < 2)
13
- minitest (~> 5.1)
14
- tzinfo (~> 1.1)
15
10
  ast (2.4.0)
16
11
  coderay (1.1.2)
17
12
  concurrent-ruby (1.1.3)
@@ -29,7 +24,7 @@ GEM
29
24
  dry-container (~> 0.2, >= 0.2.6)
30
25
  dry-core (~> 0.2)
31
26
  dry-equalizer (~> 0.2)
32
- dry-types (0.13.2)
27
+ dry-types (0.13.3)
33
28
  concurrent-ruby (~> 1.0)
34
29
  dry-container (~> 0.3)
35
30
  dry-core (~> 0.4, >= 0.4.4)
@@ -46,11 +41,8 @@ GEM
46
41
  gc_ruboconfig (2.3.13)
47
42
  rubocop (>= 0.57, < 0.61)
48
43
  rubocop-rspec (~> 1.25)
49
- i18n (1.1.1)
50
- concurrent-ruby (~> 1.0)
51
44
  jaro_winkler (1.5.1)
52
45
  method_source (0.9.2)
53
- minitest (5.11.3)
54
46
  parallel (1.12.1)
55
47
  parser (2.5.3.0)
56
48
  ast (~> 2.4.0)
@@ -84,16 +76,12 @@ GEM
84
76
  rubocop-rspec (1.30.1)
85
77
  rubocop (>= 0.60.0)
86
78
  ruby-progressbar (1.10.0)
87
- thread_safe (0.3.6)
88
- tzinfo (1.2.5)
89
- thread_safe (~> 0.1)
90
79
  unicode-display_width (1.4.0)
91
80
 
92
81
  PLATFORMS
93
82
  ruby
94
83
 
95
84
  DEPENDENCIES
96
- activesupport (~> 5.2.1)
97
85
  bundler (~> 1.17.a)
98
86
  gc_ruboconfig (~> 2.3.13)
99
87
  ncco!
@@ -3,8 +3,8 @@ en:
3
3
  strict_keys?: has attributes which aren't part of the NCCO specification
4
4
  http_or_https_url?: must be a valid HTTP or HTTPS URL
5
5
  supported_http_method?: must be a supported HTTP method
6
- single_digit?: must be a single digit from a phone keypad, as a string
7
- digits?: must be a series of one or more digits from a phone keypad, as a string
6
+ phone_keypad_digit?: must be a single digit from a phone keypad, as a string
7
+ phone_keypad_digits?: must be a series of one or more digits from a phone keypad, as a string
8
8
  e164?: must be a valid E.164-formatted phone number
9
9
  websocket_url?: must be a valid Websocket URL
10
10
  hash_with_string_keys_and_values?: must be a hash with String keys and values
@@ -4,6 +4,7 @@ module NCCO
4
4
  module Predicates
5
5
  include ::Dry::Logic::Predicates
6
6
 
7
+ # TODO: Does Nexmo accept URLs relative to the current location?
7
8
  predicate(:http_or_https_url?) do |value|
8
9
  uri = URI.parse(value)
9
10
  %w[http https].include?(uri.scheme)
@@ -25,16 +26,17 @@ module NCCO
25
26
  end
26
27
 
27
28
  NUMBERS = (0..9).map(&:to_s).freeze
28
- DIGITS = [*NUMBERS, "*", "#"].freeze
29
+ PHONE_KEYPAD_DIGITS = [*NUMBERS, "*", "#"].freeze
29
30
 
30
- predicate(:single_digit?) do |value|
31
- DIGITS.include?(value)
31
+ predicate(:phone_keypad_digit?) do |value|
32
+ PHONE_KEYPAD_DIGITS.include?(value)
32
33
  end
33
34
 
34
- predicate(:digits?) do |value|
35
+ predicate(:phone_keypad_digits?) do |value|
35
36
  value.is_a?(String) &&
36
37
  !value.empty? &&
37
- (value.chars - DIGITS).none?
38
+ # There shouldn't be any characters in the input that aren't keypad digits
39
+ (value.chars - PHONE_KEYPAD_DIGITS).none?
38
40
  end
39
41
 
40
42
  predicate(:e164?) do |value|
@@ -6,8 +6,14 @@ module NCCO
6
6
  input :hash?, :strict_keys?
7
7
 
8
8
  configure do
9
+ # `dry-validations` includes a bunch of "predicates" which you can use to
10
+ # validate values. This includes some custom Nexmo-specific ones (e.g. for
11
+ # phone digits and URLs).
9
12
  predicates(Predicates)
10
13
 
14
+ # Used to validate that the input only includes keys that are defined in
15
+ # the schema, implementing a slightly hacky "whitelisting" behaviour (which
16
+ # for some reason isn't include in `dry-validations`!)
11
17
  def strict_keys?(input)
12
18
  (input.keys - rules.keys).empty?
13
19
  end
@@ -9,9 +9,9 @@ module NCCO
9
9
  # Phone endpoint attributes
10
10
  optional(:number).value(:e164?)
11
11
  optional(:onAnswer).value(:http_or_https_url?)
12
- optional(:dtmfAnswer).value(:digits?)
12
+ optional(:dtmfAnswer).value(:phone_keypad_digits?)
13
13
 
14
- # Websocket endpoint attributes
14
+ # WebSocket endpoint attributes
15
15
  optional(:uri).value(:websocket_url?) # Also used for SIP endpoints
16
16
  optional("content-type").value(eql?: "audio/l16;rate=16000")
17
17
  optional(:headers).value(:hash_with_string_keys_and_values?)
@@ -11,7 +11,7 @@ module NCCO
11
11
  optional(:split).value(included_in?: [nil, "conversation"])
12
12
  optional(:channels).value(type?: Integer, gteq?: 1, lteq?: 32)
13
13
  optional(:endOnSilence).value(type?: Integer, gteq?: 3, lteq?: 10)
14
- optional(:endOnKey).value(:single_digit?)
14
+ optional(:endOnKey).value(:phone_keypad_digit?)
15
15
  optional(:beepStart).value(:bool?)
16
16
  optional(:timeout).value(type?: Integer, gteq?: 3, lteq?: 7200)
17
17
  optional(:eventUrl).value(:http_or_https_url?)
data/lib/ncco/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NCCO
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/ncco.rb CHANGED
@@ -14,6 +14,8 @@ require "ncco/schemas/talk"
14
14
  module NCCO
15
15
  class InvalidActionError < StandardError; end
16
16
 
17
+ # Maps the "action" attribute within an action to the schema which should be used
18
+ # to validate it
17
19
  SCHEMAS_BY_TYPE = {
18
20
  "connect" => Schemas::Connect,
19
21
  "conversation" => Schemas::Conversation,
@@ -62,7 +64,8 @@ module NCCO
62
64
  index: index)
63
65
  end
64
66
 
65
- error_messages = transform_error_messages(schema.call(action).messages(full: true))
67
+ result = schema.call(action)
68
+ error_messages = get_error_messages(result)
66
69
 
67
70
  raise_invalid_error(error_messages.join(", "), index: index) if error_messages.any?
68
71
  end
@@ -105,14 +108,16 @@ module NCCO
105
108
  end
106
109
  end
107
110
 
108
- # Transforms error messages returned by dry-validations into a consistent format. For
111
+ # Gets the error messages from `Dry::Validation::Result`s in a consistent format. For
109
112
  # field-level errors, we get back a `Hash` mapping the attribute name to an array of
110
113
  # `String` error messages, whereas for unrecognised attributes (which is a bit of a
111
114
  # hack), we just get back an array. This handles either gracefully.
112
115
  #
113
- # @param error_messages [Array<String>, Hash] messages returned by dry-validations
116
+ # @param result [Dry::Valiation::Result] the result from validating an action against
117
+ # a schema
114
118
  # @return [Array<String>] a list of error messages which is guaranteed to be an array
115
- def transform_error_messages(error_messages)
119
+ def get_error_messages(result)
120
+ error_messages = result.messages(full: true)
116
121
  return error_messages if error_messages.is_a?(Array)
117
122
 
118
123
  error_messages.values.flatten
data/ncco.gemspec CHANGED
@@ -30,7 +30,6 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  spec.add_dependency "dry-validation", "~> 0.12.2"
32
32
 
33
- spec.add_development_dependency "activesupport", "~> 5.2.1"
34
33
  spec.add_development_dependency "bundler", "~> 1.17.a"
35
34
  spec.add_development_dependency "gc_ruboconfig", "~> 2.3.13"
36
35
  spec.add_development_dependency "pry", "~> 0.12.2"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Rogers
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.12.2
27
- - !ruby/object:Gem::Dependency
28
- name: activesupport
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 5.2.1
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 5.2.1
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement