Class: Atlas::Api::Client
- Inherits:
-
Object
- Object
- Atlas::Api::Client
- Defined in:
- lib/atlas-api/client.rb
Instance Method Summary collapse
- #agent ⇒ Object
- #build(id, options = {}) ⇒ Object
-
#build_and_poll(query) ⇒ Object
Builds ————————————————————————.
- #builds(options = {}) ⇒ Object
- #create_build(options) ⇒ Object
- #delete(path, options = {}) ⇒ Object
-
#get(path, options = {}) ⇒ Object
HTTP methods ————————————————————————.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #post(path, options = {}) ⇒ Object
- #put(path, options = {}) ⇒ Object
-
#update_build_format(uuid, options = {}) ⇒ Object
Build Formats ————————————————————————.
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( = {}) @api_endpoint = [:api_endpoint] @auth_token = [:auth_token] end |
Instance Method Details
#agent ⇒ Object
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, = {}) get("builds/#{id}", ) 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( = {}) get("builds", ) end |
#create_build(options) ⇒ Object
42 43 44 |
# File 'lib/atlas-api/client.rb', line 42 def create_build() post("builds", ) end |
#delete(path, options = {}) ⇒ Object
68 69 70 |
# File 'lib/atlas-api/client.rb', line 68 def delete(path, = {}) request :delete, path, end |
#get(path, options = {}) ⇒ Object
HTTP methods
56 57 58 |
# File 'lib/atlas-api/client.rb', line 56 def get(path, = {}) request :get, path, end |
#post(path, options = {}) ⇒ Object
60 61 62 |
# File 'lib/atlas-api/client.rb', line 60 def post(path, = {}) request :post, path, end |
#put(path, options = {}) ⇒ Object
64 65 66 |
# File 'lib/atlas-api/client.rb', line 64 def put(path, = {}) request :put, path, 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, = {}) put("build_formats/#{uuid}", ) end |