Class: Snooze::Button

Inherits:
Object
  • Object
show all
Defined in:
lib/snooze/button.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clock_id, options = {}) ⇒ Button

Returns a new instance of Button.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/snooze/button.rb', line 5

def initialize(clock_id, options = {})
  @clock_id = clock_id
  @dry_run = options[:dry_run] || false
  @method = :snooze!
  @verbose = options[:verbose] || false

  if @dry_run
    @method = :ping!
    @verbose = true
  end
end

Instance Attribute Details

#clock_idObject (readonly)

Returns the value of attribute clock_id.



3
4
5
# File 'lib/snooze/button.rb', line 3

def clock_id
  @clock_id
end

#dry_runObject (readonly)

Returns the value of attribute dry_run.



3
4
5
# File 'lib/snooze/button.rb', line 3

def dry_run
  @dry_run
end

#methodObject (readonly)

Returns the value of attribute method.



3
4
5
# File 'lib/snooze/button.rb', line 3

def method
  @method
end

#verboseObject (readonly)

Returns the value of attribute verbose.



3
4
5
# File 'lib/snooze/button.rb', line 3

def verbose
  @verbose
end

Instance Method Details

#snooze!Object

Send snooze! or ping! to Snooze



18
19
20
21
# File 'lib/snooze/button.rb', line 18

def snooze!
  log "Sending #{@method} to Snooze.io"
  handle_post_response { Snooze::Post.send(@method, @clock_id) }
end

#with_backtrace(&block) ⇒ Object

With backtrace capturing do



24
25
26
27
28
29
30
31
32
# File 'lib/snooze/button.rb', line 24

def with_backtrace(&block)
  begin
    log "Yielding backtrace block"
    yield if block_given?
    Snooze::Post.snooze!
  rescue Exception => detail
    handle_post_response { Snooze::Post.exception!(@clock_id, detail.backtrace.join("\n  ")) }
  end
end