telesign 2.3.0 → 2.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 822e4153765235c2df6654fade600bf0e16c99a3e7b0d580f11486f4c588f827
4
- data.tar.gz: 25939bc63b42193b44fc983d377a6daec3fb06627abf7421ee8f18936a485355
3
+ metadata.gz: d45ef76f17a53eea559db29de43136a77ad3b1de673deb28cddccb2e8fd9179a
4
+ data.tar.gz: 022c7286d6171f6f84f18512ccfc5eb62499e8e9dc346297a5f4a8db388e8216
5
5
  SHA512:
6
- metadata.gz: 977cf4ea3bbc288742df0d0c5b4c8b09fc5f6fbe7150e1978062a662eebb1b32727b782c4a0e8a2e9d5e4cb46ac498480d21a25b1f336b18398d3ef0b641e0f1
7
- data.tar.gz: dd556115195b9ac6f14efceaa45956345fee0bbce5262189221eea79ad563b928a9421c2944351645e3426f6708ebc03049e0fa70d84202a5036ebc69eef9eeb
6
+ metadata.gz: d3c6836d6e9029a1a35ffd35cda96792bc0881fccd90d11903ab6e32183a3a83c575b6f9dc8cb28cca553643b777a3a56c8f177836bbf7230550f8958377d96c
7
+ data.tar.gz: b1a3dd4a06c4af9d92d6b07bc080ca06c60c6c5d99ffa197d21e04851b30444013b670cb5a45e87c43130187529cbbff59d80c9f7cc6e9174036f99c4c16186e
@@ -0,0 +1,3 @@
1
+ module Telesign
2
+ SDK_VERSION = '2.4.0'
3
+ end
data/lib/telesign/rest.rb CHANGED
@@ -5,9 +5,9 @@ require 'base64'
5
5
  require 'openssl'
6
6
  require 'securerandom'
7
7
  require 'net/http/persistent'
8
+ require_relative 'constants'
8
9
 
9
10
  module Telesign
10
- SDK_VERSION = '2.3.0'
11
11
 
12
12
  # The TeleSign RestClient is a generic HTTP REST client that can be extended to make requests against any of
13
13
  # TeleSign's REST API endpoints.
@@ -51,7 +51,7 @@ module Telesign
51
51
  proxy: nil,
52
52
  timeout: 10,
53
53
  source: 'ruby_telesign',
54
- sdk_version_origin: SDK_VERSION,
54
+ sdk_version_origin: Telesign::SDK_VERSION,
55
55
  sdk_version_dependency: nil)
56
56
 
57
57
  @customer_id = customer_id
@@ -60,7 +60,7 @@ module Telesign
60
60
 
61
61
  @user_agent = "TeleSignSDK/ruby Ruby/#{RUBY_VERSION} net:http:persistent/#{Net::HTTP::VERSION} OriginatingSDK/#{source} SDKVersion/#{sdk_version_origin}"
62
62
 
63
- if (source != 'ruby_telesign' && sdk_version_dependency.nil?)
63
+ if (source != 'ruby_telesign' && !sdk_version_dependency.nil?)
64
64
  @user_agent += " DependencySDKVersion/#{sdk_version_dependency}"
65
65
  end
66
66
 
@@ -82,7 +82,7 @@ module Telesign
82
82
  # * +customer_id+ - Your account customer_id.
83
83
  # * +api_key+ - Your account api_key.
84
84
  # * +method_name+ - The HTTP method name of the request as a upper case string, should be one of 'POST', 'GET',
85
- # 'PUT' or 'DELETE'.
85
+ # 'PUT', 'PATCH' or 'DELETE'.
86
86
  # * +resource+ - The partial resource URI to perform the request against, as a string.
87
87
  # * +url_encoded_fields+ - HTTP body parameters to perform the HTTP request with, must be a urlencoded string.
88
88
  # * +date_rfc2616+ - The date and time of the request formatted in rfc 2616, as a string.
@@ -96,7 +96,8 @@ module Telesign
96
96
  encoded_fields,
97
97
  date_rfc2616: nil,
98
98
  nonce: nil,
99
- user_agent: nil)
99
+ user_agent: nil,
100
+ auth_method: 'HMAC-SHA256')
100
101
 
101
102
  if date_rfc2616.nil?
102
103
  date_rfc2616 = Time.now.httpdate
@@ -106,32 +107,37 @@ module Telesign
106
107
  nonce = SecureRandom.uuid
107
108
  end
108
109
 
109
- content_type = (%w[POST PUT].include? method_name) ? content_type : ''
110
+ content_type = (%w[POST PUT PATCH].include? method_name) ? content_type : ''
110
111
 
111
- auth_method = 'HMAC-SHA256'
112
+ if auth_method == 'HMAC-SHA256'
112
113
 
113
- string_to_sign = "#{method_name}"
114
+ string_to_sign = "#{method_name}"
114
115
 
115
- string_to_sign << "\n#{content_type}"
116
+ string_to_sign << "\n#{content_type}"
116
117
 
117
- string_to_sign << "\n#{date_rfc2616}"
118
+ string_to_sign << "\n#{date_rfc2616}"
118
119
 
119
- string_to_sign << "\nx-ts-auth-method:#{auth_method}"
120
+ string_to_sign << "\nx-ts-auth-method:#{auth_method}"
120
121
 
121
- string_to_sign << "\nx-ts-nonce:#{nonce}"
122
+ string_to_sign << "\nx-ts-nonce:#{nonce}"
122
123
 
123
- if !content_type.empty? and !encoded_fields.empty?
124
- string_to_sign << "\n#{encoded_fields}"
125
- end
124
+ if !content_type.empty? and !encoded_fields.empty?
125
+ string_to_sign << "\n#{encoded_fields}"
126
+ end
126
127
 
127
- string_to_sign << "\n#{resource}"
128
+ string_to_sign << "\n#{resource}"
128
129
 
129
- digest = OpenSSL::Digest.new('sha256')
130
- key = Base64.decode64(api_key)
130
+ digest = OpenSSL::Digest.new('sha256')
131
+ key = Base64.decode64(api_key)
131
132
 
132
- signature = Base64.encode64(OpenSSL::HMAC.digest(digest, key, string_to_sign)).strip
133
+ signature = Base64.encode64(OpenSSL::HMAC.digest(digest, key, string_to_sign)).strip
133
134
 
134
- authorization = "TSA #{customer_id}:#{signature}"
135
+ authorization = "TSA #{customer_id}:#{signature}"
136
+ else
137
+ credentials = Base64.strict_encode64("#{customer_id}:#{api_key}")
138
+
139
+ authorization = "Basic #{credentials}"
140
+ end
135
141
 
136
142
  headers = {
137
143
  'Authorization'=>authorization,
@@ -144,6 +150,10 @@ module Telesign
144
150
  headers['User-Agent'] = user_agent
145
151
  end
146
152
 
153
+ if !content_type.empty?
154
+ headers['Content-Type'] = content_type
155
+ end
156
+
147
157
  headers
148
158
 
149
159
  end
@@ -188,6 +198,17 @@ module Telesign
188
198
 
189
199
  end
190
200
 
201
+ # Generic Telesign REST API PATCH handler.
202
+ #
203
+ # * +resource+ - The partial resource URI to perform the request against, as a string.
204
+ # * +auth_method+ - Method to auth.
205
+ # * +params+ - Body params to perform the PATCH request with, as a hash.
206
+ def patch(resource, auth_method: 'HMAC-SHA256', **params)
207
+
208
+ execute(Net::HTTP::Patch, 'PATCH', resource, auth_method: auth_method, **params)
209
+
210
+ end
211
+
191
212
  private
192
213
  # Generic TeleSign REST API request handler.
193
214
  #
@@ -195,12 +216,12 @@ module Telesign
195
216
  # * +method_name+ - The HTTP method name, as an upper case string.
196
217
  # * +resource+ - The partial resource URI to perform the request against, as a string.
197
218
  # * +params+ - Body params to perform the HTTP request with, as a hash.
198
- def execute(method_function, method_name, resource, **params)
219
+ def execute(method_function, method_name, resource, auth_method: 'HMAC-SHA256', **params)
199
220
 
200
221
  resource_uri = URI.parse("#{@rest_endpoint}#{resource}")
201
222
 
202
223
  encoded_fields = ''
203
- if %w[POST PUT].include? method_name
224
+ if %w[POST PUT PATCH].include? method_name
204
225
  request = method_function.new(resource_uri.request_uri)
205
226
  if content_type == "application/x-www-form-urlencoded"
206
227
  unless params.empty?
@@ -223,7 +244,8 @@ module Telesign
223
244
  resource,
224
245
  content_type,
225
246
  encoded_fields,
226
- user_agent: @user_agent)
247
+ user_agent: @user_agent,
248
+ auth_method: auth_method)
227
249
 
228
250
  headers.each do |k, v|
229
251
  request[k] = v
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telesign
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
- - TeleSign
8
- autorequire:
7
+ - Telesign
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2017-05-25 00:00:00.000000000 Z
@@ -128,7 +128,7 @@ dependencies:
128
128
  - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
- description: TeleSign Ruby SDK
131
+ description: Telesign Ruby SDK
132
132
  email: support@telesign.com
133
133
  executables: []
134
134
  extensions: []
@@ -136,6 +136,7 @@ extra_rdoc_files: []
136
136
  files:
137
137
  - lib/telesign.rb
138
138
  - lib/telesign/appverify.rb
139
+ - lib/telesign/constants.rb
139
140
  - lib/telesign/messaging.rb
140
141
  - lib/telesign/phoneid.rb
141
142
  - lib/telesign/rest.rb
@@ -146,7 +147,7 @@ homepage: http://rubygems.org/gems/telesign
146
147
  licenses:
147
148
  - MIT
148
149
  metadata: {}
149
- post_install_message:
150
+ post_install_message:
150
151
  rdoc_options: []
151
152
  require_paths:
152
153
  - lib
@@ -161,8 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
162
  - !ruby/object:Gem::Version
162
163
  version: '0'
163
164
  requirements: []
164
- rubygems_version: 3.0.3.1
165
- signing_key:
165
+ rubygems_version: 3.4.10
166
+ signing_key:
166
167
  specification_version: 4
167
- summary: TeleSign Ruby SDK
168
+ summary: Telesign Ruby SDK
168
169
  test_files: []