sms_owl 1.0.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/cacert.pem +3988 -0
- data/lib/sms_owl.rb +73 -0
- metadata +45 -0
data/lib/sms_owl.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
ENV['SSL_CERT_FILE'] = File.dirname(__FILE__) + '/cacert.pem'
|
5
|
+
|
6
|
+
class SmsOwl
|
7
|
+
|
8
|
+
class SmsType
|
9
|
+
NORMAL = "normal"
|
10
|
+
FLASH = "flash"
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
URL = URI('https://api.smsowl.in/v1/sms');
|
15
|
+
|
16
|
+
def initialize(accountId,apiKey)
|
17
|
+
@accountId = accountId
|
18
|
+
@apiKey = apiKey
|
19
|
+
end
|
20
|
+
|
21
|
+
def sendPromotionalSms(senderId,to,message,smsType = SmsOwl::SmsType::NORMAL)
|
22
|
+
req = Net::HTTP::Post.new(SmsOwl::URL, initheader = {'Content-Type' =>'application/json'})
|
23
|
+
data = getCommonArray("promotional",smsType,senderId,to)
|
24
|
+
data['message'] = message
|
25
|
+
req.body = data.to_json
|
26
|
+
res = Net::HTTP.start(URL.hostname, URL.port,
|
27
|
+
:use_ssl => URL.scheme == 'https') do |http|
|
28
|
+
http.request(req)
|
29
|
+
end
|
30
|
+
if res.code == '200'
|
31
|
+
jsonRes = JSON.parse(res.body)
|
32
|
+
if to.kind_of?(Array)
|
33
|
+
return jsonRes["smsIds"]
|
34
|
+
else
|
35
|
+
return jsonRes["smsId"]
|
36
|
+
end
|
37
|
+
elsif res.code == '400'
|
38
|
+
jsonRes = JSON.parse(res.body)
|
39
|
+
raise jsonRes['message']
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def sendTransactionalSms(senderId,to,templateId,placeholderArray)
|
44
|
+
req = Net::HTTP::Post.new(SmsOwl::URL, initheader = {'Content-Type' =>'application/json'})
|
45
|
+
data = getCommonArray("transactional","normal",senderId,to)
|
46
|
+
data['templateId'] = templateId
|
47
|
+
data['placeholders'] = placeholderArray
|
48
|
+
req.body = data.to_json
|
49
|
+
res = Net::HTTP.start(URL.hostname, URL.port,
|
50
|
+
:use_ssl => URL.scheme == 'https') do |http|
|
51
|
+
http.request(req)
|
52
|
+
end
|
53
|
+
if res.code == '200'
|
54
|
+
jsonRes = JSON.parse(res.body)
|
55
|
+
return jsonRes["smsId"]
|
56
|
+
elsif res.code == '400'
|
57
|
+
jsonRes = JSON.parse(res.body)
|
58
|
+
raise jsonRes['message']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def getCommonArray(dndType,smsType,senderId,to)
|
64
|
+
return {
|
65
|
+
accountId: @accountId,
|
66
|
+
apiKey: @apiKey,
|
67
|
+
dndType: dndType,
|
68
|
+
smsType: smsType,
|
69
|
+
senderId: senderId,
|
70
|
+
to: to
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sms_owl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mahoujas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This is Ruby wrapper for SmsOwl REST API
|
14
|
+
email: mahoujas@mahoujas.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/cacert.pem
|
20
|
+
- lib/sms_owl.rb
|
21
|
+
homepage: https://smsowl.in
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.4.5
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: This is Ruby wrapper for SmsOwl REST API
|
45
|
+
test_files: []
|