skypekit 0.0.1
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.
- data/.gitignore +18 -0
- data/Gemfile +7 -0
- data/LICENSE +22 -0
- data/README.md +51 -0
- data/Rakefile +2 -0
- data/examples/ping_pong.rb +49 -0
- data/lib/skypekit.rb +11 -0
- data/lib/skypekit/ffi.rb +92 -0
- data/lib/skypekit/ffi/account_status_data.rb +38 -0
- data/lib/skypekit/ffi/chat_message_data.rb +46 -0
- data/lib/skypekit/ffi/event.rb +46 -0
- data/lib/skypekit/skype.rb +47 -0
- data/skypekit.gemspec +18 -0
- data/spec/skypekit/ffi_spec.rb +9 -0
- data/spec/spec_helper.rb +3 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Railsware (www.railsware.com)
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Skypekit
|
2
|
+
|
3
|
+
Ruby FFI interface to libskypekit C library
|
4
|
+
|
5
|
+
## Dependencies
|
6
|
+
|
7
|
+
* libskypekit C library
|
8
|
+
* ffi gem
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Install [libskypekit](https://github.com/railsware/libskypekit).
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'skypekit'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install skypekit
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Check examples directory.
|
29
|
+
|
30
|
+
Run ping_pong example:
|
31
|
+
|
32
|
+
SK_KEY=bla.pem SK_USER=user SK_PASS=secret be ruby examples/ping_pong.rb
|
33
|
+
|
34
|
+
## Author
|
35
|
+
|
36
|
+
* Andriy Yanko
|
37
|
+
|
38
|
+
## Contributors
|
39
|
+
|
40
|
+
* Volodymyr Bezobiuk
|
41
|
+
* Alexey Vasiliev
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
* Copyright (c) 2012 Railsware (www.railsware.com)
|
46
|
+
* [MIT](www.opensource.org/licenses/MIT)
|
47
|
+
|
48
|
+
## References
|
49
|
+
|
50
|
+
* [libskypekit](https://github.com/railsware/libskypekit)
|
51
|
+
* [SkypeKit C++ Wrapper Reference](http://developer.skype.com/skypekit/reference/cpp/index.html)
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require "skypekit"
|
2
|
+
$skype = Skypekit::Skype.new(:keyfile => ENV['SK_KEY'])
|
3
|
+
|
4
|
+
$skype.start
|
5
|
+
$skype.login(ENV['SK_USER'], ENV['SK_PASS'])
|
6
|
+
|
7
|
+
def terminate
|
8
|
+
puts "Terminating"
|
9
|
+
$skype.stop
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
|
13
|
+
trap('INT') do
|
14
|
+
terminate
|
15
|
+
end
|
16
|
+
|
17
|
+
loop do
|
18
|
+
event = $skype.get_event
|
19
|
+
|
20
|
+
unless event
|
21
|
+
sleep 5
|
22
|
+
next
|
23
|
+
end
|
24
|
+
|
25
|
+
case event.type
|
26
|
+
when :account_status
|
27
|
+
|
28
|
+
if event.data.logged_in?
|
29
|
+
puts "Congrats! We are Logged in!"
|
30
|
+
end
|
31
|
+
|
32
|
+
if event.data.logged_out?
|
33
|
+
puts "Authentication failed: #{event.data.reason}"
|
34
|
+
terminate
|
35
|
+
end
|
36
|
+
|
37
|
+
when :chat_message
|
38
|
+
message = event.data
|
39
|
+
|
40
|
+
puts "@" * 80
|
41
|
+
p message
|
42
|
+
puts "@" * 80
|
43
|
+
|
44
|
+
if message.body == "ping"
|
45
|
+
$skype.send_chat_message(message.convo_id, "pong")
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
data/lib/skypekit.rb
ADDED
data/lib/skypekit/ffi.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012 Railsware (www.railsware.com)
|
3
|
+
#
|
4
|
+
module Skypekit
|
5
|
+
module FFI
|
6
|
+
extend ::FFI::Library
|
7
|
+
|
8
|
+
#
|
9
|
+
# @see https://github.com/railsware/libskypekit/blob/master/include/skypekit.h
|
10
|
+
#
|
11
|
+
|
12
|
+
#ffi_lib File.expand_path("../../../../libskypekit/lib/libskypekit.so", __FILE__)
|
13
|
+
ffi_lib "skypekit.so.1"
|
14
|
+
|
15
|
+
ErrorType = enum(
|
16
|
+
:already_running, 1,
|
17
|
+
:already_initialized,
|
18
|
+
:not_initialized,
|
19
|
+
:not_running,
|
20
|
+
:keyfile_access,
|
21
|
+
:skypename_required,
|
22
|
+
:password_required,
|
23
|
+
:account_not_found,
|
24
|
+
:conversation_not_found,
|
25
|
+
:login_failure,
|
26
|
+
:send_message_failure
|
27
|
+
)
|
28
|
+
|
29
|
+
EventType = enum(
|
30
|
+
:account_status, 1,
|
31
|
+
:chat_message
|
32
|
+
)
|
33
|
+
|
34
|
+
AccountStatusType = enum(
|
35
|
+
:logged_out, 1,
|
36
|
+
:logged_out_and_pwd_saved, # the account is logged out, but password is not needed for re-login
|
37
|
+
:connecting_to_p2p, # connecting to P2P network
|
38
|
+
:connecting_to_server, # connecting to login server
|
39
|
+
:logging_in, # waiting for response from server
|
40
|
+
:initializing, # response OK. initialising account-specific lib structures
|
41
|
+
:logged_in, # alright, we're good to go!
|
42
|
+
:logging_out # Logout() has been called but not processed yet
|
43
|
+
)
|
44
|
+
|
45
|
+
AccountLogoutReasonType = enum(
|
46
|
+
:logout_called, 1, # manual logout (or unknown reason from previous session)
|
47
|
+
:https_proxy_auth_failed, # sync errors at login/registration
|
48
|
+
:socks_proxy_auth_failed, # sync errors at login/registration
|
49
|
+
:p2p_connect_failed, # sync errors at login/registration
|
50
|
+
:server_connect_failed, # sync errors at login/registration
|
51
|
+
:server_overloaded, # sync errors at login/registration
|
52
|
+
:db_in_use, # sync errors at login/registration
|
53
|
+
:invalid_skypename, # sync errors at registration
|
54
|
+
:invalid_email, # sync errors at registration
|
55
|
+
:unacceptable_password, # sync errors at registration
|
56
|
+
:skypename_taken, # sync errors at registration
|
57
|
+
:rejected_as_underage, # sync errors at registration
|
58
|
+
:no_such_identity, # sync errors at login
|
59
|
+
:incorrect_password, # sync errors at login
|
60
|
+
:too_many_login_attempts, # sync errors at login
|
61
|
+
:password_has_changed, # async errors (can happen anytime while logged in)
|
62
|
+
:periodic_uic_update_failed, # async errors (can happen anytime while logged in)
|
63
|
+
:db_disk_full, # async errors (can happen anytime while logged in)
|
64
|
+
:db_io_error, # async errors (can happen anytime while logged in)
|
65
|
+
:db_corrupt, # async errors (can happen anytime while logged in)
|
66
|
+
:db_failure, # deprecated (superceded by more detailed DB_* errors)
|
67
|
+
:invalid_app_id, # platform sdk
|
68
|
+
:app_id_failure, # platform sdk
|
69
|
+
:unsupported_version # forced upgrade/discontinuation
|
70
|
+
)
|
71
|
+
|
72
|
+
attach_function :skypekit_skype_new, [], :pointer
|
73
|
+
|
74
|
+
attach_function :skypekit_skype_free, [:pointer], :void
|
75
|
+
|
76
|
+
attach_function :skypekit_skype_init, [:pointer, :string, :string, :int, :string], ErrorType
|
77
|
+
|
78
|
+
attach_function :skypekit_skype_start, [:pointer], ErrorType
|
79
|
+
|
80
|
+
attach_function :skypekit_skype_login, [:pointer, :string, :string], ErrorType
|
81
|
+
|
82
|
+
attach_function :skypekit_count_events, [:pointer], ErrorType
|
83
|
+
|
84
|
+
attach_function :skypekit_get_event, [:pointer], :pointer
|
85
|
+
|
86
|
+
attach_function :skypekit_event_free, [:pointer], :void
|
87
|
+
|
88
|
+
attach_function :skypekit_chat_send_message, [:pointer, :string, :string, :int], ErrorType
|
89
|
+
|
90
|
+
attach_function :skypekit_skype_stop, [:pointer], ErrorType
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012 Railsware (www.railsware.com)
|
3
|
+
#
|
4
|
+
module Skypekit
|
5
|
+
module FFI
|
6
|
+
class AccountStatusData < ::FFI::Struct
|
7
|
+
layout \
|
8
|
+
:status, FFI::AccountStatusType,
|
9
|
+
:reason, FFI::AccountLogoutReasonType,
|
10
|
+
:skypename, :string,
|
11
|
+
:payload, :pointer
|
12
|
+
|
13
|
+
def status
|
14
|
+
self[:status]
|
15
|
+
end
|
16
|
+
|
17
|
+
def skypename
|
18
|
+
self[:skypename]
|
19
|
+
end
|
20
|
+
|
21
|
+
def reason
|
22
|
+
self[:reason]
|
23
|
+
end
|
24
|
+
|
25
|
+
def logged_in?
|
26
|
+
status == :logged_in
|
27
|
+
end
|
28
|
+
|
29
|
+
def logged_out?
|
30
|
+
status == :logged_out && reason != 0
|
31
|
+
end
|
32
|
+
|
33
|
+
def inspect
|
34
|
+
"#{super} status=#{status} skypename=#{skypename} reason=#{reason}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012 Railsware (www.railsware.com)
|
3
|
+
#
|
4
|
+
module Skypekit
|
5
|
+
module FFI
|
6
|
+
class ChatMessageData < ::FFI::Struct
|
7
|
+
layout \
|
8
|
+
:convo_id, :string,
|
9
|
+
:convo_guid, :string,
|
10
|
+
:author, :string,
|
11
|
+
:author_displayname, :string,
|
12
|
+
:body_xml, :string,
|
13
|
+
:timestamp, :time_t,
|
14
|
+
:payload, :pointer
|
15
|
+
|
16
|
+
def convo_id
|
17
|
+
self[:convo_id]
|
18
|
+
end
|
19
|
+
|
20
|
+
def convo_guid
|
21
|
+
self[:convo_guid]
|
22
|
+
end
|
23
|
+
|
24
|
+
def author
|
25
|
+
self[:author]
|
26
|
+
end
|
27
|
+
|
28
|
+
def author_displayname
|
29
|
+
self[:author_displayname]
|
30
|
+
end
|
31
|
+
|
32
|
+
def sent_at
|
33
|
+
Time.at(self[:timestamp])
|
34
|
+
end
|
35
|
+
|
36
|
+
def body
|
37
|
+
self[:body_xml]
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def inspect
|
42
|
+
"#{super} convo_id=#{convo_id} convo_guid=#{convo_guid} author=#{author} author_displayname=#{author_displayname} sent_at=#{sent_at} body=#{body}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012 Railsware (www.railsware.com)
|
3
|
+
#
|
4
|
+
module Skypekit
|
5
|
+
module FFI
|
6
|
+
class Event < ::FFI::ManagedStruct
|
7
|
+
def self.release(pointer)
|
8
|
+
FFI.skypekit_event_free(pointer)
|
9
|
+
end
|
10
|
+
|
11
|
+
layout \
|
12
|
+
:type, FFI::EventType,
|
13
|
+
:timestamp, :time_t,
|
14
|
+
:data, :pointer,
|
15
|
+
:next, :pointer
|
16
|
+
|
17
|
+
def type
|
18
|
+
self[:type]
|
19
|
+
end
|
20
|
+
|
21
|
+
def timestamp
|
22
|
+
self[:timestamp]
|
23
|
+
end
|
24
|
+
|
25
|
+
def created_at
|
26
|
+
@created_at ||= Time.at(self[:timestamp])
|
27
|
+
end
|
28
|
+
|
29
|
+
def data
|
30
|
+
@data ||=
|
31
|
+
case self.type
|
32
|
+
when :account_status
|
33
|
+
AccountStatusData.new(self[:data])
|
34
|
+
when :chat_message
|
35
|
+
ChatMessageData.new(self[:data])
|
36
|
+
else
|
37
|
+
raise NotImplementedError, "event type #{type.inspect} is not implemeted"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def inspect
|
42
|
+
"#{super} type=#{type} created_at=#{created_at}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012 Railsware (www.railsware.com)
|
3
|
+
#
|
4
|
+
module Skypekit
|
5
|
+
class Skype
|
6
|
+
def self.release(pointer)
|
7
|
+
Skypekit::FFI.skypekit_skype_free(pointer)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
@keyfile = options[:keyfile] || "skypekit.pem"
|
12
|
+
@host = options[:host] || "127.0.0.1"
|
13
|
+
@port = options[:port] || 8963
|
14
|
+
@logfile = options[:logfile] || nil
|
15
|
+
|
16
|
+
@pointer = ::FFI::AutoPointer.new(Skypekit::FFI.skypekit_skype_new, self.class.method(:release))
|
17
|
+
end
|
18
|
+
|
19
|
+
def start
|
20
|
+
File.exists?(@keyfile) or raise ArgumentError, "Can't find certificate file #{@keyfile.inspect}"
|
21
|
+
Skypekit::FFI.skypekit_skype_init(pointer, @keyfile, @host, @port, @logfile)
|
22
|
+
Skypekit::FFI.skypekit_skype_start(pointer)
|
23
|
+
end
|
24
|
+
|
25
|
+
def login(username, password)
|
26
|
+
Skypekit::FFI.skypekit_skype_login(pointer, username, password)
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_event
|
30
|
+
event_pointer = Skypekit::FFI.skypekit_get_event(pointer)
|
31
|
+
Skypekit::FFI::Event.new(event_pointer) unless event_pointer.address.zero?
|
32
|
+
end
|
33
|
+
|
34
|
+
def stop
|
35
|
+
Skypekit::FFI.skypekit_skype_stop(pointer)
|
36
|
+
end
|
37
|
+
|
38
|
+
def send_chat_message(chat_id, message)
|
39
|
+
Skypekit::FFI.skypekit_chat_send_message(pointer, chat_id, message, 0)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
attr_reader :pointer
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/skypekit.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Andriy Yanko"]
|
5
|
+
gem.email = ["andriy.yanko@gmail.com"]
|
6
|
+
gem.description = %q{Ruby FFI interface to libskypekit C library}
|
7
|
+
gem.summary = %q{Ruby FFI interface to libskypekit C library}
|
8
|
+
gem.homepage = "https://github.com/railsware/skypekit"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "skypekit"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = "0.0.1"
|
16
|
+
|
17
|
+
gem.add_runtime_dependency "ffi", ">=1.0.0"
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: skypekit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andriy Yanko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ffi
|
16
|
+
requirement: &13134860 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *13134860
|
25
|
+
description: Ruby FFI interface to libskypekit C library
|
26
|
+
email:
|
27
|
+
- andriy.yanko@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- examples/ping_pong.rb
|
38
|
+
- lib/skypekit.rb
|
39
|
+
- lib/skypekit/ffi.rb
|
40
|
+
- lib/skypekit/ffi/account_status_data.rb
|
41
|
+
- lib/skypekit/ffi/chat_message_data.rb
|
42
|
+
- lib/skypekit/ffi/event.rb
|
43
|
+
- lib/skypekit/skype.rb
|
44
|
+
- skypekit.gemspec
|
45
|
+
- spec/skypekit/ffi_spec.rb
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
homepage: https://github.com/railsware/skypekit
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.15
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Ruby FFI interface to libskypekit C library
|
71
|
+
test_files:
|
72
|
+
- spec/skypekit/ffi_spec.rb
|
73
|
+
- spec/spec_helper.rb
|