skype_api 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
19
+ log/*.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@skype_api
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in skype_api.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Copyright (c) 2012 Fractal Soft
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+ Neither the name of the Fractal Soft nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # SkypeApi
2
+
3
+ SkypeApi is a gem to use Skype API in Ruby projects.
4
+ It's testing and working.
5
+
6
+ ## Installation
7
+
8
+ Install Skype, dbus, Xvfb and some fonts:
9
+
10
+ sudo aptitude install skype
11
+ sudo aptitude install dbus xvfb
12
+ sudo aptitude install xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'skype_api'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install skype_api
25
+
26
+ ## Usage
27
+
28
+ You have to run Skype at least once, because gem needs config files (authorization and API access).
29
+
30
+ At first You have to run Skype:
31
+
32
+ $ skype_api
33
+
34
+ Next You can use Skype API. For example run Echo Bot:
35
+
36
+ $ skype_echo
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/skype_api ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Any idea how to run bash script inside the gem?
4
+ number = 2
5
+ script = <<EOS
6
+ #!/bin/bash
7
+
8
+ export DISPLAY=:#{number}
9
+
10
+ if [[ ! -e /tmp/.X#{number}-lock ]]
11
+ # Virtual framebuffer X server
12
+ then Xvfb :#{number} &
13
+ fi
14
+
15
+ skype &
16
+ EOS
17
+
18
+ result = `echo "#{script}" | bash -s`
19
+ puts result
data/bin/skype_echo ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require 'skype_api'
5
+
6
+ begin
7
+ print "Echo is starting... "
8
+ SkypeApi::Api.instance.attach
9
+ puts "OK"
10
+ Thread.list.each { |thread| thread.join }
11
+ rescue Exception => e
12
+ puts "#{e.message}"
13
+ end
data/lib/skype_api.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "skype_api/version"
2
+
3
+ require "skype_api/skype_api"
4
+ require "skype_api/client"
5
+ require "skype_api/user"
6
+ require "skype_api/profile"
7
+ require "skype_api/chat_message"
8
+ require "skype_api/msg_request"
9
+
10
+ module SkypeApi
11
+ end
@@ -0,0 +1,60 @@
1
+ # coding: utf-8
2
+
3
+ module SkypeApi
4
+ class ChatMessage
5
+ COMMAND = "CHATMESSAGE"
6
+ METHOD_NAMES = [:chatname, :body, :status]
7
+
8
+ attr_reader :id, :status, :body, :chatname
9
+
10
+ def initialize(id = nil)
11
+ @id = id
12
+ @status, @body, @chatname = nil
13
+ end
14
+
15
+ def fifo
16
+ self.methods.collect do |method|
17
+ self.send method if /^get_.+$/.match(method.to_s)
18
+ end.compact
19
+ end
20
+
21
+ def reply
22
+ "#{COMMAND} #{@chatname} #{SkypeApi::MsgRequest.reply(@body)}" if @chatname and @body and @status == "RECEIVED"
23
+ end
24
+
25
+ def update(text)
26
+ destination, msg_id, property, *value = text.split
27
+ msg_id = msg_id.to_i
28
+ property = "@#{property.downcase}".to_sym
29
+ value = value.join(' ')
30
+ if query_validate(destination, msg_id, property)
31
+ self.instance_variable_set property, /^\d+$/.match(value) ? value.to_i : value
32
+ end
33
+ self
34
+ end
35
+
36
+ METHOD_NAMES.each do |name|
37
+ define_method "get_#{name.to_s}" do
38
+ get_property(name)
39
+ end
40
+ end
41
+
42
+ def to_s
43
+ text = "<id = #{id.inspect}"
44
+ METHOD_NAMES.each do |name|
45
+ text << ", #{name.to_s} = #{(self.send name).inspect}"
46
+ end
47
+ text << ">"
48
+ text
49
+ end
50
+
51
+ private
52
+ def get_property(property)
53
+ "GET #{COMMAND} #{@id} #{property.to_s.upcase}"
54
+ end
55
+
56
+ def query_validate(destination, msg_id, property)
57
+ destination.upcase == COMMAND and msg_id == @id and (self.instance_variable_defined? property)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,79 @@
1
+ # coding: utf-8
2
+ require 'logger'
3
+
4
+ module SkypeApi
5
+ class Client
6
+ attr_reader :fifo, :profile, :users_list, :msg_list, :logger
7
+ attr_accessor :auto_authorize
8
+
9
+ def self.instance
10
+ @instance ||= new
11
+ end
12
+
13
+ def proxy(text)
14
+ @logger.info(">> #{text}")
15
+ destination, target = text.split
16
+ destination = destination.downcase.to_sym
17
+ case destination
18
+ when :currentuserhandle
19
+ @profile = Profile.new(target)
20
+ @fifo += @profile.fifo
21
+ when :user
22
+ user_redirect(target, text)
23
+ when :chatmessage
24
+ msg_redirect(target.to_i, text)
25
+ when :profile
26
+ profile_redirect(text)
27
+ end
28
+ @logger.info("<< #{fifo[0]}")
29
+ # FIXME not for testing, only for Skype mode
30
+ if ENV['_'].match(/rspec$/).nil?
31
+ proxy(invoke_query[0])
32
+ end
33
+ end
34
+
35
+ private
36
+ def initialize
37
+ @users_list = {}
38
+ @auto_authorize = true
39
+ @profile = nil
40
+ @fifo = []
41
+ @msg_list = {}
42
+ @logger = Logger.new('log/skype_api.log')
43
+ # @logger = Logger.new(STDOUT)
44
+ # log.level = Logger::WARN
45
+ end
46
+
47
+ def user_redirect(target, text)
48
+ if @users_list.has_key? target
49
+ @users_list[target].update(text)
50
+ elsif is_authorize?(text)
51
+ @users_list[target] = User.new(target)
52
+ @fifo << @users_list[target].authorisation
53
+ @fifo += @users_list[target].fifo
54
+ end
55
+ end
56
+
57
+ def msg_redirect(target, text)
58
+ if @msg_list.has_key? target
59
+ @msg_list[target].update(text)
60
+ @fifo.push(@msg_list[target].reply).compact!
61
+ else
62
+ @msg_list[target] = ChatMessage.new(target)
63
+ @fifo += @msg_list[target].fifo
64
+ end
65
+ end
66
+
67
+ def profile_redirect(text)
68
+ @profile.update(text)
69
+ end
70
+
71
+ def invoke_query
72
+ SkypeApi::Api.instance.invoke(@fifo.shift) unless @fifo.empty?
73
+ end
74
+
75
+ def is_authorize?(text)
76
+ @auto_authorize
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,11 @@
1
+ # coding: utf-8
2
+
3
+ module SkypeApi
4
+ class MsgRequest
5
+ class << self
6
+ def reply(text)
7
+ text
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ require 'skype_api/user'
3
+
4
+ module SkypeApi
5
+ class Profile < User
6
+ COMMAND = "PROFILE"
7
+
8
+ def update(text)
9
+ destination, property, *value = text.split
10
+ property = "@#{property.downcase}".to_sym
11
+ value = value.join(' ')
12
+ if query_validate(destination, property)
13
+ self.instance_variable_set property, /^\d+$/.match(value) ? value.to_i : value
14
+ end
15
+ self
16
+ end
17
+
18
+ private
19
+ def get_property(property)
20
+ "GET #{COMMAND} #{property.to_s.upcase}"
21
+ end
22
+
23
+ def query_validate(destination, property)
24
+ destination.upcase == COMMAND and (self.instance_variable_defined? property)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,62 @@
1
+ # coding: utf-8
2
+ require 'dbus'
3
+ require 'thread'
4
+
5
+ module SkypeApi
6
+ SERVICE = "org.fractalsoft.skype"
7
+ SKYPE_SERVICE = "com.Skype.API"
8
+ SKYPE_TO_CLIENT_PATH = "/com/Skype/Client"
9
+ CLIENT_TO_SKYPE_PATH = "/com/Skype"
10
+ CLIENT_INTERFACE = "com.Skype.API.Client"
11
+
12
+ class Notify < DBus::Object
13
+ dbus_interface CLIENT_INTERFACE do
14
+ dbus_method :Notify, "in data:s" do |message|
15
+ # TODO testing
16
+ Client.instance.proxy(message)
17
+ end
18
+ end
19
+ end
20
+
21
+ class Api
22
+ def self.instance
23
+ @instance ||= new
24
+ end
25
+
26
+ def attach(protocol_number = 7, name = "SkypeApi")
27
+ unless @is_on
28
+ api.Invoke "NAME #{name}"
29
+ api.Invoke "PROTOCOL #{protocol_number}"
30
+
31
+ thread = Thread.new do
32
+ receiving_service = bus.request_service(SERVICE)
33
+ receiving_service.export(Notify.new(SKYPE_TO_CLIENT_PATH))
34
+ dbus_event_loop = DBus::Main.new
35
+ dbus_event_loop << bus
36
+ dbus_event_loop.run
37
+ end
38
+ thread.run
39
+
40
+ @is_on = true
41
+ end
42
+ end
43
+
44
+ def invoke(query)
45
+ api.Invoke(query)
46
+ end
47
+
48
+ private
49
+ def api
50
+ @api ||= begin
51
+ skype_service = bus.service(SKYPE_SERVICE)
52
+ skype_object = skype_service.object(CLIENT_TO_SKYPE_PATH)
53
+ skype_object.introspect
54
+ skype_object[SKYPE_SERVICE]
55
+ end
56
+ end
57
+
58
+ def bus
59
+ DBus::SessionBus.instance
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,75 @@
1
+ # coding: utf-8
2
+
3
+ module SkypeApi
4
+ class User
5
+ COMMAND = "USER"
6
+ NOT_IN_CONTACT = 0 # never been in contact list.
7
+ DELETE_FROM_CONTACT = 1 # deleted from contact list.
8
+ AUTHORISATION_PENDING = 2 # pending authorisation.
9
+ ADD_TO_CONTACT = 3 # added to contact list.
10
+ METHOD_NAMES = [:fullname, :birthday, :sex, :language, :province, :city,
11
+ :phone_home, :phone_office, :phone_mobile,
12
+ :homepage, :about, :buddystatus]
13
+
14
+ attr_reader :name, :fullname, :birthday, :sex, :language, :province, :city
15
+ attr_reader :phone_home, :phone_office, :phone_mobile
16
+ attr_reader :homepage, :about, :buddystatus
17
+
18
+ def initialize(name = "")
19
+ @name = name
20
+ @fullname, @birthday, @sex, @language, @province, @city = nil
21
+ @phone_home, @phone_office, @phone_mobile = nil
22
+ @homepage, @about, @buddystatus = nil
23
+ end
24
+
25
+ def fifo
26
+ self.methods.collect do |method|
27
+ self.send method if /^get_.+$/.match(method.to_s)
28
+ end.compact
29
+ end
30
+
31
+ def update(text)
32
+ destination, user_name, property, *value = text.split
33
+ property = "@#{property.downcase}".to_sym
34
+ value = value.join(' ')
35
+ if query_validate(destination, user_name, property)
36
+ self.instance_variable_set property, /^\d+$/.match(value) ? value.to_i : value
37
+ end
38
+ self
39
+ end
40
+
41
+ METHOD_NAMES.each do |name|
42
+ define_method "get_#{name.to_s}" do
43
+ get_property(name)
44
+ end
45
+ end
46
+
47
+ def get(*items)
48
+ items.collect do |item|
49
+ (self.respond_to? item) ? (self.send item) : nil
50
+ end
51
+ end
52
+
53
+ def to_s
54
+ text = "<name = #{name.inspect}"
55
+ METHOD_NAMES.each do |name|
56
+ text << ", #{name.to_s} = #{(self.send name).inspect}"
57
+ end
58
+ text << ">"
59
+ text
60
+ end
61
+
62
+ def authorisation
63
+ "SET #{COMMAND} #{@name} BUDDYSTATUS 2"
64
+ end
65
+
66
+ private
67
+ def query_validate(destination, user_name, property)
68
+ destination.upcase == COMMAND and user_name == @name and (self.instance_variable_defined? property)
69
+ end
70
+
71
+ def get_property(property)
72
+ "GET #{COMMAND} #{@name} #{property.to_s.upcase}"
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ module SkypeApi
2
+ VERSION = "0.0.0"
3
+ end
data/log/.gitkeep ADDED
File without changes
data/skype_api.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/skype_api/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Aleksander Malaszkiewicz"]
6
+ gem.email = ["info@fractalsoft.org"]
7
+ gem.description = %q{Skype API}
8
+ gem.summary = %q{Skype API}
9
+ gem.homepage = "https://github.com/fractalsoft/skype_api"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "skype_api"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = SkypeApi::VERSION
17
+
18
+ gem.add_development_dependency "rspec"
19
+ gem.add_dependency "ruby-dbus"
20
+ end
data/spec/.gitkeep ADDED
File without changes
@@ -0,0 +1,81 @@
1
+ # coding: utf-8
2
+ require 'skype_api/chat_message'
3
+
4
+ describe SkypeApi::ChatMessage do
5
+ let(:message) { SkypeApi::ChatMessage.new(1234) }
6
+
7
+ it "exist" do
8
+ message.should be
9
+ end
10
+
11
+ it "have id" do
12
+ message.instance_variables.should include(:@id)
13
+ end
14
+
15
+ it "have not empty id" do
16
+ message.id.should be
17
+ message.id.should_not == ""
18
+ end
19
+
20
+ it "create new with id 1234" do
21
+ message.id.should == 1234
22
+ end
23
+
24
+ it "have status, body, chatname" do
25
+ message.instance_variables.should include(:@status, :@body, :@chatname)
26
+ end
27
+
28
+ it "have access to read status, body, chatname" do
29
+ SkypeApi::ChatMessage.public_instance_methods.should include(:status, :body, :chatname)
30
+ end
31
+
32
+ [:status, :body, :chatname].each do |item|
33
+ it "return API query for #{item}" do
34
+ (message.send "get_#{item}".to_sym).should == "GET CHATMESSAGE 1234 #{item.to_s.upcase}"
35
+ end
36
+ end
37
+
38
+ it "update his own atributes" do
39
+ message.update("CHATMESSAGE 1234 BODY bot.fractalsoft Hello world!").body.should == "bot.fractalsoft Hello world!"
40
+ end
41
+
42
+ it "not update unknown chatmessage id" do
43
+ message.update("CHATMESSAGE 9999 BODY bot.fractalsoft Hello world!").body.should be_nil
44
+ end
45
+
46
+ it "not update atributes which don't know" do
47
+ message.update("CHATMESSAGE 1234 BODYY bot.fractalsoft Hello world!").body.should be_nil
48
+ end
49
+
50
+ it "generate API query FIFO to update chatmessage propertices" do
51
+ message.fifo.should include("GET CHATMESSAGE 1234 STATUS", "GET CHATMESSAGE 1234 BODY",
52
+ "GET CHATMESSAGE 1234 CHATNAME")
53
+ end
54
+
55
+ it "show his own inside" do
56
+ message.to_s.should == "<id = 1234, chatname = nil, body = nil, status = nil>"
57
+ end
58
+
59
+ it "reply for message if know body, chatname and status == received" do
60
+ message.instance_variable_set :@chatname, "#bot.fractalsoft/$fractalsoft;232295f0a5417a7b"
61
+ message.instance_variable_set :@body, "Hello world!"
62
+ message.instance_variable_set :@status, "RECEIVED"
63
+ msg = "CHATMESSAGE #bot.fractalsoft/$fractalsoft;232295f0a5417a7b Hello world!"
64
+ message.reply.should == msg
65
+ end
66
+
67
+ it "not reply for message when body or chatname or stasus is nil" do
68
+ message.reply.should be_nil
69
+ message.instance_variable_set :@chatname, "#bot.fractalsoft/$fractalsoft;232295f0a5417a7b"
70
+ message.reply.should be_nil
71
+ message.instance_variable_set :@body, "Hello world!"
72
+ message.reply.should be_nil
73
+ end
74
+
75
+ it "not reply when status != received" do
76
+ message.instance_variable_set :@chatname, "#bot.fractalsoft/$fractalsoft;232295f0a5417a7b"
77
+ message.instance_variable_set :@body, "Hello world!"
78
+ message.instance_variable_set :@status, "SEND"
79
+ message.reply.should be_nil
80
+ end
81
+ end
@@ -0,0 +1,135 @@
1
+ # coding: utf-8
2
+ require 'skype_api'
3
+
4
+ describe SkypeApi::Client do
5
+ let(:client) { SkypeApi::Client.instance }
6
+
7
+ it "instance exist" do
8
+ client.should be
9
+ end
10
+
11
+ it "have list of user" do
12
+ (client.instance_variable_defined? :@users_list).should be_true
13
+ end
14
+
15
+ it "users_list is a hash" do
16
+ (client.instance_variable_get :@users_list).should be_an_instance_of(Hash)
17
+ end
18
+
19
+ it "have property auto_authorize" do
20
+ (client.instance_variable_defined? :@auto_authorize).should be_true
21
+ end
22
+
23
+ it "have auto_authorize turn on" do
24
+ client.auto_authorize.should be_true
25
+ end
26
+
27
+ it "have proxy method which separate query" do
28
+ (SkypeApi::Client.method_defined? :proxy).should be_true
29
+ end
30
+
31
+ it "have client profile" do
32
+ (client.instance_variable_defined? :@profile).should be_true
33
+ end
34
+
35
+ it "have fifo for query" do
36
+ (client.instance_variable_defined? :@fifo).should be_true
37
+ end
38
+
39
+ it "fifo is an array" do
40
+ (client.instance_variable_get :@fifo).should be_an_instance_of(Array)
41
+ end
42
+
43
+ it "proxy redirect to profil when receive appropriately msg" do
44
+ client.proxy("CURRENTUSERHANDLE bot.fractalsoft")
45
+ client.fifo.should have_at_least(2).items
46
+ (client.instance_variable_get :@profile).should be_an_instance_of(SkypeApi::Profile)
47
+ client.profile.name.should == "bot.fractalsoft"
48
+ end
49
+
50
+ it "proxy redirect to user when receive appropriately msg - user don't exist" do
51
+ client.proxy("USER bot.fractalsoft RECEIVEDAUTHREQUEST my msg")
52
+ client.users_list.should have_at_least(1).items
53
+ client.users_list["bot.fractalsoft"].should be_an_instance_of(SkypeApi::User)
54
+ client.users_list["bot.fractalsoft"].name.should == "bot.fractalsoft"
55
+ client.fifo.should have_at_least(2).items
56
+ client.fifo.should include("SET USER bot.fractalsoft BUDDYSTATUS 2")
57
+ end
58
+
59
+ it "proxy redirect to user when receive appropriately msg - user exist" do
60
+ client.instance_variable_set :@users_list, {"bot.fractalsoft" => SkypeApi::User.new("bot.fractalsoft")}
61
+ client.proxy("USER bot.fractalsoft FULLNAME Fractal Soft")
62
+ client.users_list.should have(1).items
63
+ client.users_list["bot.fractalsoft"].fullname.should == "Fractal Soft"
64
+ end
65
+
66
+ it "have property msg_list" do
67
+ (client.instance_variable_defined? :@msg_list).should be_true
68
+ end
69
+
70
+ it "msg_list is a hash" do
71
+ (client.instance_variable_get :@msg_list).should be_an_instance_of(Hash)
72
+ end
73
+
74
+ it "proxy redirect to chatmessage when receive appropriately msg - chatmessage don't exist" do
75
+ client.proxy("CHATMESSAGE 1234 STATUS RECEIVE")
76
+ client.msg_list.should have(1).items
77
+ client.msg_list[1234].should be_an_instance_of(SkypeApi::ChatMessage)
78
+ client.msg_list[1234].id.should == 1234
79
+ client.fifo.should have_at_least(2).items
80
+ end
81
+
82
+ it "proxy redirect to chatmessage when receive appropriately msg - chatmessage exist" do
83
+ client.instance_variable_set :@msg_list, {1234 => SkypeApi::ChatMessage.new(1234)}
84
+ client.proxy("CHATMESSAGE 1234 STATUS RECEIVE")
85
+ client.msg_list.should have(1).items
86
+ client.msg_list[1234].status.should == "RECEIVE"
87
+ end
88
+
89
+ it "proxy redirect to profile when receive appropriately msg" do
90
+ client.proxy("PROFILE FULLNAME Fractal Soft")
91
+ client.profile.fullname.should == "Fractal Soft"
92
+ end
93
+
94
+ =begin
95
+ it "proxy method invoke api query from fifo" do
96
+ client.instance_variable_set :@fifo, ["GET USER bot.fractalsoft FULLNAME", "GET USER bot.fractalsoft BIRTHDAY",
97
+ "GET USER bot.fractalsoft SEX", "GET USER bot.fractalsoft LANGUAGE",
98
+ "GET USER bot.fractalsoft PROVINCE", "GET USER bot.fractalsoft CITY"]
99
+ expect{ client.proxy("test1") }.to change{ client.fifo.size }.from(6).to(5)
100
+ expect{ client.proxy("test2") }.to change{ client.fifo.size }.from(5).to(4)
101
+ end
102
+ =end
103
+
104
+ it "have method which check if authorization is possible" do
105
+ SkypeApi::Client.private_instance_methods.should include(:is_authorize?)
106
+ (client.send :is_authorize?, "USER bot.fractalsoft RECEIVEDAUTHREQUEST").should be_true
107
+ end
108
+
109
+ it "authorize User when variable auto_authorize is true" do
110
+ client.instance_variable_set :@users_list, {}
111
+ client.proxy("USER bot.fractalsoft RECEIVEDAUTHREQUEST")
112
+ client.users_list.should have(1).items
113
+ end
114
+
115
+ it "not authorize User when variable auto_authorize is false" do
116
+ client.instance_variable_set :@users_list, {}
117
+ client.auto_authorize = false
118
+ client.proxy("USER bot.fractalsoft RECEIVEDAUTHREQUEST")
119
+ client.users_list.should be_empty
120
+ end
121
+
122
+ it "have variable logger to add logs" do
123
+ client.instance_variables.should include(:@logger)
124
+ client.logger.should be_an_instance_of(Logger)
125
+ end
126
+
127
+ it "send reply for chatmessage" do
128
+ chat_message = SkypeApi::ChatMessage.new(1234)
129
+ chat_message.instance_variable_set :@body, "Hello world!"
130
+ chat_message.instance_variable_set :@chatname, "#bot.fractalsoft/$fractalsoft;232295f0a5417a7b"
131
+ client.instance_variable_set :@msg_list, {1234 => chat_message}
132
+ client.proxy("CHATMESSAGE 1234 STATUS RECEIVED")
133
+ client.fifo.should include "CHATMESSAGE #bot.fractalsoft/$fractalsoft;232295f0a5417a7b Hello world!"
134
+ end
135
+ end
@@ -0,0 +1,12 @@
1
+ # coding: utf-8
2
+ require 'skype_api/msg_request'
3
+
4
+ describe SkypeApi::MsgRequest do
5
+ it "exist" do
6
+ SkypeApi::MsgRequest.should be
7
+ end
8
+
9
+ it "reply for user message" do
10
+ SkypeApi::MsgRequest.reply("Hello world!").should == "Hello world!"
11
+ end
12
+ end
@@ -0,0 +1,56 @@
1
+ # coding: utf-8
2
+ require 'skype_api/profile'
3
+
4
+ describe SkypeApi::Profile do
5
+ let(:profile) { SkypeApi::Profile.new }
6
+
7
+ it "instance exist" do
8
+ profile.should be
9
+ end
10
+
11
+ it "is child of User class" do
12
+ profile.should be_a_kind_of(SkypeApi::User)
13
+ end
14
+
15
+ it "generate API query FIFO to update profile propertices" do
16
+ profile.fifo.should include("GET PROFILE FULLNAME", "GET PROFILE BIRTHDAY",
17
+ "GET PROFILE SEX", "GET PROFILE LANGUAGE",
18
+ "GET PROFILE PROVINCE", "GET PROFILE CITY",
19
+ "GET PROFILE PHONE_HOME", "GET PROFILE PHONE_OFFICE",
20
+ "GET PROFILE PHONE_MOBILE", "GET PROFILE HOMEPAGE",
21
+ "GET PROFILE ABOUT", "GET PROFILE BUDDYSTATUS")
22
+ end
23
+
24
+ it "update his own atributes" do
25
+ profile.update("PROFILE BUDDYSTATUS 3").buddystatus.should == 3
26
+ end
27
+
28
+ it "not update atributes which don't know" do
29
+ profile.update("USER bot.fractalsoft BUDDYSTAT 3").buddystatus.should be_nil
30
+ end
31
+
32
+ [:fullname, :birthday, :sex, :language, :province, :city].each do |item|
33
+ it "return API query for #{item}" do
34
+ (profile.send "get_#{item}".to_sym).should == "GET PROFILE #{item.to_s.upcase}"
35
+ end
36
+ end
37
+
38
+ [:phone_home, :phone_office, :phone_mobile].each do |item|
39
+ it "return API query for #{item}" do
40
+ (profile.send "get_#{item}".to_sym).should == "GET PROFILE #{item.to_s.upcase}"
41
+ end
42
+ end
43
+
44
+ [:homepage, :about, :buddystatus].each do |item|
45
+ it "return API query for #{item}" do
46
+ (profile.send "get_#{item}".to_sym).should == "GET PROFILE #{item.to_s.upcase}"
47
+ end
48
+ end
49
+
50
+ it "show his own inside" do
51
+ text = '<name = "", fullname = nil, birthday = nil, sex = nil, language = nil, '
52
+ text << 'province = nil, city = nil, phone_home = nil, phone_office = nil, '
53
+ text << 'phone_mobile = nil, homepage = nil, about = nil, buddystatus = nil>'
54
+ profile.to_s.should == text
55
+ end
56
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ require 'skype_api/skype_api'
3
+
4
+ describe SkypeApi do
5
+ it "have services and paths constans" do
6
+ SkypeApi.constants.should include(:SERVICE, :SKYPE_TO_CLIENT_PATH, :CLIENT_INTERFACE,
7
+ :CLIENT_TO_SKYPE_PATH, :SKYPE_SERVICE)
8
+ end
9
+
10
+ describe "::Api" do
11
+ it "have instance" do
12
+ SkypeApi::Api.instance.should be
13
+ end
14
+
15
+ # Test below needs a Skype connection.
16
+ # Add key "SkypeApi" to Skype public API.
17
+ it "have attach method with 2 arguments which return true" do
18
+ (SkypeApi::Api.instance.attach(7, "SkypeApi")).should be_true
19
+ SkypeApi::Api.instance.instance_variables.should include(:@is_on)
20
+ end
21
+
22
+ it "have method invoke for API query" do
23
+ SkypeApi::Api.instance.should respond_to(:invoke).with(1).arguments
24
+ end
25
+ end
26
+
27
+ describe "::Notify" do
28
+ it "have DBus subclass" do
29
+ SkypeApi::Notify.new("/com/Skype/Client").should be_a_kind_of(DBus::Object)
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,105 @@
1
+ # coding: utf-8
2
+ require 'skype_api/user'
3
+
4
+ describe SkypeApi::User do
5
+ let(:user) { SkypeApi::User.new("bot.fractalsoft") }
6
+
7
+ it "create new" do
8
+ user.should be
9
+ end
10
+
11
+ it "have name" do
12
+ user.instance_variables.should include(:@name)
13
+ end
14
+
15
+ it "have not empty name" do
16
+ user.name.should be
17
+ user.name.should_not == ""
18
+ end
19
+
20
+ it "create new with name bot.fractalsoft" do
21
+ user.name.should == "bot.fractalsoft"
22
+ end
23
+
24
+ it "have fullname, birthday, sex, language, province, city" do
25
+ user.instance_variables.should include(:@fullname, :@birthday, :@sex, :@language, :@province, :@city)
26
+ end
27
+
28
+ it "have home, office and mobile phone" do
29
+ user.instance_variables.should include(:@phone_home, :@phone_office, :@phone_mobile)
30
+ end
31
+
32
+ it "have homepage, about, buddystatus" do
33
+ user.instance_variables.should include(:@homepage, :@about, :@buddystatus)
34
+ end
35
+
36
+ it "have constants with buddystatus" do
37
+ SkypeApi::User.constants.should include(:NOT_IN_CONTACT, :DELETE_FROM_CONTACT, :AUTHORISATION_PENDING, :ADD_TO_CONTACT)
38
+ end
39
+
40
+ it "have access to read fullname, birthday, sex, language, province, city" do
41
+ SkypeApi::User.public_instance_methods.should include(:fullname, :birthday, :sex, :language, :province, :city)
42
+ end
43
+
44
+ it "have access to read home, office and mobile phone" do
45
+ SkypeApi::User.public_instance_methods.should include(:phone_home, :phone_office, :phone_mobile)
46
+ end
47
+
48
+ it "have access to read homepage, about, buddystatus" do
49
+ SkypeApi::User.public_instance_methods.should include(:homepage, :about, :buddystatus)
50
+ end
51
+
52
+ [:fullname, :birthday, :sex, :language, :province, :city].each do |item|
53
+ it "return API query for #{item}" do
54
+ (user.send "get_#{item}".to_sym).should == "GET USER bot.fractalsoft #{item.to_s.upcase}"
55
+ end
56
+ end
57
+
58
+ [:phone_home, :phone_office, :phone_mobile].each do |item|
59
+ it "return API query for #{item}" do
60
+ (user.send "get_#{item}".to_sym).should == "GET USER bot.fractalsoft #{item.to_s.upcase}"
61
+ end
62
+ end
63
+
64
+ [:homepage, :about, :buddystatus].each do |item|
65
+ it "return API query for #{item}" do
66
+ (user.send "get_#{item}".to_sym).should == "GET USER bot.fractalsoft #{item.to_s.upcase}"
67
+ end
68
+ end
69
+
70
+ it "update his own atributes" do
71
+ user.update("USER bot.fractalsoft BUDDYSTATUS 3").buddystatus.should == 3
72
+ end
73
+
74
+ it "not update unknown user atributes" do
75
+ user.update("USER not_fractalsoft BUDDYSTATUS 3").buddystatus.should be_nil
76
+ end
77
+
78
+ it "not update atributes which don't know" do
79
+ user.update("USER bot.fractalsoft BUDDYSTAT 3").buddystatus.should be_nil
80
+ end
81
+
82
+ it "show his own inside" do
83
+ text = '<name = "bot.fractalsoft", fullname = nil, birthday = nil, sex = nil, language = nil, '
84
+ text << 'province = nil, city = nil, phone_home = nil, phone_office = nil, '
85
+ text << 'phone_mobile = nil, homepage = nil, about = nil, buddystatus = nil>'
86
+ user.to_s.should == text
87
+ end
88
+
89
+ it "return array with his propertices" do
90
+ user.get(:name, :fullname, :about).should == ["bot.fractalsoft", nil, nil]
91
+ end
92
+
93
+ it "generate API query FIFO to update user propertices" do
94
+ user.fifo.should include("GET USER bot.fractalsoft FULLNAME", "GET USER bot.fractalsoft BIRTHDAY",
95
+ "GET USER bot.fractalsoft SEX", "GET USER bot.fractalsoft LANGUAGE",
96
+ "GET USER bot.fractalsoft PROVINCE", "GET USER bot.fractalsoft CITY",
97
+ "GET USER bot.fractalsoft PHONE_HOME", "GET USER bot.fractalsoft PHONE_OFFICE",
98
+ "GET USER bot.fractalsoft PHONE_MOBILE", "GET USER bot.fractalsoft HOMEPAGE",
99
+ "GET USER bot.fractalsoft ABOUT", "GET USER bot.fractalsoft BUDDYSTATUS")
100
+ end
101
+
102
+ it "have method to authorisation" do
103
+ user.authorisation.should == "SET USER bot.fractalsoft BUDDYSTATUS 2"
104
+ end
105
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: skype_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aleksander Malaszkiewicz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: ruby-dbus
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Skype API
47
+ email:
48
+ - info@fractalsoft.org
49
+ executables:
50
+ - skype_api
51
+ - skype_echo
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - .rspec
57
+ - .rvmrc
58
+ - Gemfile
59
+ - LICENSE
60
+ - README.md
61
+ - Rakefile
62
+ - bin/skype_api
63
+ - bin/skype_echo
64
+ - lib/skype_api.rb
65
+ - lib/skype_api/chat_message.rb
66
+ - lib/skype_api/client.rb
67
+ - lib/skype_api/msg_request.rb
68
+ - lib/skype_api/profile.rb
69
+ - lib/skype_api/skype_api.rb
70
+ - lib/skype_api/user.rb
71
+ - lib/skype_api/version.rb
72
+ - log/.gitkeep
73
+ - skype_api.gemspec
74
+ - spec/.gitkeep
75
+ - spec/skype_api/chat_message_spec.rb
76
+ - spec/skype_api/client_spec.rb
77
+ - spec/skype_api/msg_request_spec.rb
78
+ - spec/skype_api/profile_spec.rb
79
+ - spec/skype_api/skype_api_spec.rb
80
+ - spec/skype_api/user_spec.rb
81
+ homepage: https://github.com/fractalsoft/skype_api
82
+ licenses: []
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.24
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Skype API
105
+ test_files:
106
+ - spec/.gitkeep
107
+ - spec/skype_api/chat_message_spec.rb
108
+ - spec/skype_api/client_spec.rb
109
+ - spec/skype_api/msg_request_spec.rb
110
+ - spec/skype_api/profile_spec.rb
111
+ - spec/skype_api/skype_api_spec.rb
112
+ - spec/skype_api/user_spec.rb