sinch-ruby 0.1.3 → 0.2.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/lib/sinch.rb +4 -0
- data/lib/sinch/builder/request/send_sms.rb +17 -0
- data/lib/sinch/gateway.rb +2 -2
- data/lib/sinch/request/base.rb +4 -14
- data/lib/sinch/request/concerns/authorization.rb +72 -0
- data/lib/sinch/request/send_sms.rb +30 -0
- data/lib/sinch/response/send_sms.rb +9 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd586939fd1e9d27cdd0f69b3c81ed0ab6074d9c
|
4
|
+
data.tar.gz: 35d5fe7b459d3e65b9e1746565316bee513f0fc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a927829c5dc29f6801e0a5f523e509a8280218189a4f2e3d0948a978d1ddbb43e9ed61e76ce9ea1e057d82f12c86532b094168dcdd7cfdcfda3c9b8530c38a1
|
7
|
+
data.tar.gz: b4b4f6d38de777f58d0014ecfb1ef0f2fa5e4920aea298406d7f0f2b3fca5775dd78c48b0183b906fdcd3e59784571b8dfeff5b089d15bd96bfee1d29a6feee3
|
data/lib/sinch.rb
CHANGED
@@ -8,14 +8,18 @@ end
|
|
8
8
|
require 'sinch/builder/request/base'
|
9
9
|
require 'sinch/builder/request/verification'
|
10
10
|
require 'sinch/builder/request/report_verification'
|
11
|
+
require 'sinch/builder/request/send_sms'
|
11
12
|
|
13
|
+
require 'sinch/request/concerns/authorization'
|
12
14
|
require 'sinch/request/base'
|
13
15
|
require 'sinch/request/verification'
|
14
16
|
require 'sinch/request/report_verification'
|
17
|
+
require 'sinch/request/send_sms'
|
15
18
|
|
16
19
|
require 'sinch/response/base'
|
17
20
|
require 'sinch/response/verification'
|
18
21
|
require 'sinch/response/report_verification'
|
22
|
+
require 'sinch/response/send_sms'
|
19
23
|
|
20
24
|
require 'sinch/gateway'
|
21
25
|
require 'sinch/bogus_gateway'
|
data/lib/sinch/gateway.rb
CHANGED
@@ -6,8 +6,8 @@ module Sinch
|
|
6
6
|
class << self
|
7
7
|
def request(endpoint, params)
|
8
8
|
request =
|
9
|
-
"Sinch::Request::#{endpoint.to_s.
|
10
|
-
response = "Sinch::Response::#{endpoint.to_s.
|
9
|
+
"Sinch::Request::#{endpoint.to_s.camelize}".constantize.new params
|
10
|
+
response = "Sinch::Response::#{endpoint.to_s.camelize}".constantize.new
|
11
11
|
new(request, response, params).do_request
|
12
12
|
end
|
13
13
|
end
|
data/lib/sinch/request/base.rb
CHANGED
@@ -2,6 +2,8 @@ module Sinch
|
|
2
2
|
module Request
|
3
3
|
# Base Sinch Api Request
|
4
4
|
class Base
|
5
|
+
include Authorization
|
6
|
+
|
5
7
|
attr_reader :params
|
6
8
|
|
7
9
|
def initialize(params)
|
@@ -41,20 +43,8 @@ module Sinch
|
|
41
43
|
'https://verificationapi-v1.sinch.com'
|
42
44
|
end
|
43
45
|
|
44
|
-
def
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
def content_type
|
49
|
-
'application/json'
|
50
|
-
end
|
51
|
-
|
52
|
-
def timestamp
|
53
|
-
Time.now.utc.iso8601
|
54
|
-
end
|
55
|
-
|
56
|
-
def application_key
|
57
|
-
Sinch.config.application_key
|
46
|
+
def public_resource?
|
47
|
+
true
|
58
48
|
end
|
59
49
|
end
|
60
50
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Sinch
|
2
|
+
module Request
|
3
|
+
module Authorization
|
4
|
+
private
|
5
|
+
|
6
|
+
def authorization
|
7
|
+
@auth ||= begin
|
8
|
+
return public_resource_auth if public_resource?
|
9
|
+
protected_resource_auth
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def public_resource_auth
|
14
|
+
"Application #{application_key}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def protected_resource_auth
|
18
|
+
return unless application_secret.present?
|
19
|
+
'Application ' + [
|
20
|
+
application_key,
|
21
|
+
signature
|
22
|
+
].join(':')
|
23
|
+
end
|
24
|
+
|
25
|
+
def signature
|
26
|
+
Base64.encode64(
|
27
|
+
OpenSSL::HMAC.digest(
|
28
|
+
OpenSSL::Digest.new('sha256'),
|
29
|
+
Base64.decode64(application_secret),
|
30
|
+
string_to_sign
|
31
|
+
)
|
32
|
+
).strip
|
33
|
+
end
|
34
|
+
|
35
|
+
def string_to_sign
|
36
|
+
[
|
37
|
+
method.to_s.upcase,
|
38
|
+
content_md5,
|
39
|
+
content_type,
|
40
|
+
canonical_headers,
|
41
|
+
endpoint
|
42
|
+
].join("\n").encode('UTF-8')
|
43
|
+
end
|
44
|
+
|
45
|
+
def content_md5
|
46
|
+
Base64.encode64(
|
47
|
+
Digest::MD5.digest(payload.to_json.encode('UTF-8'))
|
48
|
+
).strip
|
49
|
+
end
|
50
|
+
|
51
|
+
def canonical_headers
|
52
|
+
"x-timestamp:#{timestamp}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def content_type
|
56
|
+
'application/json'
|
57
|
+
end
|
58
|
+
|
59
|
+
def timestamp
|
60
|
+
Time.now.utc.iso8601
|
61
|
+
end
|
62
|
+
|
63
|
+
def application_key
|
64
|
+
Sinch.config.application_key
|
65
|
+
end
|
66
|
+
|
67
|
+
def application_secret
|
68
|
+
Sinch.config.secret_key
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative './base'
|
2
|
+
|
3
|
+
module Sinch
|
4
|
+
module Request
|
5
|
+
# SMS Send Request [POST] /Sms/
|
6
|
+
class SendSms < Base
|
7
|
+
def method
|
8
|
+
:post
|
9
|
+
end
|
10
|
+
|
11
|
+
def payload
|
12
|
+
@payload ||= Builder::Request::SendSms.new(params).build
|
13
|
+
end
|
14
|
+
|
15
|
+
def endpoint
|
16
|
+
"/v1/Sms/#{params[:phone_number]}"
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def public_resource?
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
25
|
+
def base_url
|
26
|
+
'https://messagingapi.sinch.com'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinch-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Freiman
|
@@ -118,13 +118,17 @@ files:
|
|
118
118
|
- lib/sinch/bogus_gateway.rb
|
119
119
|
- lib/sinch/builder/request/base.rb
|
120
120
|
- lib/sinch/builder/request/report_verification.rb
|
121
|
+
- lib/sinch/builder/request/send_sms.rb
|
121
122
|
- lib/sinch/builder/request/verification.rb
|
122
123
|
- lib/sinch/gateway.rb
|
123
124
|
- lib/sinch/request/base.rb
|
125
|
+
- lib/sinch/request/concerns/authorization.rb
|
124
126
|
- lib/sinch/request/report_verification.rb
|
127
|
+
- lib/sinch/request/send_sms.rb
|
125
128
|
- lib/sinch/request/verification.rb
|
126
129
|
- lib/sinch/response/base.rb
|
127
130
|
- lib/sinch/response/report_verification.rb
|
131
|
+
- lib/sinch/response/send_sms.rb
|
128
132
|
- lib/sinch/response/verification.rb
|
129
133
|
homepage: https://github.com/davefreiman/sinch-ruby
|
130
134
|
licenses:
|