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,28 @@
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
+ begin
17
+
18
+ results = twizo.get_number_lookup_results
19
+
20
+ rescue Twizo::TwizoError => e
21
+
22
+ puts "#{e}: #{e.body}"
23
+
24
+ end
25
+
26
+ puts 'no number lookup results found' unless results.result.length
27
+
28
+ puts results.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 messageId: '
17
+ message_id = gets.chomp
18
+
19
+ begin
20
+
21
+ status = twizo.get_number_lookup_status(message_id)
22
+
23
+ rescue Twizo::TwizoError => e
24
+
25
+ puts "#{e}: #{e.body}"
26
+
27
+ end
28
+
29
+ puts status.inspect
@@ -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
+ sms = twizo.create_sms('test_message', number, 'TestSender')
20
+ sms.params.result_type = Twizo::NumberLookup::RESULT_TYPE_POLL
21
+
22
+ begin
23
+
24
+ sms = sms.send_simple
25
+
26
+ rescue Twizo::TwizoError => e
27
+
28
+ puts "#{e}: #{e.body}"
29
+
30
+ end
31
+
32
+ puts sms.inspect
@@ -0,0 +1,33 @@
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
+ sms = twizo.create_sms('Body', number, 'TestSender')
20
+ sms.params.result_type = Twizo::NumberLookup::RESULT_TYPE_POLL
21
+ sms.params.dcs = 4
22
+
23
+ begin
24
+
25
+ sms = sms.send
26
+
27
+ rescue Twizo::TwizoError => e
28
+
29
+ puts "#{e}: #{e.body}"
30
+
31
+ end
32
+
33
+ puts sms.inspect
@@ -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
+ sms = twizo.create_sms('x' * 200, number, 'TestSender')
20
+ sms.params.result_type = Twizo::NumberLookup::RESULT_TYPE_POLL
21
+
22
+ begin
23
+
24
+ sms = sms.send_simple
25
+
26
+ rescue Twizo::TwizoError => e
27
+
28
+ puts "#{e}: #{e.body}"
29
+
30
+ end
31
+
32
+ puts sms.inspect
@@ -0,0 +1,35 @@
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 1: '
17
+ number1 = gets.chomp
18
+
19
+ print 'Enter number 2: '
20
+ number2 = gets.chomp
21
+
22
+ sms = twizo.create_sms('test_message', [number1, number2], 'TestSender')
23
+ sms.params.result_type = Twizo::NumberLookup::RESULT_TYPE_POLL
24
+
25
+ begin
26
+
27
+ sms = sms.send_simple
28
+
29
+ rescue Twizo::TwizoError => e
30
+
31
+ puts "#{e}: #{e.body}"
32
+
33
+ end
34
+
35
+ puts sms.inspect
@@ -0,0 +1,28 @@
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
+ begin
17
+
18
+ results = twizo.get_sms_results
19
+
20
+ rescue Twizo::TwizoError => e
21
+
22
+ puts "#{e}: #{e.body}"
23
+
24
+ end
25
+
26
+ puts 'no sms results found' if results.result.nil?
27
+
28
+ puts results.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 messageId: '
17
+ message_id = gets.chomp
18
+
19
+ begin
20
+
21
+ status = twizo.get_sms_status(message_id)
22
+
23
+ rescue Twizo::TwizoError => e
24
+
25
+ puts "#{e}: #{e.body}"
26
+
27
+ end
28
+
29
+ puts status.inspect
@@ -0,0 +1,28 @@
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
+ begin
17
+
18
+ sms = twizo.create_sms('test_message', 'number', '!?')
19
+ sms.params.result_type = Twizo::NumberLookup::RESULT_TYPE_POLL
20
+ sms = sms.send_simple
21
+
22
+ rescue Twizo::TwizoError => e
23
+
24
+ puts "#{e}: #{e.body}"
25
+
26
+ end
27
+
28
+ puts sms.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 number: '
17
+ number = gets.chomp
18
+
19
+ verification = twizo.create_verification(number)
20
+
21
+ begin
22
+
23
+ verification = verification.send
24
+
25
+ rescue Twizo::TwizoError => e
26
+
27
+ puts "#{e}: #{e.body}"
28
+
29
+ end
30
+
31
+ puts verification.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 messageId: '
17
+ message_id = gets.chomp
18
+
19
+ begin
20
+
21
+ status = twizo.get_verification_status(message_id)
22
+
23
+ rescue Twizo::TwizoError => e
24
+
25
+ puts "#{e}: #{e.body}"
26
+
27
+ end
28
+
29
+ puts status.inspect
@@ -0,0 +1,39 @@
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 (enter: 12300000 for testing): '
17
+ number = gets.chomp
18
+
19
+ begin
20
+
21
+ verification = twizo.create_verification(number)
22
+
23
+ puts 'messageId = ' + verification.send.messageId
24
+
25
+ print 'Enter message id: '
26
+ message_id = gets.chomp
27
+
28
+ print 'Enter token (enter: 012345 for testing): '
29
+ token = gets.chomp
30
+
31
+ verify_token = twizo.verify_token(message_id, token)
32
+
33
+ rescue Twizo::TwizoError => e
34
+
35
+ puts "#{e}: #{e.body}"
36
+
37
+ end
38
+
39
+ puts verify_token.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 number: '
17
+ number = gets.chomp
18
+
19
+ widget = twizo.create_widget(number)
20
+
21
+ begin
22
+
23
+ widget = widget.send
24
+
25
+ rescue Twizo::TwizoError => e
26
+
27
+ puts "#{e}: #{e.body}"
28
+
29
+ end
30
+
31
+ puts widget.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 number: '
17
+ number = gets.chomp
18
+
19
+ widget = twizo.create_widget(number)
20
+
21
+ begin
22
+
23
+ print 'Enter session token: '
24
+ sessionToken = gets.chomp
25
+
26
+ status = twizo.get_widget_status(sessionToken, number)
27
+
28
+ rescue Twizo::TwizoError => e
29
+
30
+ puts "#{e}: #{e.body}"
31
+
32
+ end
33
+
34
+ puts status.inspect