tenios 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8e7bfe618abcacfe8b4c7c3158a42861608204d504717bbd729459e59cbdf8c
4
- data.tar.gz: '0906b8bde90001a38566f725b5c2d369f7c073869d6506dc75384ffedc725ccb'
3
+ metadata.gz: af1772cc247dc0e26b8b4165401cc3c735557810a5246ad8dfa02c1be98925db
4
+ data.tar.gz: b319c0b8e1f32e312fb3ede0300bf0c26e03e5f0519caa58e3bcbbc6d4cbac33
5
5
  SHA512:
6
- metadata.gz: b46601f7e863032c45689ce83d52058fd76a62f89dbc85d208c40441a4028c579d7b2fa4da594c779c4fd52c1b9819594e1f8960ca8bb194c9d1f43c01ccc521
7
- data.tar.gz: 409b88413a2759e6525ddd7e70f1f0cafa3348919c80cf8dd51405aa5f25b4876a48d97b6f85295bdf4e7b0770b6dbcff6777e8d1442016ec48d70244e3cc093
6
+ metadata.gz: f441d26e9bcdd2628d078ee3d843679b806be57837df3e85a6ef40980fdcf4f5618583a72bf43211a286832cd17c6e7fcc0e6b7751899d4ff43957348412fc3c
7
+ data.tar.gz: ec40c0cd903eb1e803deb41c86b1e2bf7bd07491a5c52d7824e65f4323b753a8a015c39dbc8b83f13385fb97b260308bad143696ad7bc2e3d435936dac62a745
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-02-11 10:20:16 +0000 using RuboCop version 0.63.1.
3
+ # on 2019-02-21 23:25:38 +0000 using RuboCop version 0.63.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -14,12 +14,12 @@ Metrics/AbcSize:
14
14
  Metrics/CyclomaticComplexity:
15
15
  Max: 10
16
16
 
17
- # Offense count: 2
17
+ # Offense count: 3
18
18
  # Configuration parameters: CountComments, ExcludedMethods.
19
19
  Metrics/MethodLength:
20
20
  Max: 13
21
21
 
22
- # Offense count: 1
22
+ # Offense count: 2
23
23
  # Configuration parameters: CountKeywordArgs.
24
24
  Metrics/ParameterLists:
25
25
  Max: 10
@@ -27,3 +27,15 @@ Metrics/ParameterLists:
27
27
  # Offense count: 1
28
28
  Metrics/PerceivedComplexity:
29
29
  Max: 10
30
+
31
+ # Offense count: 6
32
+ # Configuration parameters: Max.
33
+ RSpec/ExampleLength:
34
+ Exclude:
35
+ - 'spec/tenios/blocks_spec.rb'
36
+ - 'spec/tenios_spec.rb'
37
+
38
+ # Offense count: 3
39
+ # Configuration parameters: AggregateFailuresByDefault.
40
+ RSpec/MultipleExpectations:
41
+ Max: 2
data/README.md CHANGED
@@ -1,6 +1,61 @@
1
1
  # Tenios
2
2
 
3
- TODO: Delete this and the text above, and describe your gem
3
+ Wraps [Tenios Call Control](https://www.tenios.de/en/doc/api-spec) blocks in ruby.
4
+ Each accepted block has a corresponding object under `Tenios::Blocks`, currently these are:
5
+ - `Tenios::Blocks::Announcement`
6
+ - `Tenios::Blocks::Bridge`
7
+ - `Tenios::Blocks::CollectDigits`
8
+ - `Tenios::Blocks::CollectSpeech`
9
+ - `Tenios::Blocks::HangUp`
10
+ - `Tenios::Blocks::RoutingPlan`
11
+ - `Tenios::Blocks::Say`
12
+
13
+ Each of these can be used as part of a `Tenios::Blocks` object, by using `Tenios::Blocks#add`.
14
+
15
+ `Tenios::Blocks` implements `#as_json` which returns a JSON-like hash (although with symbolised keys).
16
+
17
+ In rails you can pass the `Tenios::Blocks` object directly to `render` under the `json:` key.
18
+
19
+ ```ruby
20
+ require 'tenios'
21
+
22
+ class TeniosController < ApplicationController
23
+ def redirect_to_number
24
+ announcement = Tenios::Blocks::Announcement.new(announcement: 'redirect', standard: false)
25
+ bridge = Tenios::Blocks::Bridge.new(mode: Tenios::Blocks::Bridge::SEQUENTIAL) do |redirect|
26
+ redirect.with_destination(Tenios::Blocks::Bridge::EXTERNAL_NUMBER, '+440123456789', 10)
27
+ end
28
+
29
+ blocks = Tenios::Blocks.new do |response|
30
+ response.add(announcement)
31
+ response.add(bridge)
32
+ end
33
+
34
+ render json: blocks
35
+ end
36
+ end
37
+ ```
38
+
39
+ Else you can use any JSON serializer that can deal with a ruby `Hash`
40
+
41
+ ```ruby
42
+ require 'json'
43
+ require 'tenios'
44
+
45
+ announcement = Tenios::Blocks::Announcement.new(announcement: 'redirect', standard: false)
46
+ bridge =
47
+ Tenios::Blocks::Bridge
48
+ .new(mode: Tenios::Blocks::Bridge::SEQUENTIAL)
49
+ .with_destination(Tenios::Blocks::Bridge::EXTERNAL_NUMBER, '+440123456789', 10)
50
+
51
+ Tenios::Blocks.new
52
+ .add(announcement)
53
+ .add(bridge)
54
+ .as_json
55
+ .yield_self { |hash| JSON.generate(hash) }
56
+ ```
57
+
58
+ As you may have noticed in the exampled above you can both chain calls to `Tenios::Blocks#add` and `Tenios::Blocks::Bridge#with_destination` or pass a block to those initialisers. :man_shrugging: whatever floats your boat.
4
59
 
5
60
  ## Installation
6
61
 
@@ -18,16 +73,6 @@ Or install it yourself as:
18
73
 
19
74
  $ gem install tenios
20
75
 
21
- ## Usage
22
-
23
- TODO: Write usage instructions here
24
-
25
- ## Development
26
-
27
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
-
29
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
-
31
76
  ## Contributing
32
77
 
33
78
  Bug reports and pull requests are welcome on GitHub at https://github.com/carwow/tenios-ruby.
data/lib/tenios/blocks.rb CHANGED
@@ -14,6 +14,90 @@ module Tenios
14
14
  self
15
15
  end
16
16
 
17
+ def announce(announcement:, standard: false)
18
+ block = Announcement.new(
19
+ announcement: announcement,
20
+ standard: standard
21
+ )
22
+
23
+ add(block)
24
+ end
25
+
26
+ def bridge(mode:, timeout: nil)
27
+ block = Bridge.new(
28
+ mode: mode,
29
+ timeout: timeout
30
+ )
31
+
32
+ yield(block) if block_given?
33
+
34
+ add(block)
35
+ end
36
+
37
+ def collect_digits(
38
+ announcement:,
39
+ standard_announcement:,
40
+ error_announcement:,
41
+ standard_error_announcement:,
42
+ variable:,
43
+ min_digits:,
44
+ max_digits:,
45
+ terminator:,
46
+ max_tries:,
47
+ timeout:
48
+ )
49
+ block = CollectDigits.new(
50
+ announcement: announcement,
51
+ standard_announcement: standard_announcement,
52
+ error_announcement: error_announcement,
53
+ standard_error_announcement: standard_error_announcement,
54
+ variable: variable,
55
+ min_digits: min_digits,
56
+ max_digits: max_digits,
57
+ terminator: terminator,
58
+ max_tries: max_tries,
59
+ timeout: timeout
60
+ )
61
+
62
+ add(block)
63
+ end
64
+
65
+ def collect_speech(
66
+ announcement:,
67
+ missing_input_announcement:,
68
+ language:,
69
+ variable:,
70
+ max_tries:
71
+ )
72
+ block = CollectSpeech.new(
73
+ announcement: announcement,
74
+ missing_input_announcement: missing_input_announcement,
75
+ language: language,
76
+ variable: variable,
77
+ max_tries: max_tries
78
+ )
79
+
80
+ add(block)
81
+ end
82
+
83
+ def hang_up(cause:)
84
+ block = HangUp.new(cause: cause)
85
+
86
+ add(block)
87
+ end
88
+
89
+ def routing_plan(routing_plan:)
90
+ block = RoutingPlan.new(routing_plan: routing_plan)
91
+
92
+ add(block)
93
+ end
94
+
95
+ def say(text:, voice:, ssml:)
96
+ block = Say.new(text: text, voice: voice, ssml: ssml)
97
+
98
+ add(block)
99
+ end
100
+
17
101
  def as_json(*)
18
102
  {
19
103
  blocks: @blocks.map(&:as_json)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tenios
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/tenios.rb CHANGED
@@ -13,5 +13,11 @@
13
13
  ].each { |f| require f }
14
14
 
15
15
  module Tenios
16
- class Error < StandardError; end
16
+ def self.blocks
17
+ blocks = Blocks.new
18
+
19
+ yield(blocks) if block_given?
20
+
21
+ blocks
22
+ end
17
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tenios
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - carwow Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-11 00:00:00.000000000 Z
11
+ date: 2019-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler