sinch_sms_send 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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/sinch_sms_send.rb +103 -0
  3. metadata +43 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c265b4a8b7eb4a78138cdcd2a628f8a194411bdd
4
+ data.tar.gz: 8620f9b53d8c4b99784740063a0db3685f9d7154
5
+ SHA512:
6
+ metadata.gz: dd2ee09151a25bf0ae3874d8948e2fb84c186ebd651595cbf87c8a44d36414d5ada3d5eeeb1c844bd639648c101071d7fe2942ef1bcd4543bb7fad302e23ef2c
7
+ data.tar.gz: 7e3a777529af9b797877eb1cfb5d103fccf55f3d682101962104c7735f0b4c9f518747b6dcfb0c447c122059d6feda2933aafae54f914d64cdb80c584e447164
@@ -0,0 +1,103 @@
1
+ require "base64"
2
+ require "openssl"
3
+ require "time"
4
+ require "net/http"
5
+ require "uri"
6
+ require "json"
7
+
8
+ class SinchSms
9
+ # def self.send(key, secret, message, to)
10
+ # body = "{\"message\":\"#{message}\"}"
11
+ # timestamp = Time.now.iso8601
12
+ # authorization = auth(key, secret, "/v1/sms/#{to}", "POST", timestamp, body)
13
+
14
+ # uri = URI.parse("https://messagingApi.sinch.com/v1/sms/" + to)
15
+ # http = Net::HTTP.new(uri.host, uri.port)
16
+ # http.use_ssl = true
17
+ # http.verify_mode = OpenSSL::SSL::VERIFY_NONE
18
+ # headers = {"content-type" => "application/json", "x-timestamp" => timestamp, "authorization" => authorization}
19
+ # request = Net::HTTP::Post.new(uri.request_uri)
20
+ # request.initialize_http_header(headers)
21
+ # request.body = body
22
+ # return JSON.parse(http.request(request).body)
23
+ # end
24
+
25
+ def self.send(key, secret, message, to, from)
26
+ body = "{\"message\":\"#{message}\", \"from\":\"#{from}\"}"
27
+ timestamp = Time.now.iso8601
28
+ authorization = auth(key, secret, "/v1/sms/#{to}", "POST", timestamp, body)
29
+
30
+ uri = URI.parse("https://messagingApi.sinch.com/v1/sms/" + to)
31
+ http = Net::HTTP.new(uri.host, uri.port)
32
+ http.use_ssl = true
33
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
34
+ headers = {"content-type" => "application/json", "x-timestamp" => timestamp, "authorization" => authorization}
35
+ request = Net::HTTP::Post.new(uri.request_uri)
36
+ request.initialize_http_header(headers)
37
+ request.body = body
38
+ return JSON.parse(http.request(request).body)
39
+ end
40
+
41
+ def self.status(key, secret, id)
42
+ timestamp = Time.now.iso8601
43
+ authorization = self.auth(key, secret, "/v1/message/status/#{id}", "GET", timestamp)
44
+
45
+ uri = URI.parse("https://messagingApi.sinch.com/v1/message/status/" + id)
46
+ http = Net::HTTP.new(uri.host, uri.port)
47
+ http.use_ssl = true
48
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
49
+ headers = {"content-type" => "application/json", "x-timestamp" => timestamp, "authorization" => authorization}
50
+ request = Net::HTTP::Get.new(uri.request_uri)
51
+ request.initialize_http_header(headers)
52
+
53
+ return JSON.parse(http.request(request).body)
54
+ end
55
+
56
+ private
57
+ def self.auth(key, secret, path, http_verb, timestamp, body=nil)
58
+ scheme = "Application"
59
+ content_type = "application/json"
60
+ digest = OpenSSL::Digest.new('sha256')
61
+ canonicalized_headers = "x-timestamp:" + timestamp
62
+
63
+ if body
64
+ content_md5 = Base64.encode64(Digest::MD5.digest(body.encode("UTF-8"))).strip
65
+ else
66
+ content_md5 = ""
67
+ end
68
+
69
+ string_to_sign = http_verb + "\n" + content_md5 + "\n" + content_type + "\n" + canonicalized_headers + "\n" + path
70
+ signature = Base64.encode64(OpenSSL::HMAC.digest(digest, Base64.decode64(secret), string_to_sign.encode("UTF-8"))).strip
71
+
72
+ return "Application #{key}:#{signature}"
73
+ end
74
+ end
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinch_sms_send
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Tom Hernandez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Modified to include a from parameter
14
+ email: tomrhernandez@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/sinch_sms_send.rb
20
+ homepage: ''
21
+ licenses: []
22
+ metadata: {}
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ required_rubygems_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ requirements: []
38
+ rubyforge_project:
39
+ rubygems_version: 2.6.8
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Sinch Sms gem
43
+ test_files: []