Class: Buildkit::Client

Inherits:
Object
  • Object
show all
Includes:
Agents, Artifacts, Builds, Jobs, Organizations, Pipelines, HeaderLinkParser
Defined in:
lib/buildkit/client.rb,
lib/buildkit/client/jobs.rb,
lib/buildkit/client/agents.rb,
lib/buildkit/client/builds.rb,
lib/buildkit/client/artifacts.rb,
lib/buildkit/client/pipelines.rb,
lib/buildkit/client/organizations.rb

Defined Under Namespace

Modules: Agents, Artifacts, Builds, Jobs, Organizations, Pipelines

Constant Summary collapse

DEFAULT_ENDPOINT =
'https://api.buildkite.com/v2/'
CONVENIENCE_HEADERS =

Header keys that can be passed in options hash to #get,#head

Set.new(%i[accept content_type])
RACK_BUILDER_CLASS =

In Faraday 0.9, Faraday::Builder was renamed to Faraday::RackBuilder

defined?(Faraday::RackBuilder) ? Faraday::RackBuilder : Faraday::Builder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HeaderLinkParser

parse_link_header

Methods included from Artifacts

#artifacts, #job_artifacts

Methods included from Jobs

#job_env, #job_log, #retry_job

Methods included from Pipelines

#archive_pipeline, #create_pipeline, #pipeline, #pipelines, #unarchive_pipeline, #update_pipeline

Methods included from Organizations

#organization, #organizations

Methods included from Builds

#build, #builds, #cancel_build, #create_build, #organization_builds, #pipeline_builds, #rebuild

Methods included from Agents

#agent, #agents, #stop_agent

Constructor Details

#initialize(endpoint: ENV.fetch('BUILDKITE_API_ENDPOINT', DEFAULT_ENDPOINT), token: ENV.fetch('BUILDKITE_API_TOKEN'), middleware: self.class.build_middleware, auto_paginate: false) ⇒ Client

Returns a new instance of Client.



43
44
45
46
47
48
49
50
# File 'lib/buildkit/client.rb', line 43

def initialize(endpoint: ENV.fetch('BUILDKITE_API_ENDPOINT', DEFAULT_ENDPOINT),
               token: ENV.fetch('BUILDKITE_API_TOKEN'),
               middleware: self.class.build_middleware, auto_paginate: false)
  @middleware = middleware
  @endpoint = endpoint
  @token = token
  @auto_paginate = auto_paginate
end

Instance Attribute Details

#auto_paginateObject

Returns the value of attribute auto_paginate.



31
32
33
# File 'lib/buildkit/client.rb', line 31

def auto_paginate
  @auto_paginate
end

#last_responseObject (readonly)

Returns the value of attribute last_response.



110
111
112
# File 'lib/buildkit/client.rb', line 110

def last_response
  @last_response
end

Class Method Details

.build_middlewareObject



34
35
36
37
38
39
40
# File 'lib/buildkit/client.rb', line 34

def build_middleware
  RACK_BUILDER_CLASS.new do |builder|
    builder.use Buildkit::Response::RaiseError
    builder.adapter Faraday.default_adapter
    yield builder if block_given?
  end
end

Instance Method Details

#delete(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP DELETE request

Parameters:

  • url (String)

    The path, relative to @endpoint

  • options (Hash) (defaults to: {})

    Query and header params for request

Returns:

  • (Sawyer::Resource)


97
98
99
# File 'lib/buildkit/client.rb', line 97

def delete(url, options = {})
  request :delete, url, options
end

#get(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP GET request

Parameters:

  • url (String)

    The path, relative to @endpoint

  • options (Hash) (defaults to: {})

    Query and header params for request

Returns:

  • (Sawyer::Resource)


57
58
59
60
61
62
63
# File 'lib/buildkit/client.rb', line 57

def get(url, options = {})
  if @auto_paginate
    paginate :get, url, parse_query_and_convenience_headers(options)
  else
    request :get, url, parse_query_and_convenience_headers(options)
  end
end

#head(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP HEAD request

Parameters:

  • url (String)

    The path, relative to @endpoint

  • options (Hash) (defaults to: {})

    Query and header params for request

Returns:

  • (Sawyer::Resource)


106
107
108
# File 'lib/buildkit/client.rb', line 106

def head(url, options = {})
  request :head, url, parse_query_and_convenience_headers(options)
end

#patch(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP PATCH request

Parameters:

  • url (String)

    The path, relative to @endpoint

  • options (Hash) (defaults to: {})

    Body and header params for request

Returns:

  • (Sawyer::Resource)


88
89
90
# File 'lib/buildkit/client.rb', line 88

def patch(url, options = {})
  request :patch, url, options
end

#post(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP POST request

Parameters:

  • url (String)

    The path, relative to @endpoint

  • options (Hash) (defaults to: {})

    Body and header params for request

Returns:

  • (Sawyer::Resource)


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

def post(url, options = {})
  request :post, url, options
end

#put(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP PUT request

Parameters:

  • url (String)

    The path, relative to @endpoint

  • options (Hash) (defaults to: {})

    Body and header params for request

Returns:

  • (Sawyer::Resource)


79
80
81
# File 'lib/buildkit/client.rb', line 79

def put(url, options = {})
  request :put, url, options
end

#rootSawyer::Resource

Fetch the root resource for the API

Returns:

  • (Sawyer::Resource)


115
116
117
# File 'lib/buildkit/client.rb', line 115

def root
  get('/')
end