comunika_gsm 0.1.17 → 0.1.18

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a65f11023e8462fd4c0b07fbecbda675059c3b74
4
- data.tar.gz: 7cabb73cef987b46008b205a2c59148e74991fbf
3
+ metadata.gz: 96133aa9b5099b0c1c96538546aef17cdd961efd
4
+ data.tar.gz: caa32b6a6c5ee877247071632a85a9e89d636c33
5
5
  SHA512:
6
- metadata.gz: 8dbe026adab1436b5f5c5b3c469330ec84120f91befbb7e1f1be3ca9b81a1a0c1ef836f60d6884a42a66cbc29cee17429ba7eee090a1e11bbc3202fe3b88b1c3
7
- data.tar.gz: 203473ac5d57d11088b91065071c98e714e1039f59338e833e609211c23644f8312cc1930bba9fc419e9b9deaf4f4c4dae04ee15d283f3cc2897fb1a349d44d0
6
+ metadata.gz: 02f0eba8fa068927bb2e29f8a4d5ca9a2dcb504f07e96a61d51b5299634e357ef832802dc270dc92e75a501f9998559107df6c2b5834dbc72f6a1e979ab9004f
7
+ data.tar.gz: 3ca6bfed477a44a179bd507b3e45b63e43ccfd8d52667463185e81b3281973d04cc45d1c12392d25970535373a963bd995261f078174e6b890256d00299225f7
@@ -44,6 +44,9 @@ module ComunikaGsm
44
44
 
45
45
  def wait
46
46
  buffer = @@port.read
47
+ while buffer.length == 0
48
+ buffer = @@port.read
49
+ end
47
50
  puts buffer if @@debug
48
51
  @@port.flush()
49
52
  buffer
@@ -51,39 +54,39 @@ module ComunikaGsm
51
54
 
52
55
  def close
53
56
  puts "Fechando conexão"
54
- @@port.close
57
+ @@port.close if @@port
55
58
  @status = false
56
59
  end
57
60
 
58
- def send_sms(msg)
59
- return {id: nil, status: "ERROR", code: "304"} if msg[:number].length == 0
60
- return {id: nil, status: "ERROR", code: "304"} if msg[:number].length < 11
61
- return {id: nil, status: "ERROR", code: "503"} if msg[:message].length == 0
61
+ def send_sms(number,message,params = {})
62
+ if number.length == 0 || number.length < 11 || message.length == 0
63
+ return {id: nil, status: "ERROR", code: "304"}
64
+ else
65
+ ## GENERATE PDU TO MESSAGE ##
66
+ pdu = PDU.encode(:number => "+55" + number, :message => message, :smsc => params[:smsc])
62
67
 
63
- ## GENERATE PDU TO MESSAGE ##
64
- pdu = PDU.encode(:number => msg[:number].prepend("+55"), :smsc => msg[:smsc], :message => msg[:message])
68
+ cmd("AT+CMGS=#{pdu[:size]}\r")
69
+ res = cmd("#{pdu[:pdu]}#{26.chr}")
65
70
 
66
- cmd("AT+CMGS=#{pdu[:size]}\r")
67
- res = cmd("#{pdu[:pdu]}#{26.chr}")
71
+ sleep 3
72
+ while res.length == 0
73
+ res = wait
74
+ end
68
75
 
69
- sleep 3
70
- while res.length == 0
71
- res = wait
72
- end
76
+ if res.include?('+CMGS')
77
+ res = res.scan(/\+(\S+)\: (\d+)\r\n/)
78
+ status = 'OK'
79
+ code = "-1"
80
+ id = res.first[1]
81
+ elsif res.include?('+CMS')
82
+ res = res.scan(/\+CMS (\S+)\: (\d+)/).first
83
+ status = 'ERROR'
84
+ code = res[1]
85
+ id = nil
86
+ end
73
87
 
74
- if res.include?('+CMGS')
75
- res = res.scan(/\+(\S+)\: (\d+)\r\n/)
76
- status = 'OK'
77
- code = "-1"
78
- id = res.first[1]
79
- elsif res.include?('+CMS')
80
- res = res.scan(/\+CMS (\S+)\: (\d+)/).first
81
- status = 'ERROR'
82
- code = res[1]
83
- id = nil
88
+ {:id => id, :code => code, :status => status}
84
89
  end
85
-
86
- {:id => id, :code => code, :status => status}
87
90
  end
88
91
 
89
92
  def messages
@@ -1,3 +1,3 @@
1
1
  module ComunikaGsm
2
- VERSION = "0.1.17"
2
+ VERSION = "0.1.18"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comunika_gsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.17
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jefferson Silva
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-29 00:00:00.000000000 Z
11
+ date: 2017-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler