xplenty-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ module Xplenty
2
+ class API
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,57 @@
1
+ module Xplenty
2
+ class API
3
+ # POST /<accountID>/api/clusters/{clusterID}/watchers
4
+ def watch_cluster(clusterID)
5
+ request(
6
+ :expects => 200,
7
+ :method => :post,
8
+ :path => "/#{account_id}/api/clusters/#{clusterID}/watchers"
9
+ )
10
+ end
11
+
12
+ # DELETE /<accountID>/api/clusters/{clusterID}/watchers
13
+ def stop_watching_cluster(clusterID)
14
+ request(
15
+ :expects => 204,
16
+ :method => :delete,
17
+ :path => "/#{account_id}/api/clusters/#{clusterID}/watchers"
18
+ )
19
+ end
20
+
21
+ # GET /<accountID>/api/clusters/{cluster_id}/watchers
22
+ def cluster_watchers(clusterID)
23
+ request(
24
+ :expects => 200,
25
+ :method => :get,
26
+ :path => "/#{account_id}/api/clusters/#{clusterID}/watchers"
27
+ )
28
+ end
29
+
30
+ # POST /<accountID>/api/jobs/{job_id}/watchers
31
+ def watch_job(jobID)
32
+ request(
33
+ :expects => 200,
34
+ :method => :post,
35
+ :path => "/#{account_id}/api/jobs/#{jobID}/watchers"
36
+ )
37
+ end
38
+
39
+ # DELETE /<accountID>/api/jobs/{job_id}/watchers
40
+ def stop_watching_job(jobID)
41
+ request(
42
+ :expects => 204,
43
+ :method => :delete,
44
+ :path => "/#{account_id}/api/jobs/#{jobID}/watchers"
45
+ )
46
+ end
47
+
48
+ # GET /<accountID>/api/jobs/{job_id}/watchers
49
+ def job_watchers(jobID)
50
+ request(
51
+ :expects => 200,
52
+ :method => :get,
53
+ :path => "/#{account_id}/api/jobs/#{jobID}/watchers"
54
+ )
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,31 @@
1
+ =begin
2
+ # can't implement mock for watchers
3
+
4
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
5
+
6
+ class TestClusterWatchers < MiniTest::Unit::TestCase
7
+ def test_watch_cluster
8
+ with_cluster({'type' => 'sandbox', 'nodes' => 1}) do |cluster|
9
+ response = xplenty.watch_cluster(cluster['id'])
10
+ assert_equal(200, response.status)
11
+ end
12
+ end
13
+
14
+ def test_stop_watching_job
15
+ with_cluster({'type' => 'sandbox', 'nodes' => 1}) do |cluster|
16
+ xplenty.watch_cluster(cluster['id'])
17
+ response = xplenty.stop_watching_cluster(cluster['id'])
18
+ assert_equal(200, response.status)
19
+ end
20
+ end
21
+
22
+ def test_list_job_watchers
23
+ with_cluster({'type' => 'sandbox', 'nodes' => 1}) do |cluster|
24
+ xplenty.watch_cluster(cluster['id'])
25
+ response = xplenty.cluster_watchers(cluster['id'])
26
+ assert_equal(200, response.status)
27
+ end
28
+ end
29
+
30
+ end
31
+ =end
@@ -0,0 +1,27 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestClusters < MiniTest::Unit::TestCase
4
+ def test_list_clusters
5
+ response = xplenty.clusters
6
+
7
+ data = File.read("#{File.dirname(__FILE__)}/../lib/xplenty/api/mock/cache/clusters.json")
8
+
9
+ assert_equal(200, response.status)
10
+ assert_equal(Xplenty::API::OkJson.decode(data), response.body)
11
+ end
12
+
13
+ def test_get_cluster_info
14
+ with_cluster({:type => 'sandbox', :nodes => 1}) do |cluster|
15
+ response = xplenty.get_cluster_info(cluster['id'])
16
+ assert_equal response.status, 200
17
+ assert_equal response.body['id'], cluster['id']
18
+ end
19
+ end
20
+
21
+ def test_terminate_cluster
22
+ with_cluster({:type => 'sandbox', :nodes => 1}) do |cluster|
23
+ response = xplenty.terminate_cluster(cluster['id'])
24
+ assert_equal response.status, 200
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestErrorConditions < MiniTest::Unit::TestCase
4
+
5
+ def test_request_without_app_returns_a_request_fail_error
6
+ assert_raises(Xplenty::API::Errors::RequestFailed) do
7
+ raise Xplenty::API::Errors::RequestFailed.new('TODO', nil) # xplenty.jobs
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../lib/xplenty/api")
2
+
3
+ require 'rubygems'
4
+ gem 'minitest' # ensure we are using the gem version
5
+ require 'minitest/autorun'
6
+ require 'time'
7
+
8
+ MOCK = ENV['MOCK'] != 'false'
9
+
10
+ def xplenty
11
+ # ENV['XPLENTY_API_KEY'] used for :api_key
12
+ # ENV['XPLENTY_ACCOUNT_ID'] used for :account_id
13
+
14
+ ENV['XPLENTY_ACCOUNT_ID'] ||= 'test_account' if MOCK
15
+
16
+ Xplenty::API.new(:mock => MOCK)
17
+ end
18
+
19
+ def random_name
20
+ "xplenty-rb-#{SecureRandom.hex(10)}"
21
+ end
22
+
23
+ def with_cluster(params={}, &block)
24
+ cluster = (xplenty.clusters.body || []).select{|x| ['available', 'creating', 'pending'].include? x['status']}.first
25
+ cluster ||= xplenty.create_cluster(params).body
26
+ @cluster_id = cluster['id']
27
+ ready = false
28
+ until ready
29
+ ready = xplenty.get_cluster_info(@cluster_id).body['status'] == 'available'
30
+ end
31
+ yield(cluster)
32
+ end
@@ -0,0 +1,34 @@
1
+ =begin
2
+ # can't implement mock for watchers
3
+
4
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
5
+
6
+ class TestJobWatchers < MiniTest::Unit::TestCase
7
+ def test_watch_job
8
+ with_cluster({'type' => 'sandbox', 'nodes' => 1}) do |cluster|
9
+ job = xplenty.run_job(cluster['id'], 682).body
10
+ response = xplenty.watch_job(job['id'])
11
+ assert_equal(200, response.status)
12
+ end
13
+ end
14
+
15
+ def test_stop_watching_job
16
+ with_cluster({'type' => 'sandbox', 'nodes' => 1}) do |cluster|
17
+ job = xplenty.run_job(cluster['id'], 682).body
18
+ xplenty.watch_job(job['id'])
19
+ response = xplenty.stop_watching_job(job['id'])
20
+ assert_equal(200, response.status)
21
+ end
22
+ end
23
+
24
+ def test_list_job_watchers
25
+ with_cluster({'type' => 'sandbox', 'nodes' => 1}) do |cluster|
26
+ job = xplenty.run_job(cluster['id'], 682).body
27
+ xplenty.watch_job(job['id'])
28
+ response = xplenty.job_watchers(job['id'])
29
+ assert_equal(200, response.status)
30
+ end
31
+ end
32
+
33
+ end
34
+ =end
@@ -0,0 +1,34 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestJobs < MiniTest::Unit::TestCase
4
+
5
+ def test_list_jobs
6
+ response = xplenty.jobs
7
+ assert_equal(200, response.status)
8
+ assert_equal(Array, response.body.class)
9
+ end
10
+
11
+ def test_run_job
12
+ with_cluster({'type' => 'sandbox', 'nodes' => 1}) do |cluster|
13
+ response = xplenty.run_job(cluster['id'], 682)
14
+ assert_equal(201, response.status)
15
+ end
16
+ end
17
+
18
+ def test_get_job_info
19
+ with_cluster({'type' => 'sandbox', 'nodes' => 1}) do |cluster|
20
+ job = xplenty.run_job(cluster['id'], 682).body
21
+ response = xplenty.get_job_info(job['id'])
22
+ assert_equal(200, response.status)
23
+ end
24
+ end
25
+
26
+ def test_terminate_job
27
+ with_cluster({'type' => 'sandbox', 'nodes' => 1}) do |cluster|
28
+ job = xplenty.run_job(cluster['id'], 682).body
29
+ response = xplenty.terminate_job(job['id'])
30
+ assert_equal(200, response.status)
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "xplenty/api/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "xplenty-api"
7
+ s.version = Xplenty::API::VERSION
8
+ s.authors = ["xmpolaris (Chen ZhongXue)"]
9
+ s.email = ["xmpolaris@gmail.com"]
10
+ s.homepage = "http://github.com/xplenty/xplenty.rb"
11
+ s.summary = %q{Ruby Client for the Xplenty API}
12
+ s.description = %q{Ruby Client for the Xplenty API}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_runtime_dependency 'excon', '~>0.20.0'
20
+
21
+ s.add_development_dependency 'minitest'
22
+ s.add_development_dependency 'rake'
23
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xplenty-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - xmpolaris (Chen ZhongXue)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: excon
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.20.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.20.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Ruby Client for the Xplenty API
63
+ email:
64
+ - xmpolaris@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .travis.yml
71
+ - Gemfile
72
+ - Gemfile.lock
73
+ - LICENSE
74
+ - README.md
75
+ - Rakefile
76
+ - changelog.txt
77
+ - lib/xplenty-api.rb
78
+ - lib/xplenty/api.rb
79
+ - lib/xplenty/api/cluster_plans.rb
80
+ - lib/xplenty/api/clusters.rb
81
+ - lib/xplenty/api/errors.rb
82
+ - lib/xplenty/api/jobs.rb
83
+ - lib/xplenty/api/mock.rb
84
+ - lib/xplenty/api/mock/cache/clusters.json
85
+ - lib/xplenty/api/mock/cache/jobs.json
86
+ - lib/xplenty/api/mock/clusters.rb
87
+ - lib/xplenty/api/mock/jobs.rb
88
+ - lib/xplenty/api/vendor/okjson.rb
89
+ - lib/xplenty/api/version.rb
90
+ - lib/xplenty/api/watchers.rb
91
+ - test/test_cluster_watchers.rb
92
+ - test/test_clusters.rb
93
+ - test/test_error_conditions.rb
94
+ - test/test_helper.rb
95
+ - test/test_job_watchers.rb
96
+ - test/test_jobs.rb
97
+ - xplenty.gemspec
98
+ homepage: http://github.com/xplenty/xplenty.rb
99
+ licenses: []
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 1.8.25
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Ruby Client for the Xplenty API
122
+ test_files:
123
+ - test/test_cluster_watchers.rb
124
+ - test/test_clusters.rb
125
+ - test/test_error_conditions.rb
126
+ - test/test_helper.rb
127
+ - test/test_job_watchers.rb
128
+ - test/test_jobs.rb