Class: Buildbox::API

Inherits:
Object
  • Object
show all
Defined in:
lib/buildbox/api.rb

Defined Under Namespace

Classes: AgentNotFoundError, ProxyLogger, ServerError

Instance Method Summary collapse

Constructor Details

#initialize(config = Buildbox.config, logger = Buildbox.logger) ⇒ API

Returns a new instance of API.



27
28
29
30
# File 'lib/buildbox/api.rb', line 27

def initialize(config = Buildbox.config, logger = Buildbox.logger)
  @config = config
  @logger = logger
end

Instance Method Details

#agent(access_token, hostname) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/buildbox/api.rb', line 38

def agent(access_token, hostname)
  put("agents/#{access_token}", :hostname => hostname)
rescue Faraday::Error::ClientError => e
  if e.response[:status] == 404
    raise AgentNotFoundError.new(e, e.response)
  else
    raise ServerError.new(e, e.response)
  end
end

#authenticate(api_key) ⇒ Object



32
33
34
35
36
# File 'lib/buildbox/api.rb', line 32

def authenticate(api_key)
  @api_key = api_key

  get("user")
end

#scheduled_builds(agent) ⇒ Object



48
49
50
# File 'lib/buildbox/api.rb', line 48

def scheduled_builds(agent)
  get(agent.scheduled_builds_url).map { |build| Buildbox::Build.new(build) }
end

#update_build(build, options) ⇒ Object



52
53
54
# File 'lib/buildbox/api.rb', line 52

def update_build(build, options)
  put(build.url, options)
end