Class: OBIX::Watch

Inherits:
Object
  • Object
show all
Defined in:
lib/obix/watch.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(watch) ⇒ Watch

Initialize a watch.

watch - An OBIX object that implements the Watch contract.



8
9
10
# File 'lib/obix/watch.rb', line 8

def initialize watch
  @watch = watch
end

Class Method Details

.connect(source) ⇒ Object

Connect to an existing watch.

source - A Hash of options (see OBIX#parse for details).



112
113
114
# File 'lib/obix/watch.rb', line 112

def connect source
  new OBIX.parse source
end

Instance Method Details

#add(list) ⇒ Object

Add objects to the watch.

list - An Array of String instances describing objects to add to the watch.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/obix/watch.rb', line 29

def add list
  add = @watch.objects.find { |obj| obj.name == "add" }

  obix = OBIX::Builder.new do |obix|
    obix.obj is: "obix:WatchIn" do |obix|
      obix.list name: "hrefs" do |obix|
        list.each do |item|
          obix.uri val: item
        end
      end
    end
  end

  add.invoke obix.object
end

#allObject

Poll all objects



74
75
76
77
78
79
80
# File 'lib/obix/watch.rb', line 74

def all
  poll = @watch.objects.find { |obj| obj.name == "pollRefresh" }

  poll.invoke.objects.find do |object|
    object.name == "values"
  end.objects
end

#changesObject

Poll objects that have changed



65
66
67
68
69
70
71
# File 'lib/obix/watch.rb', line 65

def changes
  poll = @watch.objects.find { |obj| obj.name == "pollChanges" }

  poll.invoke.objects.find do |object|
    object.name == "values"
  end.objects
end

#deleteObject

Delete the watch.



83
84
85
86
87
# File 'lib/obix/watch.rb', line 83

def delete
  @watch.objects.find do |object|
    object.name == "delete"
  end.invoke
end

#leaseObject

Reference the lease of the watch.

Returns an Integer describing the lease in seconds.



22
23
24
# File 'lib/obix/watch.rb', line 22

def lease
  @watch.objects.find { |o| o.name == "lease" }.val
end

#remove(list) ⇒ Object

Remove objects from the watch.

list - An Array of String instances describing objects to remove from the watch.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/obix/watch.rb', line 48

def remove list
  remove = @watch.objects.find { |obj| obj.name == "remove" }

  obix = OBIX::Builder.new do |obix|
    obix.obj is: "obix:WatchIn" do |obix|
      obix.list name: "hrefs" do |obix|
        list.each do |item|
          obix.uri val: item
        end
      end
    end
  end

  remove.invoke obix.object
end

#to_sObject



89
90
91
# File 'lib/obix/watch.rb', line 89

def to_s
  @watch.to_s
end

#urlObject

Reference the watch.

Returns a String describing the URL to the watch.



15
16
17
# File 'lib/obix/watch.rb', line 15

def url
  @watch.href
end