sms4 0.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 +7 -0
- data/lib/sms4.rb +54 -0
- metadata +44 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 37ec3f569affe0eb1f85b45005be8e255847fa57
|
|
4
|
+
data.tar.gz: 32637df7c5fd0f9142922824c57b4f9347a7f4e3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 02db602c15efb102c02776c56e80ea3584cbef2a3cb4a6a961b4f04c4171b94b9e23e8ed17c9700ab46b38be9023dc2f475517d9ac227fb6a0fe7b3ec24e7c68
|
|
7
|
+
data.tar.gz: 6d376422a5d6708c1ab535270a5581a7daf43a330bdd49832562af2378f528e1cd64b8e1c3b4234f10a7d8f09e53c1b32c9f8cbc7a4d3975154eb9c422d4d3a0
|
data/lib/sms4.rb
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'uri'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
$sms4_send_host = URI.parse('https://sms4.dev/send')
|
|
6
|
+
|
|
7
|
+
class SMS4
|
|
8
|
+
def self.is_valid_input(to, message, token)
|
|
9
|
+
if (to.nil?) or (not to.instance_of? String and not to.instance_of? Array) or to.empty?
|
|
10
|
+
puts 'SMS4 Error: Recepients string is invalid. Please refer to our documentation at https://sms4.dev to see correct options.'
|
|
11
|
+
return false
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
if (message.nil?) or (not message.instance_of? String) or message.empty?
|
|
15
|
+
puts 'SMS4 Error: Message string is invalid. Please refer to our documentation at https://sms4.dev to see correct options.'
|
|
16
|
+
return false
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
if (token.nil?) or (not token.instance_of? String) or token.empty?
|
|
20
|
+
puts 'SMS4 token is not defined. To fix this you have to either:','1) Set environment variable SMS4_TOKEN','or','2) Pass the token as the 3rd argument to the send function.'
|
|
21
|
+
return false
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
return true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.send(to, message, token=nil)
|
|
28
|
+
sms4_token = nil
|
|
29
|
+
if not token.nil?
|
|
30
|
+
sms4_token = token
|
|
31
|
+
elsif not ENV['SMS4_TOKEN'].nil?
|
|
32
|
+
sms4_token = ENV['SMS4_TOKEN']
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
if self.is_valid_input(to, message, sms4_token)
|
|
36
|
+
formatted_recepients = to
|
|
37
|
+
if to.instance_of? Array
|
|
38
|
+
formatted_recepients = to.join(',')
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
header = { 'Content-Type': 'application/json' }
|
|
42
|
+
data = { to: formatted_recepients, message: message, token: sms4_token }
|
|
43
|
+
|
|
44
|
+
http = Net::HTTP.new($sms4_send_host.host, $sms4_send_host.port)
|
|
45
|
+
http.use_ssl = true
|
|
46
|
+
request = Net::HTTP::Post.new($sms4_send_host.request_uri, header)
|
|
47
|
+
request.body = data.to_json
|
|
48
|
+
|
|
49
|
+
response = http.request(request)
|
|
50
|
+
|
|
51
|
+
return response.body
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sms4
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sergey Gaykov
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-07-23 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A ruby gem for utilizing sms4.dev API
|
|
14
|
+
email: sdgaykov@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/sms4.rb
|
|
20
|
+
homepage: https://rubygems.org/gems/sms4
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubyforge_project:
|
|
40
|
+
rubygems_version: 2.5.2.3
|
|
41
|
+
signing_key:
|
|
42
|
+
specification_version: 4
|
|
43
|
+
summary: Simple and straightforward way to send text messages
|
|
44
|
+
test_files: []
|