Class: Semaph::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/semaph/client.rb

Overview

Defined Under Namespace

Classes: RequestException

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, host) ⇒ Client

Returns a new instance of Client.



19
20
21
22
23
24
25
# File 'lib/semaph/client.rb', line 19

def initialize(token, host)
  @token = token
  @host = host
  @name = host.split(".").first
  @host_url = "https://#{host}"
  @base = "#{@host_url}/api/v1alpha"
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



17
18
19
# File 'lib/semaph/client.rb', line 17

def host
  @host
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/semaph/client.rb', line 17

def name
  @name
end

Instance Method Details

#job(id) ⇒ Object



70
71
72
# File 'lib/semaph/client.rb', line 70

def job(id)
  get "jobs/#{id}"
end

#job_log(id) ⇒ Object



78
79
80
# File 'lib/semaph/client.rb', line 78

def job_log(id)
  get_raw "jobs/#{id}/plain_logs.json"
end

#pipeline(id) ⇒ Object



58
59
60
# File 'lib/semaph/client.rb', line 58

def pipeline(id)
  get "pipelines/#{id}", { detailed: true }
end

#pipelines(options) ⇒ Object



54
55
56
# File 'lib/semaph/client.rb', line 54

def pipelines(options)
  get "pipelines", options
end

#projectsObject



27
28
29
# File 'lib/semaph/client.rb', line 27

def projects
  get "projects"
end

#promote(pipeline_id, name) ⇒ Object



66
67
68
# File 'lib/semaph/client.rb', line 66

def promote(pipeline_id, name)
  post "promotions", { pipeline_id: pipeline_id, name: name }
end

#promotions(pipeline_id) ⇒ Object



62
63
64
# File 'lib/semaph/client.rb', line 62

def promotions(pipeline_id)
  get "promotions", { pipeline_id: pipeline_id }
end

#rerun_workflow(workflow_id) ⇒ Object



50
51
52
# File 'lib/semaph/client.rb', line 50

def rerun_workflow(workflow_id)
  post "plumber-workflows/#{workflow_id}/reschedule?request_token=#{workflow_id}"
end

#stop_job(id) ⇒ Object



74
75
76
# File 'lib/semaph/client.rb', line 74

def stop_job(id)
  post "jobs/#{id}/stop"
end

#stop_workflow(workflow_id) ⇒ Object



46
47
48
# File 'lib/semaph/client.rb', line 46

def stop_workflow(workflow_id)
  post "plumber-workflows/#{workflow_id}/terminate"
end

#workflow(workflow_id) ⇒ Object



42
43
44
# File 'lib/semaph/client.rb', line 42

def workflow(workflow_id)
  get "plumber-workflows/#{workflow_id}"
end

#workflows(project_id) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/semaph/client.rb', line 31

def workflows(project_id)
  5.times do
    begin
      return get "plumber-workflows", { project_id: project_id }
    rescue RuntimeError => e
      puts "failed to retrieve workflows (#{e.message}) - trying again"
    end
    sleep 1
  end
end