skype 0.1.2 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 903e0cbc11719056bdfd2ed7c958998666da8e4e
4
- data.tar.gz: 15c4de23bccc80e943f6e513168a06e4a23c5ce8
3
+ metadata.gz: f55fb6515dd62ebcf14675c0baea34a9a7a7d10e
4
+ data.tar.gz: ced58a4a2c91ec00dce90a431d24810312973c2c
5
5
  SHA512:
6
- metadata.gz: e2969f9bc8c6402ecea6823225dc5f36bfbae5872d0e10f27f1552381a8a26453a408bea4f801b07896f9f9592d4b0ccfdfb2baa7b7e6211dfc622f34afe40ac
7
- data.tar.gz: 978831a1c108f4411956e9dc981e11543263e3ace9b0b8d6a740137838cc8e4aa8c9798e111a3a7c41c42a3a023fd2afb15da8b44d54acb52bcd6da6d34fdf7e
6
+ metadata.gz: eeeb14ae23fb7791b40502dc73e2a41c3e18c660625410f747ef72f28547551a02bbd60993e12d1f2729febfe1c6d2493656554eb404b12dfdfda7dc449b1027
7
+ data.tar.gz: b541ab42b556bfb088dc2c1cefdf32154295e37e4ef9b650a67ef790dc7d2308d5efd66e5f2399d78c7d415e888c50ab71c59357cb3cda2ff7f4d50a15fa0a12
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- skype (0.1.2)
4
+ skype (0.1.3)
5
5
  tmp_cache
6
6
 
7
7
  GEM
@@ -1,3 +1,8 @@
1
+ === 0.1.3 2013-06-30
2
+
3
+ * wrap the return value of chat message with Skype::Chat::Message
4
+ * add tests
5
+
1
6
  === 0.1.2 2013-06-29
2
7
 
3
8
  * bugfix Chat API wrapper
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  Skype
2
2
  =====
3
- [Skype Desktop API](http://dev.skype.com/desktop-api-reference) wrapper for Ruby
3
+ [Skype Desktop API](http://dev.skype.com/desktop-api-reference) Ruby wrapper for Mac/Linux.
4
4
 
5
5
  - https://github.com/shokai/skype-ruby
6
6
  - http://rubygems.org/gems/skype
@@ -3,6 +3,7 @@ require "kconv"
3
3
  require "tmp_cache"
4
4
 
5
5
  require "skype/version"
6
+ require "skype/register"
6
7
  require case RUBY_PLATFORM
7
8
  when /darwin/
8
9
  "skype/platforms/mac"
@@ -18,6 +18,12 @@ module Skype
18
18
  end
19
19
 
20
20
  def self.exec(command)
21
- (@@connection||=Connection.new).invoke command
21
+ res = (@@connection||=Connection.new).invoke command
22
+ @@filters.each do |filter, block|
23
+ next unless res =~ filter
24
+ res = block.call(res)
25
+ break
26
+ end
27
+ res
22
28
  end
23
29
  end
@@ -3,9 +3,13 @@ module Skype
3
3
  script = %Q{tell application "Skype"
4
4
  send command "#{Utils.escape command}" script name "#{self.config[:app_name]}"
5
5
  end tell}
6
- res = `unset LD_LIBRARY_PATH; unset DYLD_LIBRARY_PATH; /usr/bin/osascript -e '#{script}'`.split(/[\n\r]+/)
7
- res.shift if res.size > 1 and res[0] =~ /^dyld: /
8
- res[0]
6
+ res = `unset LD_LIBRARY_PATH; unset DYLD_LIBRARY_PATH; /usr/bin/osascript -e '#{script}'`.strip
7
+ @@filters.each do |filter, block|
8
+ next unless res =~ filter
9
+ res = block.call(res)
10
+ break
11
+ end
12
+ res
9
13
  end
10
14
 
11
15
  module Utils
@@ -0,0 +1,9 @@
1
+ module Skype
2
+ @@filters = {}
3
+
4
+ def self.response_filter(pattern, &block)
5
+ raise ArgumentError, "pattern must be instance of Regexp" unless pattern.kind_of? Regexp
6
+ raise ArgumentError, "block not given" unless block_given?
7
+ @@filters[pattern] = block
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Skype
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -1,5 +1,9 @@
1
1
  module Skype
2
2
 
3
+ response_filter /^(CHAT)?MESSAGE (\d+) STATUS (SENT|SENDING)$/ do |res|
4
+ Skype::Chat::Message.new res.scan(/^(CHAT)?MESSAGE (\d+) STATUS (SENT|SENDING)$/)[0][1].to_i
5
+ end
6
+
3
7
  def self.chats
4
8
  search("recentchats").
5
9
  scan(/(#[^\s,]+)[\s,]/).
@@ -12,9 +16,9 @@ module Skype
12
16
  attr_reader :id, :topic, :members
13
17
 
14
18
  def initialize(id)
15
- @id = id
16
- @topic = ::Skype::exec("GET CHAT #{@id} TOPIC").scan(/TOPIC (.*)$/)[0][0].toutf8
17
- @members = ::Skype::exec("GET CHAT #{@id} MEMBERS").scan(/MEMBERS (.+)$/)[0][0].split(/\s/)
19
+ @id = id.to_i
20
+ @topic = ::Skype.exec("GET CHAT #{@id} TOPIC").scan(/TOPIC (.*)$/)[0][0].toutf8 rescue @topic = ""
21
+ @members = ::Skype.exec("GET CHAT #{@id} MEMBERS").scan(/MEMBERS (.+)$/)[0][0].split(/\s/) rescue @members = []
18
22
  end
19
23
 
20
24
  def messages
@@ -35,7 +39,7 @@ module Skype
35
39
  attr_reader :id, :user, :body, :time
36
40
 
37
41
  def initialize(id)
38
- @id = id
42
+ @id = id.to_i
39
43
  @user = ::Skype.exec("GET CHATMESSAGE #{@id} from_handle").split(/\s/).last rescue @user = ""
40
44
  @body = ::Skype.exec("GET CHATMESSAGE #{@id} body").scan(/^(CHAT)?MESSAGE #{@id} BODY (.+)$/)[0][1] rescue @body = ""
41
45
  @time = Time.at ::Skype.exec("GET CHATMESSAGE #{@id} timestamp").split(/\s/).last.to_i
@@ -6,7 +6,7 @@ require 'skype'
6
6
 
7
7
  chats = Skype.chats
8
8
  puts "#{chats.length} chats found"
9
- chat = chats.find{|c| c.members.include? "shokaishokai" and c.topic =~ /test/}
9
+ chat = chats.find{|c| c.members.include? "shokaishokai" and c.topic =~ /test/} || chats[0]
10
10
 
11
11
  p chat
12
12
  chat.post "test"
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Skype::VERSION
9
9
  spec.authors = ["Sho Hashimoto"]
10
10
  spec.email = ["hashimoto@shokai.org"]
11
- spec.description = %q{Skype Desktop API wrapper for Ruby}
11
+ spec.description = %q{Skype Desktop API Ruby wrapper for Mac/Linux.}
12
12
  spec.summary = spec.description
13
13
  spec.homepage = "https://github.com/shokai/skype-ruby"
14
14
  spec.license = "MIT"
@@ -0,0 +1,38 @@
1
+ require File.expand_path 'test_helper', File.dirname(__FILE__)
2
+
3
+ class TestSkype < MiniTest::Test
4
+
5
+ SKYPE_FROM = ENV["SKYPE_FROM"]
6
+ SKYPE_TO = ENV["SKYPE_TO"] || "echo123"
7
+
8
+ def test_exec
9
+ body = "hello exec"
10
+ msg = Skype.exec "MESSAGE #{SKYPE_TO} #{body}"
11
+ assert_equal msg.body, body
12
+ assert_equal msg.time.class, Time
13
+ assert_equal msg.user, SKYPE_FROM
14
+ end
15
+
16
+ def test_message
17
+ body = "hello hello"
18
+ msg = Skype.message SKYPE_TO, body
19
+ assert_equal msg.body, body
20
+ assert_equal msg.time.class, Time
21
+ assert_equal msg.user, SKYPE_FROM
22
+ end
23
+
24
+ def test_message_escape
25
+ body = "hello \"'$@&()^![]{};*?<>`\\ world"
26
+ msg = Skype.message SKYPE_TO, body
27
+ assert_equal msg.body, body
28
+ assert_equal msg.time.class, Time
29
+ assert_equal msg.user, SKYPE_FROM
30
+ end
31
+
32
+ def test_chats
33
+ chat = Skype.chats[0]
34
+ assert_equal chat.class, Skype::Chat
35
+ assert_equal chat.topic.class, String
36
+ assert_equal chat.members.class, Array
37
+ end
38
+ end
@@ -2,42 +2,9 @@ require File.expand_path 'test_helper', File.dirname(__FILE__)
2
2
 
3
3
  class TestSkype < MiniTest::Test
4
4
 
5
- SKYPE_FROM = ENV["SKYPE_FROM"]
6
- SKYPE_TO = ENV["SKYPE_TO"]
7
-
8
- def test_exec
9
- body = "hello exec"
10
- res = Skype.exec "MESSAGE #{SKYPE_TO} #{body}"
11
- assert res =~ /^(CHAT)?MESSAGE \d+ STATUS (SENT|SENDING)$/, "Skype API response error"
12
- res_id = res.scan(/(CHAT)?MESSAGE (\d+) STATUS (SENT|SENDING)$/)[0][1].to_i
13
- msg = Skype::Chat::Message.new res_id
14
- assert_equal msg.id, res_id
15
- assert_equal msg.body, body
16
- assert_equal msg.time.class, Time
17
- assert_equal msg.user, SKYPE_FROM
18
- end
19
-
20
- def test_message
21
- body = "hello hello"
22
- res = Skype.message SKYPE_TO, body
23
- assert res =~ /^(CHAT)?MESSAGE \d+ STATUS (SENT|SENDING)$/, "Skype API response error"
24
- res_id = res.scan(/(CHAT)?MESSAGE (\d+) STATUS (SENT|SENDING)$/)[0][1].to_i
25
- msg = Skype::Chat::Message.new res_id
26
- assert_equal msg.id, res_id
27
- assert_equal msg.body, body
28
- assert_equal msg.time.class, Time
29
- assert_equal msg.user, SKYPE_FROM
5
+ def test_username
6
+ res = Skype.exec "GET USER echo123 FULLNAME"
7
+ assert res =~ /Sound Test Service/i, "API response error"
30
8
  end
31
9
 
32
- def test_message_escape
33
- body = "hello \"'$@&()^![]{};*?<>`\\ world"
34
- res = Skype.message SKYPE_TO, body
35
- assert res =~ /^(CHAT)?MESSAGE \d+ STATUS (SENT|SENDING)$/, "Skype API response error"
36
- res_id = res.scan(/(CHAT)?MESSAGE (\d+) STATUS (SENT|SENDING)$/)[0][1].to_i
37
- msg = Skype::Chat::Message.new res_id
38
- assert_equal msg.id, res_id
39
- assert_equal msg.body, body
40
- assert_equal msg.time.class, Time
41
- assert_equal msg.user, SKYPE_FROM
42
- end
43
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skype
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sho Hashimoto
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '5.0'
69
- description: Skype Desktop API wrapper for Ruby
69
+ description: Skype Desktop API Ruby wrapper for Mac/Linux.
70
70
  email:
71
71
  - hashimoto@shokai.org
72
72
  executables: []
@@ -84,12 +84,14 @@ files:
84
84
  - lib/skype/main.rb
85
85
  - lib/skype/platforms/linux.rb
86
86
  - lib/skype/platforms/mac.rb
87
+ - lib/skype/register.rb
87
88
  - lib/skype/version.rb
88
89
  - lib/skype/wrappers/chat.rb
89
90
  - samples/call.rb
90
91
  - samples/chat.rb
91
92
  - samples/send_message.rb
92
93
  - skype.gemspec
94
+ - test/test_chat.rb
93
95
  - test/test_helper.rb
94
96
  - test/test_skype.rb
95
97
  homepage: https://github.com/shokai/skype-ruby
@@ -115,7 +117,8 @@ rubyforge_project:
115
117
  rubygems_version: 2.0.3
116
118
  signing_key:
117
119
  specification_version: 4
118
- summary: Skype Desktop API wrapper for Ruby
120
+ summary: Skype Desktop API Ruby wrapper for Mac/Linux.
119
121
  test_files:
122
+ - test/test_chat.rb
120
123
  - test/test_helper.rb
121
124
  - test/test_skype.rb