ServerPilot 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/.autotest +2 -0
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/README.md +38 -34
- data/Rakefile +1 -2
- data/ServerPilot.gemspec +10 -10
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/ServerPilot.rb +101 -77
- data/lib/ServerPilot/version.rb +2 -1
- metadata +31 -15
- data/lib/ServerPilot/connection.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d44a36c34d4a41c172bf7a433091e810ed64fbf
|
4
|
+
data.tar.gz: 1f1f65da52d92ee8bcfeeefe71c243237b64c497
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 124910be3eaa3cabd523078dbc35a5a83811ee5ac3362169875f61472b86b7b094beb7c8d06e63fc3d31ba427feb1653ef7b05a4a35e9133124c8d7c21771181
|
7
|
+
data.tar.gz: 6e72616b8065db191ddc615c7aa6a40c3fbd9e3c1c98e8f4781ff03beb89b2b8607c6ed4f802b8f74b4d0d6bdae2cca8a3e1999e2c948f19fb7f418a695f2191
|
data/.autotest
ADDED
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,36 +1,56 @@
|
|
1
1
|
# ServerPilot
|
2
2
|
|
3
|
-
ServerPilot
|
4
|
-
===========
|
5
|
-
|
6
3
|
Ruby client gem for accessing <a href="http://www.serverpilot.io" target="_blank">ServerPilot</a> API
|
4
|
+
Current version (0.0.4). This version has been tested against a sinatra app at
|
5
|
+
http://www.github.com/signalfire/serverpilot-sinatra to mock up calls to API methods.
|
7
6
|
|
8
|
-
|
9
|
-
-------
|
7
|
+
## Installation
|
10
8
|
|
11
|
-
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ServerPilot'
|
13
|
+
```
|
12
14
|
|
13
|
-
|
15
|
+
And then execute:
|
14
16
|
|
15
|
-
|
17
|
+
$ bundle
|
16
18
|
|
17
|
-
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ServerPilot
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
To create a connection **require 'ServerPilot'**
|
26
|
+
In your code add something like **sp = ServerPilot::API.new(api_client, api_key)**
|
18
27
|
where client_id and key are your API information from ServerPilot.
|
19
28
|
|
20
|
-
|
21
|
-
|
29
|
+
If the serverpilot api changes host, port, or scheme you can alter these using calls
|
30
|
+
to properties on the class
|
31
|
+
|
32
|
+
sp.scheme = 'http' or 'https'
|
33
|
+
|
34
|
+
sp.host = 'newserverpilotaddress.io'
|
35
|
+
|
36
|
+
sp.port = 1000
|
37
|
+
|
38
|
+
These should be called before you start doing anything with the class
|
22
39
|
|
40
|
+
## Functions
|
23
41
|
Commands are issued such as sp.[verb]_[action]
|
24
42
|
|
25
43
|
In use it would look something like:
|
44
|
+
|
26
45
|
sp.get_servers 'UXOSIYrdtL4cSGp3'
|
46
|
+
|
27
47
|
or using hash params:
|
28
|
-
|
48
|
+
|
49
|
+
sp.post_sysusers {serverid: 'UXOSIYrdtL4cSGp3', name: 'abc123', password: '1234'}
|
29
50
|
|
30
51
|
This is a list of the ruby functions to call on the server pilot object (e.g sp.get_servers)
|
31
52
|
and matching ServerPilot API methods. [id] is the identifier of the server, app, database
|
32
|
-
that you can retrieve via the API. [params] is a hash
|
33
|
-
api as JSON
|
53
|
+
that you can retrieve via the API. [params] is a hash of data to send to the api as JSON
|
34
54
|
|
35
55
|
<table width="100%">
|
36
56
|
<tr>
|
@@ -154,32 +174,16 @@ api as JSON
|
|
154
174
|
<td>GET /actions/:id</td>
|
155
175
|
</tr>
|
156
176
|
</table>
|
157
|
-
This is early code and my first ever Ruby Gem so things may possibly break or not be quite
|
158
|
-
ruby enough....
|
159
|
-
|
160
|
-
## Installation
|
161
177
|
|
162
|
-
|
163
|
-
|
164
|
-
```ruby
|
165
|
-
gem 'ServerPilot'
|
166
|
-
```
|
178
|
+
## Development
|
167
179
|
|
168
|
-
|
169
|
-
|
170
|
-
$ bundle
|
171
|
-
|
172
|
-
Or install it yourself as:
|
173
|
-
|
174
|
-
$ gem install ServerPilot
|
175
|
-
|
176
|
-
## Usage
|
180
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
177
181
|
|
178
|
-
|
182
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
179
183
|
|
180
184
|
## Contributing
|
181
185
|
|
182
|
-
1. Fork it ( https://github.com/
|
186
|
+
1. Fork it ( https://github.com/[my-github-username]/ServerPilot/fork )
|
183
187
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
184
188
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
185
189
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
data/ServerPilot.gemspec
CHANGED
@@ -8,18 +8,18 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = ServerPilot::VERSION
|
9
9
|
spec.authors = ['Robert Coster']
|
10
10
|
spec.email = ['rob@signalfire.co.uk']
|
11
|
-
spec.summary ='ServerPilot'
|
12
|
-
spec.description = 'An API client gem to allow interaction from Ruby with the ServerPilot.io API'
|
13
|
-
spec.homepage = 'http://www.signalfire.co.uk'
|
14
|
-
spec.license = 'MIT'
|
15
11
|
|
16
|
-
spec.
|
17
|
-
spec.
|
18
|
-
spec.
|
12
|
+
spec.summary = 'An API client for interaction with ServerPilot API'
|
13
|
+
spec.description = 'An API client for interaction with ServerPilot API'
|
14
|
+
spec.homepage = 'http://www.github.com/signalfire/serverpilot'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.
|
21
|
+
spec.required_ruby_version = '>= 2.2'
|
22
|
+
spec.add_runtime_dependency 'rest-client', '>= 1.8.0'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.8'
|
22
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
-
spec.required_ruby_version = '~> 2.1'
|
24
|
-
|
25
25
|
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'ServerPilot'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/ServerPilot.rb
CHANGED
@@ -1,106 +1,130 @@
|
|
1
1
|
require 'ServerPilot/version'
|
2
|
-
require '
|
2
|
+
require 'rest-client'
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
require 'ostruct'
|
3
6
|
|
4
7
|
module ServerPilot
|
5
|
-
|
8
|
+
# Class to access the serverpilot api
|
6
9
|
class API
|
10
|
+
attr_accessor :scheme
|
11
|
+
attr_accessor :host
|
12
|
+
attr_accessor :port
|
13
|
+
attr_accessor :client_id
|
14
|
+
attr_accessor :secret_key
|
15
|
+
|
16
|
+
def initialize(api_client, api_key)
|
17
|
+
@client_id = api_client
|
18
|
+
@secret_key = api_key
|
19
|
+
@scheme = 'https'
|
20
|
+
@host = 'api.serverpilot.io'
|
21
|
+
@port = 443
|
22
|
+
end
|
7
23
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
24
|
+
def build_path(action, id = nil)
|
25
|
+
if action == 'ssl'
|
26
|
+
['/v1', 'apps', id, 'ssl'].join('/') unless id.nil?
|
27
|
+
else
|
28
|
+
(id.nil?) ? ['/v1', action].join('/') : ['/v1', action, id].join('/')
|
29
|
+
end
|
30
|
+
end
|
13
31
|
|
32
|
+
def check_function_name_valid(name)
|
33
|
+
(name.to_s.include? '_') && (name.to_s.count('_') == 1) ? true : false
|
14
34
|
end
|
15
35
|
|
16
|
-
def
|
36
|
+
def get_function_verb(name)
|
37
|
+
case name.to_s.downcase
|
38
|
+
when /^get/ then 'get'
|
39
|
+
when /^post/ then 'post'
|
40
|
+
when /^delete/ then 'delete'
|
41
|
+
end
|
42
|
+
end
|
17
43
|
|
18
|
-
|
44
|
+
def get_params(arguments)
|
45
|
+
params = nil
|
46
|
+
arguments.each do |argument|
|
47
|
+
params = argument if argument.is_a?(Hash)
|
48
|
+
end
|
49
|
+
params
|
50
|
+
end
|
19
51
|
|
20
|
-
|
52
|
+
def get_action_name(name)
|
53
|
+
name.to_s.downcase.split('_').last
|
54
|
+
end
|
21
55
|
|
56
|
+
def get_path(arguments, action)
|
57
|
+
if arguments.length == 0
|
58
|
+
build_path(action)
|
22
59
|
else
|
23
|
-
|
24
|
-
|
25
|
-
['/v1', action, id] * '/'
|
60
|
+
if arguments[0].is_a?(Integer) || arguments[0].is_a?(String)
|
61
|
+
build_path(action, arguments[0])
|
26
62
|
else
|
27
|
-
|
63
|
+
build_path(action)
|
28
64
|
end
|
29
|
-
|
30
65
|
end
|
31
|
-
|
32
66
|
end
|
33
67
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
when /^post/ then 'post'
|
43
|
-
when /^delete/ then 'delete'
|
44
|
-
else nil
|
45
|
-
end
|
46
|
-
|
47
|
-
#Check if the verb used is not nil
|
48
|
-
if verb
|
49
|
-
|
50
|
-
#Get the action to execute
|
51
|
-
action = name.to_s.downcase.split('_').last
|
52
|
-
|
53
|
-
#Check the number of arguments passed is zero
|
54
|
-
if arguments.length === 0
|
55
|
-
|
56
|
-
#Get the path (e.g. /servers) to call without id
|
57
|
-
path = build_path action
|
58
|
-
|
59
|
-
else
|
60
|
-
|
61
|
-
#Check if the first argument is an integer value
|
62
|
-
if (arguments[0].is_a? Integer) || (arguments[0].is_a? String)
|
63
|
-
|
64
|
-
#Get the path (e.g. /servers) to call passing the integer
|
65
|
-
path = build_path action, arguments[0]
|
66
|
-
|
67
|
-
#Check if the second argument is a hash and assign to params
|
68
|
-
if arguments[1].is_a? Hash
|
69
|
-
params = arguments[1]
|
70
|
-
end
|
71
|
-
|
72
|
-
else
|
73
|
-
|
74
|
-
#Get the path (e.g. /servers) to call
|
75
|
-
path = build_path action
|
76
|
-
|
77
|
-
#If the first argument is a hash
|
78
|
-
if arguments[0].is_a? Hash
|
79
|
-
params = arguments[0]
|
80
|
-
end
|
68
|
+
def create_uri(path)
|
69
|
+
URI::Generic.build(
|
70
|
+
scheme: @scheme,
|
71
|
+
host: @host,
|
72
|
+
path: path,
|
73
|
+
port: @port
|
74
|
+
).to_s
|
75
|
+
end
|
81
76
|
|
82
|
-
|
77
|
+
def create_rest_client(verb, path, params = nil)
|
78
|
+
if params
|
79
|
+
RestClient::Request.new(
|
80
|
+
method: verb,
|
81
|
+
url: create_uri(path),
|
82
|
+
user: @client_id,
|
83
|
+
password: @secret_key,
|
84
|
+
headers: { 'Content-Type' => 'application/json' },
|
85
|
+
payload: params.to_json
|
86
|
+
)
|
87
|
+
else
|
88
|
+
RestClient::Request.new(
|
89
|
+
method: verb,
|
90
|
+
url: create_uri(path),
|
91
|
+
user: @client_id,
|
92
|
+
password: @secret_key
|
93
|
+
)
|
94
|
+
end
|
95
|
+
end
|
83
96
|
|
84
|
-
|
97
|
+
def execute_api_command(verb, path, params = nil)
|
98
|
+
client = create_rest_client verb, path, params
|
99
|
+
client.execute
|
100
|
+
end
|
85
101
|
|
86
|
-
|
87
|
-
|
102
|
+
def parse_json(response)
|
103
|
+
body = JSON.parse(response.to_str) if response.code == 200
|
104
|
+
OpenStruct.new(code: response.code, body: body)
|
105
|
+
end
|
88
106
|
|
89
|
-
|
90
|
-
|
107
|
+
def execute_request(verb, name, arguments)
|
108
|
+
parse_json(
|
109
|
+
execute_api_command(
|
110
|
+
verb,
|
111
|
+
get_path(arguments, get_action_name(name)),
|
112
|
+
get_params(arguments)
|
113
|
+
)
|
114
|
+
)
|
115
|
+
end
|
91
116
|
|
117
|
+
def method_missing(name, *arguments)
|
118
|
+
if check_function_name_valid name
|
119
|
+
verb = get_function_verb name
|
120
|
+
if verb
|
121
|
+
execute_request verb, name, arguments
|
92
122
|
else
|
93
|
-
|
94
|
-
raise ArgumentError, 'Unsupported verb, functions should begin get_ post_ or delete_', caller
|
123
|
+
fail 'Invalid verb (get, post or delete supported)'
|
95
124
|
end
|
96
|
-
|
97
125
|
else
|
98
|
-
|
99
|
-
raise ArgumentError, 'Multiple underscores not allowed in function call', caller
|
126
|
+
fail 'Invalid function name'
|
100
127
|
end
|
101
|
-
|
102
128
|
end
|
103
|
-
|
104
129
|
end
|
105
|
-
|
106
130
|
end
|
data/lib/ServerPilot/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ServerPilot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Coster
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.8.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - "~>"
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
33
|
+
version: '1.8'
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
40
|
+
version: '1.8'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,26 +52,28 @@ dependencies:
|
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '10.0'
|
41
|
-
description: An API client
|
42
|
-
API
|
55
|
+
description: An API client for interaction with ServerPilot API
|
43
56
|
email:
|
44
57
|
- rob@signalfire.co.uk
|
45
58
|
executables: []
|
46
59
|
extensions: []
|
47
60
|
extra_rdoc_files: []
|
48
61
|
files:
|
62
|
+
- ".autotest"
|
49
63
|
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
50
66
|
- Gemfile
|
51
67
|
- LICENSE.txt
|
52
68
|
- README.md
|
53
69
|
- Rakefile
|
54
70
|
- ServerPilot.gemspec
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
55
73
|
- lib/ServerPilot.rb
|
56
|
-
- lib/ServerPilot/connection.rb
|
57
74
|
- lib/ServerPilot/version.rb
|
58
|
-
homepage: http://www.signalfire
|
59
|
-
licenses:
|
60
|
-
- MIT
|
75
|
+
homepage: http://www.github.com/signalfire/serverpilot
|
76
|
+
licenses: []
|
61
77
|
metadata: {}
|
62
78
|
post_install_message:
|
63
79
|
rdoc_options: []
|
@@ -65,9 +81,9 @@ require_paths:
|
|
65
81
|
- lib
|
66
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
67
83
|
requirements:
|
68
|
-
- - "
|
84
|
+
- - ">="
|
69
85
|
- !ruby/object:Gem::Version
|
70
|
-
version: '2.
|
86
|
+
version: '2.2'
|
71
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
88
|
requirements:
|
73
89
|
- - ">="
|
@@ -75,8 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
91
|
version: '0'
|
76
92
|
requirements: []
|
77
93
|
rubyforge_project:
|
78
|
-
rubygems_version: 2.
|
94
|
+
rubygems_version: 2.4.6
|
79
95
|
signing_key:
|
80
96
|
specification_version: 4
|
81
|
-
summary: ServerPilot
|
97
|
+
summary: An API client for interaction with ServerPilot API
|
82
98
|
test_files: []
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'uri'
|
3
|
-
require 'json'
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
module ServerPilot
|
7
|
-
|
8
|
-
class Connection
|
9
|
-
|
10
|
-
ENDPOINT = {
|
11
|
-
:scheme => 'https',
|
12
|
-
:host => 'api.serverpilot.io',
|
13
|
-
:port => 443
|
14
|
-
}
|
15
|
-
|
16
|
-
def initialize(api_client_id, api_key)
|
17
|
-
@sp_client_id = api_client_id
|
18
|
-
@sp_key = api_key
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_uri(path)
|
22
|
-
|
23
|
-
URI::Generic.build({:scheme=>ENDPOINT[:scheme], :host=>ENDPOINT[:host], :path=>path, :port=>ENDPOINT[:port]})
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
def request(verb, path, params = nil)
|
28
|
-
|
29
|
-
uri = create_uri path
|
30
|
-
|
31
|
-
Net::HTTP.start(uri.host,uri.port,:use_ssl => true) do |http|
|
32
|
-
|
33
|
-
case verb.downcase
|
34
|
-
when 'get'
|
35
|
-
request = Net::HTTP::Get.new uri.path
|
36
|
-
when 'post'
|
37
|
-
request = Net::HTTP::Post.new uri.path, initheader = {'Content-Type' => 'application/json'}
|
38
|
-
request.body = params.to_json
|
39
|
-
when 'delete'
|
40
|
-
request = Net::HTTP::Delete.new uri.path
|
41
|
-
end
|
42
|
-
|
43
|
-
request.basic_auth @sp_client_id, @sp_key
|
44
|
-
|
45
|
-
http.request request
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
def parse_json(response)
|
52
|
-
|
53
|
-
body = JSON.parse(response.body)
|
54
|
-
|
55
|
-
OpenStruct.new(:code => response.code, :body => body)
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
def execute(verb, path, params = nil)
|
60
|
-
|
61
|
-
response = request(verb, path, params)
|
62
|
-
|
63
|
-
parse_json response
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|