Class: Thunk
- Inherits:
-
Object
- Object
- Thunk
- Defined in:
- lib/thunk.rb,
lib/thunk/server.rb
Defined Under Namespace
Classes: Server
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#puuid ⇒ Object
readonly
Returns the value of attribute puuid.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
- #bad!(payload = nil) ⇒ Object
- #bad? ⇒ Boolean
- #exists? ⇒ Boolean
- #good!(payload = nil) ⇒ Object
- #good? ⇒ Boolean
- #iffy!(payload = nil) ⇒ Object
- #iffy? ⇒ Boolean
-
#initialize(server, json) ⇒ Thunk
constructor
A new instance of Thunk.
-
#json ⇒ Object
Used for the –raw option in the command-line client.
- #poke(state, payload = nil) ⇒ Object
- #pokeable? ⇒ Boolean
- #public? ⇒ Boolean
- #unknown!(payload = nil) ⇒ Object
- #unknown? ⇒ Boolean
- #url ⇒ Object
Constructor Details
#initialize(server, json) ⇒ Thunk
Returns a new instance of Thunk.
25 26 27 28 |
# File 'lib/thunk.rb', line 25 def initialize server, json @server = server apply json end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/thunk.rb', line 6 def name @name end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
7 8 9 |
# File 'lib/thunk.rb', line 7 def payload @payload end |
#puuid ⇒ Object (readonly)
Returns the value of attribute puuid.
8 9 10 |
# File 'lib/thunk.rb', line 8 def puuid @puuid end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
9 10 11 |
# File 'lib/thunk.rb', line 9 def state @state end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
10 11 12 |
# File 'lib/thunk.rb', line 10 def updated @updated end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
11 12 13 |
# File 'lib/thunk.rb', line 11 def uuid @uuid end |
Class Method Details
.create(*args) ⇒ Object
13 14 15 |
# File 'lib/thunk.rb', line 13 def self.create *args server.create *args end |
.get(*args) ⇒ Object
17 18 19 |
# File 'lib/thunk.rb', line 17 def self.get *args server.get *args end |
Instance Method Details
#bad!(payload = nil) ⇒ Object
34 35 36 |
# File 'lib/thunk.rb', line 34 def bad! payload = nil poke :bad, payload end |
#bad? ⇒ Boolean
30 31 32 |
# File 'lib/thunk.rb', line 30 def bad? :bad == state end |
#exists? ⇒ Boolean
38 39 40 |
# File 'lib/thunk.rb', line 38 def exists? @server.request :get, url end |
#good!(payload = nil) ⇒ Object
46 47 48 |
# File 'lib/thunk.rb', line 46 def good! payload = nil poke :good, payload end |
#good? ⇒ Boolean
42 43 44 |
# File 'lib/thunk.rb', line 42 def good? :good == state end |
#iffy!(payload = nil) ⇒ Object
54 55 56 |
# File 'lib/thunk.rb', line 54 def iffy! payload = nil poke :iffy, payload end |
#iffy? ⇒ Boolean
50 51 52 |
# File 'lib/thunk.rb', line 50 def iffy? :iffy == state end |
#json ⇒ Object
Used for the –raw option in the command-line client.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/thunk.rb', line 60 def json # :nodoc: json = { :name => name, :payload => payload, :puuid => puuid, :state => state, :updated => updated, :url => url, :uuid => uuid } json.reject! { |k, v| v.nil? } JSON.generate json end |
#poke(state, payload = nil) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/thunk.rb', line 75 def poke state, payload = nil if @server.request :post, "#{url}/#{state}", :payload => payload @payload = payload @state = state.to_sym @updated = Time.now.utc end @state end |
#pokeable? ⇒ Boolean
85 86 87 |
# File 'lib/thunk.rb', line 85 def pokeable? puuid end |
#public? ⇒ Boolean
89 90 91 |
# File 'lib/thunk.rb', line 89 def public? !puuid end |
#unknown!(payload = nil) ⇒ Object
97 98 99 |
# File 'lib/thunk.rb', line 97 def unknown! payload = nil poke :unknown, payload end |
#unknown? ⇒ Boolean
93 94 95 |
# File 'lib/thunk.rb', line 93 def unknown? :unknown == state end |
#url ⇒ Object
101 102 103 |
# File 'lib/thunk.rb', line 101 def url "#{@server.url}/#{uuid}" end |