chronatog-client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,93 @@
1
+ require 'rack/client'
2
+
3
+ module Chronatog
4
+ module Client
5
+
6
+ def self.setup!(service_url, auth_username, auth_password)
7
+ @connection = Connection.new(service_url, auth_username, auth_password)
8
+ end
9
+
10
+ def self.connection
11
+ @connection or raise "connection not setup! yet"
12
+ end
13
+
14
+ class Connection
15
+ def initialize(service_url, auth_username, auth_password)
16
+ @service_url = service_url
17
+ @creds = [auth_username, auth_password]
18
+ @standard_headers = {
19
+ 'CONTENT_TYPE' => 'application/json',
20
+ 'Accept' => 'application/json'
21
+ }
22
+ end
23
+
24
+ def create_job(callback_url, schedule)
25
+ response = client.post(@service_url, @standard_headers, {:callback_url => callback_url, :schedule => schedule}.to_json)
26
+ if response.status == 201
27
+ JSON.parse(response.body)
28
+ else
29
+ raise "Unexpected response #{response.status}: #{response.body}"
30
+ end
31
+ end
32
+
33
+ def destroy_job(job_url)
34
+ response = client.delete(job_url)
35
+ unless response.status == 200
36
+ raise "Unexpected response #{response.status}: #{response.body}"
37
+ end
38
+ end
39
+
40
+ def list_jobs
41
+ response = client.get(@service_url, @standard_headers)
42
+ if response.status == 200
43
+ JSON.parse(response.body)
44
+ else
45
+ raise "Unexpected response #{response.status}: #{response.body}"
46
+ end
47
+ end
48
+
49
+ def get_job(job_url)
50
+ response = client.get(job_url, @standard_headers)
51
+ if response.status == 200
52
+ JSON.parse(response.body)
53
+ else
54
+ raise "Unexpected response #{response.status}: #{response.body}"
55
+ end
56
+ end
57
+
58
+ attr_writer :backend
59
+ def backend
60
+ @backend ||= Rack::Client::Handler::NetHTTP
61
+ end
62
+
63
+ protected
64
+
65
+ def client
66
+ #need to set vars in scope here because Rack::Client.new instance_evals
67
+ bak = @backend
68
+ creds = @creds
69
+ @client ||= Rack::Client.new do
70
+ use BasicAuth, creds
71
+ run bak
72
+ end
73
+ end
74
+
75
+ private
76
+
77
+ class BasicAuth
78
+ def initialize(app, creds)
79
+ @app = app
80
+ @username, @password = creds
81
+ end
82
+
83
+ def call(env)
84
+ env["HTTP_AUTHORIZATION"] = 'Basic ' + ["#{@username}:#{@password}"].pack('m').delete("\r\n")
85
+ @app.call(env)
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+
93
+ end
@@ -0,0 +1,5 @@
1
+ module Chronatog
2
+ module Client
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chronatog-client
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Jacob Burkhart & Josh Lane & Others
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-08 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rack-client
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: "Client for Chronatog: Web cron as a service. See git repo for more details: https://github.com/engineyard/chronatog"
35
+ email:
36
+ - jacob@engineyard.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - lib/chronatog/client.rb
45
+ - lib/chronatog/client/version.rb
46
+ homepage: http://chronatog.engineyard.com
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.11
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: "Client for Chronatog: Web cron as a service."
79
+ test_files: []
80
+