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



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

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



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

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

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

HTTP methods




53
54
55
# File 'lib/atlas-api/client.rb', line 53

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

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



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

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

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



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

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

#update_build(id, formats = {}) ⇒ Object



46
47
48
# File 'lib/atlas-api/client.rb', line 46

def update_build(id, formats = {})
  put("builds/#{id}", :formats => formats)
end