magti 0.1.0.beta5 → 0.1.0.beta6
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.
- data/lib/magti/sms.rb +22 -4
- data/lib/magti/version.rb +1 -1
- metadata +1 -1
data/lib/magti/sms.rb
CHANGED
@@ -5,6 +5,17 @@ require 'httparty'
|
|
5
5
|
require 'c12-commons'
|
6
6
|
|
7
7
|
module Magti
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def self.validate_security_options(options)
|
12
|
+
if options.nil? or options.empty? or Set[:username, :password, :service_id, :client_id] != Set.new(options.keys)
|
13
|
+
raise ArgumentError, 'specify Magti.config(options) with :username, :password, :client and :service keys'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
public
|
18
|
+
|
8
19
|
# Response object.
|
9
20
|
# It contains information on response code and message id.
|
10
21
|
class Response
|
@@ -21,14 +32,21 @@ module Magti
|
|
21
32
|
raise ArgumentError, 'illegal mobile number' unless C12.correct_mobile?(mobile)
|
22
33
|
raise ArgumentError, 'max size exceeded' if text.length > Magti::MAX_SIZE
|
23
34
|
options = Magti.config.security_options
|
24
|
-
|
25
|
-
raise ArgumentError, 'specify Magti.config(options) with :username, :password, :client and :service keys'
|
26
|
-
end
|
35
|
+
Magti.validate_security_options(options)
|
27
36
|
options = options.merge(:to => "995#{mobile}", :text => text)
|
28
|
-
http_resp = HTTParty.get(Magti::SMS_SEND_URL, {:query => options})
|
37
|
+
http_resp = HTTParty.get(Magti::SMS_SEND_URL, {:query => options}).body
|
29
38
|
resp = Response.new
|
30
39
|
resp.code, resp.id = http_resp.split(' - ')
|
31
40
|
resp
|
32
41
|
end
|
33
42
|
|
43
|
+
# Tracking SMS.
|
44
|
+
def self.track_sms(msg_id)
|
45
|
+
options = Magti.config.security_options
|
46
|
+
Magti.validate_security_options(options)
|
47
|
+
options = options.merge(:message_id => msg_id)
|
48
|
+
http_resp = HTTParty.get(Magti::SMS_TRACK_URL, {:query => options}).body
|
49
|
+
http_resp.to_i
|
50
|
+
end
|
51
|
+
|
34
52
|
end
|
data/lib/magti/version.rb
CHANGED