twizo 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.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/Gemfile +6 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +126 -0
  6. data/Rakefile +2 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/examples/backup_codes.rb +31 -0
  10. data/examples/backup_codes_check.rb +29 -0
  11. data/examples/backup_codes_delete.rb +31 -0
  12. data/examples/backup_codes_update.rb +31 -0
  13. data/examples/backup_codes_verify.rb +34 -0
  14. data/examples/balance.rb +18 -0
  15. data/examples/examples_init.rb +43 -0
  16. data/examples/number_lookup.rb +32 -0
  17. data/examples/number_lookup_results.rb +28 -0
  18. data/examples/number_lookup_status.rb +29 -0
  19. data/examples/sms.rb +32 -0
  20. data/examples/sms_advanced.rb +33 -0
  21. data/examples/sms_concat.rb +32 -0
  22. data/examples/sms_multiple.rb +35 -0
  23. data/examples/sms_results.rb +28 -0
  24. data/examples/sms_status.rb +29 -0
  25. data/examples/sms_validation_errors.rb +28 -0
  26. data/examples/verification.rb +31 -0
  27. data/examples/verification_status.rb +29 -0
  28. data/examples/verification_verify_token.rb +39 -0
  29. data/examples/widget.rb +31 -0
  30. data/examples/widget_status.rb +34 -0
  31. data/lib/twizo.rb +190 -0
  32. data/lib/twizo/client.rb +45 -0
  33. data/lib/twizo/client/net_http_client.rb +48 -0
  34. data/lib/twizo/entity.rb +114 -0
  35. data/lib/twizo/modules/backup_codes.rb +100 -0
  36. data/lib/twizo/modules/balance.rb +40 -0
  37. data/lib/twizo/modules/number_lookup.rb +81 -0
  38. data/lib/twizo/modules/params/backup_codes_params.rb +19 -0
  39. data/lib/twizo/modules/params/number_lookup_params.rb +23 -0
  40. data/lib/twizo/modules/params/params.rb +37 -0
  41. data/lib/twizo/modules/params/sms_params.rb +34 -0
  42. data/lib/twizo/modules/params/verification_params.rb +30 -0
  43. data/lib/twizo/modules/params/widget_params.rb +29 -0
  44. data/lib/twizo/modules/sms.rb +130 -0
  45. data/lib/twizo/modules/verification.rb +73 -0
  46. data/lib/twizo/modules/widget.rb +59 -0
  47. data/lib/twizo/result.rb +66 -0
  48. data/lib/twizo/status_codes.rb +32 -0
  49. data/lib/twizo/twizo_error.rb +26 -0
  50. data/lib/twizo/version.rb +3 -0
  51. data/test/test_all.rb +19 -0
  52. data/test/test_backup_codes.rb +120 -0
  53. data/test/test_balance.rb +51 -0
  54. data/test/test_init.rb +41 -0
  55. data/test/test_number_lookup.rb +215 -0
  56. data/test/test_sms.rb +270 -0
  57. data/test/test_verification.rb +106 -0
  58. data/test/test_widget.rb +107 -0
  59. data/twizo.gemspec +34 -0
  60. metadata +154 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b0c45a74332fda987fc6aa8aae79d0aae5b0eb2a
4
+ data.tar.gz: 40e1ddc80715533d0389df0a905067e496f854b5
5
+ SHA512:
6
+ metadata.gz: d5cdd29be65081bafc79656905c741b1506f0d71a6c3dfe82387267c11b7151c2f89433074af3c455af32da6a164b979f03b51f4defb52bbb74faab836504e4c
7
+ data.tar.gz: f4a459eb0bbb4ba040a7716083ca4481a0bfbdfe37968f64130e013cb9a9cf185f29b90a0afa84b93d6b22183b81b45a5c7d00ef5244d8adecf6f89674ff407d
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /test/credentials.rb
11
+ /examples/credentials.rb
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in twizo.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Twizo
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.
@@ -0,0 +1,126 @@
1
+ ![Twizo](https://www.twizo.com/wp-content/themes/twizo/_/images/twizo-logo-0474ce6f.png)
2
+
3
+ # Twizo Ruby API
4
+
5
+ Connect to the Twizo API using the Ruby library. This API includes functions to send verifications (2FA), SMS and Number Lookup.
6
+
7
+ ## Requirements ##
8
+ * Ruby >= ???
9
+
10
+ ## Get application secret and api host ##
11
+ To use the Twizo API client, the following things are required:
12
+
13
+ * Create a [Twizo account](https://register.twizo.com/)
14
+ * Login on the Twizo portal
15
+ * Find your [application](https://portal.twizo.com/applications/) secret
16
+ * Find your nearest api [node](https://www.twizo.com/developers/documentation/#introduction_api-url)
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'twizo'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install twizo
33
+
34
+ ## Usage
35
+
36
+ Require the Twizo gem first:
37
+
38
+ ```ruby
39
+ require 'twizo'
40
+ ```
41
+
42
+ Initializing the Twizo Api using your api secret and api host
43
+
44
+ ```ruby
45
+ twizo = Twizo::Twizo.new('api_key', 'api_host')
46
+ ```
47
+
48
+
49
+ Create a verification
50
+
51
+ ```ruby
52
+ verification = twizo.create_verification('610123456789')
53
+ verification = verification.send
54
+ ```
55
+
56
+ Verify token
57
+
58
+ ```ruby
59
+ begin
60
+ verify_token = twizo.verify_token(verification.messageId, '12345')
61
+ puts verify_token
62
+ rescue Twizo::TwizoException => e
63
+ puts e.body
64
+ end
65
+ ```
66
+
67
+
68
+ Create a number lookup, you can specify a single number or multiple numbers
69
+ in an array.
70
+
71
+ ```ruby
72
+ number_lookup = twizo.create_number_lookup('610123456789')
73
+ number_lookup = number_lookup.send
74
+ ```
75
+
76
+ Create an sms, you can specify a single recipient or multiple recipients
77
+ in an array.
78
+
79
+ ```ruby
80
+ sms = twizo.create_sms('body', '610123456789', 'Sender')
81
+ sms = sms.send_simple
82
+ ```
83
+
84
+ When you want to configure the dcs or udh, simply use sms.send. For more information about sending concatenated messages, visit https://www.twizo.com/developers/tutorials/#concat.
85
+
86
+
87
+ Create a widget
88
+
89
+ ```ruby
90
+ widget = twizo.create_widget('610123456789')
91
+ widget = widget.send
92
+ ```
93
+
94
+ Get the status of a widget
95
+
96
+ ```ruby
97
+ status = twizo.get_widget_status(widget.sessionToken, widget.recipient)
98
+ ```
99
+
100
+
101
+ ## Examples
102
+ In the examples directory you can find a collection of cli examples of how to use the api. When first running an example you will be asked for a host name and secret; this will be written to a credentials file.
103
+
104
+ ## Testing
105
+ In the test directory you can find a collection of tests. When first running a test you will be asked for a host name and secret; this will be written to a credentials file.
106
+
107
+ ## Development
108
+
109
+ After checking out the repo, run `bin/setup` to install dependencies. `bin/setup` requires the bundler gem to be installed. You can do this by running `gem install bundler` in the console.
110
+
111
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
112
+
113
+
114
+ ## Contributing
115
+
116
+ Bug reports and pull requests are welcome on GitHub at https://github.com/twizoapi/lib-api-ruby. 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.
117
+
118
+ You can also contact support@silverstreet.com for issues.
119
+
120
+ ## License
121
+
122
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
123
+
124
+ ## Code of Conduct
125
+
126
+ Everyone interacting in the Twizo project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/twizo/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "twizo"
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ require_relative 'examples_init'
2
+
3
+ =begin
4
+
5
+ This file is part of the Twizo php api
6
+
7
+ (c) Twizo <info@twizo.com>
8
+
9
+ For the full copyright and license information, please view the LICENSE
10
+ File that was distributed with this source code.
11
+
12
+ =end
13
+
14
+ twizo = Twizo::Twizo.new(API_KEY, API_HOST)
15
+
16
+ print 'Enter number: '
17
+ number = gets.chomp
18
+
19
+ backup_code = twizo.create_backup_codes(number)
20
+
21
+ begin
22
+
23
+ backup_code = backup_code.send
24
+
25
+ rescue Twizo::TwizoError => e
26
+
27
+ puts "#{e}: #{e.body}"
28
+
29
+ end
30
+
31
+ puts backup_code.inspect
@@ -0,0 +1,29 @@
1
+ require_relative 'examples_init'
2
+
3
+ =begin
4
+
5
+ This file is part of the Twizo php api
6
+
7
+ (c) Twizo <info@twizo.com>
8
+
9
+ For the full copyright and license information, please view the LICENSE
10
+ File that was distributed with this source code.
11
+
12
+ =end
13
+
14
+ twizo = Twizo::Twizo.new(API_KEY, API_HOST)
15
+
16
+ print 'Enter identifier: '
17
+ identifier = gets.chomp
18
+
19
+ begin
20
+
21
+ check = twizo.get_backup_code(identifier)
22
+
23
+ rescue Twizo::TwizoError => e
24
+
25
+ puts "#{e}: #{e.body}"
26
+
27
+ end
28
+
29
+ puts check.inspect
@@ -0,0 +1,31 @@
1
+ require_relative 'examples_init'
2
+
3
+ =begin
4
+
5
+ This file is part of the Twizo php api
6
+
7
+ (c) Twizo <info@twizo.com>
8
+
9
+ For the full copyright and license information, please view the LICENSE
10
+ File that was distributed with this source code.
11
+
12
+ =end
13
+
14
+ twizo = Twizo::Twizo.new(API_KEY, API_HOST)
15
+
16
+ print 'Enter identifier: '
17
+ identifier = gets.chomp
18
+
19
+ backup_code = twizo.create_backup_codes(identifier)
20
+
21
+ begin
22
+
23
+ backup_code = backup_code.delete
24
+
25
+ rescue Twizo::TwizoError => e
26
+
27
+ puts "#{e}: #{e.body}"
28
+
29
+ end
30
+
31
+ puts 'success' if backup_code.code == '204'
@@ -0,0 +1,31 @@
1
+ require_relative 'examples_init'
2
+
3
+ =begin
4
+
5
+ This file is part of the Twizo php api
6
+
7
+ (c) Twizo <info@twizo.com>
8
+
9
+ For the full copyright and license information, please view the LICENSE
10
+ File that was distributed with this source code.
11
+
12
+ =end
13
+
14
+ twizo = Twizo::Twizo.new(API_KEY, API_HOST)
15
+
16
+ print 'Enter identifier: '
17
+ identifier = gets.chomp
18
+
19
+ backup_code = twizo.create_backup_codes(identifier)
20
+
21
+ begin
22
+
23
+ backup_code = backup_code.update
24
+
25
+ rescue Twizo::TwizoError => e
26
+
27
+ puts "#{e}: #{e.body}"
28
+
29
+ end
30
+
31
+ puts backup_code.inspect
@@ -0,0 +1,34 @@
1
+ require_relative 'examples_init'
2
+
3
+ =begin
4
+
5
+ This file is part of the Twizo php api
6
+
7
+ (c) Twizo <info@twizo.com>
8
+
9
+ For the full copyright and license information, please view the LICENSE
10
+ File that was distributed with this source code.
11
+
12
+ =end
13
+
14
+ twizo = Twizo::Twizo.new(API_KEY, API_HOST)
15
+
16
+ print 'Enter identifier: '
17
+ identifier = gets.chomp
18
+
19
+ print 'Enter backup code: '
20
+ code = gets.chomp
21
+
22
+ backup_code = twizo.create_backup_codes(identifier)
23
+
24
+ begin
25
+
26
+ backup_code = backup_code.verify(code)
27
+
28
+ rescue Twizo::TwizoError => e
29
+
30
+ puts "#{e}: #{e.body}"
31
+
32
+ end
33
+
34
+ puts backup_code.inspect
@@ -0,0 +1,18 @@
1
+ require_relative 'examples_init'
2
+
3
+ =begin
4
+
5
+ This file is part of the Twizo php api
6
+
7
+ (c) Twizo <info@twizo.com>
8
+
9
+ For the full copyright and license information, please view the LICENSE
10
+ File that was distributed with this source code.
11
+
12
+ =end
13
+
14
+ twizo = Twizo::Twizo.new(API_KEY, API_HOST)
15
+
16
+ balance = twizo.get_balance
17
+
18
+ puts balance.inspect
@@ -0,0 +1,43 @@
1
+ require 'json'
2
+
3
+ require 'twizo'
4
+
5
+ =begin
6
+
7
+ Run examples from the comman line
8
+ -> ruby foo.rb
9
+
10
+ This file is part of the Twizo php api
11
+
12
+ (c) Twizo <info@twizo.com>
13
+
14
+ For the full copyright and license information, please view the LICENSE
15
+ File that was distributed with this source code.
16
+
17
+ =end
18
+
19
+ class ExamplesInit
20
+
21
+ def load_config
22
+ filename = 'credentials.rb'
23
+
24
+ unless File.exist?("#{File.dirname(__FILE__)}/#{filename}")
25
+ print 'Enter api key: '
26
+ api_key = gets.chomp
27
+
28
+ print 'Enter api host: '
29
+ api_host = gets.chomp
30
+
31
+ file = File.new("#{File.dirname(__FILE__)}/#{filename}", 'w')
32
+ file.puts("API_KEY = '#{api_key}'")
33
+ file.puts("API_HOST = '#{api_host}'")
34
+ file.close
35
+ end
36
+
37
+ require_relative filename
38
+ end
39
+
40
+ end
41
+
42
+ examples = ExamplesInit.new
43
+ examples.load_config
@@ -0,0 +1,32 @@
1
+ require_relative 'examples_init'
2
+
3
+ =begin
4
+
5
+ This file is part of the Twizo php api
6
+
7
+ (c) Twizo <info@twizo.com>
8
+
9
+ For the full copyright and license information, please view the LICENSE
10
+ File that was distributed with this source code.
11
+
12
+ =end
13
+
14
+ twizo = Twizo::Twizo.new(API_KEY, API_HOST)
15
+
16
+ print 'Enter number: '
17
+ number = gets.chomp
18
+
19
+ number_lookup = twizo.create_number_lookup(number)
20
+ number_lookup.params.result_type = Twizo::NumberLookup::RESULT_TYPE_POLL
21
+
22
+ begin
23
+
24
+ number_lookup = number_lookup.send
25
+
26
+ rescue Twizo::TwizoError => e
27
+
28
+ puts "#{e}: #{e.body}"
29
+
30
+ end
31
+
32
+ puts number_lookup.inspect