Hire Us

Libskypekit and Skypekit – C and Ruby interface for Skype

Preface

There are two methods to programmatically use Skype:

The first method is rather slow due to an interaction with the user interface. The second one is more interesting as there is no UI application.

SkypeKit SDK includes only wrappers for:

  • C++
  • Python
  • Java

Is Ruby wrapper missed? No more!

On the way to gem

Before releasing gem, we tried several approaches. We tried to implement SkypeKit in pure Ruby as it done in SkypeKit Python Wrapper. But then, we realized that even if we make do it, its implementation will not be as fast as it should be. Then, we started to write a C extension for Ruby using the SkypeKit C++ Wrapper. But then, we admitted that this implementation will be inefficient due to asynchronous SkypeKit API and pure Ruby thread. Finally, we came to the implementation via Ruby FFI. We think that it’s the best way to do it because:

  • Thread stuff are completely on C side.
  • Synchronous program is easy to debug an test.
  • SkypeKit gem works in Ruby.
  • SkypeKit gem works in jRuby!
  • It’s possible to quickly implement SkypeKit in Perl/Python/lua/etc.

SkypeKit C library

Libskypekit is a simple C library that brings asynchronous SkypeKit C++ wrapper functionality to the usual synchronous C applications.

The goal of Libskypekit is to catch all asynchronous callbacks of SkypeKit C++ SDK and push them as events into a simple queue. Then synchronous application can pull this queue, retrieve each event and process it.

Libskypekit is rather a young library, but we have already implemented the next basic events:

  • Account status changed
  • Chat message received

It’s enough to write simple chat applications. If your are familiar with C language look at
ping_pong example

Is Ruby wrapper still missed? No more! :)

Skypekit Ruby gem

Thus LibskypeKit has a simple API, it’s was relatively easy to create a Ruby library using Ruby FFI.

Plus the Skypekit Ruby library provides a simple interface. For example, look at ping_pong example:

require "skypekit"

$skype = Skypekit::Skype.new(:keyfile => 'myskypekit.pem')

$skype.start
$skype.login('myskypename', 'mypassword')

def terminate
  puts "Terminating"
  $skype.stop
  exit
end

trap('INT') do
  terminate
end

loop do
  event = $skype.get_event

  unless event
    sleep 5
    next
  end

  case event.type
  when :account_status

    if event.data.logged_in?
      puts "Congrats! We are Logged in!"
    end

    if event.data.logged_out?
      puts "Authentication failed: #{event.data.reason}"
      terminate
    end

  when :chat_message
    message = event.data

    puts "@" * 80
    p message
    puts "@" * 80

    if message.body == "ping"
      $skype.send_chat_message(message.convo_id, "pong")
    end

  end
end

I want try it

In order to play with SkypeKit gem you need:

  • Register at developer.skype.com
  • Obtain SkypeKit SDK
  • Obtain SkypeKit Runtime
  • Obtain SkypeKit personal keypair

Then:

  • Compile SkypeKit SDK – see SDK documentation
  • Compile LibSkypeKit – see README in repository
  • Install SkypeKit gem – see README in repository

Now you can play with it.

Legal part

Libskypekit and Skypekit gem are both released under the MIT license.

But SkypeKit SDK is not!

Please carefully read SkypeKit License Agreement.

There are a lot of restrictions!

References