Class: Chronatog::Client::Connection
- Inherits:
-
Object
- Object
- Chronatog::Client::Connection
- Defined in:
- lib/chronatog/client.rb
Defined Under Namespace
Classes: BasicAuth
Instance Attribute Summary collapse
Instance Method Summary collapse
- #create_job(callback_url, schedule) ⇒ Object
- #destroy_job(job_url) ⇒ Object
- #get_job(job_url) ⇒ Object
-
#initialize(service_url, auth_username, auth_password) ⇒ Connection
constructor
A new instance of Connection.
- #list_jobs ⇒ Object
Constructor Details
#initialize(service_url, auth_username, auth_password) ⇒ Connection
Returns a new instance of Connection.
50 51 52 53 54 55 56 57 |
# File 'lib/chronatog/client.rb', line 50 def initialize(service_url, auth_username, auth_password) @service_url = service_url @creds = [auth_username, auth_password] @standard_headers = { 'CONTENT_TYPE' => 'application/json', 'Accept' => 'application/json' } end |
Instance Attribute Details
#backend ⇒ Object
94 95 96 |
# File 'lib/chronatog/client.rb', line 94 def backend @backend ||= Rack::Client::Handler::NetHTTP end |
Instance Method Details
#create_job(callback_url, schedule) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/chronatog/client.rb', line 59 def create_job(callback_url, schedule) response = client.post(@service_url, @standard_headers, {:callback_url => callback_url, :schedule => schedule}.to_json) if response.status == 201 JSON.parse(response.body) else raise "Unexpected response #{response.status}: #{response.body}" end end |
#destroy_job(job_url) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/chronatog/client.rb', line 68 def destroy_job(job_url) response = client.delete(job_url) unless response.status == 200 raise "Unexpected response #{response.status}: #{response.body}" end end |
#get_job(job_url) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/chronatog/client.rb', line 84 def get_job(job_url) response = client.get(job_url, @standard_headers) if response.status == 200 JSON.parse(response.body) else raise "Unexpected response #{response.status}: #{response.body}" end end |
#list_jobs ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/chronatog/client.rb', line 75 def list_jobs response = client.get(@service_url, @standard_headers) if response.status == 200 JSON.parse(response.body) else raise "Unexpected response #{response.status}: #{response.body}" end end |