magti 0.1.0.beta5 → 0.1.0.beta6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/magti/sms.rb +22 -4
  2. data/lib/magti/version.rb +1 -1
  3. metadata +1 -1
@@ -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
- if options.nil? or options.empty? or Set[:username, :password, :service_id, :client_id] != Set.new(options.keys)
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
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Magti
3
- VERSION = "0.1.0.beta5"
3
+ VERSION = "0.1.0.beta6"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta5
4
+ version: 0.1.0.beta6
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors: