Class: Skype::Api
Class Method Summary collapse
Instance Method Summary collapse
- #attach(application_name = "ruby-skype") ⇒ Object
- #invoke(message, &block) ⇒ Object
- #notify(message) ⇒ Object
- #on_notification(scope, proc = nil, &block) ⇒ Object
Class Method Details
.instance ⇒ Object
18 19 20 |
# File 'lib/skype/api.rb', line 18 def instance @instance ||= new end |
Instance Method Details
#attach(application_name = "ruby-skype") ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/skype/api.rb', line 23 def attach(application_name="ruby-skype") raise "Already attached." if @attached # Say hi to Skype. api.Invoke "NAME #{application_name}" api.Invoke "PROTOCOL 7" run_notification_thread @attached = true end |
#invoke(message, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/skype/api.rb', line 35 def invoke(, &block) raise "Not attached to skype. Call Skype::Api.attach first." unless @attached log_outgoing if block_given? api.Invoke() do |headers, answer| log_incoming answer block.call(answer) end else answer = api.Invoke() do |_, _| # Huh? Without passing in a block, sometimes it hangs...?? end log_incoming answer answer end end |
#notify(message) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/skype/api.rb', line 60 def notify() log_incoming callbacks.keys.each do |key| next unless match = Regexp.new("^#{key}").match() callbacks[key].each{ |callback| callback.call(*match.captures) } end end |
#on_notification(scope, proc = nil, &block) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/skype/api.rb', line 53 def on_notification(scope, proc=nil, &block) raise "Need to register callbacks before attaching to Skype." if @attached callbacks[scope] ||= [] callbacks[scope] << (proc ? proc : block) end |