Class: Rype::Api
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Class Method Summary collapse
Instance Method Summary collapse
- #attach(application_name = "rype") ⇒ Object
- #invoke(message, &block) ⇒ Object
- #notify(message) ⇒ Object
- #on_notification(scope, proc = nil, &block) ⇒ Object
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
23 24 25 |
# File 'lib/rype/api.rb', line 23 def thread @thread end |
Class Method Details
.instance ⇒ Object
18 19 20 |
# File 'lib/rype/api.rb', line 18 def instance @instance ||= new end |
Instance Method Details
#attach(application_name = "rype") ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rype/api.rb', line 25 def attach(application_name="rype") raise "Already attached." if attached? # Say hi to Skype. status, = api.Invoke "NAME #{application_name}" if status == 'CONNSTATUS OFFLINE' raise Rype::Offline elsif status != 'OK' raise Rype::Denied end api.Invoke "PROTOCOL 7" run_notification_thread end |
#invoke(message, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rype/api.rb', line 42 def invoke(, &block) raise "Not attached to Skype. Call Rype::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
67 68 69 70 71 72 73 74 |
# File 'lib/rype/api.rb', line 67 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
60 61 62 63 64 65 |
# File 'lib/rype/api.rb', line 60 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 |