locasms 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +30 -0
- data/.travis.yml +11 -4
- data/Gemfile +2 -0
- data/Guardfile +4 -2
- data/README.md +1 -1
- data/Rakefile +3 -1
- data/bin/console +2 -0
- data/lib/locasms.rb +4 -0
- data/lib/locasms/client.rb +22 -17
- data/lib/locasms/exception.rb +7 -7
- data/lib/locasms/helpers/date_time_helper.rb +38 -69
- data/lib/locasms/numbers.rb +14 -12
- data/lib/locasms/rest_client.rb +21 -13
- data/lib/locasms/version.rb +3 -1
- data/locasms.gemspec +25 -20
- data/spec/lib/locasms/client_spec.rb +96 -138
- data/spec/lib/locasms/helpers/date_time_helper_spec.rb +11 -35
- data/spec/lib/locasms/numbers_spec.rb +54 -68
- data/spec/lib/locasms/rest_client_spec.rb +43 -31
- data/spec/spec_helper.rb +5 -4
- metadata +50 -22
- data/.ruby-style.yml +0 -1063
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 39596e51a28908193ac0455bf97fb1c703becaedc33c569fe509e1ce450a6e70
|
4
|
+
data.tar.gz: f4a5d880167d667f952ebd75f68116b4dcfda9da03579d9a2b4bca87f735b1ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '028885bb02e34a3f5bb918e805795e24e62a1f7d9bd18acc81bafb53e824502b263128b159c75af90d06d5764b210cd0fc01968d865cfed31a89bf1041fbdbd6'
|
7
|
+
data.tar.gz: 56ca283b83035314141fadcf0b48cedbf875176822c5ca159c99c7a70857260cfe9c3a8284f0ddcd8fe9b147edd4f4a3f91542df4107c683a1f1d2e1a87f3422
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2020-10-15 23:34:33 UTC using RuboCop version 0.93.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 8
|
10
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
|
11
|
+
# ExcludedMethods: refine
|
12
|
+
Metrics/BlockLength:
|
13
|
+
Max: 171
|
14
|
+
|
15
|
+
# Offense count: 1
|
16
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
|
17
|
+
Metrics/MethodLength:
|
18
|
+
Max: 27
|
19
|
+
|
20
|
+
# Offense count: 1
|
21
|
+
# Configuration parameters: CountKeywordArgs.
|
22
|
+
Metrics/ParameterLists:
|
23
|
+
Max: 13
|
24
|
+
|
25
|
+
# Offense count: 1
|
26
|
+
# Cop supports --auto-correct.
|
27
|
+
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
28
|
+
# URISchemes: http, https
|
29
|
+
Layout/LineLength:
|
30
|
+
Max: 179
|
data/.travis.yml
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
+
- 2.7
|
4
|
+
- 2.6
|
3
5
|
- 2.5
|
4
6
|
- 2.4
|
5
|
-
- 2.3
|
6
|
-
- 2.2
|
7
|
-
- 2.1
|
8
7
|
env:
|
9
8
|
- TRAVIS=true
|
10
|
-
|
9
|
+
before_script:
|
10
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
11
|
+
- chmod +x ./cc-test-reporter
|
12
|
+
- ./cc-test-reporter before-build
|
13
|
+
script:
|
14
|
+
- bundle exec rspec
|
15
|
+
- bundle exec rubocop
|
16
|
+
after_script:
|
17
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# locasms
|
2
|
-
[![Gem Version](https://badge.fury.io/rb/locasms.svg)](http://badge.fury.io/rb/locasms) [![Build Status](https://travis-ci.org/mcorp/locasms.png?branch=master)](https://travis-ci.org/mcorp/locasms) [![Code Climate](https://codeclimate.com/github/mcorp/locasms.
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/locasms.svg)](http://badge.fury.io/rb/locasms) [![Build Status](https://travis-ci.org/mcorp/locasms.png?branch=master)](https://travis-ci.org/mcorp/locasms) [![Code Climate](https://api.codeclimate.com/v1/badges/4187ea939aabd3b66bf7/maintainability)](https://codeclimate.com/github/mcorp/locasms) [![CC Coverage](https://api.codeclimate.com/v1/badges/4187ea939aabd3b66bf7/test_coverage)](https://codeclimate.com/github/mcorp/locasms/test_coverage) [![Inline docs](http://inch-ci.org/github/mcorp/locasms.svg?branch=master)](http://inch-ci.org/github/mcorp/locasms)
|
3
3
|
|
4
4
|
> :warning: After `February, 10, 2018` the base IP of the service will change as noticed on this [issue](https://github.com/mcorp/locasms/issues/21). If you don't upgrade to version `0.3.1` your app will stop delivering SMS.
|
5
5
|
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
require 'bundler'
|
3
5
|
|
@@ -14,4 +16,4 @@ task :console do
|
|
14
16
|
sh 'bundle exec irb -rubygems -I lib -r locasms.rb'
|
15
17
|
end
|
16
18
|
|
17
|
-
task :
|
19
|
+
task default: (ENV['TRAVIS'] ? :spec : :console)
|
data/bin/console
CHANGED
data/lib/locasms.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'locasms/version'
|
2
4
|
|
3
5
|
autoload :CSV, 'csv'
|
4
6
|
autoload :MultiJson, 'multi_json'
|
5
7
|
|
8
|
+
# Module to encapsulate implementation
|
6
9
|
module LocaSMS
|
7
10
|
autoload :Client, 'locasms/client'
|
8
11
|
autoload :Exception, 'locasms/exception'
|
@@ -11,6 +14,7 @@ module LocaSMS
|
|
11
14
|
autoload :Numbers, 'locasms/numbers'
|
12
15
|
autoload :RestClient, 'locasms/rest_client'
|
13
16
|
|
17
|
+
# Module to encapsulate helpers
|
14
18
|
module Helpers
|
15
19
|
autoload :DateTimeHelper, 'locasms/helpers/date_time_helper'
|
16
20
|
end
|
data/lib/locasms/client.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module LocaSMS
|
3
4
|
# Client to interact with LocaSMS API
|
4
5
|
class Client
|
5
6
|
# Default API "domain"
|
6
|
-
DOMAIN = 'app.locasms.com.br'
|
7
|
+
DOMAIN = 'app.locasms.com.br'
|
7
8
|
|
8
9
|
# Default API address
|
9
10
|
ENDPOINT = {
|
10
|
-
default:
|
11
|
+
default: "http://#{DOMAIN}/painel/api.ashx",
|
11
12
|
shortcode: "http://#{DOMAIN}/shortcode/api.ashx"
|
12
13
|
}.freeze
|
13
14
|
|
@@ -17,7 +18,7 @@ module LocaSMS
|
|
17
18
|
# @param [String] password access password
|
18
19
|
# @param [Hash] opts
|
19
20
|
# @option opts :rest_client (RestClient) client to be used to handle http requests
|
20
|
-
def initialize(login, password, opts={})
|
21
|
+
def initialize(login, password, opts = {})
|
21
22
|
@login = login
|
22
23
|
@password = password
|
23
24
|
@type = opts[:type] || :default
|
@@ -65,20 +66,24 @@ module LocaSMS
|
|
65
66
|
|
66
67
|
# Gets the current status of the given campaign
|
67
68
|
# @param [String] id campaign id
|
68
|
-
# @return [Array<Hash>]
|
69
|
+
# @return [Array<Hash>]
|
70
|
+
# { campaign_id: id, delivery_id: delivery_id, enqueue_time: enqueue_time,
|
71
|
+
# delivery_time: delivery_time, status: status, carrier: carrier,
|
72
|
+
# mobile_number: mobile_number, message: message }
|
69
73
|
def campaign_status(id)
|
70
74
|
response = rest.get(:getstatus, id: id)
|
71
75
|
begin
|
72
76
|
CSV.new(response['data'] || '', col_sep: ';', quote_char: '"').map do |delivery_id, _, enqueue_time, _, delivery_time, _, status, _, _, carrier, mobile_number, _, message|
|
73
|
-
status =
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
status = case status
|
78
|
+
when /aguardando envio/i
|
79
|
+
waiting
|
80
|
+
when /sucesso/i
|
81
|
+
success
|
82
|
+
when /numero invalido|nao cadastrado/i
|
83
|
+
invalid
|
84
|
+
else
|
85
|
+
unknown
|
86
|
+
end
|
82
87
|
|
83
88
|
{
|
84
89
|
campaign_id: id,
|
@@ -91,8 +96,8 @@ module LocaSMS
|
|
91
96
|
message: message
|
92
97
|
}
|
93
98
|
end
|
94
|
-
rescue
|
95
|
-
raise Exception.new 'Invalid delivery response data'
|
99
|
+
rescue StandardError
|
100
|
+
raise LocaSMS::Exception.new(message: 'Invalid delivery response data')
|
96
101
|
end
|
97
102
|
end
|
98
103
|
|
@@ -128,7 +133,7 @@ module LocaSMS
|
|
128
133
|
numbers = Numbers.new mobiles
|
129
134
|
return numbers.to_s unless numbers.bad?
|
130
135
|
|
131
|
-
raise Exception("Bad numbers were given: #{numbers.bad.join(',')}")
|
136
|
+
raise LocaSMS::Exception.new(message: "Bad numbers were given: #{numbers.bad.join(',')}")
|
132
137
|
end
|
133
138
|
end
|
134
139
|
end
|
data/lib/locasms/exception.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module LocaSMS
|
3
4
|
# Common base exception
|
4
|
-
class Exception <
|
5
|
+
class Exception < RuntimeError
|
5
6
|
attr_reader :raw, :action
|
6
7
|
|
7
8
|
def initialize(data = {})
|
@@ -11,7 +12,7 @@ module LocaSMS
|
|
11
12
|
super data[:message] || default_message
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
+
private
|
15
16
|
|
16
17
|
def default_message
|
17
18
|
nil
|
@@ -20,17 +21,16 @@ module LocaSMS
|
|
20
21
|
|
21
22
|
# Raised when asked for an invalid operation
|
22
23
|
# @see https://github.com/mcorp/locasms/wiki/A-API-de-envio#lista-das-a%C3%A7%C3%B5es-dispon%C3%ADveis
|
23
|
-
class InvalidOperation <
|
24
|
+
class InvalidOperation < RuntimeError
|
24
25
|
def default_message
|
25
26
|
'Invalid Operation'
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
30
|
# Raised when the given credentials are invalid
|
30
|
-
class InvalidLogin <
|
31
|
+
class InvalidLogin < RuntimeError
|
31
32
|
def default_message
|
32
33
|
'Invalid Login'
|
33
34
|
end
|
34
35
|
end
|
35
|
-
|
36
|
-
end
|
36
|
+
end
|
@@ -1,74 +1,43 @@
|
|
1
|
-
|
2
|
-
module Helpers
|
3
|
-
|
4
|
-
# Helper class to handle with time parsing
|
5
|
-
class DateTimeHelper
|
6
|
-
# Parse a value into a time
|
7
|
-
# @param [Fixnum,String,DateTime,Time,#to_time] date
|
8
|
-
# @result [Time] return a parsed time
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
#
|
12
|
-
# DateTimeHelper.parse '1977-03-14 14:12:00'
|
13
|
-
# # => 1977-03-14 14:12:00 -0300
|
14
|
-
#
|
15
|
-
# DateTimeHelper.split 227207520
|
16
|
-
# # => 1977-03-14 14:12:00 -0300
|
17
|
-
#
|
18
|
-
def self.parse(date)
|
19
|
-
date = Time.at(date) if date.is_a? Fixnum
|
20
|
-
date = Time.parse(date) if date.is_a? String
|
21
|
-
date = date.to_time if date.respond_to? :to_time
|
22
|
-
end
|
23
|
-
|
24
|
-
# Breaks a given date in date and time
|
25
|
-
# @param [Fixnum,String,DateTime,Time,#to_time] date
|
26
|
-
# @result [Array<String>] an array containing respectively DD/MM/YYYY and HH:MM
|
27
|
-
#
|
28
|
-
# @example
|
29
|
-
#
|
30
|
-
# DateTimeHelper.split Time.now
|
31
|
-
# # => ['14/03/1977', '14:12']
|
32
|
-
#
|
33
|
-
# DateTimeHelper.split 227207520
|
34
|
-
# # => ['14/03/1977', '14:12']
|
35
|
-
#
|
36
|
-
def self.split(date)
|
37
|
-
parse(date).strftime('%d/%m/%Y %H:%M').split(' ')
|
38
|
-
end
|
1
|
+
# frozen_string_literal: true
|
39
2
|
|
40
|
-
|
41
|
-
|
42
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
DateTimeHelper.
|
54
|
-
|
3
|
+
module LocaSMS
|
4
|
+
module Helpers
|
5
|
+
# Helper class to handle with time parsing
|
6
|
+
class DateTimeHelper
|
7
|
+
# Parse a value into a time
|
8
|
+
# @param [Fixnum,String,DateTime,Time,#to_time] date
|
9
|
+
# @result [Time] return a parsed time
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
#
|
13
|
+
# DateTimeHelper.parse '1977-03-14 14:12:00'
|
14
|
+
# # => 1977-03-14 14:12:00 -0300
|
15
|
+
#
|
16
|
+
# DateTimeHelper.split 227207520
|
17
|
+
# # => 1977-03-14 14:12:00 -0300
|
18
|
+
#
|
19
|
+
def self.parse(date)
|
20
|
+
date = Time.at(date) if date.is_a? Integer
|
21
|
+
date = Time.parse(date) if date.is_a? String
|
22
|
+
date = date.to_time if date.respond_to? :to_time
|
23
|
+
date
|
24
|
+
end
|
55
25
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
26
|
+
# Breaks a given date in date and time
|
27
|
+
# @param [Fixnum,String,DateTime,Time,#to_time] date
|
28
|
+
# @result [Array<String>] an array containing respectively DD/MM/YYYY and HH:MM
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
#
|
32
|
+
# DateTimeHelper.split Time.now
|
33
|
+
# # => ['14/03/1977', '14:12']
|
34
|
+
#
|
35
|
+
# DateTimeHelper.split 227207520
|
36
|
+
# # => ['14/03/1977', '14:12']
|
37
|
+
#
|
38
|
+
def self.split(date)
|
39
|
+
parse(date).strftime('%d/%m/%Y %H:%M').split(' ')
|
40
|
+
end
|
70
41
|
end
|
71
42
|
end
|
72
|
-
|
73
43
|
end
|
74
|
-
end
|
data/lib/locasms/numbers.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module LocaSMS
|
3
4
|
# Class that sanitizes and validates a list of mobile's numbers
|
4
5
|
class Numbers
|
5
6
|
attr_reader :good, :bad
|
@@ -9,15 +10,16 @@ module LocaSMS
|
|
9
10
|
# @see #normalize
|
10
11
|
# @see #evaluate
|
11
12
|
def initialize(*numbers)
|
12
|
-
evaluated
|
13
|
-
@good
|
13
|
+
evaluated = evaluate(numbers)
|
14
|
+
@good = evaluated[:good]
|
15
|
+
@bad = evaluated[:bad]
|
14
16
|
end
|
15
17
|
|
16
18
|
# Checks if there are bad numbers
|
17
19
|
# @return [TrueClass, FalseClass] true if there are bad numbers
|
18
20
|
# @see #valid_number?
|
19
21
|
def bad?
|
20
|
-
|
22
|
+
!bad.empty?
|
21
23
|
end
|
22
24
|
|
23
25
|
# Clears all non digits from a mobile's number and converts into a normalized array
|
@@ -34,17 +36,19 @@ module LocaSMS
|
|
34
36
|
# numbers.normalize '8888-9999', ['AA', '6666-9999', '7777-0000'], '3333-4444,555-9999'
|
35
37
|
# # => ['88889999','AA','66669999','77770000','33334444','5559999']
|
36
38
|
def normalize(*numbers)
|
37
|
-
numbers
|
39
|
+
numbers
|
40
|
+
.join(',')
|
38
41
|
.split(',')
|
39
|
-
.map{|number| number.gsub(/[^0-9a-zA-Z]/, '') }
|
40
|
-
.delete_if
|
42
|
+
.map { |number| number.gsub(/[^0-9a-zA-Z]/, '') }
|
43
|
+
.delete_if(&:empty?)
|
41
44
|
end
|
42
45
|
|
43
46
|
# Validates if a mobile's number has only digits
|
44
47
|
# @param [String] number given number to be validated
|
45
48
|
# @return [TrueClass, FalseClass] true if the number is valid
|
46
49
|
def valid_number?(number)
|
47
|
-
return false if number.nil?
|
50
|
+
return false if number.nil? || number =~ (/[^0-9a-zA-Z]/)
|
51
|
+
|
48
52
|
[10, 11].include? number.size
|
49
53
|
end
|
50
54
|
|
@@ -63,10 +67,9 @@ module LocaSMS
|
|
63
67
|
# Numbers.new.evaluate('4199998888','11777770000','5551212')
|
64
68
|
# #=> {good: ['4199998888','11777770000'], bad: ['5551212']}
|
65
69
|
def evaluate(*numbers)
|
66
|
-
normalize(numbers).
|
70
|
+
normalize(numbers).each_with_object({ good: [], bad: [] }) do |number, hash|
|
67
71
|
bucket = valid_number?(number) ? :good : :bad
|
68
72
|
hash[bucket] << number
|
69
|
-
hash
|
70
73
|
end
|
71
74
|
end
|
72
75
|
|
@@ -76,5 +79,4 @@ module LocaSMS
|
|
76
79
|
(good || []).join(',')
|
77
80
|
end
|
78
81
|
end
|
79
|
-
|
80
|
-
end
|
82
|
+
end
|
data/lib/locasms/rest_client.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
require 'net/http'
|
3
5
|
|
4
6
|
module LocaSMS
|
5
|
-
|
6
7
|
# Class that handle http calls to LocaSMS api
|
7
|
-
# @see https://github.com/mcorp/locasms/wiki/A-API-de-envio
|
8
|
+
# @see https://github.com/mcorp/locasms/wiki/A-API-de-envio
|
9
|
+
# List of avaiable services
|
8
10
|
class RestClient
|
9
11
|
attr_accessor :base_url, :base_params
|
10
12
|
|
11
13
|
# Creates a new instance of the RestClient class
|
12
14
|
# @param [String] base_url a well formed url
|
13
15
|
# @param [Hash] base_params base params to send on every call
|
14
|
-
def initialize(base_url, base_params={})
|
16
|
+
def initialize(base_url, base_params = {})
|
15
17
|
@base_url = base_url
|
16
18
|
@base_params = base_params
|
17
19
|
end
|
@@ -35,11 +37,12 @@ module LocaSMS
|
|
35
37
|
# client.get :holdsms, id: 345678
|
36
38
|
# # => {"status"=>1,"data"=>nil,"msg"=>"SUCESSO"}
|
37
39
|
#
|
38
|
-
# @see https://github.com/mcorp/locasms/wiki/A-API-de-envio#lista-das-a%C3%A7%C3%B5es-dispon%C3%ADveis
|
40
|
+
# @see https://github.com/mcorp/locasms/wiki/A-API-de-envio#lista-das-a%C3%A7%C3%B5es-dispon%C3%ADveis
|
41
|
+
# List of avaiable actions
|
39
42
|
# @raise [LocaSMS::InvalidOperation] when asked for an invalid operation
|
40
43
|
# @raise [LocaSMS::InvalidLogin] when the given credentials are invalid
|
41
|
-
def get(action, params={})
|
42
|
-
params
|
44
|
+
def get(action, params = {})
|
45
|
+
params = params_for action, params
|
43
46
|
|
44
47
|
uri = URI.parse(base_url)
|
45
48
|
uri.query = URI.encode_www_form(params)
|
@@ -59,9 +62,10 @@ module LocaSMS
|
|
59
62
|
# client.params_for :ACTION, a: 1, b: 2
|
60
63
|
# # => { action: :ACTION, lgn: 'LOGIN', pwd: 'PASSWORD', a: 1, b: 2 }
|
61
64
|
#
|
62
|
-
# @see https://github.com/mcorp/locasms/wiki/A-API-de-envio#lista-das-a%C3%A7%C3%B5es-dispon%C3%ADveis
|
63
|
-
|
64
|
-
|
65
|
+
# @see https://github.com/mcorp/locasms/wiki/A-API-de-envio#lista-das-a%C3%A7%C3%B5es-dispon%C3%ADveis
|
66
|
+
# List of avaiable actions
|
67
|
+
def params_for(action, params = {})
|
68
|
+
{ action: action }.merge(base_params).merge(params).select { |_k, v| v }
|
65
69
|
end
|
66
70
|
|
67
71
|
# Parses a result trying to get it in json
|
@@ -73,13 +77,17 @@ module LocaSMS
|
|
73
77
|
def parse_response(action, response)
|
74
78
|
raise InvalidOperation.new(action: action) if response =~ /^0:OPERACAO INVALIDA$/i
|
75
79
|
|
76
|
-
j =
|
80
|
+
j = begin
|
81
|
+
MultiJson.load(response)
|
82
|
+
rescue StandardError
|
83
|
+
{ 'status' => 1, 'data' => response, 'msg' => nil }
|
84
|
+
end
|
77
85
|
|
78
|
-
return j if j['status'] == 1
|
86
|
+
return j if (j['status'] == 1) || (action == :getstatus)
|
79
87
|
|
80
88
|
raise InvalidLogin.new(action: action) if j['msg'] =~ /^falha ao realizar login$/i
|
81
|
-
|
89
|
+
|
90
|
+
raise LocaSMS::Exception.new(message: j['msg'], raw: response, action: action)
|
82
91
|
end
|
83
92
|
end
|
84
|
-
|
85
93
|
end
|