Class: Terraspace::Terraform::Api::Runs

Inherits:
Base
  • Object
show all
Extended by:
Memoist
Defined in:
lib/terraspace/terraform/api/runs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Logging

#logger

Methods included from Http::Concern

#http

Constructor Details

#initialize(workspace_id) ⇒ Runs

Returns a new instance of Runs.



6
7
8
# File 'lib/terraspace/terraform/api/runs.rb', line 6

def initialize(workspace_id)
  @workspace_id = workspace_id
end

Instance Attribute Details

#workspace_idObject (readonly)

Returns the value of attribute workspace_id.



5
6
7
# File 'lib/terraspace/terraform/api/runs.rb', line 5

def workspace_id
  @workspace_id
end

Instance Method Details

#action(action, id) ⇒ Object



34
35
36
37
# File 'lib/terraspace/terraform/api/runs.rb', line 34

def action(action, id)
  payload = http.post("runs/#{id}/actions/#{action}")
  payload['data'] if payload
end

#cancel(id) ⇒ Object



30
31
32
# File 'lib/terraspace/terraform/api/runs.rb', line 30

def cancel(id)
  action("cancel", id)
end

#discard(id) ⇒ Object



26
27
28
# File 'lib/terraspace/terraform/api/runs.rb', line 26

def discard(id)
  action("discard", id)
end

#listObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/terraspace/terraform/api/runs.rb', line 10

def list
  data, next_page = [], :start
  while next_page == :start || next_page
    url = "workspaces/#{@workspace_id}/runs"
    if next_page
      qs = URI.encode_www_form('page[number]': next_page) if next_page
      url += "?#{qs}"
    end
    payload = http.get(url)
    return unless payload
    data += payload['data']
    next_page = payload['meta']['pagination']['next-page']
  end
  data
end