cpaas-sdk 1.0.0 → 1.1.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 +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -1
- data/README.md +2 -2
- data/docs/Cpaas/{TwoFactor.html → Twofactor.html} +0 -0
- data/examples/2fa/Gemfile +1 -1
- data/examples/sms/Gemfile +1 -1
- data/examples/sms/app.rb +0 -1
- data/examples/sms/config.ru +3 -0
- data/examples/sms/helper.rb +15 -1
- data/lib/cpaas-sdk/resources/twofactor.rb +4 -0
- data/lib/cpaas-sdk/version.rb +1 -1
- data/tutorials/2FA.md +5 -4
- data/tutorials/GetStarted.md +12 -10
- data/tutorials/SMSMessaging.md +6 -7
- data/tutorials/index.html +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bd743f490632a5245f1c0cd2baf7187cf8623f38ded092fe0f020470445e419
|
4
|
+
data.tar.gz: 4b9bfcd28a1bf3c555686f79eea6e6c10fd276a2192f4dbf28cffc3ee9d87fd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 202495f68be89189d7336ce9d1a282aa35832a7699d621935d366e08d4ce720d72afcd002ee59bf0f7c5fba4e8f0e70a655fba247781c4f9b4a06b365f1e9a19
|
7
|
+
data.tar.gz: 9f69c5ce0195a0dc4e88eeb2e41770d897a390bf3328218f28ae676216b4ddfa4601afbbbc223b3111ed5e145961b8ffcea78c8b44afd81e4d85d4baa729b625
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
+ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) recommendations.
|
7
7
|
|
8
|
+
## 1.1.0 - 2019-12-10
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- Added `subject` to list of params for Twofactor's sendCode and resendCode methods to enable sending code via email.
|
8
12
|
|
9
13
|
## 1.0.0
|
10
14
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
Add this line to your application's Gemfile:
|
6
6
|
|
7
7
|
```ruby
|
8
|
-
gem 'cpaas-
|
8
|
+
gem 'cpaas-sdk'
|
9
9
|
```
|
10
10
|
|
11
11
|
And then execute:
|
@@ -14,7 +14,7 @@ And then execute:
|
|
14
14
|
|
15
15
|
Or install it yourself as:
|
16
16
|
|
17
|
-
$ gem install cpaas-
|
17
|
+
$ gem install cpaas-sdk
|
18
18
|
|
19
19
|
## Reference
|
20
20
|
|
File without changes
|
data/examples/2fa/Gemfile
CHANGED
data/examples/sms/Gemfile
CHANGED
data/examples/sms/app.rb
CHANGED
@@ -30,7 +30,6 @@ class App < Sinatra::Application
|
|
30
30
|
#
|
31
31
|
# The method create_message would send an sms when the 'type' attribute is 'SMS'
|
32
32
|
#
|
33
|
-
puts ENV['PHONE_NUMBER']
|
34
33
|
response = Cpaas::Conversation.create_message({
|
35
34
|
type: Cpaas::Conversation.types[:SMS],
|
36
35
|
destination_address: params['number'],
|
data/examples/sms/config.ru
CHANGED
data/examples/sms/helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
FILE_NAME = 'notifications.json'
|
2
|
-
|
2
|
+
DIR_NAME = "tmp"
|
3
|
+
PATH = "#{Dir.pwd}/#{DIR_NAME}/#{FILE_NAME}"
|
3
4
|
|
4
5
|
def error_message(error)
|
5
6
|
"#{error[:name]}: #{error[:message]} (#{error[:exception_id]})"
|
@@ -31,3 +32,16 @@ def write_file(content)
|
|
31
32
|
notification_file.puts(content)
|
32
33
|
notification_file.close
|
33
34
|
end
|
35
|
+
|
36
|
+
def initial_setup
|
37
|
+
if !File.file?(PATH)
|
38
|
+
dirname = File.dirname(Dir.pwd)
|
39
|
+
unless File.directory?(DIR_NAME)
|
40
|
+
FileUtils.mkdir_p(DIR_NAME)
|
41
|
+
end
|
42
|
+
|
43
|
+
notification_file = File.new(PATH, 'w')
|
44
|
+
notification_file.puts("{}")
|
45
|
+
notification_file.close
|
46
|
+
end
|
47
|
+
end
|
@@ -14,6 +14,7 @@ module Cpaas
|
|
14
14
|
# @option params [String|Array[string]] :destination_address Destination address of the authentication code being sent. For sms type authentication codes, it should contain a E164 phone number. For e-mail type authentication codes, it should contain a valid e-mail address.
|
15
15
|
# @option params [String] :message Message text sent to the destination, containing the placeholder for the code within the text. CPaaS requires to have *{code}* string within the text in order to generate a code and inject into the text. For email type code, one usage is to have the *{code}* string located within the link in order to get a unique link.
|
16
16
|
# @option params [String] :method ('sms') +optional+ Type of the authentication code delivery method, sms and email are supported types. Possible values: sms, email
|
17
|
+
# @option params [String] :subject +optional+ When the method is passed as email then subject becomes a mandatory field to pass. The value passed becomes the subject line of the 2FA code email that is sent out to the destination_address.
|
17
18
|
# @option params [Number] :expiry (120) +optional+ Lifetime duration of the code sent in seconds. This can contain values between 30 and 3600 seconds.
|
18
19
|
# @option params [Number] :length (6) +optional+ Length of the authentication code tha CPaaS should generate for this request. It can contain values between 4 and 10.
|
19
20
|
# @option params [String] :type ('numeric') +optional+ Type of the code that is generated. If not provided, default value is numeric. Possible values: numeric, alphanumeric, alphabetic
|
@@ -31,6 +32,7 @@ module Cpaas
|
|
31
32
|
type: params[:type] || 'numeric'
|
32
33
|
},
|
33
34
|
expiry: params[:expiry] || 120,
|
35
|
+
subject: params[:subject],
|
34
36
|
message: params[:message]
|
35
37
|
}
|
36
38
|
}
|
@@ -86,6 +88,7 @@ module Cpaas
|
|
86
88
|
# @option params [String] :message Message text sent to the destination, containing the placeholder for the code within the text. CPaaS requires to have *{code}* string within the text in order to generate a code and inject into the text. For email type code, one usage is to have the *{code}* string located within the link in order to get a unique link.
|
87
89
|
# @option params [String] :code_id ID of the authentication code.
|
88
90
|
# @option params [String] :method ('sms') +optional+ Type of the authentication code delivery method, sms and email are supported types. Possible values: sms, email
|
91
|
+
# @option params [String] :subject +optional+ When the method is passed as email then subject becomes a mandatory field to pass. The value passed becomes the subject line of the 2FA code email that is sent out to the destination_address.
|
89
92
|
# @option params [Number] :expiry (120) +optional+ Lifetime duration of the code sent in seconds. This can contain values between 30 and 3600 seconds.
|
90
93
|
# @option params [Number] :length (6) +optional+ Length of the authentication code tha CPaaS should generate for this request. It can contain values between 4 and 10.
|
91
94
|
# @option params [String] :type ('numeric') +optional+ Type of the code that is generated. If not provided, default value is numeric. Possible values: numeric, alphanumeric, alphabetic
|
@@ -103,6 +106,7 @@ module Cpaas
|
|
103
106
|
type: params[:type] || 'numeric'
|
104
107
|
},
|
105
108
|
expiry: params[:expiry] || 120,
|
109
|
+
subject: params[:subject],
|
106
110
|
message: params[:message]
|
107
111
|
}
|
108
112
|
}
|
data/lib/cpaas-sdk/version.rb
CHANGED
data/tutorials/2FA.md
CHANGED
@@ -39,7 +39,7 @@ The response contains `code_id` which is a unique ID needed for `verify_code`. T
|
|
39
39
|
|
40
40
|
Walking through the method parameters:
|
41
41
|
|
42
|
-
+ `destination_address` is required with a routable destination number in E.164 format, either with tel schema or not. For v1, only one address is supported.
|
42
|
+
+ `destination_address` is required with a routable destination number in E.164 format, either with tel schema or not. For SDK v1, only one address is supported.
|
43
43
|
+ `method` is mandatory and must have `sms` for verification via SMS flow.
|
44
44
|
+ `expiry` indicates the desired period of time in seconds that the code will be valid on $KANDY$. It is optional having default value as 120 seconds, while application can ask for values between 30 and 3600 seconds.
|
45
45
|
+ `message` is required with a `{code}` string within the text so that $KANDY$ can replace that with the real code generated, and send it as the SMS content.
|
@@ -76,7 +76,7 @@ An invalid/failed verification will have the following response:
|
|
76
76
|
## Two-Factor Authentication via E-mail
|
77
77
|
A similar flow with the SMS section above can be implemented for e-mail verification.
|
78
78
|
|
79
|
-
The following email code request example, requires
|
79
|
+
The following email code request example, requires an additional parameter `subject`. When value `email` is used in the `method` parameter then `subject` becomes a mandatory field to pass. The value passed becomes the subject line of the 2FA code email that is sent out to the destinationAddress:
|
80
80
|
|
81
81
|
```ruby
|
82
82
|
Cpaas::Twofactor.send_code({
|
@@ -85,7 +85,8 @@ Cpaas::Twofactor.send_code({
|
|
85
85
|
length: 10,
|
86
86
|
type: 'alphanumeric',
|
87
87
|
expiry: 3600,
|
88
|
-
message: 'Here is your code: {code}'
|
88
|
+
message: 'Here is your code: {code}',
|
89
|
+
subject: 'Verification code'
|
89
90
|
})
|
90
91
|
```
|
91
92
|
The response contains `code_id` which is a unique ID needed for `verify_code`. The response object can look something like this:
|
@@ -95,7 +96,7 @@ The response contains `code_id` which is a unique ID needed for `verify_code`. T
|
|
95
96
|
}
|
96
97
|
```
|
97
98
|
|
98
|
-
As can be seen within the example, `method` parameter has `email` value, while `destination_address` field includes a destination e-mail address. For v1, only plain text is supported.
|
99
|
+
As can be seen within the example, `method` parameter has `email` value, while `destination_address` field includes a destination e-mail address. For SDK v1, only plain text is supported.
|
99
100
|
|
100
101
|
Verification procedure for two-factor authentication via e-mail is same with two-factor authentication via SMS as described in previous section.
|
101
102
|
|
data/tutorials/GetStarted.md
CHANGED
@@ -9,7 +9,7 @@ To begin, you will need to install the ruby library in your application. The lib
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem 'cpaas-
|
12
|
+
gem 'cpaas-sdk'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
@@ -20,7 +20,7 @@ bundle
|
|
20
20
|
|
21
21
|
Or install it yourself as:
|
22
22
|
```bash
|
23
|
-
gem install cpaas-
|
23
|
+
gem install cpaas-sdk
|
24
24
|
```
|
25
25
|
|
26
26
|
In your application, you simply need to create a new initializer `config/initializers/cpaas.rb`.
|
@@ -36,6 +36,15 @@ After you've configured the SDK client, you can begin playing around with it to
|
|
36
36
|
|
37
37
|
## Configuration
|
38
38
|
|
39
|
+
Before starting, you need to learn following information from your CPaaS account, specifically from Developer Portal.
|
40
|
+
|
41
|
+
Log into your Developer Portal account and the configuration information required to be authenticated should be under:
|
42
|
+
|
43
|
+
+ `Projects` -> `{your project}` -> `Project info`/`Project secret`
|
44
|
+
|
45
|
+
> + `Private Project key` should be mapped to `client_id`
|
46
|
+
> + `Private Project secret` should be mapped to `client_secret`
|
47
|
+
|
39
48
|
```ruby
|
40
49
|
Cpaas.configure do |config|
|
41
50
|
config.client_id = '<private project key>'
|
@@ -44,16 +53,9 @@ Cpaas.configure do |config|
|
|
44
53
|
end
|
45
54
|
```
|
46
55
|
|
47
|
-
The information required to be authenticated should be under:
|
48
|
-
|
49
|
-
+ `Projects` -> `{your project}` -> `Project info`/`Project secret`
|
50
|
-
|
51
|
-
> + `Private Project key` should be mapped to `client_id`
|
52
|
-
> + `Private Project secret` should be mapped to `client_secret`
|
53
|
-
|
54
56
|
## Usage
|
55
57
|
|
56
|
-
All modules can be accessed via
|
58
|
+
All modules can be accessed via `Cpaas`, refer to [References](/developer/references/ruby) for details about all modules and it's methods. All method invocations follow the namespaced signature
|
57
59
|
|
58
60
|
`{Client}::{ModuleName}.{method_name}(params)`
|
59
61
|
|
data/tutorials/SMSMessaging.md
CHANGED
@@ -16,16 +16,15 @@ Before moving to how the response body looks, let's walk through the highlights
|
|
16
16
|
|
17
17
|
+ `sender_address` indicates which DID number that user desires to send the SMS from. It is expected to be an E.164 formatted number.
|
18
18
|
+ If `sender_address` field contains `default` keyword, $KANDY$ discovers the default assigned SMS DID number for that user and utilizes it as the sender address.
|
19
|
-
+ `destination_address` can either be an array of phone numbers or a single phone number string within the params containing the destinations that corresponding SMS message will be sent. For v1, only one destination is supported on $KANDY$.
|
19
|
+
+ `destination_address` can either be an array of phone numbers or a single phone number string within the params containing the destinations that corresponding SMS message will be sent. For SDK v1, only one destination is supported on $KANDY$.
|
20
20
|
+ Address value needs to contain a phone number, ideally in E.164 format. Some valid formats are:
|
21
21
|
- +16131234567
|
22
|
-
- 6131234567
|
23
22
|
- tel:+16131234567
|
24
23
|
- sip:+16131234567@domain
|
25
24
|
- sip:6131234567@domain
|
26
25
|
+ `message` field contains the text message in `UTF-8` encoded format.
|
27
26
|
|
28
|
-
> The number provided in `sender_address` field should be
|
27
|
+
> The number provided in `sender_address` field should be purchased by the account and assigned to the project, otherwise $KANDY$ replies back with a Forbidden error.
|
29
28
|
|
30
29
|
Now, let's check the successful response:
|
31
30
|
|
@@ -39,9 +38,9 @@ Now, let's check the successful response:
|
|
39
38
|
sender_address: '+16139998877'
|
40
39
|
}
|
41
40
|
```
|
42
|
-
In case of
|
41
|
+
In case of passing `default` as sender_address in the request, the actual number from which sms is sent can be identified with `sender_address` field in the response
|
43
42
|
|
44
|
-
> + The delivery_status can have the following values `DeliveredToNetwork`, `DeliveryImpossible`
|
43
|
+
> + The delivery_status can have the following values: `DeliveredToNetwork`, `DeliveryImpossible`
|
45
44
|
|
46
45
|
|
47
46
|
## Receive SMS
|
@@ -60,7 +59,7 @@ Cpaas::Conversation.subscribe({
|
|
60
59
|
destination_address: '+16139998877'
|
61
60
|
})
|
62
61
|
```
|
63
|
-
+ `destination_address` is an optional parameter to indicate which SMS DID number has been desired to receive SMS messages. Corresponding number should be one of the assigned/purchased numbers of the
|
62
|
+
+ `destination_address` is an optional parameter to indicate which SMS DID number has been desired to receive SMS messages. Corresponding number should be one of the assigned/purchased numbers of the project, otherwise $KANDY$ replies back with Forbidden error. Also not providing this parameter triggers $KANDY$ to use the default assigned DID number against this user, in which case the response message for the subscription contains the `destination_address` field. It is highly recommended to provide `destination_address` parameter.
|
64
63
|
+ `webhook_url` is a webhook that is present in your application which is accessible from the public web. The sms notifications would be delivered to the webhook and the received notification can be consumed by using the `Cpaas::Notification.parse` helper method. The usage of `Cpaas::Notification.parse` is explained in Step 2.
|
65
64
|
|
66
65
|
A successful subscription would return:
|
@@ -73,7 +72,7 @@ A successful subscription would return:
|
|
73
72
|
```
|
74
73
|
|
75
74
|
> + For every number required to receive incoming SMS, there should be an individual subscription.
|
76
|
-
> + When a number has been unassigned from a
|
75
|
+
> + When a number has been unassigned from a project, all corresponding inbound SMS subscriptions are cancelled and `sms_subscription_cancellation_notification` notification is sent.
|
77
76
|
|
78
77
|
Now, you are ready to receive inbound SMS messages via webhook, for example - 'https://myapp.com/inbound-sms/webhook'.
|
79
78
|
|
data/tutorials/index.html
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
<head>
|
4
4
|
<meta charset="utf-8">
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
6
|
-
<title>
|
6
|
+
<title>Ruby SDK Tutorials</title>
|
7
7
|
<link rel="stylesheet" href="https://unpkg.com/docute@4/dist/docute.css">
|
8
8
|
</head>
|
9
9
|
<body>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cpaas-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keepworks
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -143,7 +143,7 @@ files:
|
|
143
143
|
- docs/Cpaas.html
|
144
144
|
- docs/Cpaas/Conversation.html
|
145
145
|
- docs/Cpaas/Notification.html
|
146
|
-
- docs/Cpaas/
|
146
|
+
- docs/Cpaas/Twofactor.html
|
147
147
|
- docs/_index.html
|
148
148
|
- docs/_index.md
|
149
149
|
- docs/class_list.html
|