firstmiler_sms_oauth 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -28,21 +28,12 @@ module FirstmilerSmsOauth
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def handle_response(response)
|
31
|
-
flag
|
31
|
+
flag= FirstmilerSmsOauth::FmSmsException.check_response(response)
|
32
32
|
if flag
|
33
33
|
FirstmilerSmsOauth::FmSmsResponse.new(response)
|
34
|
-
else
|
35
|
-
raise msg
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
39
|
-
def exotel_sid
|
40
|
-
FirstmilerSmsOauth.exotel_sid
|
41
|
-
end
|
42
|
-
|
43
|
-
def raise_blank_sms_template_exception
|
44
|
-
raise "Sms Template content should not be blank."
|
45
|
-
end
|
46
37
|
class << self
|
47
38
|
def send(number, content)
|
48
39
|
new.send(number, content)
|
@@ -4,14 +4,40 @@ module FirstmilerSmsOauth
|
|
4
4
|
module FmSmsException
|
5
5
|
module_function
|
6
6
|
def check_response(response)
|
7
|
-
exotel_hash=Hash.from_xml(response.gsub("\n", ""))
|
7
|
+
exotel_hash = Hash.from_xml(response.gsub("\n", ""))
|
8
8
|
if exotel_hash["TwilioResponse"].has_key?("SMSMessage")
|
9
9
|
return true
|
10
10
|
elsif exotel_hash["TwilioResponse"].has_key?("RestException")
|
11
|
-
|
11
|
+
hash = exotel_hash["TwilioResponse"]["RestException"]
|
12
|
+
raise_exception(hash["status"], hash["Message"])
|
13
|
+
end
|
14
|
+
false
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def raise_exception(code, message = nil)
|
19
|
+
case code.to_i
|
20
|
+
when 400
|
21
|
+
raise ParamsError, message
|
22
|
+
when 401
|
23
|
+
raise AuthenticationError, message
|
24
|
+
when 403
|
25
|
+
raise ExotelAccountError, message
|
26
|
+
when 500
|
27
|
+
raise InvalidSmsTemplateError, "Sms Template is invalid, format for sms template should be 'sms content %{key}'"
|
12
28
|
else
|
13
|
-
|
29
|
+
raise UnexpectedError, "#{code} #{message}"
|
14
30
|
end
|
15
31
|
end
|
16
32
|
end
|
33
|
+
|
34
|
+
class AuthenticationError < StandardError; end
|
35
|
+
|
36
|
+
class UnexpectedError < StandardError; end
|
37
|
+
|
38
|
+
class ParamsError < StandardError; end
|
39
|
+
|
40
|
+
class ExotelAccountError < StandardError; end
|
41
|
+
|
42
|
+
class InvalidSmsTemplateError < StandardError; end
|
17
43
|
end
|
@@ -11,7 +11,18 @@ module FirstmilerSmsOauth
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def sms_template
|
14
|
-
FirstmilerSmsOauth.sms_template
|
14
|
+
template = FirstmilerSmsOauth.sms_template
|
15
|
+
unless is_valid_sms_template?(template)
|
16
|
+
FirstmilerSmsOauth::FmSmsException.raise_exception(500)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def is_valid_sms_template?(template)
|
21
|
+
template.present? && check_valid_formate?(template)
|
22
|
+
end
|
23
|
+
|
24
|
+
def check_valid_formate?(template)
|
25
|
+
template.include? '%{key}'
|
15
26
|
end
|
16
27
|
end
|
17
28
|
end
|
@@ -13,13 +13,8 @@ module FirstmilerSmsOauth
|
|
13
13
|
|
14
14
|
module InstanceMethods
|
15
15
|
def send_otp_token
|
16
|
-
|
17
|
-
|
18
|
-
FirstmilerSmsOauth::FmSms.send(self.phone_no, content)
|
19
|
-
rescue Exception => e
|
20
|
-
delete_user_sms_oauth_tokens
|
21
|
-
p e.to_s
|
22
|
-
end
|
16
|
+
content = sms_content
|
17
|
+
FirstmilerSmsOauth::FmSms.send(self.phone_no, content)
|
23
18
|
end
|
24
19
|
|
25
20
|
def delete_user_sms_oauth_tokens
|
@@ -42,7 +37,7 @@ module FirstmilerSmsOauth
|
|
42
37
|
key
|
43
38
|
end
|
44
39
|
|
45
|
-
def
|
40
|
+
def verify_otp?(token)
|
46
41
|
flag = all_tokens.include?(token.to_s)
|
47
42
|
delete_user_sms_oauth_tokens
|
48
43
|
flag
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firstmiler_sms_oauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-03-
|
12
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|