Class: Chronatog::Client::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/chronatog/client.rb

Defined Under Namespace

Classes: BasicAuth

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#backendObject



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_jobsObject



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