mortar-api-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +30 -0
- data/LICENSE +202 -0
- data/NOTICE +7 -0
- data/README.md +0 -0
- data/Rakefile +14 -0
- data/lib/mortar/api/basicauth.rb +36 -0
- data/lib/mortar/api/clusters.rb +29 -0
- data/lib/mortar/api/describe.rb +67 -0
- data/lib/mortar/api/errors.rb +44 -0
- data/lib/mortar/api/illustrate.rb +73 -0
- data/lib/mortar/api/jobs.rb +103 -0
- data/lib/mortar/api/login.rb +31 -0
- data/lib/mortar/api/projects.rb +59 -0
- data/lib/mortar/api/tasks.rb +39 -0
- data/lib/mortar/api/user.rb +49 -0
- data/lib/mortar/api/validate.rb +66 -0
- data/lib/mortar/api/vendor/okjson.rb +610 -0
- data/lib/mortar/api/version.rb +25 -0
- data/lib/mortar/api.rb +132 -0
- data/lib/mortar-api-ruby.rb +1 -0
- data/mortar-api-ruby.gemspec +29 -0
- data/spec/mortar/api/basicauth_spec.rb +31 -0
- data/spec/mortar/api/clusters_spec.rb +44 -0
- data/spec/mortar/api/describe_spec.rb +62 -0
- data/spec/mortar/api/illustrate_spec.rb +62 -0
- data/spec/mortar/api/jobs_spec.rb +112 -0
- data/spec/mortar/api/login_spec.rb +53 -0
- data/spec/mortar/api/projects_spec.rb +83 -0
- data/spec/mortar/api/tasks_spec.rb +43 -0
- data/spec/mortar/api/user_spec.rb +64 -0
- data/spec/mortar/api/validate_spec.rb +60 -0
- data/spec/mortar/api_spec.rb +44 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +29 -0
- metadata +186 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2012 Mortar Data Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'set'
|
18
|
+
|
19
|
+
module Mortar
|
20
|
+
class API
|
21
|
+
module Projects
|
22
|
+
STATUS_PENDING = "PENDING"
|
23
|
+
STATUS_CREATING = "CREATING"
|
24
|
+
STATUS_ACTIVE = "ACTIVE"
|
25
|
+
STATUS_FAILED = "FAILED"
|
26
|
+
|
27
|
+
STATUSES_COMPLETE = Set.new([STATUS_ACTIVE,
|
28
|
+
STATUS_FAILED])
|
29
|
+
end
|
30
|
+
|
31
|
+
# GET /vX/projects
|
32
|
+
def get_projects()
|
33
|
+
request(
|
34
|
+
:expects => 200,
|
35
|
+
:method => :get,
|
36
|
+
:path => versioned_path("/projects")
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
# GET /vX/projects/:project
|
41
|
+
def get_project(project_id)
|
42
|
+
request(
|
43
|
+
:expects => 200,
|
44
|
+
:method => :get,
|
45
|
+
:path => versioned_path("/projects/#{project_id}")
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
# POST /vX/projects
|
50
|
+
def post_project(project_name)
|
51
|
+
request(
|
52
|
+
:expects => 200,
|
53
|
+
:method => :post,
|
54
|
+
:path => versioned_path("/projects"),
|
55
|
+
:body => json_encode({"project_name" => project_name})
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2012 Mortar Data Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'set'
|
18
|
+
|
19
|
+
module Mortar
|
20
|
+
class API
|
21
|
+
module Task
|
22
|
+
STATUS_FAILURE = "FAILURE"
|
23
|
+
STATUS_SUCCESS = "SUCCESS"
|
24
|
+
|
25
|
+
STATUSES_COMPLETE = Set.new([STATUS_FAILURE,
|
26
|
+
STATUS_SUCCESS])
|
27
|
+
end
|
28
|
+
|
29
|
+
# GET /vX/tasks/:task
|
30
|
+
def get_task(task_id)
|
31
|
+
request(
|
32
|
+
:expects => 200,
|
33
|
+
:method => :get,
|
34
|
+
:path => versioned_path("/tasks/#{task_id}")
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2012 Mortar Data Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
# Portions of this code from heroku.rb (https://github.com/heroku/heroku.rb/),
|
17
|
+
# used under an MIT license
|
18
|
+
# (https://github.com/heroku/heroku.rb/blob/56fa8ed4cba0ab7e5785d6df75a9de687237124f/README.md#meta).
|
19
|
+
#
|
20
|
+
|
21
|
+
module Mortar
|
22
|
+
class API
|
23
|
+
|
24
|
+
# GET /v2/user
|
25
|
+
def get_user
|
26
|
+
request(
|
27
|
+
:expects => 200,
|
28
|
+
:method => :get,
|
29
|
+
:path => versioned_path("/user")
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
# PUT /v2/user/:user
|
34
|
+
def update_user(user_id, options={})
|
35
|
+
update_params = {}
|
36
|
+
options.each do |key, value|
|
37
|
+
update_params[key.to_s()] = value
|
38
|
+
end
|
39
|
+
body = json_encode(update_params)
|
40
|
+
request(
|
41
|
+
:expects => 200,
|
42
|
+
:method => :put,
|
43
|
+
:path => versioned_path("/user/#{user_id}"),
|
44
|
+
:body => body
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2012 Mortar Data Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'set'
|
18
|
+
|
19
|
+
module Mortar
|
20
|
+
class API
|
21
|
+
module Validate
|
22
|
+
|
23
|
+
STATUS_QUEUED = "QUEUED"
|
24
|
+
STATUS_GATEWAY_STARTING = "GATEWAY_STARTING"
|
25
|
+
STATUS_PROGRESS = "PROGRESS"
|
26
|
+
|
27
|
+
STATUS_FAILURE = "FAILURE"
|
28
|
+
STATUS_SUCCESS = "SUCCESS"
|
29
|
+
STATUS_KILLED = "KILLED"
|
30
|
+
|
31
|
+
STATUSES_IN_PROGRESS = Set.new([STATUS_QUEUED,
|
32
|
+
STATUS_GATEWAY_STARTING,
|
33
|
+
STATUS_PROGRESS])
|
34
|
+
|
35
|
+
STATUSES_COMPLETE = Set.new([STATUS_FAILURE,
|
36
|
+
STATUS_SUCCESS,
|
37
|
+
STATUS_KILLED])
|
38
|
+
end
|
39
|
+
|
40
|
+
# GET /vX/validates/:validate
|
41
|
+
def get_validate(validate_id, options = {})
|
42
|
+
exclude_result = options[:exclude_result] || false
|
43
|
+
request(
|
44
|
+
:expects => 200,
|
45
|
+
:method => :get,
|
46
|
+
:path => versioned_path("/validates/#{validate_id}"),
|
47
|
+
:query => {:exclude_result => exclude_result}
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
# POST /vX/validates
|
52
|
+
def post_validate(project_name, pigscript, git_ref, options = {})
|
53
|
+
parameters = options[:parameters] || {}
|
54
|
+
request(
|
55
|
+
:expects => 200,
|
56
|
+
:method => :post,
|
57
|
+
:path => versioned_path("/validates"),
|
58
|
+
:body => json_encode({"project_name" => project_name,
|
59
|
+
"pigscript_name" => pigscript,
|
60
|
+
"git_ref" => git_ref,
|
61
|
+
"parameters" => parameters
|
62
|
+
})
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|