Class: AutomateSoup::Topic
- Inherits:
-
Object
- Object
- AutomateSoup::Topic
show all
- Defined in:
- lib/automate_soup/topic.rb
Overview
Class to represent operations on a topic.
Instance Method Summary
collapse
Constructor Details
#initialize(hash) ⇒ Topic
Returns a new instance of Topic
9
10
11
|
# File 'lib/automate_soup/topic.rb', line 9
def initialize(hash)
@source = OpenStruct.new hash
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
13
14
15
|
# File 'lib/automate_soup/topic.rb', line 13
def method_missing(method, *args, &block)
@source.send(method, *args, &block)
end
|
Instance Method Details
#approve ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/automate_soup/topic.rb', line 25
def approve
return nil if current_stage.stage != 'verify'
raise 'Must run AutomateSoup.setup first' if AutomateSoup.url.nil? || AutomateSoup.credentials.nil?
raise 'Approve link not available' if links.nil? || links['approve'].nil? || links['approve']['href'].nil?
url = "#{AutomateSoup.url}#{links['approve']['href']}"
res = AutomateSoup::Rest.post(
url: url,
username: AutomateSoup.credentials.username,
token: AutomateSoup.credentials.token
)
raise "Failed to approve topic: #{res.code}" if res.code != '204'
true
end
|
#current_stage ⇒ Object
17
18
19
|
# File 'lib/automate_soup/topic.rb', line 17
def current_stage
Stage.new @source.stages.last
end
|
#deliver ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/automate_soup/topic.rb', line 39
def deliver
raise 'Must approve change first' if current_stage.stage.eql? 'verify'
return nil if current_stage.stage != 'acceptance'
raise 'Must run AutomateSoup.setup first' if AutomateSoup.url.nil? || AutomateSoup.credentials.nil?
raise 'Deliver link not available' if links.nil? || links['deliver'].nil? || links['deliver']['href'].nil?
url = "#{AutomateSoup.url}#{links['deliver']['href']}"
res = AutomateSoup::Rest.post(
url: url,
username: AutomateSoup.credentials.username,
token: AutomateSoup.credentials.token
)
raise "Failed to deliver topic: #{res.code}" if res.code != '204'
true
end
|
#links ⇒ Object
21
22
23
|
# File 'lib/automate_soup/topic.rb', line 21
def links
@source._links
end
|