Class: DroneCI::Client

Inherits:
Object
  • Object
show all
Includes:
API
Defined in:
lib/drone-ci/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UsersAPI

#users_create, #users_delete, #users_info, #users_list, #users_update

Methods included from UserAPI

#user_builds, #user_info, #user_repos, #user_sync, #user_token

Methods included from TemplatesAPI

#template_create, #template_delete, #template_info, #template_list, #template_update

Methods included from SecretsAPI

#secret_create, #secret_delete, #secret_info, #secret_list, #secret_update

Methods included from ReposAPI

#repo_chown, #repo_create, #repo_delete, #repo_info, #repo_list, #repo_repair, #repo_update

Methods included from CronAPI

#cron_create, #cron_delete, #cron_info, #cron_list, #cron_trigger, #cron_update

Methods included from BuildsAPI

#build_approve, #build_create, #build_decline, #build_info, #build_list, #build_logs, #build_promote, #build_start, #build_stop

Constructor Details

#initialize(**options) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/drone-ci/client.rb', line 13

def initialize(**options)
  @api = options.fetch(:client) do
    server = options.fetch(:server) { ENV.fetch('DRONE_SERVER') }
    token  = options.fetch(:token)  { ENV.fetch('DRONE_TOKEN')  }
    Faraday.new(server) do |client|
      client.adapter :httpx
      client.headers = {
        'Authorization' => "Bearer #{token}"
      }.merge(options.fetch(:headers, {}))
      client.path_prefix = '/api'
      client.request :json
      client.request :retry
      client.response :json
      yield client if block_given?
    end
  end
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



31
32
33
# File 'lib/drone-ci/client.rb', line 31

def api
  @api
end