xway 0.0.1.beta → 0.0.2.beta

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  rvm:
2
- - rbx-19mode
2
+ - 2.0.0
3
3
 
data/README.md CHANGED
@@ -34,6 +34,12 @@ Or install it yourself as:
34
34
  4. Push to the branch (`git push origin my-new-feature`)
35
35
  5. Create new Pull Request
36
36
 
37
+ ### Development
38
+
39
+ To run the binary from the repository use the following command with ruby libray path:
40
+
41
+ RUBYLIB=lib bin/xway
42
+
37
43
  ### Coding guide
38
44
 
39
45
  * Using global methods like `Xway.parameter`
@@ -9,36 +9,67 @@ module Xway
9
9
  Request.new 'post', '/applications', options
10
10
  end
11
11
 
12
- def find options={app: ':name'}
13
- Request.new 'get', "/applications/#{options[:app]}"
12
+ def find options={}
13
+ require_options options, :name
14
+ options[:name] ||= ':name'
15
+ Request.new 'get', "/applications/#{options[:name]}"
14
16
  end
15
17
 
16
- def update options={app: ':name'}
17
- Request.new 'put', "/applications/#{options[:app]}"
18
+ def update options={}
19
+ require_options options, :name
20
+ options[:name] ||= ':name'
21
+ Request.new 'put', "/applications/#{options[:name]}"
18
22
  end
19
23
 
20
- def delete options={app: ':name'}
21
- Request.new 'delete', "/applications/#{options[:app]}"
24
+ def delete options={}
25
+ require_options options, :name
26
+ options[:name] ||= ':name'
27
+ Request.new 'delete', "/applications/#{options[:name]}"
22
28
  end
23
29
 
24
- def log options={app: ':name'}
25
- Request.new 'get', "/applications/#{options[:app]}/log"
30
+ def log options={}
31
+ require_options options, :name
32
+ options[:name] ||= ':name'
33
+ Request.new 'get', "/applications/#{options[:name]}/log"
26
34
  end
27
35
 
28
- def start options={app: ':name'}
29
- Request.new 'post', "/applications/#{options[:app]}/start"
36
+ def start options={}
37
+ require_options options, :name
38
+ options[:name] ||= ':name'
39
+ Request.new 'post', "/applications/#{options[:name]}/start"
30
40
  end
31
41
 
32
- def stop options={app: ':name'}
33
- Request.new 'post', "/applications/#{options[:app]}/stop"
42
+ def stop options={}
43
+ require_options options, :name
44
+ options[:name] ||= ':name'
45
+ Request.new 'post', "/applications/#{options[:name]}/stop"
34
46
  end
35
47
 
36
- def restart options={app: ':name'}
37
- Request.new 'post', "/applications/#{options[:app]}/restart"
48
+ def restart options={}
49
+ require_options options, :name
50
+ options[:name] ||= ':name'
51
+ Request.new 'post', "/applications/#{options[:name]}/restart"
38
52
  end
39
53
 
40
- def redeploy options={app: ':name'}
41
- Request.new 'post', "/applications/#{options[:app]}/redeploy"
54
+ def redeploy options={}
55
+ require_options options, :name
56
+ options[:name] ||= ':name'
57
+ Request.new 'post', "/applications/#{options[:name]}/redeploy"
58
+ end
59
+
60
+ private
61
+
62
+ def require_options options, *keys
63
+ missing_keys = []
64
+ keys.each do |key|
65
+ if !options || options[key] == nil || options[key] == ''
66
+ missing_keys << key
67
+ end
68
+ end
69
+ unless missing_keys.empty?
70
+ raise MissingParameter, "Missing app parameter(s): "\
71
+ "#{missing_keys.map(&:to_s).join(', ')}"
72
+ end
42
73
  end
43
74
  end
44
75
  end
data/lib/xway/api/http.rb CHANGED
@@ -10,7 +10,7 @@ module Xway
10
10
  end
11
11
  HTTParty.send(request.method_name, uri, http_options)
12
12
  rescue => e
13
- raise Error, ["#{server} appears offline", e]
13
+ raise ConnectionError, ["#{server} appears offline", e]
14
14
  end
15
15
  end
16
16
  end
data/lib/xway/cli.rb CHANGED
@@ -14,6 +14,8 @@ module Xway
14
14
  else
15
15
  @out.puts @api.request(*commands)
16
16
  end
17
+ rescue MissingParameter => e
18
+ @out.puts e.message
17
19
  end
18
20
  end
19
21
  end
data/lib/xway/error.rb CHANGED
@@ -4,4 +4,8 @@ module Xway
4
4
 
5
5
  class ManifestFileNotFound < Error; end
6
6
  class ManifestFileTypeUnsupported < Error; end
7
+
8
+ class MissingParameter < Error; end
9
+
10
+ class ConnectionError < Error; end
7
11
  end
@@ -8,11 +8,9 @@ module Xway
8
8
  flag: 's',
9
9
  description: 'all appway servers',
10
10
  default: ['http://localhost:8000']
11
- @param.define 'app.name', type: String,
12
- flag: 'a',
11
+ @param.define 'app.name', flag: 'a',
13
12
  description: 'name of your app'
14
- @param.define 'app.manifest', type: String,
15
- flag: 'm',
13
+ @param.define 'app.manifest', flag: 'm',
16
14
  description: 'path to your app.way file'
17
15
  @param.define :debug, flag: 'd',
18
16
  description: 'print debug info to stdout',
data/lib/xway/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Xway
2
- VERSION = "0.0.1.beta"
2
+ VERSION = "0.0.2.beta"
3
3
  end
@@ -1,89 +1,125 @@
1
1
  require 'spec_helper'
2
+ require 'xway/error'
2
3
  require 'xway/api/endpoints'
3
4
  require 'xway/api/request'
4
5
 
5
6
  describe Xway::Api::Endpoints do
6
7
  subject('endpoints') { described_class.new }
7
8
 
8
- describe 'list' do
9
- subject { endpoints.list({}) }
10
- its('method_name') { should eq 'get' }
11
- its('path') { should eq '/applications' }
12
- its('headers') { should eq('X-App' => 'appway') }
13
- its('body') { should eq(nil) }
9
+ specify 'list doesnt require_options' do
10
+ expect{ subject.list }.not_to raise_error(Xway::MissingParameter)
14
11
  end
15
-
16
- describe 'create' do
17
- let('manifest') { File.join(ASSETS_PATH, 'appway-example.json') }
18
- subject { endpoints.create manifest: manifest }
19
- its('method_name') { should eq 'post' }
20
- its('path') { should eq '/applications' }
21
- its('headers') { should eq('X-App' => 'appway',
22
- 'Content-Type' => 'application/json') }
23
- its('body') { should be_kind_of(Xway::Api::Request::Body) }
12
+ specify 'create doesnt require_options' do
13
+ expect{ subject.create }.not_to raise_error(Xway::MissingParameter)
24
14
  end
25
-
26
- describe 'find' do
27
- subject { endpoints.find app: 'foo' }
28
- its('method_name') { should eq 'get' }
29
- its('path') { should eq '/applications/foo' }
30
- its('headers') { should eq('X-App' => 'appway') }
31
- its('body') { should eq(nil) }
15
+ specify 'find does require_options' do
16
+ expect{ subject.find }.to raise_error(Xway::MissingParameter)
32
17
  end
33
-
34
- describe 'update' do
35
- subject { endpoints.update app: 'foo' }
36
- its('method_name') { should eq 'put' }
37
- its('path') { should eq '/applications/foo' }
38
- its('headers') { should eq('X-App' => 'appway') }
39
- its('body') { should eq(nil) }
18
+ specify 'update does require_options' do
19
+ expect{ subject.update }.to raise_error(Xway::MissingParameter)
40
20
  end
41
-
42
- describe 'delete' do
43
- subject { endpoints.delete app: 'foo' }
44
- its('method_name') { should eq 'delete' }
45
- its('path') { should eq '/applications/foo' }
46
- its('headers') { should eq('X-App' => 'appway') }
47
- its('body') { should eq(nil) }
21
+ specify 'delete does require_options' do
22
+ expect{ subject.delete }.to raise_error(Xway::MissingParameter)
48
23
  end
49
-
50
- describe 'log' do
51
- subject { endpoints.log app: 'foo' }
52
- its('method_name') { should eq 'get' }
53
- its('path') { should eq '/applications/foo/log' }
54
- its('headers') { should eq('X-App' => 'appway') }
55
- its('body') { should eq(nil) }
24
+ specify 'log does require_options' do
25
+ expect{ subject.log }.to raise_error(Xway::MissingParameter)
56
26
  end
57
-
58
- describe 'start' do
59
- subject { endpoints.start app: 'foo' }
60
- its('method_name') { should eq 'post' }
61
- its('path') { should eq '/applications/foo/start' }
62
- its('headers') { should eq('X-App' => 'appway') }
63
- its('body') { should eq(nil) }
27
+ specify 'start does require_options' do
28
+ expect{ subject.start }.to raise_error(Xway::MissingParameter)
64
29
  end
65
-
66
- describe 'stop' do
67
- subject { endpoints.stop app: 'foo' }
68
- its('method_name') { should eq 'post' }
69
- its('path') { should eq '/applications/foo/stop' }
70
- its('headers') { should eq('X-App' => 'appway') }
71
- its('body') { should eq(nil) }
30
+ specify 'stop does require_options' do
31
+ expect{ subject.stop }.to raise_error(Xway::MissingParameter)
72
32
  end
73
-
74
- describe 'restart' do
75
- subject { endpoints.restart app: 'foo' }
76
- its('method_name') { should eq 'post' }
77
- its('path') { should eq '/applications/foo/restart' }
78
- its('headers') { should eq('X-App' => 'appway') }
79
- its('body') { should eq(nil) }
33
+ specify 'restart does require_options' do
34
+ expect{ subject.restart }.to raise_error(Xway::MissingParameter)
80
35
  end
36
+ specify 'redeploy does require_options' do
37
+ expect{ subject.redeploy }.to raise_error(Xway::MissingParameter)
38
+ end
39
+
40
+ context 'mock require_options' do
41
+ before { endpoints.stub('require_options') }
42
+
43
+ describe 'list' do
44
+ subject { endpoints.list({}) }
45
+ its('method_name') { should eq 'get' }
46
+ its('path') { should eq '/applications' }
47
+ its('headers') { should eq('X-App' => 'appway') }
48
+ its('body') { should eq(nil) }
49
+ end
50
+
51
+ describe 'create' do
52
+ let('manifest') { File.join(ASSETS_PATH, 'appway-example.json') }
53
+ subject { endpoints.create manifest: manifest }
54
+ its('method_name') { should eq 'post' }
55
+ its('path') { should eq '/applications' }
56
+ its('headers') { should eq('X-App' => 'appway',
57
+ 'Content-Type' => 'application/json') }
58
+ its('body') { should be_kind_of(Xway::Api::Request::Body) }
59
+ end
60
+
61
+ describe 'find' do
62
+ subject { endpoints.find name: 'foo' }
63
+ its('method_name') { should eq 'get' }
64
+ its('path') { should eq '/applications/foo' }
65
+ its('headers') { should eq('X-App' => 'appway') }
66
+ its('body') { should eq(nil) }
67
+ end
68
+
69
+ describe 'update' do
70
+ subject { endpoints.update name: 'foo' }
71
+ its('method_name') { should eq 'put' }
72
+ its('path') { should eq '/applications/foo' }
73
+ its('headers') { should eq('X-App' => 'appway') }
74
+ its('body') { should eq(nil) }
75
+ end
76
+
77
+ describe 'delete' do
78
+ subject { endpoints.delete name: 'foo' }
79
+ its('method_name') { should eq 'delete' }
80
+ its('path') { should eq '/applications/foo' }
81
+ its('headers') { should eq('X-App' => 'appway') }
82
+ its('body') { should eq(nil) }
83
+ end
84
+
85
+ describe 'log' do
86
+ subject { endpoints.log name: 'foo' }
87
+ its('method_name') { should eq 'get' }
88
+ its('path') { should eq '/applications/foo/log' }
89
+ its('headers') { should eq('X-App' => 'appway') }
90
+ its('body') { should eq(nil) }
91
+ end
92
+
93
+ describe 'start' do
94
+ subject { endpoints.start name: 'foo' }
95
+ its('method_name') { should eq 'post' }
96
+ its('path') { should eq '/applications/foo/start' }
97
+ its('headers') { should eq('X-App' => 'appway') }
98
+ its('body') { should eq(nil) }
99
+ end
100
+
101
+ describe 'stop' do
102
+ subject { endpoints.stop name: 'foo' }
103
+ its('method_name') { should eq 'post' }
104
+ its('path') { should eq '/applications/foo/stop' }
105
+ its('headers') { should eq('X-App' => 'appway') }
106
+ its('body') { should eq(nil) }
107
+ end
108
+
109
+ describe 'restart' do
110
+ subject { endpoints.restart name: 'foo' }
111
+ its('method_name') { should eq 'post' }
112
+ its('path') { should eq '/applications/foo/restart' }
113
+ its('headers') { should eq('X-App' => 'appway') }
114
+ its('body') { should eq(nil) }
115
+ end
81
116
 
82
- describe 'redeploy' do
83
- subject { endpoints.redeploy app: 'foo' }
84
- its('method_name') { should eq 'post' }
85
- its('path') { should eq '/applications/foo/redeploy' }
86
- its('headers') { should eq('X-App' => 'appway') }
87
- its('body') { should eq(nil) }
117
+ describe 'redeploy' do
118
+ subject { endpoints.redeploy name: 'foo' }
119
+ its('method_name') { should eq 'post' }
120
+ its('path') { should eq '/applications/foo/redeploy' }
121
+ its('headers') { should eq('X-App' => 'appway') }
122
+ its('body') { should eq(nil) }
123
+ end
88
124
  end
89
125
  end
@@ -15,7 +15,7 @@ describe Xway::Api::Http do
15
15
  it 'wraps errors' do
16
16
  HTTParty.stub('get') { raise StandardError, 'foo' }
17
17
  expect { subject.request 'http://foo', request }.to\
18
- raise_error(Xway::Error)
18
+ raise_error(Xway::ConnectionError)
19
19
  end
20
20
 
21
21
  describe 'calls HTTParty' do
@@ -63,7 +63,6 @@ describe Xway::Parameter do
63
63
 
64
64
  it 'defines app.name' do
65
65
  param.should_receive('define').with('app.name',
66
- type: String,
67
66
  flag: 'a',
68
67
  description: 'name of your app')
69
68
  subject.reload!
@@ -71,7 +70,6 @@ describe Xway::Parameter do
71
70
 
72
71
  it 'defines app.manifest' do
73
72
  param.should_receive('define').with('app.manifest',
74
- type: String,
75
73
  flag: 'm',
76
74
  description: 'path to your app.way file')
77
75
  subject.reload!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta
4
+ version: 0.0.2.beta
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-12 00:00:00.000000000 Z
12
+ date: 2013-05-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: configliere