ruggby 0.3.2.1 → 0.3.3

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 80171c0ba9069ce373bab30b0163f849cd9bff96
4
+ data.tar.gz: 47ca496e0a459e95cac0626a00265d40900f637b
5
+ SHA512:
6
+ metadata.gz: ed4dd9b23bb589f3034fafd95fc4f2209104ecf4c71a5c204315ce24cec67f5e6184dde4b2c5dfa3da6c6b46f8a299d83f7cfd25a5593f756c0920598ae5f880
7
+ data.tar.gz: 748a24a0ec15c6040c0513bbdce4bf648edd287f1d4657b05b93c3bfe56d1eb9324478a786587d767d118f0566f016ad9c3481f2c9b3409b1d07adeba8b8a038
@@ -4,3 +4,5 @@
4
4
  * Multiply lines handler fix
5
5
  = Version 0.3.2.1
6
6
  * Gsub fix (fuc**ng exclamation)
7
+ = Version 0.3.3
8
+ * Added buddy list status change observer
data/Manifest CHANGED
@@ -1,16 +1,19 @@
1
1
  CHANGELOG.rdoc
2
2
  Gemfile
3
3
  MIT-LICENSE
4
+ Manifest
4
5
  README.md
5
6
  Rakefile
6
7
  init.rb
7
8
  lib/ruggby.rb
8
9
  lib/ruggby/action/base.rb
9
10
  lib/ruggby/action/change_status.rb
11
+ lib/ruggby/action/check_uin_status.rb
10
12
  lib/ruggby/action/create_message.rb
11
13
  lib/ruggby/action/login.rb
12
14
  lib/ruggby/action/mark.rb
13
15
  lib/ruggby/action/new_message.rb
16
+ lib/ruggby/action/new_status.rb
14
17
  lib/ruggby/action/ping.rb
15
18
  lib/ruggby/action/read.rb
16
19
  lib/ruggby/callback.rb
@@ -21,9 +24,11 @@ lib/ruggby/packet/factory.rb
21
24
  lib/ruggby/packet/incoming/base.rb
22
25
  lib/ruggby/packet/incoming/login_status.rb
23
26
  lib/ruggby/packet/incoming/message.rb
27
+ lib/ruggby/packet/incoming/status.rb
24
28
  lib/ruggby/packet/incoming/welcome.rb
25
29
  lib/ruggby/packet/outgoing/base.rb
26
30
  lib/ruggby/packet/outgoing/change_status.rb
31
+ lib/ruggby/packet/outgoing/check_uin_status.rb
27
32
  lib/ruggby/packet/outgoing/login.rb
28
33
  lib/ruggby/packet/outgoing/mark.rb
29
34
  lib/ruggby/packet/outgoing/message.rb
@@ -33,6 +38,6 @@ lib/ruggby/socket.rb
33
38
  lib/ruggby/string_encoder.rb
34
39
  lib/ruggby/threader.rb
35
40
  lib/ruggby/version.rb
41
+ ruggby.gemspec
36
42
  spec/callback_spec.rb
37
43
  spec/spec_helper.rb
38
- Manifest
data/README.md CHANGED
@@ -130,6 +130,7 @@ RuGGby supports events, so you can assign your own events on demand. Events list
130
130
  * :login - event triggered after login
131
131
  * :create_message - event triggered after message has been send
132
132
  * :change_status - event triggered after our status/description change
133
+ * :status_changed - event triggered after someone on buddy list change status
133
134
 
134
135
  Each event block is triggered with parameters:
135
136
 
@@ -140,6 +141,7 @@ Each event block is triggered with parameters:
140
141
  * :login - no parameters
141
142
  * :create_message(uin, message)
142
143
  * :change_status(status, description)
144
+ * :check_uin_status(uin)
143
145
 
144
146
  In order to assign an action to an event, pass a block into events hash:
145
147
 
@@ -166,6 +168,17 @@ end
166
168
 
167
169
  The *:new_message* event is triggered in a separate thread so the socket read process is still going. The above code will (after login!) return a message to it's sender.
168
170
 
171
+ To add a friend to a buddy list to listening his status you can:
172
+
173
+ ```ruby
174
+ gg.check_uin_status(uin) # to listen buddy initial status, move this line after 'on_status_changed'
175
+
176
+ gg.on_status_changed do |uin,status|
177
+ print "Friend #{uin} changed status to #{status}"
178
+ end
179
+
180
+ ```
181
+
169
182
  ## TODO
170
183
 
171
184
  * Tests (currently there is no :()
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('ruggby', '0.3.2.1') do |p|
5
+ Echoe.new('ruggby', '0.3.3') do |p|
6
6
  p.description = 'Gadu Gadu protocol client implementation in Ruby language'
7
7
  p.url = 'https://github.com/mensfeld/ruGGby'
8
8
  p.author = 'Maciej Mensfeld'
data/init.rb CHANGED
@@ -1 +1,2 @@
1
1
  require 'ruggby'
2
+ require 'iconv'
@@ -19,54 +19,58 @@ $:.unshift File.dirname(__FILE__)
19
19
 
20
20
  module RuGGby
21
21
 
22
- autoload :Version, 'ruggby/version.rb'
22
+ autoload :Version, 'ruggby/version'
23
23
 
24
24
  module Packet
25
25
  # Factory used to build incoming packets out of raw socket messages
26
- autoload :Factory, 'ruggby/packet/factory.rb'
26
+ autoload :Factory, 'ruggby/packet/factory'
27
27
 
28
28
  # Incoming packets used to wrap the raw socket messages send by GG server
29
29
  module Incoming
30
30
  path = 'ruggby/packet/incoming'
31
- autoload :Base, "#{path}/base.rb"
32
- autoload :LoginStatus, "#{path}/login_status.rb"
33
- autoload :Message, "#{path}/message.rb"
34
- autoload :Welcome, "#{path}/welcome.rb"
31
+ autoload :Base, "#{path}/base"
32
+ autoload :LoginStatus, "#{path}/login_status"
33
+ autoload :Message, "#{path}/message"
34
+ autoload :Status, "#{path}/status"
35
+ autoload :Welcome, "#{path}/welcome"
35
36
  end
36
37
 
37
38
  # Outgoing packets send to GG server
38
39
  module Outgoing
39
40
  path = 'ruggby/packet/outgoing'
40
- autoload :Base, "#{path}/base.rb"
41
- autoload :Login, "#{path}/login.rb"
42
- autoload :Mark, "#{path}/mark.rb"
43
- autoload :Message, "#{path}/message.rb"
44
- autoload :Ping, "#{path}/ping.rb"
45
- autoload :ChangeStatus, "#{path}/change_status.rb"
41
+ autoload :Base, "#{path}/base"
42
+ autoload :Login, "#{path}/login"
43
+ autoload :Mark, "#{path}/mark"
44
+ autoload :Message, "#{path}/message"
45
+ autoload :Ping, "#{path}/ping"
46
+ autoload :ChangeStatus, "#{path}/change_status"
47
+ autoload :CheckUinStatus, "#{path}/check_uin_status"
46
48
  end
47
49
  end
48
50
 
49
51
  # Available actions (we can hookup to all of them)
50
52
  module Action
51
53
  path = 'ruggby/action'
52
- autoload :Base, "#{path}/base.rb"
53
- autoload :CreateMessage, "#{path}/create_message.rb"
54
- autoload :Login, "#{path}/login.rb"
55
- autoload :Mark, "#{path}/mark.rb"
56
- autoload :NewMessage, "#{path}/new_message.rb"
57
- autoload :Ping, "#{path}/ping.rb"
58
- autoload :Read, "#{path}/read.rb"
59
- autoload :ChangeStatus, "#{path}/change_status.rb"
54
+ autoload :Base, "#{path}/base"
55
+ autoload :CreateMessage, "#{path}/create_message"
56
+ autoload :Login, "#{path}/login"
57
+ autoload :Mark, "#{path}/mark"
58
+ autoload :NewMessage, "#{path}/new_message"
59
+ autoload :NewStatus, "#{path}/new_status"
60
+ autoload :Ping, "#{path}/ping"
61
+ autoload :Read, "#{path}/read"
62
+ autoload :ChangeStatus, "#{path}/change_status"
63
+ autoload :CheckUinStatus, "#{path}/check_uin_status"
60
64
  end
61
65
 
62
66
  # Other stuff that is needed
63
- autoload :Socket, 'ruggby/socket'
64
- autoload :Logger, 'ruggby/logger'
65
- autoload :Callback, 'ruggby/callback'
66
- autoload :Converter, 'ruggby/converter'
67
- autoload :Password, 'ruggby/password'
68
- autoload :Threader, 'ruggby/threader'
67
+ autoload :Socket, 'ruggby/socket'
68
+ autoload :Logger, 'ruggby/logger'
69
+ autoload :Callback, 'ruggby/callback'
70
+ autoload :Converter, 'ruggby/converter'
71
+ autoload :Password, 'ruggby/password'
72
+ autoload :Threader, 'ruggby/threader'
69
73
  autoload :StringEncoder, 'ruggby/string_encoder'
70
- autoload :Client, 'ruggby/client'
74
+ autoload :Client, 'ruggby/client'
71
75
 
72
76
  end
@@ -8,9 +8,9 @@ module RuGGby
8
8
  attr_reader :status, :description
9
9
 
10
10
  def initialize(client, status, description)
11
- @client = client
12
- @block = client.actions[:change_status]
13
- @status = status
11
+ @client = client
12
+ @block = client.actions[:change_status]
13
+ @status = status
14
14
  @description = description
15
15
  end
16
16
 
@@ -0,0 +1,25 @@
1
+ module RuGGby
2
+
3
+ module Action
4
+
5
+ class CheckUinStatus < Base
6
+
7
+ def initialize(client, uin)
8
+ @client = client
9
+ @uin = uin
10
+ end
11
+
12
+ def run!
13
+ @client.logger.debug('RuGGby::Action::CheckUinStatus')
14
+
15
+ msg = Packet::Outgoing::CheckUinStatus.new(@uin)
16
+ @client.socket.write(msg)
17
+
18
+ @block.call(@uin) if @block
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -6,9 +6,9 @@ module RuGGby
6
6
  class CreateMessage < Base
7
7
 
8
8
  def initialize(client, uin, message)
9
- @client = client
10
- @block = client.actions[:create_message]
11
- @uin = uin
9
+ @client = client
10
+ @block = client.actions[:create_message]
11
+ @uin = uin
12
12
  @message = message
13
13
  end
14
14
 
@@ -7,7 +7,7 @@ module RuGGby
7
7
 
8
8
  def initialize(client)
9
9
  @client = client
10
- @block = client.actions[:login]
10
+ @block = client.actions[:login]
11
11
  end
12
12
 
13
13
  def run!
@@ -16,10 +16,10 @@ module RuGGby
16
16
  welcome = RuGGby::Packet::Factory.new(@client.socket).build
17
17
 
18
18
  login = Packet::Outgoing::Login.new(
19
- :uin => @client.login,
20
- :hash => Password.hash(@client.password, welcome.seed),
21
- :status => @client.status,
22
- :description => @client.description
19
+ :uin => @client.login,
20
+ :hash => Password.hash(@client.password, welcome.seed),
21
+ :status => @client.status,
22
+ :description => @client.description
23
23
  )
24
24
 
25
25
  @client.logger.debug('RuGGby::Action::Login sending Login packet')
@@ -28,7 +28,7 @@ module RuGGby
28
28
  login_status = RuGGby::Packet::Factory.new(@client.socket).build
29
29
 
30
30
  @client.logger.debug("RuGGby::Action::Login #{login_status.class}")
31
-
31
+
32
32
  @client.logged = login_status.successful?
33
33
  @block.call if @block
34
34
  end
@@ -8,7 +8,7 @@ module RuGGby
8
8
 
9
9
  def initialize(client)
10
10
  @client = client
11
- @block = client.actions[:mark]
11
+ @block = client.actions[:mark]
12
12
  end
13
13
 
14
14
  # Send a mark packet
@@ -8,11 +8,11 @@ module RuGGby
8
8
  attr_reader :uin, :message
9
9
 
10
10
  def initialize(client, data)
11
- @client = client
12
- @block = client.actions[:new_message]
13
- @uin = data[0]
11
+ @client = client
12
+ @block = client.actions[:new_message]
13
+ @uin = data[0]
14
14
  @created_at = Time.at(data[2])
15
- @message = StringEncoder.complex(data[4])
15
+ @message = StringEncoder.complex(data[4])
16
16
  end
17
17
 
18
18
  def run!
@@ -0,0 +1,29 @@
1
+ module RuGGby
2
+
3
+ module Action
4
+
5
+ # Action invoken when new message occures
6
+ class NewStatus < Base
7
+
8
+ attr_reader :uin, :status
9
+
10
+ def initialize(client, data)
11
+ @client = client
12
+ @block = client.actions[:status_changed]
13
+ @uin = data[0]
14
+ @status = data[1]
15
+ end
16
+
17
+ def run!
18
+ if @uin && @status
19
+ @client.logger.debug('RuGGby::Action::NewStatus')
20
+ @status = RuGGby::Converter::FROM_STATUS[@status]
21
+ @block.call(@uin, @status) if @block
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -13,7 +13,7 @@ module RuGGby
13
13
 
14
14
  def initialize(client)
15
15
  @client = client
16
- @block = client.actions[:ping]
16
+ @block = client.actions[:ping]
17
17
  end
18
18
 
19
19
  def run!
@@ -10,7 +10,7 @@ module RuGGby
10
10
 
11
11
  def initialize(client)
12
12
  @client = client
13
- @block = client.actions[:read]
13
+ @block = client.actions[:read]
14
14
  end
15
15
 
16
16
  # Start a thread that reads data and if there is any data - try to create
@@ -30,6 +30,9 @@ module RuGGby
30
30
  when :new_message then
31
31
  action = RuGGby::Action::NewMessage.new(@client, el.data)
32
32
  Threader.run(@client, action)
33
+ when :status_changed then
34
+ action = RuGGby::Action::NewStatus.new(@client, el.data)
35
+ Threader.run(@client, action)
33
36
  end
34
37
 
35
38
  @block.call(el) if @block
@@ -17,6 +17,10 @@ module RuGGby
17
17
  self.actions[:change_status] = block
18
18
  end
19
19
 
20
+ def on_status_changed(&block)
21
+ self.actions[:status_changed] = block
22
+ end
23
+
20
24
  end
21
25
 
22
26
  end
@@ -10,20 +10,20 @@ module RuGGby
10
10
  attr_accessor :log_level
11
11
  end
12
12
 
13
- @logger ||= RuGGby::Logger
13
+ @logger ||= RuGGby::Logger
14
14
  @log_level ||= :debug
15
15
 
16
16
  attr_reader :socket, :password
17
17
  attr_writer :logged
18
- attr_accessor :loops, :actions, :threads, :reconnect, :status,
19
- :description, :login, :logger
18
+ attr_accessor :loops, :actions, :threads, :reconnect, :status,
19
+ :description, :login, :logger
20
20
 
21
21
  def initialize()
22
- @loops = {}
22
+ @loops = {}
23
23
  @actions = {}
24
24
  @threads = []
25
- @logged = false
26
- @logger = self.class.logger.new(self.class.log_level)
25
+ @logged = false
26
+ @logger = self.class.logger.new(self.class.log_level)
27
27
 
28
28
  @logger.debug('RuGGby::Client initialized')
29
29
  end
@@ -31,9 +31,9 @@ module RuGGby
31
31
  def login!(gg_nr, password, params = {})
32
32
  @logger.debug('RuGGby::Client login in')
33
33
 
34
- @login = gg_nr
35
- @password = password
36
- @status = params[:status] || :available
34
+ @login = gg_nr
35
+ @password = password
36
+ @status = params[:status] || :available
37
37
  @description = params[:description]
38
38
 
39
39
  if logged?
@@ -59,7 +59,7 @@ module RuGGby
59
59
  RuGGby::Action::Ping.new(self).run!
60
60
  RuGGby::Action::Read.new(self).run!
61
61
  end
62
-
62
+
63
63
  @logged
64
64
  end
65
65
 
@@ -70,8 +70,8 @@ module RuGGby
70
70
  def logout!
71
71
  @logger.debug('RuGGby::Client logout')
72
72
 
73
- @threads.each { |t| t.exit }
74
- @loops.each { |k, v| v.exit }
73
+ @threads.each { |t| t.exit }
74
+ @loops.each { |k, v| v.exit }
75
75
  @socket.close
76
76
  @logged = false
77
77
  end
@@ -90,6 +90,12 @@ module RuGGby
90
90
  @loops[:ping].join
91
91
  end
92
92
 
93
+ def check_uin_status(uin)
94
+ @logger.debug('RuGGby::Client checking buddy')
95
+
96
+ RuGGby::Action::CheckUinStatus.new(self, uin).run!
97
+ end
98
+
93
99
  end
94
100
 
95
101
  end
@@ -5,35 +5,42 @@ module RuGGby
5
5
 
6
6
  # Available actions
7
7
  ACTION = {
8
- Packet::Incoming::Message::TYPE => :new_message
8
+ Packet::Incoming::Message::TYPE => :new_message,
9
+ Packet::Incoming::Status::TYPE => :status_changed
9
10
  }
10
11
 
11
12
  # Available statuses (sent by GG server)
12
13
  STATUS = {
13
- 0x02 => :available,
14
- 0x04 => :available,
15
- 0x03 => :busy,
16
- 0x05 => :busy,
17
- 0x14 => :invisible,
18
- 0x16 => :invisible,
19
- 0x01 => :not_available,
20
- 0x15 => :not_available
14
+ 0x02 => :available,
15
+ 0x04 => :available,
16
+ 0x03 => :busy,
17
+ 0x05 => :busy,
18
+ 0x14 => :invisible,
19
+ 0x16 => :invisible,
20
+ 0x01 => :not_available,
21
+ 0x15 => :not_available
21
22
  }
22
23
 
23
24
  # Statuses that we can use
24
25
  TO_STATUS = {
25
- :available => 0x02,
26
- :busy => 0x03,
27
- :invisible => 0x14,
28
- :not_available => 0x01
26
+ :available => 0x02,
27
+ :busy => 0x03,
28
+ :invisible => 0x14,
29
+ :not_available => 0x01
30
+ }
31
+
32
+ FROM_STATUS = {
33
+ 0x02 => :available,
34
+ 0x03 => :busy,
35
+ 0x01 => :not_available
29
36
  }
30
37
 
31
38
  # Statuses that are available but we also need to provide a description
32
39
  TO_STATUS_DESCRIPTION = {
33
- :available => 0x04,
34
- :busy => 0x05,
35
- :invisible => 0x16,
36
- :not_available => 0x15
40
+ :available => 0x04,
41
+ :busy => 0x05,
42
+ :invisible => 0x16,
43
+ :not_available => 0x15
37
44
  }
38
45
 
39
46
  def self.status(status)
@@ -2,16 +2,16 @@ module RuGGby
2
2
 
3
3
  class Logger
4
4
 
5
- DEBUG = 0
6
- INFO = 1
7
- ERROR = 2
8
- FATAL = 3
5
+ DEBUG = 0
6
+ INFO = 1
7
+ ERROR = 2
8
+ FATAL = 3
9
9
 
10
10
  LEVEL_MAP = {
11
- :debug => DEBUG,
12
- :info => INFO,
13
- :error => ERROR,
14
- :fatal => FATAL
11
+ :debug => DEBUG,
12
+ :info => INFO,
13
+ :error => ERROR,
14
+ :fatal => FATAL
15
15
  }
16
16
 
17
17
  # Available log levels
@@ -24,19 +24,27 @@ module RuGGby
24
24
 
25
25
  # Returns +true+ iff the current level allows for the printing of
26
26
  # +DEBUG+ messages.
27
- def debug?; @level <= DEBUG; end
27
+ def debug?;
28
+ @level <= DEBUG;
29
+ end
28
30
 
29
31
  # Returns +true+ iff the current level allows for the printing of
30
32
  # +INFO+ messages.
31
- def info?; @level <= INFO; end
33
+ def info?;
34
+ @level <= INFO;
35
+ end
32
36
 
33
37
  # Returns +true+ iff the current level allows for the printing of
34
38
  # +ERROR+ messages.
35
- def error?; @level <= ERROR; end
39
+ def error?;
40
+ @level <= ERROR;
41
+ end
36
42
 
37
43
  # Returns +true+ iff the current level allows for the printing of
38
44
  # +FATAL+ messages.
39
- def fatal?; @level <= FATAL; end
45
+ def fatal?;
46
+ @level <= FATAL;
47
+ end
40
48
 
41
49
  def debug(msg)
42
50
  handle_message(msg, :debug)
@@ -25,6 +25,10 @@ module RuGGby
25
25
  Packet::Incoming::LoginStatus.new(true)
26
26
  when Packet::Incoming::Message::TYPE then
27
27
  Packet::Incoming::Message.new(@data)
28
+ when Packet::Incoming::Status::TYPE then
29
+ Packet::Incoming::Status.new(@data)
30
+ when Packet::Incoming::Status::TYPE_2 then
31
+ Packet::Incoming::Status.new(@data)
28
32
  when nil
29
33
  Packet::Incoming::LoginStatus.new(false)
30
34
  else
@@ -35,5 +39,5 @@ module RuGGby
35
39
  end
36
40
 
37
41
  end
38
-
42
+
39
43
  end
@@ -8,7 +8,8 @@ module RuGGby
8
8
  # Unpacks the data accorging to the pattern method
9
9
  class Base
10
10
 
11
- class NotImplemented < Exception; end
11
+ class NotImplemented < Exception;
12
+ end
12
13
 
13
14
  attr_reader :data
14
15
 
@@ -8,16 +8,16 @@ module RuGGby
8
8
  # Message packet contains not formatted data (not parsed, etc) so
9
9
  class Message < RuGGby::Packet::Incoming::Base
10
10
 
11
- TYPE = 0x002e
11
+ TYPE = 0x002e
12
12
  PATTERN = 'LLLLa*'
13
13
 
14
14
  attr_reader :uin, :message, :data, :created_at
15
15
 
16
16
  def initialize(data)
17
17
  super
18
- @uin = @data[0]
18
+ @uin = @data[0]
19
19
  @created_at = @data[2]
20
- @message = @data[4]
20
+ @message = @data[4]
21
21
  end
22
22
 
23
23
  private
@@ -0,0 +1,35 @@
1
+ module RuGGby
2
+
3
+ module Packet
4
+
5
+ module Incoming
6
+
7
+ # Packet containing and incoming message
8
+ # Message packet contains not formatted data (not parsed, etc) so
9
+ class Status < RuGGby::Packet::Incoming::Base
10
+
11
+ TYPE = 0x0036
12
+ TYPE_2 = 0x0037
13
+ PATTERN = 'LLa*'
14
+
15
+ attr_reader :uin, :status
16
+
17
+ def initialize(data)
18
+ super
19
+ @uin = @data[0]
20
+ @status = @data[1]
21
+ end
22
+
23
+ private
24
+
25
+ def pattern
26
+ PATTERN
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -8,7 +8,7 @@ module RuGGby
8
8
  # Contains a seed used to mix with password before authorization
9
9
  class Welcome < RuGGby::Packet::Incoming::Base
10
10
 
11
- TYPE = 0x0001
11
+ TYPE = 0x0001
12
12
  PATTERN = 'I'
13
13
 
14
14
  attr_reader :seed
@@ -22,7 +22,8 @@ module RuGGby
22
22
 
23
23
  end
24
24
 
25
- class NotImplemented < Exception; end
25
+ class NotImplemented < Exception;
26
+ end
26
27
 
27
28
  def initialize(params = {})
28
29
  params.each do |key, value|
@@ -61,7 +62,7 @@ module RuGGby
61
62
  end
62
63
 
63
64
  end
64
-
65
+
65
66
  end
66
67
 
67
68
  end
@@ -10,8 +10,8 @@ module RuGGby
10
10
  # => description
11
11
  class ChangeStatus < RuGGby::Packet::Outgoing::Base
12
12
 
13
- TYPE = 0x0038
14
- PATTERN = 'LLL'
13
+ TYPE = 0x0038
14
+ PATTERN = 'LLL'
15
15
 
16
16
  attr_accessor :status, :description
17
17
 
@@ -29,10 +29,10 @@ module RuGGby
29
29
 
30
30
  def body
31
31
  [
32
- @status, # L
33
- 0, # L
34
- @description.length, # L
35
- @description # a
32
+ @status, # L
33
+ 0, # L
34
+ @description.length, # L
35
+ @description # a
36
36
  ]
37
37
  end
38
38
 
@@ -0,0 +1,43 @@
1
+ module RuGGby
2
+
3
+ module Packet
4
+
5
+ module Outgoing
6
+
7
+ # Out going check uin status class
8
+ # When we want to check if someone is available or not we need to provide
9
+ # a GG number
10
+ class CheckUinStatus < RuGGby::Packet::Outgoing::Base
11
+
12
+ TYPE = 0x000d
13
+ PATTERN = 'LC'
14
+
15
+ attr_accessor :uin
16
+
17
+ # uin => GG nr
18
+ def initialize(uin)
19
+ # Type uin (gg number) to integer, just to be sure
20
+ @uin = uin.to_i
21
+ end
22
+
23
+ private
24
+
25
+ def body
26
+ [@uin, 0x03]
27
+ end
28
+
29
+ def pattern
30
+ PATTERN
31
+ end
32
+
33
+ def type
34
+ TYPE
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -13,8 +13,8 @@ module RuGGby
13
13
  # => :status
14
14
  class Login < RuGGby::Packet::Outgoing::Base
15
15
 
16
- TYPE = 0x0031
17
- PATTERN = 'La2Ca64LLLLSLSCCLa35L'
16
+ TYPE = 0x0031
17
+ PATTERN = 'La2Ca64LLLLSLSCCLa35L'
18
18
  GG_VERSION = 'Gadu-Gadu Client build 10.0.0.10450'
19
19
 
20
20
  attr_accessor :uin, :hash, :status, :description
@@ -34,23 +34,23 @@ module RuGGby
34
34
 
35
35
  def body
36
36
  [
37
- @uin.to_i, # L
38
- 'pl', # a2
39
- 0x02, # C
40
- @hash, # a64
41
- @status, # L
42
- 0, # L
43
- 0x00000007, # L
44
- 0, # L
45
- 0, # S
46
- 0, # L
47
- 0, # S
48
- 64, # C
49
- 0x64, # C
50
- GG_VERSION.length, # L
51
- GG_VERSION, #a35
52
- @description.length, #L,
53
- @description # Nothing?
37
+ @uin.to_i, # L
38
+ 'pl', # a2
39
+ 0x02, # C
40
+ @hash, # a64
41
+ @status, # L
42
+ 0, # L
43
+ 0x00000007, # L
44
+ 0, # L
45
+ 0, # S
46
+ 0, # L
47
+ 0, # S
48
+ 64, # C
49
+ 0x64, # C
50
+ GG_VERSION.length, # L
51
+ GG_VERSION, #a35
52
+ @description.length, #L,
53
+ @description # Nothing?
54
54
  ]
55
55
  end
56
56
 
@@ -9,7 +9,7 @@ module RuGGby
9
9
  # a GG number an a message
10
10
  class Message < RuGGby::Packet::Outgoing::Base
11
11
 
12
- TYPE = 0x0b
12
+ TYPE = 0x0b
13
13
  PATTERN = 'LLLa*C'
14
14
 
15
15
  attr_accessor :message, :uin
@@ -8,9 +8,10 @@ module RuGGby
8
8
  # GG version that we send to the URL
9
9
  VERSION = '10.0.0.7669'
10
10
  # URL with 'real' server address
11
- URL = 'http://appmsg.gadu-gadu.pl'
11
+ URL = 'http://appmsg.gadu-gadu.pl'
12
12
 
13
- class NotOperating < Exception; end
13
+ class NotOperating < Exception;
14
+ end
14
15
 
15
16
  attr_reader :host, :port
16
17
 
@@ -42,7 +43,7 @@ module RuGGby
42
43
 
43
44
  # Create a TCPSocket
44
45
  def socket
45
- @socket ||= ::TCPSocket.new(@host , @port)
46
+ @socket ||= ::TCPSocket.new(@host, @port)
46
47
  end
47
48
 
48
49
  # Get connection params
@@ -51,8 +52,8 @@ module RuGGby
51
52
  {:host => gg_info[0], :port => gg_info[1]}
52
53
  end
53
54
 
54
- # Buduje caly adres ktory bedziemy odpytywac o IP i port serwera do laczenia
55
- # sie z GG
55
+ # Build the whole GG address
56
+ # It is needed to obtain the "real" server IP address
56
57
  def self.build_url(gg_nr)
57
58
  @build_url ||= "#{URL}/appsvc/appmsg_ver8.asp?fmnumber=#{gg_nr}&version=#{VERSION}&lastmsg=0"
58
59
  end
@@ -6,7 +6,7 @@ module RuGGby
6
6
  # Methods used to do stuff on the strings
7
7
  class StringEncoder
8
8
 
9
- INPUT = 'UTF-8'
9
+ INPUT = 'UTF-8'
10
10
  OUTPUT = 'windows-1250'
11
11
 
12
12
  STRIP_REGEXP = /<span.*?>(.*)<\/span>/ix
@@ -1,5 +1,5 @@
1
1
  module RuGGby
2
2
 
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.3'
4
4
 
5
5
  end
@@ -1,25 +1,26 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # stub: ruggby 0.3.3 ruby lib
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = "ruggby"
5
- s.version = "0.3.2.1"
6
+ s.version = "0.3.3"
6
7
 
7
8
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib"]
8
10
  s.authors = ["Maciej Mensfeld"]
9
- s.date = "2012-04-08"
11
+ s.date = "2014-08-13"
10
12
  s.description = "Gadu Gadu protocol client implementation in Ruby language"
11
13
  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.extra_rdoc_files = ["CHANGELOG.rdoc", "README.md", "lib/ruggby.rb", "lib/ruggby/action/base.rb", "lib/ruggby/action/change_status.rb", "lib/ruggby/action/check_uin_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/new_status.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/status.rb", "lib/ruggby/packet/incoming/welcome.rb", "lib/ruggby/packet/outgoing/base.rb", "lib/ruggby/packet/outgoing/change_status.rb", "lib/ruggby/packet/outgoing/check_uin_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"]
15
+ s.files = ["CHANGELOG.rdoc", "Gemfile", "MIT-LICENSE", "Manifest", "README.md", "Rakefile", "init.rb", "lib/ruggby.rb", "lib/ruggby/action/base.rb", "lib/ruggby/action/change_status.rb", "lib/ruggby/action/check_uin_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/new_status.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/status.rb", "lib/ruggby/packet/incoming/welcome.rb", "lib/ruggby/packet/outgoing/base.rb", "lib/ruggby/packet/outgoing/change_status.rb", "lib/ruggby/packet/outgoing/check_uin_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", "ruggby.gemspec", "spec/callback_spec.rb", "spec/spec_helper.rb"]
14
16
  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.rdoc_options = ["--line-numbers", "--title", "Ruggby", "--main", "README.md"]
17
18
  s.rubyforge_project = "ruggby"
18
- s.rubygems_version = "1.8.15"
19
+ s.rubygems_version = "2.2.2"
19
20
  s.summary = "Gadu Gadu protocol client implementation in Ruby language"
20
21
 
21
22
  if s.respond_to? :specification_version then
22
- s.specification_version = 3
23
+ s.specification_version = 4
23
24
 
24
25
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
26
  s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
metadata CHANGED
@@ -1,38 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruggby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2.1
5
- prerelease:
4
+ version: 0.3.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Maciej Mensfeld
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-04-08 00:00:00.000000000Z
11
+ date: 2014-08-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
- requirement: &9371040 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 2.0.0
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *9371040
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: mocha
27
- requirement: &9370340 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *9370340
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
36
41
  description: Gadu Gadu protocol client implementation in Ruby language
37
42
  email: maciej@mensfeld.pl
38
43
  executables: []
@@ -43,10 +48,12 @@ extra_rdoc_files:
43
48
  - lib/ruggby.rb
44
49
  - lib/ruggby/action/base.rb
45
50
  - lib/ruggby/action/change_status.rb
51
+ - lib/ruggby/action/check_uin_status.rb
46
52
  - lib/ruggby/action/create_message.rb
47
53
  - lib/ruggby/action/login.rb
48
54
  - lib/ruggby/action/mark.rb
49
55
  - lib/ruggby/action/new_message.rb
56
+ - lib/ruggby/action/new_status.rb
50
57
  - lib/ruggby/action/ping.rb
51
58
  - lib/ruggby/action/read.rb
52
59
  - lib/ruggby/callback.rb
@@ -57,9 +64,11 @@ extra_rdoc_files:
57
64
  - lib/ruggby/packet/incoming/base.rb
58
65
  - lib/ruggby/packet/incoming/login_status.rb
59
66
  - lib/ruggby/packet/incoming/message.rb
67
+ - lib/ruggby/packet/incoming/status.rb
60
68
  - lib/ruggby/packet/incoming/welcome.rb
61
69
  - lib/ruggby/packet/outgoing/base.rb
62
70
  - lib/ruggby/packet/outgoing/change_status.rb
71
+ - lib/ruggby/packet/outgoing/check_uin_status.rb
63
72
  - lib/ruggby/packet/outgoing/login.rb
64
73
  - lib/ruggby/packet/outgoing/mark.rb
65
74
  - lib/ruggby/packet/outgoing/message.rb
@@ -73,16 +82,19 @@ files:
73
82
  - CHANGELOG.rdoc
74
83
  - Gemfile
75
84
  - MIT-LICENSE
85
+ - Manifest
76
86
  - README.md
77
87
  - Rakefile
78
88
  - init.rb
79
89
  - lib/ruggby.rb
80
90
  - lib/ruggby/action/base.rb
81
91
  - lib/ruggby/action/change_status.rb
92
+ - lib/ruggby/action/check_uin_status.rb
82
93
  - lib/ruggby/action/create_message.rb
83
94
  - lib/ruggby/action/login.rb
84
95
  - lib/ruggby/action/mark.rb
85
96
  - lib/ruggby/action/new_message.rb
97
+ - lib/ruggby/action/new_status.rb
86
98
  - lib/ruggby/action/ping.rb
87
99
  - lib/ruggby/action/read.rb
88
100
  - lib/ruggby/callback.rb
@@ -93,9 +105,11 @@ files:
93
105
  - lib/ruggby/packet/incoming/base.rb
94
106
  - lib/ruggby/packet/incoming/login_status.rb
95
107
  - lib/ruggby/packet/incoming/message.rb
108
+ - lib/ruggby/packet/incoming/status.rb
96
109
  - lib/ruggby/packet/incoming/welcome.rb
97
110
  - lib/ruggby/packet/outgoing/base.rb
98
111
  - lib/ruggby/packet/outgoing/change_status.rb
112
+ - lib/ruggby/packet/outgoing/check_uin_status.rb
99
113
  - lib/ruggby/packet/outgoing/login.rb
100
114
  - lib/ruggby/packet/outgoing/mark.rb
101
115
  - lib/ruggby/packet/outgoing/message.rb
@@ -105,38 +119,35 @@ files:
105
119
  - lib/ruggby/string_encoder.rb
106
120
  - lib/ruggby/threader.rb
107
121
  - lib/ruggby/version.rb
122
+ - ruggby.gemspec
108
123
  - spec/callback_spec.rb
109
124
  - spec/spec_helper.rb
110
- - Manifest
111
- - ruggby.gemspec
112
125
  homepage: https://github.com/mensfeld/ruGGby
113
126
  licenses: []
127
+ metadata: {}
114
128
  post_install_message:
115
129
  rdoc_options:
116
- - --line-numbers
117
- - --inline-source
118
- - --title
130
+ - "--line-numbers"
131
+ - "--title"
119
132
  - Ruggby
120
- - --main
133
+ - "--main"
121
134
  - README.md
122
135
  require_paths:
123
136
  - lib
124
137
  required_ruby_version: !ruby/object:Gem::Requirement
125
- none: false
126
138
  requirements:
127
- - - ! '>='
139
+ - - ">="
128
140
  - !ruby/object:Gem::Version
129
141
  version: '0'
130
142
  required_rubygems_version: !ruby/object:Gem::Requirement
131
- none: false
132
143
  requirements:
133
- - - ! '>='
144
+ - - ">="
134
145
  - !ruby/object:Gem::Version
135
146
  version: '1.2'
136
147
  requirements: []
137
148
  rubyforge_project: ruggby
138
- rubygems_version: 1.8.15
149
+ rubygems_version: 2.2.2
139
150
  signing_key:
140
- specification_version: 3
151
+ specification_version: 4
141
152
  summary: Gadu Gadu protocol client implementation in Ruby language
142
153
  test_files: []