Class: WerckerAPI::Client

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

Constant Summary collapse

API_ENDPOINT =
URI('https://app.wercker.com').freeze

Instance Method Summary collapse

Constructor Details

#initialize(token = nil, api_version = 'v3') ⇒ Client



17
18
19
20
21
# File 'lib/wercker_api/client.rb', line 17

def initialize(token = nil, api_version = 'v3')
  self.api_token = token || ENV['WERCKER_API_TOKEN']
  raise_token_nil_error if api_token.nil?
  self.api_version = api_version
end

Instance Method Details

#abort_run(run_id) ⇒ Object

Abort a run

Abort an already running run instance.

Returns an object.



222
223
224
# File 'lib/wercker_api/client.rb', line 222

def abort_run(run_id)
  request build_put_request(Run::ABORT[api_version, run_id]), Run
end

#application(user_name, application) ⇒ WerckerAPI::Application

Get an application

Get the details of a single application.



47
48
49
50
51
52
53
54
# File 'lib/wercker_api/client.rb', line 47

def application(user_name, application)
  request(
    build_get_request(
      Application::SHOW[api_version, user_name, application]
    ),
    Application
  )
end

#application_builds(user_name, application) ⇒ Object

List builds

Retrieve all builds of an application.



80
81
82
83
84
85
86
87
# File 'lib/wercker_api/client.rb', line 80

def application_builds(user_name, application)
  request(
    build_get_request(
      Application::Build::INDEX[api_version, user_name, application]
    ),
    Application::BuildCollection
  )
end

#application_deploys(user_name, application) ⇒ Object

List deploys

Retrieve all deploys of an application.



96
97
98
99
100
101
102
103
# File 'lib/wercker_api/client.rb', line 96

def application_deploys(user_name, application)
  request(
    build_get_request(
      Application::Deploy::INDEX[api_version, user_name, application]
    ),
    Application::DeployCollection
  )
end

#application_workflow(workflow_id) ⇒ Object

Get a workflow

Get the details of a single workflow.

Returns a workflow object, which contains a collection of runs.



128
129
130
131
132
133
134
135
# File 'lib/wercker_api/client.rb', line 128

def application_workflow(workflow_id)
  request(
    build_get_request(
      Application::Workflow::SHOW[api_version, workflow_id]
    ),
    Application::Workflow
  )
end

#application_workflows(application_id) ⇒ Object

Get all workflows

Get the last 10 workflows.



112
113
114
115
116
117
118
119
# File 'lib/wercker_api/client.rb', line 112

def application_workflows(application_id)
  request(
    build_get_request(
      Application::Workflow::INDEX[api_version], applicationId: application_id
    ),
    Application::WorkflowCollection
  )
end

#applications(user_name, params = {}) ⇒ WerckerAPI::ApplicationCollection

List user applications

List all applications owned by the user or organization. The result will only contain applications that the authenticated user has access to. If the call is made without a token, only public applications will be returned.



32
33
34
35
36
37
38
# File 'lib/wercker_api/client.rb', line 32

def applications(user_name, params = {})
  request(
    build_get_request(
      Application::INDEX[api_version, user_name], params
    ), ApplicationCollection
  )
end

#run(run_id) ⇒ Object

Get a run

Get the details of a single run.

Returns a run object.



177
178
179
# File 'lib/wercker_api/client.rb', line 177

def run(run_id)
  request build_get_request(Run::SHOW[api_version, run_id]), Run
end

#run_steps(run_id) ⇒ Object

Get steps for run

Get the steps for a run.

Returns an array of step objects.


189
190
191
# File 'lib/wercker_api/client.rb', line 189

def run_steps(run_id)
  request build_get_request(Run::STEPS[api_version, run_id]), Run::StepCollection
end

#runs(application_id: nil, pipeline_id: nil, params: {}) ⇒ Object

Get all runs

Get the last 20 runs for a given pipeline or application.

Returns an array of run objects.

An application_id
or a pipeline_id

is required!

Options Hash (params:):

  • :limit (Integer)

    Specify how many run objects should be returned. Max: 20, default: 20

  • :skip (Integer)

    Skip the first X runs. Min: 1, default: 0

  • :sort (Integer)
    Valid values: creationDateAsc
    or creationDateDesc::. Default creationDateDesc
  • :status (Integer)
    Filter by status. Valid values: notstarted, started::, finished::, running
  • :result (Integer)
    Filter by result. Valid values: aborted::, unknown::, passed::, **failed
  • :branch (Integer)

    ilter by branch

  • :pipelineId (Integer)

    Filter by pipeline

  • :commit (Integer)

    Filter by commit hash

  • :sourceRun (Integer)

    Filter by source run

  • :author (Integer)

    Filter by Wercker username



160
161
162
163
164
165
166
167
# File 'lib/wercker_api/client.rb', line 160

def runs(application_id: nil, pipeline_id: nil, params: {})
  if application_id
    params[:applicationId] = application_id
  elsif pipeline_id
    params[:pipelineId] = pipeline_id
  end
  request build_get_request(Run::INDEX[api_version], params), RunCollection
end

#trigger_run(pipeline_id, params = {}) ⇒ Object

Trigger a new run

Trigger a new run for an application.

Returns a run object.

It is possible to add environment variables, which will be added to the run. The order of the array will be maintained, which makes it possible to use environment variables that were defined earlier. Any environment variables defined as part of the application or workflow will be overwritten, if using the same key.

Options Hash (params):

  • sourceRunId (String)
    The id
    of the run that should be used as input for this run, including artifacts. This is the same as chaining

    a pipeline.

  • branch (String)
    The Git branch

    that the run should use. If not specified, the default branch will be used.

  • commitHash (String)
    The Git commit hash that the run should used. *Requires branch*

    to be set. If not specified, the latest commit is fetched

  • message (String)

    The message to use for the run. If not specified, the Git commit message is used.

  • envVars (Array)
    Environment variables which should be added to run. Contains objects with key
    and value

    properties.



209
210
211
212
# File 'lib/wercker_api/client.rb', line 209

def trigger_run(pipeline_id, params = {})
  params[:pipelineId] = pipeline_id
  request build_post_request(Run::TRIGGER[api_version], params), Run
end

#update_application(user_name, application, branches) ⇒ WerckerAPI::Application

Update an application

Update a single application. Currently it is only possible to change the ignored branches for the application. The updated application will be returned.



64
65
66
67
68
69
70
71
# File 'lib/wercker_api/client.rb', line 64

def update_application(user_name, application, branches)
  request(
    build_patch_request(
      Application::SHOW[api_version, user_name, application], ignoredBranches: branches
    ),
    Application
  )
end