imstat 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
1
+ # Imstat
2
+
3
+ Ruby lib for checking user status in the instant messengers
4
+
5
+ ### Getting it
6
+
7
+ gem install imstat
8
+
9
+ ### Using it
10
+
11
+ #### Getting Skype status
12
+
13
+ If you want to use Skype status you must be sure about support this feature in the skype profile (go to Tools->Options->Privacy->Allow my online status to be shown on the web)
14
+
15
+ ##### Output
16
+
17
+ - "Online"
18
+ - "Offline"
19
+
20
+ ##### Example
21
+
22
+ Imstat::get_user_status(:messenger => :skype, :user => "echo") # => "Offline"
23
+
24
+ #### Getting ICQ status
25
+
26
+ ##### Output
27
+
28
+ - "Online"
29
+ - "Offline"
30
+ - "N/A"
31
+ - "It's not a valid icq uin"
32
+
33
+ ##### Example
34
+
35
+ Imstat::get_user_status(:messenger => :icq, :user => "123456") # => "N/A"
36
+
37
+ #### Getting Yahoo status
38
+
39
+ ##### Output
40
+
41
+ - "Online"
42
+ - "Offline"
43
+
44
+ ##### Example
45
+
46
+ Imstat::get_user_status(:messenger => :yahoo, :user => "cdfdsdfgsd") # => "Offline"
47
+
@@ -0,0 +1,25 @@
1
+ require "rake"
2
+ require "rake/testtask"
3
+ require "rake/gempackagetask"
4
+ require "rake/rdoctask"
5
+ require "rake/clean"
6
+
7
+ CLEAN << "pkg" << "doc" << "coverage"
8
+
9
+ Rake::GemPackageTask.new(eval(File.read("imstat.gemspec"))) { |pkg| }
10
+ Rake::TestTask.new(:test) { |t| t.pattern = "test/*_test.rb" }
11
+
12
+ Rake::RDocTask.new do |r|
13
+ r.rdoc_dir = "doc"
14
+ r.rdoc_files.include "lib/**/*.rb"
15
+ end
16
+
17
+ begin
18
+ require "rcov/rcovtask"
19
+ Rcov::RcovTask.new do |r|
20
+ r.test_files = FileList["test/*_test.rb"]
21
+ r.verbose = true
22
+ r.rcov_opts << "--exclude gems/*"
23
+ end
24
+ rescue LoadError
25
+ end
@@ -0,0 +1,21 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "imstat")
2
+
3
+ require "skype"
4
+ require "icq"
5
+ require "yahoo"
6
+
7
+ module Imstat
8
+
9
+ def self.get_user_status(options)
10
+
11
+ case options[:messenger]
12
+ when :skype
13
+ skype_status = Imstat::Skype::get_status(options[:user])
14
+ when :icq
15
+ icq_status = Imstat::Icq::get_status(options[:user])
16
+ when :yahoo
17
+ yahoo_status = Imstat::Yahoo::get_status(options[:user])
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ require 'open-uri'
2
+
3
+ module Imstat
4
+
5
+ class Icq
6
+
7
+ def self.get_status(user)
8
+ raw_icq_status = ""
9
+ begin
10
+ open("http://status.icq.com/online.gif?icq=#{user}") {|f| raw_icq_status = f.base_uri.request_uri}
11
+ rescue OpenURI::HTTPError
12
+ raw_icq_status = "It's not a valid icq uin"
13
+ end
14
+ if /online0/ =~ raw_icq_status
15
+ icq_status = "Offline"
16
+ elsif /online1/ =~ raw_icq_status
17
+ icq_status = "Online"
18
+ elsif /online2/ =~ raw_icq_status
19
+ icq_status = "N/A"
20
+ elsif /It\'s not a valid icq uin/ =~ raw_icq_status
21
+ icq_status = "It's not a valid icq uin"
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ require 'open-uri'
2
+ require "rexml/document"
3
+
4
+ module Imstat
5
+
6
+ class Skype
7
+
8
+ def self.get_status(user)
9
+ skype_xml_status = REXML::Document.new open("http://mystatus.skype.com/#{user}.xml").read
10
+ status = Hash.new
11
+ REXML::XPath.each(skype_xml_status, "//presence") do |el|
12
+ status[el.attributes["xml:lang"].to_sym] = el.text
13
+ end
14
+ status[:en]
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ require 'open-uri'
2
+
3
+ module Imstat
4
+
5
+ class Yahoo
6
+
7
+ @@yahoo_online_status_image_size = 140 #bytes
8
+ @@yahoo_offline_status_image_size = 84 #bytes
9
+
10
+ def self.get_status(user)
11
+
12
+ raw_yahoo_status = open("http://opi.yahoo.com/online?u=#{user}").read
13
+
14
+ if raw_yahoo_status.size == @@yahoo_online_status_image_size
15
+ yahoo_status = "Online"
16
+ elsif raw_yahoo_status.size == @@yahoo_offline_status_image_size
17
+ yahoo_status = "Offline"
18
+ else
19
+ yahoo_status = "WTF?"
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "../lib")
2
+ require "imstat"
3
+ require 'test/unit'
4
+
5
+ class TestImstat < Test::Unit::TestCase
6
+ def test_skype_status
7
+ assert_equal("Offline", Imstat::get_user_status(:messenger => :skype, :user => "echo"))
8
+ end
9
+
10
+ def test_normal_icq_uin
11
+ assert_not_equal("It's not a valid icq uin", Imstat::get_user_status(:messenger => :icq, :user => "422905313"))
12
+ end
13
+
14
+ def test_wrong_icq_status
15
+ assert_equal("It's not a valid icq uin", Imstat::get_user_status(:messenger => :icq, :user => "asf"))
16
+ end
17
+
18
+ def test_mormal_yahoo_id
19
+ assert_not_equal("WTF?", Imstat::get_user_status(:messenger => :yahoo, :user => "cdfdsdfgsd"))
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imstat
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - Vasiliy Ermolovich
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2011-02-02 00:00:00 +02:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description: Check user status in the instant messengers from ruby
21
+ email:
22
+ - younash@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/imstat/icq.rb
31
+ - lib/imstat/skype.rb
32
+ - lib/imstat/yahoo.rb
33
+ - lib/imstat.rb
34
+ - README.md
35
+ - Rakefile
36
+ - test/imstat_test.rb
37
+ has_rdoc: true
38
+ homepage: https://github.com/nashby/imstat
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.7
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Check user status in the instant messengers from ruby
69
+ test_files:
70
+ - test/imstat_test.rb