coolsms 0.0.2 → 0.0.3
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/coolsms.gemspec +1 -1
- data/lib/coolsms.rb +3 -62
- data/lib/coolsms/auth.rb +29 -0
- data/lib/coolsms/send.rb +76 -0
- data/lib/coolsms/version.rb +1 -1
- metadata +5 -4
- data/coolsms-0.0.1.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bb3a232a35a1ee89255976d1959a97a2b2f2d34
|
4
|
+
data.tar.gz: fdfba1088988faa59bcd231808636d584945e536
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32a5480a41363d0b739bb604c2f247c36ee2707da252116930979f98a88095f518cf6d1c570ae3d1805edac912b6d0c25ef7d55c89e2f1f4828a38d91fa9c671
|
7
|
+
data.tar.gz: 8e1e30f9384434b2f2379c4fdf2e9db9c9988e5bf945b78a29080ce99eeacb2c7ee6622743b645be35f57bbeb4101b5a26ea83128bad056fcb5e0d50bc74e8ee
|
data/coolsms.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["JunSangPil"]
|
10
10
|
spec.email = ["jun85664396@gmail.com"]
|
11
11
|
spec.summary = %q{coolsms Rest API helper}
|
12
|
-
spec.description = %q{
|
12
|
+
spec.description = %q{coolsms Rest API helper, made by customer}
|
13
13
|
spec.homepage = "http://github.com/jun85664396"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/lib/coolsms.rb
CHANGED
@@ -2,71 +2,12 @@ require "coolsms/version"
|
|
2
2
|
require 'securerandom'
|
3
3
|
require 'net/http'
|
4
4
|
require 'json'
|
5
|
+
require_relative 'coolsms/send'
|
5
6
|
|
6
7
|
module Coolsms
|
7
8
|
class SMS
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
attr_accessor :uri
|
12
|
-
|
13
|
-
#API KEY
|
14
|
-
attr_accessor :api_key
|
15
|
-
|
16
|
-
#API SECRET KEY
|
17
|
-
attr_accessor :api_secret
|
18
|
-
|
19
|
-
#SMS Type default : SMS
|
20
|
-
attr_accessor :type
|
21
|
-
|
22
|
-
#Salt
|
23
|
-
attr_accessor :salt
|
24
|
-
|
25
|
-
#Time Default : now
|
26
|
-
attr_accessor :timestamp
|
27
|
-
|
28
|
-
#Salt
|
29
|
-
attr_accessor :salt
|
30
|
-
|
31
|
-
#Charset
|
32
|
-
attr_accessor :charset
|
33
|
-
|
34
|
-
#Datetime Format YYYYMMDDHHMISS
|
35
|
-
attr_accessor :datetime
|
36
|
-
|
37
|
-
#Delay
|
38
|
-
attr_accessor :delay
|
39
|
-
|
40
|
-
def initialize(api_key, api_secret, options = {})
|
41
|
-
self.uri = URI("https://api.coolsms.co.kr/")
|
42
|
-
self.api_key ||= api_key
|
43
|
-
self.api_secret ||= api_secret
|
44
|
-
self.type ||= options[:type]
|
45
|
-
self.charset ||= options[:charset]
|
46
|
-
self.datetime ||= options[:datetime]
|
47
|
-
self.delay ||= options[:delay]
|
48
|
-
end
|
49
|
-
|
50
|
-
def signature
|
51
|
-
self.timestamp = Time.now.to_i
|
52
|
-
self.salt = SecureRandom.hex
|
53
|
-
hmac_data = self.timestamp.to_s + self.salt.to_s
|
54
|
-
OpenSSL::HMAC.hexdigest("md5", self.api_secret, hmac_data)
|
55
|
-
end
|
56
|
-
|
57
|
-
public
|
58
|
-
def send(from, to, text)
|
59
|
-
signature = self.signature
|
60
|
-
fields = {api_key: self.api_key, timestamp: self.timestamp, salt: self.salt, signature: signature, from: from, to: to, text: text, type: self.type, charset: self.charset, datetime: self.datetime, delay: self.delay}
|
61
|
-
res = Net::HTTP.post_form(self.uri+"/1/send", fields)
|
62
|
-
if res.code == "200"
|
63
|
-
body = JSON.parse(res.body)
|
64
|
-
return {ret: true, message: body['result_message'], code: res.code} if body['result_code'] == "00"
|
65
|
-
return {ret: false, message: body['result_message'], code: res.code}
|
66
|
-
else
|
67
|
-
return {ret: false, code: res.code}
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
10
|
+
Send = Class.new(Send)
|
11
|
+
|
71
12
|
end
|
72
13
|
end
|
data/lib/coolsms/auth.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
class Auth
|
2
|
+
|
3
|
+
#Time Default : now
|
4
|
+
attr_accessor :timestamp
|
5
|
+
|
6
|
+
#Salt
|
7
|
+
attr_accessor :salt
|
8
|
+
|
9
|
+
#API KEY
|
10
|
+
attr_accessor :api_key
|
11
|
+
|
12
|
+
#API SECRET KEY
|
13
|
+
attr_accessor :api_secret
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
self.api_key ||= ENV['COOLSMS_KEY']
|
17
|
+
self.api_secret ||= ENV['COOLSMS_SECRET_KEY']
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def signature
|
22
|
+
self.timestamp = Time.now.to_i
|
23
|
+
self.salt = SecureRandom.hex
|
24
|
+
hmac_data = self.timestamp.to_s + self.salt.to_s
|
25
|
+
OpenSSL::HMAC.hexdigest( "md5", self.api_secret, hmac_data )
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
data/lib/coolsms/send.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require_relative "auth"
|
2
|
+
class Send
|
3
|
+
#URI
|
4
|
+
attr_accessor :uri
|
5
|
+
|
6
|
+
#SMS Type default : SMS
|
7
|
+
attr_accessor :type
|
8
|
+
|
9
|
+
#Salt
|
10
|
+
attr_accessor :salt
|
11
|
+
|
12
|
+
#Charset
|
13
|
+
attr_accessor :charset
|
14
|
+
|
15
|
+
#Datetime Format YYYYMMDDHHMISS
|
16
|
+
attr_accessor :datetime
|
17
|
+
|
18
|
+
#Delay
|
19
|
+
attr_accessor :delay
|
20
|
+
|
21
|
+
#Refname
|
22
|
+
attr_accessor :refname
|
23
|
+
|
24
|
+
#Country Korea => 82, Japan => 81, China => 86, USA => 1
|
25
|
+
attr_accessor :country
|
26
|
+
|
27
|
+
#Subject
|
28
|
+
attr_accessor :subject
|
29
|
+
|
30
|
+
#Srk
|
31
|
+
attr_accessor :srk
|
32
|
+
|
33
|
+
#Mode
|
34
|
+
attr_accessor :mode
|
35
|
+
|
36
|
+
#Extension
|
37
|
+
attr_accessor :extension
|
38
|
+
|
39
|
+
#Force_sms
|
40
|
+
attr_accessor :force_sms
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def initialize(options = {})
|
45
|
+
self.uri = URI("https://api.coolsms.co.kr/")
|
46
|
+
options.each do |key, value|
|
47
|
+
self.public_send( "#{key}=", value ) if self.class.instance_methods.include? key
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
public
|
52
|
+
|
53
|
+
def send (from, to, text)
|
54
|
+
fields = self.fields( :type, :charset, :datetime, :delay )
|
55
|
+
fields = fields.merge(from: from, to: to, text: text, type: self.type )
|
56
|
+
res = Net::HTTP.post_form(self.uri+"/1/send", fields)
|
57
|
+
if res.code == "200"
|
58
|
+
body = JSON.parse(res.body)
|
59
|
+
{ ret: body['result_code'] == "00", message: body['result_message'], code: res.code }
|
60
|
+
else
|
61
|
+
{ ret: false, code: res.code }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def fields(*keys)
|
66
|
+
auth = Auth.new
|
67
|
+
field = { api_key: auth.api_key, signature: auth.signature, timestamp: auth.timestamp, salt: auth.salt}
|
68
|
+
keys.each do |key|
|
69
|
+
if self.class.instance_methods.include? key
|
70
|
+
field[key] = self.public_send(key)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
return field
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
data/lib/coolsms/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coolsms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JunSangPil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
description:
|
41
|
+
description: coolsms Rest API helper, made by customer
|
42
42
|
email:
|
43
43
|
- jun85664396@gmail.com
|
44
44
|
executables: []
|
@@ -50,9 +50,10 @@ files:
|
|
50
50
|
- LICENSE.txt
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
|
-
- coolsms-0.0.1.gem
|
54
53
|
- coolsms.gemspec
|
55
54
|
- lib/coolsms.rb
|
55
|
+
- lib/coolsms/auth.rb
|
56
|
+
- lib/coolsms/send.rb
|
56
57
|
- lib/coolsms/version.rb
|
57
58
|
homepage: http://github.com/jun85664396
|
58
59
|
licenses:
|
data/coolsms-0.0.1.gem
DELETED
Binary file
|