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
-
#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(id, formats = {}) ⇒ Object
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
65 66 67 68 |
# File 'lib/atlas-api/client.rb', line 65 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 > 100 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 |
#get(path, options = {}) ⇒ Object
HTTP methods
53 54 55 |
# File 'lib/atlas-api/client.rb', line 53 def get(path, = {}) request :get, path, end |
#post(path, options = {}) ⇒ Object
57 58 59 |
# File 'lib/atlas-api/client.rb', line 57 def post(path, = {}) request :post, path, end |
#put(path, options = {}) ⇒ Object
61 62 63 |
# File 'lib/atlas-api/client.rb', line 61 def put(path, = {}) request :put, path, 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 |