utel 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
File without changes
data/Gemfile CHANGED
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
data/balance.rb CHANGED
File without changes
File without changes
@@ -1,24 +1,20 @@
1
1
  module Utel
2
2
  class Balance
3
- def self.summary
4
- new.summary
5
- end
6
-
7
- def self.vas
8
- new.vas
3
+ class << self
4
+ [:summary, :vas].each{|method| define_method(method) { new.send(method) }}
9
5
  end
10
6
 
11
7
  def summary
12
- get_balance "*100#"
8
+ call_ussd "*100#"
13
9
  end
14
10
 
15
11
  def vas
16
- get_balance "*121#"
12
+ call_ussd "*121#"
17
13
  end
18
14
 
19
15
  private
20
16
  # @param [String] number USSD number service
21
- def get_balance number
17
+ def call_ussd number
22
18
  File.open(Utel::DEVICE, "w+") do |f|
23
19
  f.write "AT+CUSD=1,#{Utel::Pdu.encode(number)},15\r\n"
24
20
  parse_result f
@@ -1,15 +1,14 @@
1
1
  module Utel
2
2
  class Device
3
- def self.send_at
4
- new.send_at
5
- end
6
-
7
- def self.pin(*args)
8
- new.pin(*args)
9
- end
3
+ [:send_at, :pin].each{|method| define_method(method) {|*args| new.send(method, *args) }}
10
4
 
11
5
  def pin(code=PIN_CODE)
12
- puts code
6
+ File.open(Utel::DEVICE, 'w+') do |f|
7
+ f.write "AT+CPIN=\"code\"\r\n"
8
+ while (s = f.gets) do
9
+ break if s.slice(0,2) == "OK"
10
+ end
11
+ end
13
12
  end
14
13
 
15
14
  def send_at
File without changes
@@ -1,43 +1,45 @@
1
1
  module Utel
2
2
  class Pdu
3
- # Encode and decode pdu strings
4
- def self.encode string
5
- out = ''
6
- for i in (0..string.length - 1) do
7
- t = i%8+1
8
- next if t == 8
9
- c = string[i] >> i%8
10
- b = (string[i+1] || 0) & ((1 << t)-1)
11
- c = (b << (8-t)) | c
12
- out << c.to_s(16).rjust(2, '0').upcase
3
+ class << self
4
+ # Encode and decode pdu strings
5
+ def encode string
6
+ out = ''
7
+ for i in (0..string.length - 1) do
8
+ t = i%8+1
9
+ next if t == 8
10
+ c = string[i] >> i%8
11
+ b = (string[i+1] || 0) & ((1 << t)-1)
12
+ c = (b << (8-t)) | c
13
+ out << c.to_s(16).rjust(2, '0').upcase
14
+ end
15
+ out
13
16
  end
14
- out
15
- end
16
17
 
17
- def self.decode string
18
- out = ''
19
- b = 0; d = 0
20
- string.scan(/.{2}/).each do |part|
21
- byte = part.to_i(16)
22
- c = ((byte & ((1 << 7-d)-1)) << d) | b;
23
- b = byte >> (7-d);
24
- out << c.chr
25
- d += 1
26
- if d == 7
27
- out << b.chr
28
- d = 0; b = 0
18
+ def decode string
19
+ out = ''
20
+ b = 0; d = 0
21
+ string.scan(/.{2}/).each do |part|
22
+ byte = part.to_i(16)
23
+ c = ((byte & ((1 << 7-d)-1)) << d) | b;
24
+ b = byte >> (7-d);
25
+ out << c.chr
26
+ d += 1
27
+ if d == 7
28
+ out << b.chr
29
+ d = 0; b = 0
30
+ end
29
31
  end
32
+ out
30
33
  end
31
- out
32
- end
33
34
 
34
- def self.decimal_semi_octets number
35
- reversed = ''
36
- number.to_s.split('').each_slice(2) do |pair|
37
- a,b = pair
38
- reversed << (b.nil? ? "F" : b) << a
35
+ def decimal_semi_octets number
36
+ reversed = ''
37
+ number.to_s.split('').each_slice(2) do |pair|
38
+ a,b = pair
39
+ reversed << (b.nil? ? "F" : b) << a
40
+ end
41
+ reversed
39
42
  end
40
- reversed
41
43
  end
42
44
  end
43
45
  end
File without changes
@@ -1,3 +1,3 @@
1
1
  module Utel
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.version = Utel::VERSION
9
9
  s.authors = ["Eugene Russkikh"]
10
10
  s.email = ["eugene@russkikh.org.ua"]
11
- s.homepage = "http://komba.org.ua"
11
+ s.homepage = "https://github.com/komba/utel"
12
12
  s.summary = %q{Utel USSD}
13
13
  s.description = %q{Utel USSD services balance checker}
14
14
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eugene Russkikh
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-05 00:00:00 +03:00
19
- default_executable:
18
+ date: 2012-07-19 00:00:00 Z
20
19
  dependencies: []
21
20
 
22
21
  description: Utel USSD services balance checker
@@ -42,8 +41,7 @@ files:
42
41
  - lib/utel/sms.rb
43
42
  - lib/utel/version.rb
44
43
  - utel.gemspec
45
- has_rdoc: true
46
- homepage: http://komba.org.ua
44
+ homepage: https://github.com/komba/utel
47
45
  licenses: []
48
46
 
49
47
  post_install_message:
@@ -72,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
70
  requirements: []
73
71
 
74
72
  rubyforge_project:
75
- rubygems_version: 1.6.2
73
+ rubygems_version: 1.8.10
76
74
  signing_key:
77
75
  specification_version: 3
78
76
  summary: Utel USSD