biju 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .rvmrc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in biju.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Rodrigo Pinto
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Biju
2
+
3
+ [WIP] Biju is an easy way to mount a GSM modem to send, to receive and to delete messages through a ruby interface.
4
+ This is project is based on this [code snippet](http://dzone.com/snippets/send-and-receive-sms-text).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'biju'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install biju
19
+
20
+ ## Usage
21
+
22
+ ```
23
+ @modem = Biju::Modem.new("/dev/tty.HUAWEIMobile-Modem")
24
+
25
+ # method to list all messages
26
+ @modem.messages.each do |sms|
27
+ puts sms
28
+ end
29
+
30
+ @modem.close
31
+ ```
32
+ ## TODO
33
+
34
+ 1. Write missing test for modem module.
35
+ 2. Write a documentation.
36
+ 3. Test with different kinds of modem and OS.
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs.push "lib"
7
+ t.test_files = FileList['spec/**/*_spec.rb']
8
+ t.verbose = true
9
+ end
data/biju.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/biju/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Rodrigo Pinto"]
6
+ gem.email = ["rodrigopqn@gmail.com"]
7
+ gem.description = %q{An easiest way to mount a GSM modem to send and to receive sms message}
8
+ gem.summary = %q{A ruby interface to use a GSM modem}
9
+ gem.homepage = "http://github.com/rodrigopinto/biju"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "biju"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Biju::VERSION
17
+
18
+ gem.add_development_dependency "minitest", "3.0.0"
19
+
20
+ gem.add_dependency "serialport", "1.0.4"
21
+ end
data/lib/biju/modem.rb ADDED
@@ -0,0 +1,48 @@
1
+ require 'serialport'
2
+ require_relative 'sms'
3
+
4
+ module Biju
5
+ class Modem
6
+ def initialize(options={})
7
+ raise Exception.new("Port is required") unless options[:port]
8
+ @connection = connection(options)
9
+ cmd("AT")
10
+ cmd("AT+CMGF=1")
11
+ end
12
+
13
+ def connection(options)
14
+ port = options.delete(:port)
15
+ SerialPort.new(port, default_options.merge!(options))
16
+ end
17
+
18
+ def close
19
+ @connection.close
20
+ end
21
+
22
+ def messages
23
+ sms = cmd("AT+CMGL=\"ALL\"")
24
+ msgs = sms.scan(/\+CMGL\:\s*?(\d+)\,.*?\,\"(.+?)\"\,.*?\,\"(.+?)\".*?\n(.*)/)
25
+ return nil unless msgs
26
+ msgs.collect!{ |msg| Biju::Sms.new(:id => msg[0], :phone_number => msg[1], :datetime => msg[2], :message => msg[3].chomp) }
27
+ end
28
+
29
+ private
30
+ def default_options
31
+ { :baud => 9600, :data_bits => 8, :stop_bits => 1, :parity => SerialPort::NONE }
32
+ end
33
+
34
+ def cmd(cmd)
35
+ @connection.write(cmd + "\r")
36
+ wait
37
+ end
38
+
39
+ def wait
40
+ buffer = ''
41
+ while IO.select([@connection], [], [], 0.25)
42
+ chr = @connection.getc.chr;
43
+ buffer += chr
44
+ end
45
+ buffer
46
+ end
47
+ end
48
+ end
data/lib/biju/sms.rb ADDED
@@ -0,0 +1,19 @@
1
+ module Biju
2
+ class Sms
3
+ attr_accessor :id, :phone_number, :datetime, :message
4
+
5
+ def initialize(params={})
6
+ params.each do |attr, value|
7
+ self.public_send("#{attr}=", value)
8
+ end if params
9
+ end
10
+
11
+ def datetime
12
+ @datetime.sub(/(\d+)\D+(\d+)\D+(\d+),(\d*\D)(\d*\D)(\d+)(.*)/, '20\1-\2-\3 \4\5\6')
13
+ end
14
+
15
+ def to_s
16
+ "#{id} - #{phone_number} - #{datetime} - #{message}"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Biju
2
+ VERSION = "0.0.1"
3
+ end
data/lib/biju.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'biju/version'
2
+ require "biju/modem"
3
+ require "biju/sms"
@@ -0,0 +1,10 @@
1
+ require_relative '../spec_helper'
2
+
3
+ # TODO: Fix missing tests SOON
4
+ describe Biju::Modem do
5
+ describe ".new" do
6
+ it "should raise an Exception without port option" do
7
+ lambda { Biju::Modem.new }.must_raise Exception
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Biju::Sms do
4
+ subject { Biju::Sms.new(:id => "1", :phone_number => "144", :datetime => "11/07/28,15:34:08-12", :message => "Some text here")}
5
+
6
+ it { subject.id.must_equal "1" }
7
+
8
+ it { subject.phone_number.must_equal "144" }
9
+
10
+ it { subject.datetime.must_equal "2011-07-28 15:34:08" }
11
+
12
+ it { subject.message.must_equal "Some text here" }
13
+
14
+ it { subject.to_s.must_equal "1 - 144 - 2011-07-28 15:34:08 - Some text here"}
15
+ end
@@ -0,0 +1,2 @@
1
+ require 'minitest/autorun'
2
+ require "./lib/biju"
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: biju
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rodrigo Pinto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: &2156178580 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2156178580
25
+ - !ruby/object:Gem::Dependency
26
+ name: serialport
27
+ requirement: &2156178040 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.4
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2156178040
36
+ description: An easiest way to mount a GSM modem to send and to receive sms message
37
+ email:
38
+ - rodrigopqn@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - biju.gemspec
49
+ - lib/biju.rb
50
+ - lib/biju/modem.rb
51
+ - lib/biju/sms.rb
52
+ - lib/biju/version.rb
53
+ - spec/biju/modem_spec.rb
54
+ - spec/biju/sms_spec.rb
55
+ - spec/spec_helper.rb
56
+ homepage: http://github.com/rodrigopinto/biju
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 1.8.15
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: A ruby interface to use a GSM modem
80
+ test_files:
81
+ - spec/biju/modem_spec.rb
82
+ - spec/biju/sms_spec.rb
83
+ - spec/spec_helper.rb