utel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ gemspec
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ Utel::Balance
2
+ ============
3
+
4
+ Установка
5
+ ------------
6
+
7
+ $ gem install utel
8
+
9
+ Для корректной работы, в порт USB должен быть вставлен модем ОГО!Мобильный. Скрипт обращается к /dev/ttyUSB2, так что я думаю, что будет поддерживаться не только модемы Huawei, но и остальные
10
+
11
+
12
+ Проверка баланса
13
+ ----------------
14
+
15
+ Utel::Balance.summary
16
+ => "Vash balans:zagal'nyi 46,06; paketnyi 0,00; dodatkovyi 0,00 hrn.Perevirka dodatkovykh poslug *121#"
17
+
18
+ Utel::Balance.vas
19
+ => "Internet:3G 1572602.0Kb,Universalnyi 144140.0Kb,Nat.rouming 0.0Kb;0.0SMS po Ukraini;0v mezhah Ukrainy;0na inshi mobilni Ukrainy"
20
+
21
+ Или же кастомным скриптом
22
+ ---------------------------
23
+
24
+ $ ruby balance.rb
25
+ Vash balans:zagal'nyi 46,06; paketnyi 0,00; dodatkovyi 0,00 hrn.Perevirka dodatkovykh poslug *121#
26
+ Internet:3G 1572602.0Kb,Universalnyi 144140.0Kb,Nat.rouming 0.0Kb;0.0SMS po Ukraini;0v mezhah Ukrainy;0na inshi mobilni Ukrainy
27
+
28
+ TODO
29
+ ----
30
+
31
+ Сделать так, чтобы была разбивка по типам баланса. Regexp наше все
32
+ Utel::Balance.detailed
33
+ => {
34
+ :primary => 46.06,
35
+ :pocket => 0.00,
36
+ :additional => 0.00,
37
+ :internet => {
38
+ :3g => 1572602.0,
39
+ :universal => 144140.0
40
+ },
41
+ :vas => {
42
+ :sms => 0,
43
+ :ukraine => 0,
44
+ :other => 0
45
+ }
46
+ }
47
+
48
+ FIXME
49
+ -----
50
+
51
+ Данные можно получить только после установления соединения с интернетом и получения каких-либо пакетных данных.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/balance.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'utel'
3
+
4
+ puts Utel::Balance.summary
5
+ puts Utel::Balance.vas
data/lib/utel.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "utel/version"
2
+ require "utel/balance"
3
+ require "utel/pdu"
4
+
5
+ module Utel
6
+ end
@@ -0,0 +1,42 @@
1
+ module Utel
2
+ class Balance
3
+ def self.summary
4
+ new.summary
5
+ end
6
+
7
+ def self.vas
8
+ new.vas
9
+ end
10
+
11
+ def summary
12
+ get_balance "*100#"
13
+ end
14
+
15
+ def vas
16
+ get_balance "*121#"
17
+ end
18
+
19
+ private
20
+ # @param [String] number USSD number service
21
+ def get_balance number
22
+ File.open("/dev/ttyUSB2", "w+") do |f|
23
+ f.write "AT+CUSD=1,#{Utel::Pdu.encode(number)},15\r\n"
24
+ parse_result f
25
+ end
26
+ end
27
+
28
+ def parse_result file_link
29
+ out = ''
30
+ while (s = file_link.gets) do
31
+ if s.slice(0, 5) == "+CUSD"
32
+ out << Utel::Pdu.decode(s.strip.slice(10..-5))
33
+ if out.include?("1 - Dalee")
34
+ file_link.write "AT+CUSD=1,#{Utel::Pdu.encode('1')},15\r\n"
35
+ else
36
+ break
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
data/lib/utel/pdu.rb ADDED
@@ -0,0 +1,34 @@
1
+ module Utel
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
13
+ end
14
+ out
15
+ end
16
+
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
29
+ end
30
+ end
31
+ out
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Utel
2
+ VERSION = "0.1.0"
3
+ end
data/utel.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path("../lib/", __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+ require "utel/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "utel"
8
+ s.version = Utel::VERSION
9
+ s.authors = ["Eugene Russkikh"]
10
+ s.email = ["eugene@russkikh.org.ua"]
11
+ s.homepage = "http://komba.org.ua"
12
+ s.summary = %q{Utel USSD}
13
+ s.description = %q{Utel USSD services balance checker}
14
+
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: utel
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Eugene Russkikh
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-13 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Utel USSD services balance checker
22
+ email:
23
+ - eugene@russkikh.org.ua
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - README.md
34
+ - Rakefile
35
+ - balance.rb
36
+ - lib/utel.rb
37
+ - lib/utel/balance.rb
38
+ - lib/utel/pdu.rb
39
+ - lib/utel/version.rb
40
+ - utel.gemspec
41
+ homepage: http://komba.org.ua
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.5
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Utel USSD
74
+ test_files: []
75
+