voicepartner 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.rubocop.yml +195 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +61 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/voicepartner.rb +31 -0
- data/lib/voicepartner/client.rb +64 -0
- data/lib/voicepartner/configurator.rb +21 -0
- data/lib/voicepartner/version.rb +3 -0
- data/voicepartner.gemspec +38 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 99f6ac083e39949985b1e255eeeaebe6a995cf4d
|
4
|
+
data.tar.gz: 429085fff918e9aadd441e0caff8172ce49f2bb8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d4f4c479db09afc2c0a4b44388c688a55ebb4a080eb7b82c15214044f66e38f59f6b7fe4080fe40b0a5206fa41b7596d2ab5b6d24e04312405429694db8963c9
|
7
|
+
data.tar.gz: 3919b6602d0c156f6640b2f5f0bfec962f56590c289cdd53d41a5550c3d8231c7f6d0759aaa23c246afd86d1e4fe85ab6e80f37945aee11eb6a8509051d2c2de
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'vendor/**/*'
|
4
|
+
- 'db/*'
|
5
|
+
- 'db/migrate/*'
|
6
|
+
- 'db/fixtures/**/*'
|
7
|
+
- 'tmp/**/*'
|
8
|
+
- 'builds/**/*'
|
9
|
+
- 'Gemfile'
|
10
|
+
- 'config/environments/*'
|
11
|
+
- 'config/puma.rb'
|
12
|
+
- 'test/application_system_test_case.rb'
|
13
|
+
- 'test/test_helper.rb'
|
14
|
+
- 'config/initializers/*.rb'
|
15
|
+
- 'Guardfile'
|
16
|
+
- 'node_modules/**/*'
|
17
|
+
- 'Capfile'
|
18
|
+
- 'config/deploy.rb'
|
19
|
+
- 'config/deploy/**/*'
|
20
|
+
|
21
|
+
# Commonly used screens these days easily fit more than 80 characters.
|
22
|
+
Metrics/LineLength:
|
23
|
+
Max: 100
|
24
|
+
|
25
|
+
# Too short methods lead to extraction of single-use methods, which can make
|
26
|
+
# the code easier to read (by naming things), but can also clutter the class
|
27
|
+
Metrics/MethodLength:
|
28
|
+
Max: 20
|
29
|
+
|
30
|
+
# The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
|
31
|
+
Metrics/ClassLength:
|
32
|
+
Max: 1500
|
33
|
+
|
34
|
+
# No space makes the method definition shorter and differentiates
|
35
|
+
# from a regular assignment.
|
36
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
37
|
+
EnforcedStyle: no_space
|
38
|
+
|
39
|
+
# We do not need to support Ruby 1.9, so this is good to use.
|
40
|
+
Style/SymbolArray:
|
41
|
+
Enabled: true
|
42
|
+
|
43
|
+
# Most readable form.
|
44
|
+
Layout/AlignHash:
|
45
|
+
EnforcedHashRocketStyle: table
|
46
|
+
EnforcedColonStyle: table
|
47
|
+
|
48
|
+
# Mixing the styles looks just silly.
|
49
|
+
Style/HashSyntax:
|
50
|
+
EnforcedStyle: ruby19_no_mixed_keys
|
51
|
+
|
52
|
+
# has_key? and has_value? are far more readable than key? and value?
|
53
|
+
Style/PreferredHashMethods:
|
54
|
+
Enabled: false
|
55
|
+
|
56
|
+
# String#% is by far the least verbose and only object oriented variant.
|
57
|
+
Style/FormatString:
|
58
|
+
EnforcedStyle: percent
|
59
|
+
|
60
|
+
Style/CollectionMethods:
|
61
|
+
Enabled: true
|
62
|
+
PreferredMethods:
|
63
|
+
# inject seems more common in the community.
|
64
|
+
reduce: inject
|
65
|
+
|
66
|
+
|
67
|
+
# Either allow this style or don't. Marking it as safe with parenthesis
|
68
|
+
# is silly. Let's try to live without them for now.
|
69
|
+
Style/ParenthesesAroundCondition:
|
70
|
+
AllowSafeAssignment: false
|
71
|
+
Lint/AssignmentInCondition:
|
72
|
+
AllowSafeAssignment: false
|
73
|
+
|
74
|
+
# A specialized exception class will take one or more arguments and construct the message from it.
|
75
|
+
# So both variants make sense.
|
76
|
+
Style/RaiseArgs:
|
77
|
+
Enabled: false
|
78
|
+
|
79
|
+
# Indenting the chained dots beneath each other is not supported by this cop,
|
80
|
+
# see https://github.com/bbatsov/rubocop/issues/1633
|
81
|
+
Layout/MultilineOperationIndentation:
|
82
|
+
Enabled: false
|
83
|
+
|
84
|
+
# Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
|
85
|
+
# The argument that fail should be used to abort the program is wrong too,
|
86
|
+
# there's Kernel#abort for that.
|
87
|
+
Style/SignalException:
|
88
|
+
EnforcedStyle: only_raise
|
89
|
+
|
90
|
+
# Suppressing exceptions can be perfectly fine, and be it to avoid to
|
91
|
+
# explicitly type nil into the rescue since that's what you want to return,
|
92
|
+
# or suppressing LoadError for optional dependencies
|
93
|
+
Lint/HandleExceptions:
|
94
|
+
Enabled: false
|
95
|
+
|
96
|
+
# { ... } for multi-line blocks is okay, follow Weirichs rule instead:
|
97
|
+
# https://web.archive.org/web/20140221124509/http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
|
98
|
+
Style/BlockDelimiters:
|
99
|
+
Enabled: false
|
100
|
+
|
101
|
+
# do / end blocks should be used for side effects,
|
102
|
+
# methods that run a block for side effects and have
|
103
|
+
# a useful return value are rare, assign the return
|
104
|
+
# value to a local variable for those cases.
|
105
|
+
Style/MethodCalledOnDoEndBlock:
|
106
|
+
Enabled: true
|
107
|
+
|
108
|
+
# Enforcing the names of variables? To single letter ones? Just no.
|
109
|
+
Style/SingleLineBlockParams:
|
110
|
+
Enabled: false
|
111
|
+
|
112
|
+
# Shadowing outer local variables with block parameters is often useful
|
113
|
+
# to not reinvent a new name for the same thing, it highlights the relation
|
114
|
+
# between the outer variable and the parameter. The cases where it's actually
|
115
|
+
# confusing are rare, and usually bad for other reasons already, for example
|
116
|
+
# because the method is too long.
|
117
|
+
Lint/ShadowingOuterLocalVariable:
|
118
|
+
Enabled: false
|
119
|
+
|
120
|
+
# Check with yard instead.
|
121
|
+
Style/Documentation:
|
122
|
+
Enabled: false
|
123
|
+
|
124
|
+
# This is just silly. Calling the argument `other` in all cases makes no sense.
|
125
|
+
Naming/BinaryOperatorParameterName:
|
126
|
+
Enabled: false
|
127
|
+
|
128
|
+
# There are valid cases, for example debugging Cucumber steps,
|
129
|
+
# also they'll fail CI anyway
|
130
|
+
Lint/Debugger:
|
131
|
+
Enabled: false
|
132
|
+
|
133
|
+
# Style preference
|
134
|
+
Style/MethodDefParentheses:
|
135
|
+
Enabled: false
|
136
|
+
|
137
|
+
# Disable frozen string
|
138
|
+
Style/FrozenStringLiteralComment:
|
139
|
+
Enabled: false
|
140
|
+
|
141
|
+
# Disable No ASCII char in comments
|
142
|
+
Style/AsciiComments:
|
143
|
+
Enabled: false
|
144
|
+
|
145
|
+
# Disable ordered Gems By ascii
|
146
|
+
Bundler/OrderedGems:
|
147
|
+
Enabled: false
|
148
|
+
|
149
|
+
# Change ABC max value
|
150
|
+
Metrics/AbcSize:
|
151
|
+
Max: 20
|
152
|
+
|
153
|
+
# Disable empty method in one line
|
154
|
+
Style/EmptyMethod:
|
155
|
+
EnforcedStyle: expanded
|
156
|
+
|
157
|
+
# Disable max height block
|
158
|
+
Metrics/BlockLength:
|
159
|
+
Enabled: true
|
160
|
+
Exclude:
|
161
|
+
- 'spec/**/*.rb'
|
162
|
+
- 'lib/**/*'
|
163
|
+
- 'config/routes.rb'
|
164
|
+
|
165
|
+
Layout/EmptyLinesAroundClassBody:
|
166
|
+
EnforcedStyle: empty_lines
|
167
|
+
Exclude:
|
168
|
+
- 'app/channels/*/*'
|
169
|
+
- 'config/*'
|
170
|
+
- 'app/controllers/application_controller.rb'
|
171
|
+
- 'app/mailers/application_mailer.rb'
|
172
|
+
- 'app/models/application_record.rb'
|
173
|
+
- 'test/*/*'
|
174
|
+
|
175
|
+
Layout/EmptyLinesAroundModuleBody:
|
176
|
+
EnforcedStyle: no_empty_lines
|
177
|
+
Exclude:
|
178
|
+
- 'app/channels/*/*'
|
179
|
+
- 'config/*'
|
180
|
+
- 'app/helpers/application_helper.rb'
|
181
|
+
|
182
|
+
Style/PercentLiteralDelimiters:
|
183
|
+
PreferredDelimiters:
|
184
|
+
default: '()'
|
185
|
+
'%i': '[]'
|
186
|
+
'%I': '[]'
|
187
|
+
'%r': '{}'
|
188
|
+
'%w': '[]'
|
189
|
+
'%W': '[]'
|
190
|
+
|
191
|
+
Style/UnneededPercentQ:
|
192
|
+
Enabled: false
|
193
|
+
|
194
|
+
Layout/SpaceInLambdaLiteral:
|
195
|
+
EnforcedStyle: require_space
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at brenau_j@modulotech.fr. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
voicepartner (0.1.0)
|
5
|
+
httparty (~> 0.13)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.0)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
httparty (0.16.4)
|
13
|
+
mime-types (~> 3.0)
|
14
|
+
multi_xml (>= 0.5.2)
|
15
|
+
jaro_winkler (1.5.2)
|
16
|
+
mime-types (3.2.2)
|
17
|
+
mime-types-data (~> 3.2015)
|
18
|
+
mime-types-data (3.2019.0331)
|
19
|
+
multi_xml (0.6.0)
|
20
|
+
parallel (1.17.0)
|
21
|
+
parser (2.6.2.1)
|
22
|
+
ast (~> 2.4.0)
|
23
|
+
psych (3.1.0)
|
24
|
+
rainbow (3.0.0)
|
25
|
+
rake (10.5.0)
|
26
|
+
rspec (3.8.0)
|
27
|
+
rspec-core (~> 3.8.0)
|
28
|
+
rspec-expectations (~> 3.8.0)
|
29
|
+
rspec-mocks (~> 3.8.0)
|
30
|
+
rspec-core (3.8.0)
|
31
|
+
rspec-support (~> 3.8.0)
|
32
|
+
rspec-expectations (3.8.2)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.8.0)
|
35
|
+
rspec-mocks (3.8.0)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.8.0)
|
38
|
+
rspec-support (3.8.0)
|
39
|
+
rubocop (0.67.2)
|
40
|
+
jaro_winkler (~> 1.5.1)
|
41
|
+
parallel (~> 1.10)
|
42
|
+
parser (>= 2.5, != 2.5.1.1)
|
43
|
+
psych (>= 3.1.0)
|
44
|
+
rainbow (>= 2.2.2, < 4.0)
|
45
|
+
ruby-progressbar (~> 1.7)
|
46
|
+
unicode-display_width (>= 1.4.0, < 1.6)
|
47
|
+
ruby-progressbar (1.10.0)
|
48
|
+
unicode-display_width (1.5.0)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
bundler (~> 1.16)
|
55
|
+
rake (~> 10.0)
|
56
|
+
rspec (~> 3.0)
|
57
|
+
rubocop (~> 0.50)
|
58
|
+
voicepartner!
|
59
|
+
|
60
|
+
BUNDLED WITH
|
61
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Jean-Baptiste Brenaut
|
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,74 @@
|
|
1
|
+
# Voicepartner
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/voicepartner`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'voicepartner', '~> 0.1'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install voicepartner
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Configure with
|
26
|
+
```ruby
|
27
|
+
Voicepartner.configure do |config|
|
28
|
+
# This is just a suggestion YourCredentialsRepository can be anything
|
29
|
+
# you can just initialize YourCredentialsRepository with ENV, like this
|
30
|
+
# YourCredentialsRepository = ENV
|
31
|
+
config.api_key = YourCredentialsRepository.fetch('VOICE_PARTNER_API_KEY')
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
Use like
|
36
|
+
```ruby
|
37
|
+
res = Voicepartner.send_vocal_message(
|
38
|
+
to: '0623456789',
|
39
|
+
message_text: 'Test from Voicepartner gem'
|
40
|
+
)
|
41
|
+
|
42
|
+
if res.success
|
43
|
+
puts res.raw_response,
|
44
|
+
res.rate_limit,
|
45
|
+
res.rate_limit.limit.parsed,
|
46
|
+
res.rate_limit.limit.raw,
|
47
|
+
res.rate_limit.remaining.parsed,
|
48
|
+
res.rate_limit.remaining.raw,
|
49
|
+
res.rate_limit.resets_at.parsed,
|
50
|
+
res.rate_limit.resets_at.raw
|
51
|
+
else
|
52
|
+
warn res.raw_response.error
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
## Development
|
57
|
+
|
58
|
+
Don't forget to create `.rspec_api_key` and `.rspec_number` to use your api key and a phone number for using the test suite.
|
59
|
+
|
60
|
+
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.
|
61
|
+
|
62
|
+
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).
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/voicepartner. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
67
|
+
|
68
|
+
## License
|
69
|
+
|
70
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
71
|
+
|
72
|
+
## Code of Conduct
|
73
|
+
|
74
|
+
Everyone interacting in the Voicepartner project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/voicepartner/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'voicepartner'
|
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(__FILE__)
|
data/bin/setup
ADDED
data/lib/voicepartner.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'voicepartner/version'
|
2
|
+
require 'voicepartner/configurator'
|
3
|
+
require 'voicepartner/client'
|
4
|
+
|
5
|
+
module Voicepartner
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def configure
|
9
|
+
raise 'You need to provide a block to configure' unless block_given?
|
10
|
+
|
11
|
+
configurator = Configurator.new
|
12
|
+
yield configurator
|
13
|
+
self.configuration = configurator.config
|
14
|
+
self.client = Client.new(self.configuration)
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_accessor :configuration
|
18
|
+
|
19
|
+
attr_accessor :client
|
20
|
+
|
21
|
+
def send_vocal_message(to:, message_text:)
|
22
|
+
if client.nil?
|
23
|
+
raise 'Initialization Error: ' \
|
24
|
+
'You must call Voicepartner.configure before calling send_vocal_message'
|
25
|
+
end
|
26
|
+
|
27
|
+
client.send_vocal_message(to: to, message_text: message_text)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Voicepartner
|
5
|
+
class Client
|
6
|
+
|
7
|
+
def initialize(config)
|
8
|
+
@api_key = config.fetch(:api_key)
|
9
|
+
end
|
10
|
+
|
11
|
+
def send_vocal_message(to:, message_text:)
|
12
|
+
res = send_request(
|
13
|
+
phoneNumbers: to,
|
14
|
+
text: message_text
|
15
|
+
)
|
16
|
+
|
17
|
+
OpenStruct.new(
|
18
|
+
raw_response: res.parsed_response,
|
19
|
+
success: res.parsed_response&.[]('success'),
|
20
|
+
rate_limit: {
|
21
|
+
limit: extract_header(res.headers['x-ratelimit-limit']),
|
22
|
+
remaining: extract_header(res.headers['x-ratelimit-remaining']),
|
23
|
+
resets_at: extract_header(res.headers['x-ratelimit-reset'])
|
24
|
+
}
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def send_request(payload)
|
31
|
+
HTTParty.post(
|
32
|
+
SEND_VOCAL_MESSAGE_URL,
|
33
|
+
body: payload.merge(apiKey: @api_key).to_json,
|
34
|
+
headers: HEADERS
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def extract_header(value, strategy: :to_i)
|
39
|
+
{
|
40
|
+
parsed: handle_strategy(value, strategy),
|
41
|
+
raw: value
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def handle_strategy(value, strategy)
|
46
|
+
case strategy
|
47
|
+
when :to_i
|
48
|
+
value.to_i
|
49
|
+
when :time_at
|
50
|
+
Time.at(value.to_i).utc
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
SEND_VOCAL_MESSAGE_URL = 'http://api.voicepartner.fr/v1/tts/send'.freeze
|
55
|
+
|
56
|
+
HEADERS = {
|
57
|
+
'Content-type' => 'application/json;charset=utf-8'
|
58
|
+
}.freeze
|
59
|
+
|
60
|
+
private_constant :SEND_VOCAL_MESSAGE_URL
|
61
|
+
private_constant :HEADERS
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Voicepartner
|
2
|
+
class Configurator
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@api_key = nil
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_accessor :api_key
|
9
|
+
|
10
|
+
def config
|
11
|
+
raise 'Initialization Error: you must specify the api_key when configuring' if api_key.nil?
|
12
|
+
|
13
|
+
{
|
14
|
+
api_key: api_key
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
private_constant :Configurator
|
21
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'voicepartner/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'voicepartner'
|
7
|
+
spec.version = Voicepartner::VERSION
|
8
|
+
spec.authors = ['Jean-Baptiste Brenaut']
|
9
|
+
spec.email = ['philib_j@modulotech.fr']
|
10
|
+
|
11
|
+
spec.summary = 'VoicePartner API wrapper'
|
12
|
+
spec.description = 'Ruby interface for https://my.voicepartner.fr/app/api/documentation'
|
13
|
+
spec.homepage = 'http://modulotech.fr'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = 'TODO: Set to 'http://mygemserver.com''
|
20
|
+
# else
|
21
|
+
# raise 'RubyGems 2.0 or newer is required to protect against ' \
|
22
|
+
# 'public gem pushes.'
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_dependency 'httparty', '~> 0.13'
|
33
|
+
|
34
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
spec.add_development_dependency 'rubocop', '~> 0.50'
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: voicepartner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jean-Baptiste Brenaut
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.13'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.50'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.50'
|
83
|
+
description: Ruby interface for https://my.voicepartner.fr/app/api/documentation
|
84
|
+
email:
|
85
|
+
- philib_j@modulotech.fr
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- lib/voicepartner.rb
|
103
|
+
- lib/voicepartner/client.rb
|
104
|
+
- lib/voicepartner/configurator.rb
|
105
|
+
- lib/voicepartner/version.rb
|
106
|
+
- voicepartner.gemspec
|
107
|
+
homepage: http://modulotech.fr
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.6.14
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: VoicePartner API wrapper
|
131
|
+
test_files: []
|