ruggby 0.3.0

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.
Files changed (40) hide show
  1. data/CHANGELOG.rdoc +2 -0
  2. data/Gemfile +2 -0
  3. data/MIT-LICENSE +20 -0
  4. data/Manifest +38 -0
  5. data/README.md +187 -0
  6. data/Rakefile +12 -0
  7. data/init.rb +1 -0
  8. data/lib/ruggby.rb +72 -0
  9. data/lib/ruggby/action/base.rb +16 -0
  10. data/lib/ruggby/action/change_status.rb +30 -0
  11. data/lib/ruggby/action/create_message.rb +27 -0
  12. data/lib/ruggby/action/login.rb +40 -0
  13. data/lib/ruggby/action/mark.rb +27 -0
  14. data/lib/ruggby/action/new_message.rb +28 -0
  15. data/lib/ruggby/action/ping.rb +40 -0
  16. data/lib/ruggby/action/read.rb +49 -0
  17. data/lib/ruggby/callback.rb +22 -0
  18. data/lib/ruggby/client.rb +95 -0
  19. data/lib/ruggby/converter.rb +57 -0
  20. data/lib/ruggby/logger.rb +67 -0
  21. data/lib/ruggby/packet/factory.rb +39 -0
  22. data/lib/ruggby/packet/incoming/base.rb +31 -0
  23. data/lib/ruggby/packet/incoming/login_status.rb +28 -0
  24. data/lib/ruggby/packet/incoming/message.rb +35 -0
  25. data/lib/ruggby/packet/incoming/welcome.rb +33 -0
  26. data/lib/ruggby/packet/outgoing/base.rb +67 -0
  27. data/lib/ruggby/packet/outgoing/change_status.rb +57 -0
  28. data/lib/ruggby/packet/outgoing/login.rb +75 -0
  29. data/lib/ruggby/packet/outgoing/mark.rb +28 -0
  30. data/lib/ruggby/packet/outgoing/message.rb +47 -0
  31. data/lib/ruggby/packet/outgoing/ping.rb +27 -0
  32. data/lib/ruggby/password.rb +19 -0
  33. data/lib/ruggby/socket.rb +67 -0
  34. data/lib/ruggby/string_encoder.rb +42 -0
  35. data/lib/ruggby/threader.rb +21 -0
  36. data/lib/ruggby/version.rb +5 -0
  37. data/ruggby.gemspec +35 -0
  38. data/spec/callback_spec.rb +40 -0
  39. data/spec/spec_helper.rb +7 -0
  40. metadata +142 -0
@@ -0,0 +1,42 @@
1
+ autoload :Iconv, 'iconv'
2
+
3
+
4
+ module RuGGby
5
+
6
+ # Methods used to do stuff on the strings
7
+ class StringEncoder
8
+
9
+ INPUT = 'UTF-8'
10
+ OUTPUT = 'windows-1250'
11
+
12
+ STRIP_REGEXP = /<span.*>(.*)<\/span>/ix
13
+
14
+ # Convert message into INPUT format
15
+ def self.to_input(msg)
16
+ msg.force_encoding(INPUT)
17
+ rescue
18
+ msg
19
+ end
20
+
21
+ # Convert message to OUTPUT format
22
+ def self.to_output(msg)
23
+ Iconv.iconv(OUTPUT, INPUT, msg).first.to_s
24
+ rescue
25
+ msg
26
+ end
27
+
28
+ # String all the tags and live the pure GG message
29
+ def self.strip(msg)
30
+ msg.scan(STRIP_REGEXP).first.first
31
+ rescue
32
+ msg
33
+ end
34
+
35
+ # Perform both strip and utf8 conversion
36
+ def self.complex(msg)
37
+ to_input(strip(msg))
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,21 @@
1
+ module RuGGby
2
+
3
+ # Class used to ignite actions in threads
4
+ class Threader
5
+
6
+ def self.run(client, element)
7
+ client.threads << Thread.new do
8
+ begin
9
+ client.logger.debug("RuGGby::Threader run #{element.class}")
10
+ element.run!
11
+ client.logger.debug("RuGGby::Threader finish #{element.class}")
12
+ rescue => e
13
+ client.logger.fatal("RuGGby::Threader #{e}")
14
+ raise e
15
+ end
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,5 @@
1
+ module RuGGby
2
+
3
+ VERSION = '0.3.0'
4
+
5
+ end
data/ruggby.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "ruggby"
5
+ s.version = "0.3.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Maciej Mensfeld"]
9
+ s.date = "2012-04-08"
10
+ s.description = "Gadu Gadu protocol client implementation in Ruby language"
11
+ s.email = "maciej@mensfeld.pl"
12
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.md", "lib/ruggby.rb", "lib/ruggby/action/base.rb", "lib/ruggby/action/change_status.rb", "lib/ruggby/action/create_message.rb", "lib/ruggby/action/login.rb", "lib/ruggby/action/mark.rb", "lib/ruggby/action/new_message.rb", "lib/ruggby/action/ping.rb", "lib/ruggby/action/read.rb", "lib/ruggby/callback.rb", "lib/ruggby/client.rb", "lib/ruggby/converter.rb", "lib/ruggby/logger.rb", "lib/ruggby/packet/factory.rb", "lib/ruggby/packet/incoming/base.rb", "lib/ruggby/packet/incoming/login_status.rb", "lib/ruggby/packet/incoming/message.rb", "lib/ruggby/packet/incoming/welcome.rb", "lib/ruggby/packet/outgoing/base.rb", "lib/ruggby/packet/outgoing/change_status.rb", "lib/ruggby/packet/outgoing/login.rb", "lib/ruggby/packet/outgoing/mark.rb", "lib/ruggby/packet/outgoing/message.rb", "lib/ruggby/packet/outgoing/ping.rb", "lib/ruggby/password.rb", "lib/ruggby/socket.rb", "lib/ruggby/string_encoder.rb", "lib/ruggby/threader.rb", "lib/ruggby/version.rb"]
13
+ s.files = ["CHANGELOG.rdoc", "Gemfile", "MIT-LICENSE", "README.md", "Rakefile", "init.rb", "lib/ruggby.rb", "lib/ruggby/action/base.rb", "lib/ruggby/action/change_status.rb", "lib/ruggby/action/create_message.rb", "lib/ruggby/action/login.rb", "lib/ruggby/action/mark.rb", "lib/ruggby/action/new_message.rb", "lib/ruggby/action/ping.rb", "lib/ruggby/action/read.rb", "lib/ruggby/callback.rb", "lib/ruggby/client.rb", "lib/ruggby/converter.rb", "lib/ruggby/logger.rb", "lib/ruggby/packet/factory.rb", "lib/ruggby/packet/incoming/base.rb", "lib/ruggby/packet/incoming/login_status.rb", "lib/ruggby/packet/incoming/message.rb", "lib/ruggby/packet/incoming/welcome.rb", "lib/ruggby/packet/outgoing/base.rb", "lib/ruggby/packet/outgoing/change_status.rb", "lib/ruggby/packet/outgoing/login.rb", "lib/ruggby/packet/outgoing/mark.rb", "lib/ruggby/packet/outgoing/message.rb", "lib/ruggby/packet/outgoing/ping.rb", "lib/ruggby/password.rb", "lib/ruggby/socket.rb", "lib/ruggby/string_encoder.rb", "lib/ruggby/threader.rb", "lib/ruggby/version.rb", "spec/callback_spec.rb", "spec/spec_helper.rb", "Manifest", "ruggby.gemspec"]
14
+ s.homepage = "https://github.com/mensfeld/ruGGby"
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ruggby", "--main", "README.md"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = "ruggby"
18
+ s.rubygems_version = "1.8.15"
19
+ s.summary = "Gadu Gadu protocol client implementation in Ruby language"
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
26
+ s.add_development_dependency(%q<mocha>, [">= 0"])
27
+ else
28
+ s.add_dependency(%q<rspec>, [">= 2.0.0"])
29
+ s.add_dependency(%q<mocha>, [">= 0"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<rspec>, [">= 2.0.0"])
33
+ s.add_dependency(%q<mocha>, [">= 0"])
34
+ end
35
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ ROOT = File.expand_path(File.dirname(__FILE__))
4
+
5
+ class Dummy
6
+ include RuGGby::Callback
7
+
8
+ attr_accessor :actions
9
+
10
+ def initialize
11
+ @actions = {}
12
+ end
13
+
14
+ end
15
+
16
+ describe RuGGby::Callback do
17
+ subject { Dummy.new }
18
+
19
+ context 'when we invoke on_new_message method' do
20
+ it 'should assign a block to actions' do
21
+ s = subject
22
+ s.actions[:new_message].should == nil
23
+ s.on_new_message do
24
+ self
25
+ end
26
+ s.actions[:new_message].should_not == nil
27
+ end
28
+ end
29
+
30
+ context 'when we invoke on_change_status method' do
31
+ it 'should assign a block to actions' do
32
+ s = subject
33
+ s.actions[:change_status].should == nil
34
+ s.on_change_status do
35
+ self
36
+ end
37
+ s.actions[:change_status].should_not == nil
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rubygems'
5
+ require 'ruggby'
6
+ require 'mocha'
7
+
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruggby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Maciej Mensfeld
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-08 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &9186120 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *9186120
25
+ - !ruby/object:Gem::Dependency
26
+ name: mocha
27
+ requirement: &9185560 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *9185560
36
+ description: Gadu Gadu protocol client implementation in Ruby language
37
+ email: maciej@mensfeld.pl
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files:
41
+ - CHANGELOG.rdoc
42
+ - README.md
43
+ - lib/ruggby.rb
44
+ - lib/ruggby/action/base.rb
45
+ - lib/ruggby/action/change_status.rb
46
+ - lib/ruggby/action/create_message.rb
47
+ - lib/ruggby/action/login.rb
48
+ - lib/ruggby/action/mark.rb
49
+ - lib/ruggby/action/new_message.rb
50
+ - lib/ruggby/action/ping.rb
51
+ - lib/ruggby/action/read.rb
52
+ - lib/ruggby/callback.rb
53
+ - lib/ruggby/client.rb
54
+ - lib/ruggby/converter.rb
55
+ - lib/ruggby/logger.rb
56
+ - lib/ruggby/packet/factory.rb
57
+ - lib/ruggby/packet/incoming/base.rb
58
+ - lib/ruggby/packet/incoming/login_status.rb
59
+ - lib/ruggby/packet/incoming/message.rb
60
+ - lib/ruggby/packet/incoming/welcome.rb
61
+ - lib/ruggby/packet/outgoing/base.rb
62
+ - lib/ruggby/packet/outgoing/change_status.rb
63
+ - lib/ruggby/packet/outgoing/login.rb
64
+ - lib/ruggby/packet/outgoing/mark.rb
65
+ - lib/ruggby/packet/outgoing/message.rb
66
+ - lib/ruggby/packet/outgoing/ping.rb
67
+ - lib/ruggby/password.rb
68
+ - lib/ruggby/socket.rb
69
+ - lib/ruggby/string_encoder.rb
70
+ - lib/ruggby/threader.rb
71
+ - lib/ruggby/version.rb
72
+ files:
73
+ - CHANGELOG.rdoc
74
+ - Gemfile
75
+ - MIT-LICENSE
76
+ - README.md
77
+ - Rakefile
78
+ - init.rb
79
+ - lib/ruggby.rb
80
+ - lib/ruggby/action/base.rb
81
+ - lib/ruggby/action/change_status.rb
82
+ - lib/ruggby/action/create_message.rb
83
+ - lib/ruggby/action/login.rb
84
+ - lib/ruggby/action/mark.rb
85
+ - lib/ruggby/action/new_message.rb
86
+ - lib/ruggby/action/ping.rb
87
+ - lib/ruggby/action/read.rb
88
+ - lib/ruggby/callback.rb
89
+ - lib/ruggby/client.rb
90
+ - lib/ruggby/converter.rb
91
+ - lib/ruggby/logger.rb
92
+ - lib/ruggby/packet/factory.rb
93
+ - lib/ruggby/packet/incoming/base.rb
94
+ - lib/ruggby/packet/incoming/login_status.rb
95
+ - lib/ruggby/packet/incoming/message.rb
96
+ - lib/ruggby/packet/incoming/welcome.rb
97
+ - lib/ruggby/packet/outgoing/base.rb
98
+ - lib/ruggby/packet/outgoing/change_status.rb
99
+ - lib/ruggby/packet/outgoing/login.rb
100
+ - lib/ruggby/packet/outgoing/mark.rb
101
+ - lib/ruggby/packet/outgoing/message.rb
102
+ - lib/ruggby/packet/outgoing/ping.rb
103
+ - lib/ruggby/password.rb
104
+ - lib/ruggby/socket.rb
105
+ - lib/ruggby/string_encoder.rb
106
+ - lib/ruggby/threader.rb
107
+ - lib/ruggby/version.rb
108
+ - spec/callback_spec.rb
109
+ - spec/spec_helper.rb
110
+ - Manifest
111
+ - ruggby.gemspec
112
+ homepage: https://github.com/mensfeld/ruGGby
113
+ licenses: []
114
+ post_install_message:
115
+ rdoc_options:
116
+ - --line-numbers
117
+ - --inline-source
118
+ - --title
119
+ - Ruggby
120
+ - --main
121
+ - README.md
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '1.2'
136
+ requirements: []
137
+ rubyforge_project: ruggby
138
+ rubygems_version: 1.8.15
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: Gadu Gadu protocol client implementation in Ruby language
142
+ test_files: []