cheezmiz 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.
@@ -0,0 +1,41 @@
1
+ = cheezmiz
2
+
3
+ a ruby library for Chikka
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == TODO
16
+ * Documentation
17
+ * Tests (d'oh!)
18
+ * Inbox functions
19
+ * Other buddy functions
20
+
21
+ == See Also
22
+
23
+ http://chikka.com
24
+ http://chix.sf.net
25
+
26
+ == Copyright
27
+ cheezmiz - a ruby library for Chikka
28
+ Copyright (c) 2010 parasquid. See LICENSE for details.
29
+
30
+ This program is free software: you can redistribute it and/or modify
31
+ it under the terms of the GNU Affero General Public License as published by
32
+ the Free Software Foundation, either version 3 of the License, or
33
+ (at your option) any later version.
34
+
35
+ This program is distributed in the hope that it will be useful,
36
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
37
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38
+ GNU Affero General Public License for more details.
39
+
40
+ You should have received a copy of the GNU Affero General Public License
41
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "cheezmiz"
8
+ gem.summary = 'a ruby library for Chikka'
9
+ gem.description = 'a ruby library for Chikka'
10
+ gem.email = "parasquid@gmail.com"
11
+ gem.homepage = "http://github.com/parasquid/cheezmiz"
12
+ gem.authors = ["parasquid"]
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/test_*.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "cheezmiz #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,20 @@
1
+
2
+ [indentation]
3
+ indent_width=2
4
+ indent_type=0
5
+ indent_hard_tab_width=2
6
+ detect_indent=false
7
+ indent_mode=3
8
+
9
+ [project]
10
+ name=cheezmiz
11
+ base_path=/home/kaliwanagan/projects/cheezmiz/
12
+ make_in_base_path=false
13
+ description=cheezmiz - a ruby library for Chikka
14
+ run_cmd=
15
+
16
+ [files]
17
+ current_page=0
18
+ FILE_NAME_0=5;Ruby;0;16;0;1;0;/home/kaliwanagan/projects/cheezmiz/lib/cheezmiz.rb;0
19
+ FILE_NAME_1=113;Ruby;0;16;0;1;0;/home/kaliwanagan/projects/cheezmiz/lib/broker.rb;0
20
+ FILE_NAME_2=987;Conf;0;16;0;1;0;/home/kaliwanagan/.config/geany/snippets.conf;0
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{cheezmiz}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["parasquid"]
12
+ s.date = %q{2010-02-19}
13
+ s.description = %q{a ruby library for Chikka}
14
+ s.email = %q{parasquid@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "cheezmiz.geany",
27
+ "cheezmiz.gemspec",
28
+ "docs/chikka-1.capture",
29
+ "examples/callbacks.rb",
30
+ "lib/broker.rb",
31
+ "lib/cheezmiz.rb",
32
+ "lib/helper.rb",
33
+ "lib/protocol.rb",
34
+ "lib/protocol/buddy.rb",
35
+ "lib/protocol/client_ready.rb",
36
+ "lib/protocol/connection_established.rb",
37
+ "lib/protocol/information.rb",
38
+ "lib/protocol/keep_alive.rb",
39
+ "lib/protocol/login.rb",
40
+ "lib/protocol/message.rb",
41
+ "lib/protocol/submit.rb",
42
+ "lib/protocol/system_message.rb",
43
+ "lib/protocol/unknown_operation.rb",
44
+ "test/helper.rb",
45
+ "test/test_cheezmiz.rb"
46
+ ]
47
+ s.homepage = %q{http://github.com/parasquid/cheezmiz}
48
+ s.rdoc_options = ["--charset=UTF-8"]
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = %q{1.3.5}
51
+ s.summary = %q{a ruby library for Chikka}
52
+ s.test_files = [
53
+ "test/test_cheezmiz.rb",
54
+ "test/helper.rb",
55
+ "examples/callbacks.rb"
56
+ ]
57
+
58
+ if s.respond_to? :specification_version then
59
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
60
+ s.specification_version = 3
61
+
62
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
63
+ else
64
+ end
65
+ else
66
+ end
67
+ end
68
+
@@ -0,0 +1,37 @@
1
+ CTPv1.2 Kamusta 122.52.247.56:11400 1265980959. Manila, Philippines!
2
+ 01:001 005:user@email.com 002:password 003:5 004:8 93
3
+ 51:001 004:1 44
4
+ 41:000 016:first_name 017:last_name 018:user@email.com 019:0 020:2 031: 022: 005: 024: 025: 026: 027:0 028:0 001:008841587 030:0 007:Chikka 021:0 023:0 006: 051: 029:0 041: 032: AD
5
+ 91:000 3F
6
+ 30:002 001:0 002:1 44
7
+ 31:004 010:639291234567 015:0 012:alias 008:0 016: 017: 018: 019:0 020:2 031: 022: 005: 024: 025: 026: 027:1 014:0 013:0 029:0 030:0 007:Smart Communications (PH) 023:0 021:0 050:0 032: 21
8
+ 39:006 001:0 4B
9
+ 89:006 4C
10
+ 14:003 001:639191234567 030:1 032:test message 24
11
+ 64:003 42
12
+ 56:003 010:639191234567 015:1 012: 008:0 016:first_name 017: 018: 019:0 020:0 031: 022: 005: 024: 025: 026: 027:1 014:0 013:0 029:0 030:0 007:Smart Communications (PH) 002:0 021:0 023:0 032: A9
13
+ 23:005 3F
14
+ 73:005 44
15
+ 30:008 001:4 002:28 87
16
+ 47:010 040:Smart Communications (PH) 041:20 042:1 55
17
+ 47:012 040:Globe Telecom (PH) 041:30 042:0 39
18
+ 47:014 040:Other U.S. Mobile Phones 041:30 042:0 8B
19
+ 47:016 040:Cingular Wireless (US) 041:20 042:0 1D
20
+ 47:018 040:SUN Cellular (PH) 041:20 042:0 B6
21
+ 47:020 040:Guamcell/Saipancell 041:20 042:0 B1
22
+ 47:022 040:INDIA Mobile Phones 041:10 042:0 C7
23
+ 47:024 040:Verizon Wireless (US) 041:20 042:0 D4
24
+ 47:026 040:Sprint (US) 041:20 042:0 FB
25
+ 47:028 040:Alltel (US) 041:20 042:0 DB
26
+ 47:030 040:Excelcomindo 041:20 042:0 37
27
+ 47:032 040:Nextel (US) 041:20 042:0 E8
28
+ 47:034 040:Boost (US) 041:20 042:0 81
29
+ 47:036 040:UK 041:30 042:0 04
30
+ 47:038 040:Spain 041:30 042:0 61
31
+ 47:040 040:1528 Smart (HK) 041:30 042:0 5A
32
+ 47:042 040:Smart Pinoy (Italy) 041:30 042:0 0B
33
+ 39:044 001:4 51
34
+ 89:044 4E
35
+
36
+
37
+
@@ -0,0 +1,84 @@
1
+ # cheezmiz - a ruby library for Chikka
2
+ # Copyright (C) 2010 parasquid
3
+ #
4
+ # This file is part of cheezmiz
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
20
+ require 'cheezmiz'
21
+
22
+ if __FILE__ == $0
23
+ CHIKKA_USERNAME = 'user@email.com'
24
+ CHIKKA_PASSWORD = 'password'
25
+ TEST_MESSAGE = 'a test message'
26
+
27
+ socket = TCPSocket.open('ctp-a.chikka.com', 6301)
28
+ broker = Cheezmiz::Broker.new :socket => socket
29
+ broker.register_callback(:connection_established) do |msg|
30
+ puts 'connection has been established'
31
+ message = Cheezmiz::LoginRequest.new(
32
+ :username => "#{CHIKKA_USERNAME}",
33
+ :password => "#{CHIKKA_PASSWORD}"
34
+ )
35
+ broker.send(message)
36
+ end
37
+
38
+ broker.register_callback(:login_response) {
39
+ puts 'login successful'
40
+ }
41
+
42
+ broker.register_callback(:account_information) do
43
+ puts 'received account information'
44
+ puts 'sending buddy list request'
45
+ broker.send(Cheezmiz::BuddyListRequest.new)
46
+ end
47
+
48
+ broker.register_callback(:buddy_information) do
49
+ puts 'received buddy information'
50
+ end
51
+
52
+ broker.register_callback(:buddy_list_end) do
53
+ broker.send(Cheezmiz::ClientReady.new)
54
+ end
55
+
56
+ broker.register_callback(:keep_alive_request) do |msg|
57
+ broker.send(Cheezmiz::KeepAliveResponse.new, :response_to => msg)
58
+ puts 'sending test message'
59
+ message = Cheezmiz::SubmitRequest.new(
60
+ :message => "#{TEST_MESSAGE}",
61
+ :buddy_number => 0
62
+ )
63
+ broker.send(message)
64
+ end
65
+
66
+ broker.register_callback(:submit_response) do
67
+ puts 'server has acknowledged submit request'
68
+ end
69
+
70
+ broker.register_callback(:incoming) do |msg|
71
+ if msg.operation == :unknown_operation
72
+ puts "unknown operation: #{msg.prototype}"
73
+ else
74
+ puts "incoming message #{msg.operation} #{msg.data_fields.inspect}"
75
+ end
76
+ end
77
+
78
+ broker.register_callback(:outgoing) do |msg|
79
+ puts "outgoing message: #{msg.operation} #{msg.data_fields.inspect}"
80
+ end
81
+
82
+ broker.start
83
+ broker.join
84
+ end
@@ -0,0 +1,120 @@
1
+ # cheezmiz - a ruby library for Chikka
2
+ # Copyright (C) 2010 parasquid
3
+ #
4
+ # This file is part of cheezmiz
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ $: << File.expand_path(File.dirname(__FILE__))
20
+ require 'socket'
21
+ require 'helper'
22
+ require 'protocol'
23
+
24
+ module Cheezmiz
25
+ class Broker
26
+ STX = "\x02"
27
+ ETX = "\x03"
28
+ def initialize(params = {})
29
+ @socket = params[:socket] || begin
30
+ params[:host] ||= 'ctp-a.chikka.com'
31
+ params[:port] ||= 6301
32
+ TCPSocket.open(params[:host], params[:port])
33
+ end
34
+ @sequence_number = 1
35
+ @callbacks = Hash.new { |hash, key| hash[key] = [] }
36
+ end
37
+
38
+ def register_callback(operation, &proc)
39
+ @callbacks[operation] << proc
40
+ end
41
+
42
+ def register_observer(observer, &proc)
43
+ @observers[observer] << proc
44
+ end
45
+
46
+ def callbacks
47
+ @callbacks
48
+ end
49
+
50
+ def observers
51
+ @observers
52
+ end
53
+
54
+ def send(message, params = {})
55
+ raw = encode({ :message => message }.merge(params))
56
+ result = @socket.send(raw, 0)
57
+ process_callbacks(@callbacks[:outgoing], message)
58
+ return raw, result
59
+ end
60
+
61
+ def start
62
+ @thread = Thread.new do
63
+ @socket.while_reading { |buffer| process_messages(buffer) }
64
+ end
65
+ end
66
+
67
+ def join
68
+ @thread.join
69
+ end
70
+
71
+ private
72
+
73
+ def tokenize(stream)
74
+ #TODO: handle incomplete messages
75
+ stream.scan(/.*?|^CTPv1\.[123] Kamusta.*/)
76
+ end
77
+
78
+ def checksum(message)
79
+ checksum = 0
80
+ message.bytes.each do |b|
81
+ checksum += b
82
+ checksum &= 0xFF
83
+ end
84
+ checksum
85
+ end
86
+
87
+ def encode(options)
88
+ raw = "#{STX}" + options[:message].prototype
89
+ sequence_number = begin
90
+ options[:response_to].sequence_number
91
+ rescue NoMethodError
92
+ options[:response_to]
93
+ end || @sequence_number
94
+ raw.sub! /NNN/, sequence_number.to_s.rjust(3, '0')
95
+ @sequence_number += 2
96
+ @sequence_number &= 0xFF
97
+ raw + sprintf('%2X', checksum(raw)) + "#{ETX}"
98
+ end
99
+
100
+ def process_messages(buffer)
101
+ tokenize(buffer).each do |raw|
102
+ message = Message.parse(raw)
103
+ process_callbacks(@callbacks[:incoming], message)
104
+ process_callbacks(@callbacks, message)
105
+ end
106
+ end
107
+
108
+ def process_callbacks(callbacks, message)
109
+ if callbacks.respond_to? :each_pair
110
+ callbacks[message.operation].each do |callback|
111
+ callback.call(message)
112
+ end
113
+ else
114
+ callbacks.each do |callback|
115
+ callback.call(message)
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,20 @@
1
+ # cheezmiz - a ruby library for Chikka
2
+ # Copyright (C) 2010 parasquid
3
+ #
4
+ # This file is part of cheezmiz
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ $: << File.expand_path(File.dirname(__FILE__))
20
+ require 'broker'