Class: Catlass::Client
- Inherits:
-
Object
- Object
- Catlass::Client
- Defined in:
- lib/catlass/client.rb
Constant Summary collapse
- CA_BASE_URI =
'https://manager.cloudautomator.com/api/v1'
Instance Method Summary collapse
- #create_job(job) ⇒ Object
- #delete_job(job_id) ⇒ Object
- #get_jobs(next_uri = nil) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #set_options(options) ⇒ Object
- #update_job(job_id, job) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 |
# File 'lib/catlass/client.rb', line 8 def initialize @headers = { content_type: :json, accept: :json, Authorization: "Bearer #{ENV['CA_API_KEY']}" } end |
Instance Method Details
#create_job(job) ⇒ Object
28 29 30 31 |
# File 'lib/catlass/client.rb', line 28 def create_job(job) uri = "#{CA_BASE_URI}/jobs" RestClient.post(uri, job['attributes'].to_json, headers=@headers) end |
#delete_job(job_id) ⇒ Object
38 39 40 41 |
# File 'lib/catlass/client.rb', line 38 def delete_job(job_id) uri = "#{CA_BASE_URI}/jobs/#{job_id}" RestClient.delete(uri, headers=@headers) end |
#get_jobs(next_uri = nil) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/catlass/client.rb', line 20 def get_jobs(next_uri=nil) uri = "#{CA_BASE_URI}/jobs" uri = next_uri unless next_uri.nil? jobs = JSON.parse(RestClient.get(uri, headers=@headers).body) jobs['data'].concat(list_jobs(jobs['links']['next'])) if jobs['links'].has_key?('next') jobs['data'] end |
#set_options(options) ⇒ Object
16 17 18 |
# File 'lib/catlass/client.rb', line 16 def () = end |
#update_job(job_id, job) ⇒ Object
33 34 35 36 |
# File 'lib/catlass/client.rb', line 33 def update_job(job_id, job) uri = "#{CA_BASE_URI}/jobs/#{job_id}" RestClient.patch(uri, job['attributes'].to_json, headers=@headers) end |