biju 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
  ## Usage
21
21
 
22
22
  ```
23
- @modem = Biju::Modem.new("/dev/tty.HUAWEIMobile-Modem")
23
+ @modem = Biju::Modem.new(:port => "/dev/tty.HUAWEIMobile-Modem")
24
24
 
25
25
  # method to list all messages
26
26
  @modem.messages.each do |sms|
data/lib/biju/modem.rb CHANGED
@@ -3,6 +3,12 @@ require_relative 'sms'
3
3
 
4
4
  module Biju
5
5
  class Modem
6
+
7
+ # @param [Hash] Options to serial connection.
8
+ # @option options [String] :port The modem port to connect
9
+ #
10
+ # Biju::Modem.new(:port => '/dev/ttyUSB0')
11
+ #
6
12
  def initialize(options={})
7
13
  raise Exception.new("Port is required") unless options[:port]
8
14
  @connection = connection(options)
@@ -10,15 +16,12 @@ module Biju
10
16
  cmd("AT+CMGF=1")
11
17
  end
12
18
 
13
- def connection(options)
14
- port = options.delete(:port)
15
- SerialPort.new(port, default_options.merge!(options))
16
- end
17
-
19
+ # Close the serial connection.
18
20
  def close
19
21
  @connection.close
20
22
  end
21
23
 
24
+ # Return an Array of Sms if there is messages nad return nil if not.
22
25
  def messages
23
26
  sms = cmd("AT+CMGL=\"ALL\"")
24
27
  msgs = sms.scan(/\+CMGL\:\s*?(\d+)\,.*?\,\"(.+?)\"\,.*?\,\"(.+?)\".*?\n(.*)/)
@@ -26,7 +29,18 @@ module Biju
26
29
  msgs.collect!{ |msg| Biju::Sms.new(:id => msg[0], :phone_number => msg[1], :datetime => msg[2], :message => msg[3].chomp) }
27
30
  end
28
31
 
32
+ # Delete a sms message by id.
33
+ # @param [Fixnum] Id of sms message on modem.
34
+ def delete(id)
35
+ cmd("AT+CMGD=#{id}")
36
+ end
37
+
29
38
  private
39
+ def connection(options)
40
+ port = options.delete(:port)
41
+ SerialPort.new(port, default_options.merge!(options))
42
+ end
43
+
30
44
  def default_options
31
45
  { :baud => 9600, :data_bits => 8, :stop_bits => 1, :parity => SerialPort::NONE }
32
46
  end
data/lib/biju/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Biju
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biju
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-18 00:00:00.000000000 Z
12
+ date: 2012-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &2156178580 !ruby/object:Gem::Requirement
16
+ requirement: &2151898080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2156178580
24
+ version_requirements: *2151898080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: serialport
27
- requirement: &2156178040 !ruby/object:Gem::Requirement
27
+ requirement: &2151897520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 1.0.4
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2156178040
35
+ version_requirements: *2151897520
36
36
  description: An easiest way to mount a GSM modem to send and to receive sms message
37
37
  email:
38
38
  - rodrigopqn@gmail.com