Class: Atlas::Api::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/atlas-api/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
# File 'lib/atlas-api/client.rb', line 9

def initialize(options = {})
  @api_endpoint = options[:api_endpoint]
  @auth_token = options[:auth_token]
end

Instance Method Details

#agentObject



72
73
74
75
# File 'lib/atlas-api/client.rb', line 72

def agent
  @agent ||= Faraday.new(url: @api_endpoint, params: { auth_token: @auth_token })
  @agent
end

#build(id, options = {}) ⇒ Object



38
39
40
# File 'lib/atlas-api/client.rb', line 38

def build(id, options = {})
  get("builds/#{id}", options)
end

#build_and_poll(query) ⇒ Object

Builds




17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/atlas-api/client.rb', line 17

def build_and_poll(query)
  post_response = create_build(query)
  tries = 0

  while(true)
    last_response = build(post_response.id)  
    break if last_response.status.find { |format| format.status == "queued" || format.status == "working" }.nil?
    tries += 1
    if tries > 20
      raise "The build is taking too long. Exiting"
    end
    sleep(5)
  end

  last_response
end

#builds(options = {}) ⇒ Object



34
35
36
# File 'lib/atlas-api/client.rb', line 34

def builds(options = {})
  get("builds", options)
end

#create_build(options) ⇒ Object



42
43
44
# File 'lib/atlas-api/client.rb', line 42

def create_build(options)
  post("builds", options)
end

#delete(path, options = {}) ⇒ Object



68
69
70
# File 'lib/atlas-api/client.rb', line 68

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

#get(path, options = {}) ⇒ Object

HTTP methods




56
57
58
# File 'lib/atlas-api/client.rb', line 56

def get(path, options = {})
  request :get, path, options
end

#post(path, options = {}) ⇒ Object



60
61
62
# File 'lib/atlas-api/client.rb', line 60

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

#put(path, options = {}) ⇒ Object



64
65
66
# File 'lib/atlas-api/client.rb', line 64

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

#update_build_format(uuid, options = {}) ⇒ Object

Build Formats




49
50
51
# File 'lib/atlas-api/client.rb', line 49

def update_build_format(uuid, options = {})
  put("build_formats/#{uuid}", options)
end