Class: Buildkit::Client

Inherits:
Object
  • Object
show all
Includes:
Agents, Artifacts, Builds, Jobs, Organizations, Pipelines
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/'.freeze
CONVENIENCE_HEADERS =

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

Set.new([: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 Artifacts

#artifacts

Methods included from Jobs

#job_env, #retry_job

Methods included from Pipelines

#create_pipeline, #pipeline, #pipelines, #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) ⇒ Client

Returns a new instance of Client.



37
38
39
40
41
42
43
# File 'lib/buildkit/client.rb', line 37

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

Instance Attribute Details

#last_responseObject (readonly)

Returns the value of attribute last_response.



99
100
101
# File 'lib/buildkit/client.rb', line 99

def last_response
  @last_response
end

Class Method Details

.build_middlewareObject



28
29
30
31
32
33
34
# File 'lib/buildkit/client.rb', line 28

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)


86
87
88
# File 'lib/buildkit/client.rb', line 86

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)


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

def get(url, options = {})
  request :get, url, parse_query_and_convenience_headers(options)
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)


95
96
97
# File 'lib/buildkit/client.rb', line 95

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)


77
78
79
# File 'lib/buildkit/client.rb', line 77

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)


59
60
61
# File 'lib/buildkit/client.rb', line 59

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)


68
69
70
# File 'lib/buildkit/client.rb', line 68

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

#rootSawyer::Resource

Fetch the root resource for the API

Returns:

  • (Sawyer::Resource)


104
105
106
# File 'lib/buildkit/client.rb', line 104

def root
  get('/')
end