telnyx 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +4 -0
  3. data/.github/ISSUE_TEMPLATE.md +5 -0
  4. data/.gitignore +9 -0
  5. data/.rubocop.yml +32 -0
  6. data/.rubocop_todo.yml +50 -0
  7. data/.travis.yml +42 -0
  8. data/CHANGELOG.md +2 -0
  9. data/CONTRIBUTORS +0 -0
  10. data/Gemfile +40 -0
  11. data/Guardfile +8 -0
  12. data/LICENSE +22 -0
  13. data/README.md +173 -0
  14. data/Rakefile +28 -0
  15. data/VERSION +1 -0
  16. data/bin/telnyx-console +16 -0
  17. data/lib/telnyx.rb +151 -0
  18. data/lib/telnyx/api_operations/create.rb +12 -0
  19. data/lib/telnyx/api_operations/delete.rb +13 -0
  20. data/lib/telnyx/api_operations/list.rb +29 -0
  21. data/lib/telnyx/api_operations/nested_resource.rb +63 -0
  22. data/lib/telnyx/api_operations/request.rb +57 -0
  23. data/lib/telnyx/api_operations/save.rb +103 -0
  24. data/lib/telnyx/api_resource.rb +69 -0
  25. data/lib/telnyx/available_phone_number.rb +9 -0
  26. data/lib/telnyx/errors.rb +166 -0
  27. data/lib/telnyx/event.rb +9 -0
  28. data/lib/telnyx/list_object.rb +155 -0
  29. data/lib/telnyx/message.rb +9 -0
  30. data/lib/telnyx/messaging_phone_number.rb +10 -0
  31. data/lib/telnyx/messaging_profile.rb +32 -0
  32. data/lib/telnyx/messaging_sender_id.rb +12 -0
  33. data/lib/telnyx/messaging_short_code.rb +10 -0
  34. data/lib/telnyx/number_order.rb +11 -0
  35. data/lib/telnyx/number_reservation.rb +11 -0
  36. data/lib/telnyx/public_key.rb +7 -0
  37. data/lib/telnyx/singleton_api_resource.rb +24 -0
  38. data/lib/telnyx/telnyx_client.rb +545 -0
  39. data/lib/telnyx/telnyx_object.rb +521 -0
  40. data/lib/telnyx/telnyx_response.rb +50 -0
  41. data/lib/telnyx/util.rb +328 -0
  42. data/lib/telnyx/version.rb +5 -0
  43. data/lib/telnyx/webhook.rb +66 -0
  44. data/telnyx.gemspec +25 -0
  45. data/test/api_stub_helpers.rb +1 -0
  46. data/test/openapi/README.md +9 -0
  47. data/test/telnyx/api_operations_test.rb +85 -0
  48. data/test/telnyx/api_resource_test.rb +293 -0
  49. data/test/telnyx/available_phone_number_test.rb +14 -0
  50. data/test/telnyx/errors_test.rb +23 -0
  51. data/test/telnyx/list_object_test.rb +244 -0
  52. data/test/telnyx/message_test.rb +19 -0
  53. data/test/telnyx/messaging_phone_number_test.rb +33 -0
  54. data/test/telnyx/messaging_profile_test.rb +70 -0
  55. data/test/telnyx/messaging_sender_id_test.rb +46 -0
  56. data/test/telnyx/messaging_short_code_test.rb +33 -0
  57. data/test/telnyx/number_order_test.rb +39 -0
  58. data/test/telnyx/number_reservation_test.rb +12 -0
  59. data/test/telnyx/public_key_test.rb +13 -0
  60. data/test/telnyx/telnyx_client_test.rb +631 -0
  61. data/test/telnyx/telnyx_object_test.rb +497 -0
  62. data/test/telnyx/telnyx_response_test.rb +49 -0
  63. data/test/telnyx/util_test.rb +380 -0
  64. data/test/telnyx/webhook_test.rb +108 -0
  65. data/test/telnyx_mock.rb +78 -0
  66. data/test/telnyx_test.rb +40 -0
  67. data/test/test_data.rb +149 -0
  68. data/test/test_helper.rb +73 -0
  69. metadata +162 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 16c98a1dc79356b27c3c8155c14fd316000665e4316aa528d519c3e14ab12396
4
+ data.tar.gz: c174b8954c79aae466162c0ce0f3507ec627ca91571f482d962254e03b367548
5
+ SHA512:
6
+ metadata.gz: b3c9c49a9e5442607f606237cbb03465f311590668457eded220a7516d4a7e1cae0a3d26268d19d656eb7f0b6d94cd48538a2513cb2ce19aeaddd67416e353e7
7
+ data.tar.gz: 1aaa22d941afd491b3a5be114c0cab65b594a79b0d929f224a701618e53c782dd9a1b0357c2b92faf57198223c4ee20b0dd689b29b8ee77c05ab0b335f86fbf6
data/.gitattributes ADDED
@@ -0,0 +1,4 @@
1
+ # may be useful in hiding large schema changes in pull request diffs (but not
2
+ # using it for now)
3
+ spec/*.json binary
4
+ spec/*.yaml binary
@@ -0,0 +1,5 @@
1
+ Please only file issues here that you believe represent actual bugs or feature requests for the Telnyx Ruby library.
2
+
3
+ If you're having general trouble with your Telnyx integration, please reach out to support using the form at https://support.telnyx.com/ (preferred) or via email to support@telnyx.com.
4
+
5
+ If you are reporting a bug, please include your Ruby version and the version of the Telnyx Ruby library you're using, as well as any other details that may be helpful in reproducing the problem.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /telnyx-*.gem
2
+ /Gemfile.lock
3
+ .rvmrc
4
+ Gemfile.lock
5
+ tags
6
+ /.bundle/
7
+ coverage/
8
+ .idea/
9
+ .vscode/
data/.rubocop.yml ADDED
@@ -0,0 +1,32 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ DisplayCopNames: true
5
+ TargetRubyVersion: 2.0
6
+
7
+ Layout/CaseIndentation:
8
+ EnforcedStyle: end
9
+
10
+ Layout/IndentArray:
11
+ EnforcedStyle: consistent
12
+
13
+ Layout/IndentHash:
14
+ EnforcedStyle: consistent
15
+
16
+ Metrics/MethodLength:
17
+ # There's ~2 long methods in `TelnyxClient`. If we want to truncate those a
18
+ # little, we could move this to be closer to ~30 (but the default of 10 is
19
+ # probably too short).
20
+ Max: 50
21
+
22
+ Metrics/ModuleLength:
23
+ Enabled: false
24
+
25
+ Style/FrozenStringLiteralComment:
26
+ EnforcedStyle: always
27
+
28
+ Style/StringLiterals:
29
+ EnforcedStyle: double_quotes
30
+
31
+ Style/TrailingCommaInLiteral:
32
+ EnforcedStyleForMultiline: consistent_comma
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,50 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-07-19 14:22:24 +0200 using RuboCop version 0.50.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 19
10
+ Metrics/AbcSize:
11
+ Max: 52
12
+
13
+ # Offense count: 27
14
+ # Configuration parameters: CountComments, ExcludedMethods.
15
+ Metrics/BlockLength:
16
+ Max: 498
17
+
18
+ # Offense count: 8
19
+ # Configuration parameters: CountComments.
20
+ Metrics/ClassLength:
21
+ Max: 659
22
+
23
+ # Offense count: 11
24
+ Metrics/CyclomaticComplexity:
25
+ Max: 15
26
+
27
+ # Offense count: 278
28
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
29
+ # URISchemes: http, https
30
+ Metrics/LineLength:
31
+ Max: 310
32
+
33
+ # Offense count: 6
34
+ # Configuration parameters: CountKeywordArgs.
35
+ Metrics/ParameterLists:
36
+ Max: 7
37
+
38
+ # Offense count: 5
39
+ Metrics/PerceivedComplexity:
40
+ Max: 17
41
+
42
+ # Offense count: 2
43
+ Style/ClassVars:
44
+ Exclude:
45
+ - 'lib/telnyx/telnyx_object.rb'
46
+ - 'test/telnyx/api_resource_test.rb'
47
+
48
+ # Offense count: 56
49
+ Style/Documentation:
50
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,42 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
9
+ - jruby-9.0.5.0
10
+
11
+ notifications:
12
+ email:
13
+ on_success: never
14
+
15
+ sudo: false
16
+
17
+ env:
18
+ global:
19
+ # If changing this number, please also change it in `test/test_helper.rb`.
20
+ - TELNYX_MOCK_VERSION=0.40.1
21
+
22
+ cache:
23
+ directories:
24
+ - telnyx-mock
25
+
26
+ before_install:
27
+ # Install bundler 1.x, because we need to support Ruby 2.1 for now
28
+ - gem install bundler -v "~> 1.0"
29
+ # Unpack and start telnyx-mock so that the test suite can talk to it
30
+ - |
31
+ if [ ! -d "telnyx-mock/telnyx-mock_${TELNYX_MOCK_VERSION}" ]; then
32
+ mkdir -p telnyx-mock/telnyx-mock_${TELNYX_MOCK_VERSION}/
33
+ curl -L "https://github.com/telnyx/telnyx-mock/releases/download/v${TELNYX_MOCK_VERSION}/telnyx-mock_${TELNYX_MOCK_VERSION}_linux_amd64.tar.gz" -o "telnyx-mock/telnyx-mock_${TELNYX_MOCK_VERSION}_linux_amd64.tar.gz"
34
+ tar -zxf "telnyx-mock/telnyx-mock_${TELNYX_MOCK_VERSION}_linux_amd64.tar.gz" -C "telnyx-mock/telnyx-mock_${TELNYX_MOCK_VERSION}/"
35
+ fi
36
+ - |
37
+ telnyx-mock/telnyx-mock_${TELNYX_MOCK_VERSION}/telnyx-mock > /dev/null &
38
+ TELNYX_MOCK_PID=$!
39
+ - export PATH="${PATH}:${PWD}/telnyx-mock/telnyx-mock_${TELNYX_MOCK_VERSION}"
40
+
41
+ script:
42
+ - bundle exec rake
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ # Changelog
2
+
data/CONTRIBUTORS ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ group :development do
8
+ gem "coveralls", require: false
9
+ gem "mocha", "~> 0.13.2"
10
+ gem "rake"
11
+ gem "shoulda-context"
12
+ gem "test-unit"
13
+ gem "timecop"
14
+ gem "webmock"
15
+
16
+ # Rubocop changes pretty quickly: new cops get added and old cops change
17
+ # names or go into new namespaces. This is a library and we don't have
18
+ # `Gemfile.lock` checked in, so to prevent good builds from suddenly going
19
+ # bad, pin to a specific version number here. Try to keep this relatively
20
+ # up-to-date, but it's not the end of the world if it's not.
21
+ gem "guard"
22
+ gem "guard-rake"
23
+ gem "rubocop", "0.50.0"
24
+ gem "solargraph"
25
+
26
+ # Rack 2.0+ requires Ruby >= 2.2.2 which is problematic for the test suite on
27
+ # older Ruby versions. Check Ruby the version here and put a maximum
28
+ # constraint on Rack if necessary.
29
+ if RUBY_VERSION >= "2.2.2"
30
+ gem "rack", ">= 2.0.6"
31
+ else
32
+ gem "rack", ">= 1.6.11", "< 2.0" # rubocop:disable Bundler/DuplicatedGem
33
+ end
34
+
35
+ platforms :mri do
36
+ gem "byebug"
37
+ gem "pry"
38
+ gem "pry-byebug"
39
+ end
40
+ end
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ directories(%w[lib test]) \
4
+ .select { |d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist") }
5
+
6
+ guard "rake", task: "test" do
7
+ watch(/.*/)
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2019- Telnyx, Inc. (https://www.telnyx.com)
4
+ Copyright (c) 2011-2019 Stripe, Inc. (https://stripe.com)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,173 @@
1
+ # Telnyx Ruby Library
2
+
3
+ [![Build Status](https://travis-ci.org/team-telnyx/telnyx-ruby.svg?branch=master)](https://travis-ci.org/telnyx/telnyx-ruby)
4
+ [![Coverage Status](https://coveralls.io/repos/github/team-telnyx/telnyx-ruby/badge.svg?branch=master)](https://coveralls.io/github/telnyx/telnyx-ruby?branch=master)
5
+
6
+ The Telnyx Ruby library provides convenient access to the Telnyx API from
7
+ applications written in the Ruby language. It includes a pre-defined set of
8
+ classes for API resources that initialize themselves dynamically from API
9
+ responses.
10
+
11
+ The library also provides other features. For example:
12
+
13
+ * Easy configuration path for fast setup and use.
14
+ * Helpers for pagination.
15
+ * Tracking of "fresh" values in API resources so that partial updates can be
16
+ executed.
17
+ * Built-in mechanisms for the serialization of parameters according to the
18
+ expectations of Telnyx's API.
19
+
20
+ ## Documentation
21
+
22
+ See the [API docs](https://developers.telnyx.com/docs/v2/overview).
23
+
24
+ ## Installation
25
+
26
+ You don't need this source code unless you want to modify the gem. If you just
27
+ want to use the package, just run:
28
+
29
+ gem install telnyx
30
+
31
+ If you want to build the gem from source:
32
+
33
+ gem build telnyx.gemspec
34
+
35
+ ### Requirements
36
+
37
+ * Ruby 2.0+.
38
+
39
+ ### Bundler
40
+
41
+ If you are installing via bundler, you should be sure to use the https rubygems
42
+ source in your Gemfile, as any gems fetched over http could potentially be
43
+ compromised in transit and alter the code of gems fetched securely over https:
44
+
45
+ ``` ruby
46
+ source 'https://rubygems.org'
47
+
48
+ gem 'telnyx'
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ The library needs to be configured with your account's secret key which is
54
+ available in your [Telnyx Portal][api-keys]. Set `Telnyx.api_key` to its
55
+ value:
56
+
57
+ ``` ruby
58
+ require "telnyx"
59
+ Telnyx.api_key = "super-secret-key"
60
+
61
+ # list messaging profiles
62
+ Telnyx::MessagingProfile.list()
63
+
64
+ # retrieve single messaging profile
65
+ Telnyx::MessagingProfile.retrieve("123")
66
+ ```
67
+
68
+ ### Configuring a Client
69
+
70
+ While a default HTTP client is used by default, it's also possible to have the
71
+ library use any client supported by [Faraday][faraday] by initializing a
72
+ `Telnyx::TelnyxClient` object and giving it a connection:
73
+
74
+ ``` ruby
75
+ conn = Faraday.new
76
+ client = Telnyx::TelnyxClient.new(conn)
77
+ connection, resp = client.request do
78
+ Telnyx::MessagingProfile.retrieve(
79
+ "123",
80
+ )
81
+ end
82
+ puts resp.request_id
83
+ ```
84
+
85
+ ### Configuring Automatic Retries
86
+
87
+ The library can be configured to automatically retry requests that fail due to
88
+ an intermittent network problem:
89
+
90
+ Telnyx.max_network_retries = 2
91
+
92
+ ### Configuring Timeouts
93
+
94
+ Open and read timeouts are configurable:
95
+
96
+ ```ruby
97
+ Telnyx.open_timeout = 30 # in seconds
98
+ Telnyx.read_timeout = 80
99
+ ```
100
+
101
+ Please take care to set conservative read timeouts. Some API requests can take
102
+ some time, and a short timeout increases the likelihood of a problem within our
103
+ servers.
104
+
105
+ ### Logging
106
+
107
+ The library can be configured to emit logging that will give you better insight
108
+ into what it's doing. The `info` logging level is usually most appropriate for
109
+ production use, but `debug` is also available for more verbosity.
110
+
111
+ There are a few options for enabling it:
112
+
113
+ 1. Set the environment variable `TELNYX_LOG_LEVEL` to the value `debug` or `info`:
114
+ ```
115
+ $ export TELNYX_LOG_LEVEL=info
116
+ ```
117
+
118
+ 2. Set `Telnyx.log_level`:
119
+ ``` ruby
120
+ Telnyx.log_level = Telnyx::LEVEL_INFO
121
+ ```
122
+
123
+ ## Development
124
+
125
+ The test suite depends on [telnyx-mock], so make sure to fetch and run it from a
126
+ background terminal ([telnyx-mock's README][telnyx-mock] also contains
127
+ instructions for installing via Homebrew and other methods):
128
+
129
+ go get -u github.com/telnyx/telnyx-mock
130
+ telnyx-mock
131
+
132
+ Run all tests:
133
+
134
+ bundle exec rake test
135
+
136
+ Run a single test suite:
137
+
138
+ bundle exec ruby -Ilib/ test/telnyx/util_test.rb
139
+
140
+ Run a single test:
141
+
142
+ bundle exec ruby -Ilib/ test/telnyx/util_test.rb -n /should.convert.names.to.symbols/
143
+
144
+ Run the linter:
145
+
146
+ bundle exec rake rubocop
147
+
148
+ Run guard:
149
+
150
+ bundle exec guard
151
+
152
+ Update the bundled [telnyx-mock] by editing the version number found in
153
+ `.travis.yml`.
154
+
155
+ ### Adding a new resource
156
+
157
+ To add a new resource:
158
+
159
+ 1. Add the class for the resource under `lib/telnyx/`.
160
+ 2. Require the new class in `lib/telnyx.rb`.
161
+ 3. Add the association between `OBJECT_NAME` and class name in the `object_classes` hash in `lib/telnyx/util.rb`.
162
+ 4. Add tests to validate the behaviour of the new class.
163
+
164
+ ## Acknowledgements
165
+
166
+ The contributors and maintainers of Telnyx Ruby would like to extend their deep gratitude to the
167
+ authors of [Stripe Ruby](https://github.com/stripe/stripe-ruby), upon which
168
+ this project is based. Thank you for developing such elegant, usable, extensible code
169
+ and for sharing it with the community.
170
+
171
+ [api-keys]: https://portal.telnyx.com/#/app/auth/v2
172
+ [faraday]: https://github.com/lostisland/faraday
173
+ [telnyx-mock]: https://github.com/telnyx/telnyx-mock
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake/testtask"
4
+ require "rubocop/rake_task"
5
+
6
+ task default: %i[test rubocop]
7
+
8
+ Rake::TestTask.new do |t|
9
+ t.pattern = "./test/**/*_test.rb"
10
+ end
11
+
12
+ RuboCop::RakeTask.new
13
+
14
+ #
15
+ # helpers
16
+ #
17
+
18
+ def fetch_file(url, dest)
19
+ ::File.open(dest, "w") do |file|
20
+ resp = Faraday.get(url)
21
+ unless resp.status == 200
22
+ abort("bad response when fetching: #{url}\n" \
23
+ "Status #{resp.status}: #{resp.body}")
24
+ end
25
+ file.write(resp.body)
26
+ puts "Successfully fetched: #{url}"
27
+ end
28
+ end