ServerPilot 0.0.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 66cb9861282795741aadd7d9ce6d82804e7bf835
4
+ data.tar.gz: d922e0c149d2ff21b1a47efd4e2c505fad5cab0a
5
+ SHA512:
6
+ metadata.gz: 35ade37164b91ec0763b04db0c34269110ac6f2b886bf6f50ee617f9fc98eb96dd6bd95614efc7c9a82263aeb01f6df0a5ce48e39fe851dc855e3bc153d4d601
7
+ data.tar.gz: e43399b08252874c5136e46544cc59ac56f494bd2023bb3dd66fc9af8722c260ec1cce2de3a8786a2fc5d8e5c7c14cdf52e777a59a23af57264a71c9df595153
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ServerPilot.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Robert Coster
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,186 @@
1
+ # ServerPilot
2
+
3
+ ServerPilot
4
+ ===========
5
+
6
+ Ruby client gem for accessing <a href="http://www.serverpilot.io" target="_blank">ServerPilot</a> API
7
+
8
+ Install
9
+ -------
10
+
11
+ Install from RubyGems with **gem install serverpilot** or clone from this github
12
+
13
+ Project on RubyGems at <a href="https://rubygems.org/gems/serverpilot" target="_blank">https://rubygems.org/gems/serverpilot</a>
14
+
15
+ To create a connection **require 'serverpilot'**
16
+
17
+ In your code add something like **sp = Signalfire::ServerPilot.new(client_id,key)**
18
+ where client_id and key are your API information from ServerPilot.
19
+
20
+ Functions
21
+ ---------
22
+
23
+ Commands are issued such as sp.[verb]_[action]
24
+
25
+ In use it would look something like:
26
+ sp.get_servers 'UXOSIYrdtL4cSGp3'
27
+ or using hash params:
28
+ sp.post_sysusers {'serverid'=>'UXOSIYrdtL4cSGp3','name'=>'abc123',=>'password'=>'1234'}
29
+
30
+ This is a list of the ruby functions to call on the server pilot object (e.g sp.get_servers)
31
+ 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 (Hash.new) of data to send to the
33
+ api as JSON
34
+
35
+ <table width="100%">
36
+ <tr>
37
+ <td><strong>Ruby Method</strong></td>
38
+ <td><strong>Description</strong></td>
39
+ <td><strong>Serverpilot API</strong></td>
40
+ </tr>
41
+ <tr>
42
+ <td>[obj].get_servers</td>
43
+ <td>Get a list of your servers</td>
44
+ <td>GET /servers</td>
45
+ </tr>
46
+ <tr>
47
+ <td>[obj].post_servers</td>
48
+ <td>Connect a new server</td>
49
+ <td>POST /servers</td>
50
+ </tr>
51
+ <tr>
52
+ <td>[obj].get_servers [id]</td>
53
+ <td>Retrieve existing server</td>
54
+ <td>GET /servers/:id</td>
55
+ </tr>
56
+ <tr>
57
+ <td>[obj].delete_servers [id]</td>
58
+ <td>Delete a server</td>
59
+ <td>DELETE /servers/:id</td>
60
+ </tr>
61
+ <tr>
62
+ <td>[obj].post_servers [id] [params]</td>
63
+ <td>Update a server</td>
64
+ <td>POST /server/:id</td>
65
+ </tr>
66
+ <tr>
67
+ <td>[obj].get_sysusers</td>
68
+ <td>List all system users</td>
69
+ <td>GET /sysusers</td>
70
+ </tr>
71
+ <tr>
72
+ <td>[obj].post_sysusers [params]</td>
73
+ <td>Create new system user</td>
74
+ <td>POST /sysusers</td>
75
+ </tr>
76
+ <tr>
77
+ <td>[obj].get_sysusers [id]</td>
78
+ <td>Retrieve existing user</td>
79
+ <td>GET /sysusers/:id</td>
80
+ </tr>
81
+ <tr>
82
+ <td>[obj].delete_sysusers [id]</td>
83
+ <td>Delete a system user</td>
84
+ <td>DELETE /sysusers/:id</td>
85
+ </tr>
86
+ <tr>
87
+ <td>[obj].post_sysusers [id] [params]</td>
88
+ <td>Update the password of a system user</td>
89
+ <td>POST /sysusers/:id</td>
90
+ </tr>
91
+ <tr>
92
+ <td>[obj].get_apps</td>
93
+ <td>List all apps</td>
94
+ <td>GET /apps</td>
95
+ </tr>
96
+ <tr>
97
+ <td>[obj].post_apps [params]</td>
98
+ <td>Create an app</td>
99
+ <td>POST /apps</td>
100
+ </tr>
101
+ <tr>
102
+ <td>[obj].get_apps [id]</td>
103
+ <td>Retrieve app</td>
104
+ <td>GET /apps/:id</td>
105
+ </tr>
106
+ <tr>
107
+ <td>[obj].delete_apps [id]</td>
108
+ <td>Delete an app</td>
109
+ <td>DELETE /apps/:id</td>
110
+ </tr>
111
+ <tr>
112
+ <td>[obj].post_apps [id] [params]</td>
113
+ <td>Update an app</td>
114
+ <td>POST /apps/:id</td>
115
+ </tr>
116
+ <tr>
117
+ <td>[obj].post_ssl [id] [params]</td>
118
+ <td>Add an SSL</td>
119
+ <td>POST /apps/:id/ssl</td>
120
+ </tr>
121
+ <tr>
122
+ <td>[obj].delete_ssl [id]</td>
123
+ <td>Delete an SSL</td>
124
+ <td>DELETE /apps/:id/ssl</td>
125
+ </tr>
126
+ <tr>
127
+ <td>[obj].get_dbs</td>
128
+ <td>Get databases</td>
129
+ <td>GET /dbs</td>
130
+ </tr>
131
+ <tr>
132
+ <td>[obj].post_dbs [params]</td>
133
+ <td>Create a new database</td>
134
+ <td>POST /dbs</td>
135
+ </tr>
136
+ <tr>
137
+ <td>[obj].get_dbs [id]</td>
138
+ <td>Retrieve existing db</td>
139
+ <td>GET /dbs/:id</td>
140
+ </tr>
141
+ <tr>
142
+ <td>[obj].delete_dbs [id]</td>
143
+ <td>Delete a database</td>
144
+ <td>DELETE /dbs/:id</td>
145
+ </tr>
146
+ <tr>
147
+ <td>[obj].post_dbs [id] [params]</td>
148
+ <td>Update the database user password</td>
149
+ <td>POST /dbs/:id</td>
150
+ </tr>
151
+ <tr>
152
+ <td>[obj].get_actions [id]</td>
153
+ <td>Get status of action</td>
154
+ <td>GET /actions/:id</td>
155
+ </tr>
156
+ </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
+
162
+ Add this line to your application's Gemfile:
163
+
164
+ ```ruby
165
+ gem 'ServerPilot'
166
+ ```
167
+
168
+ And then execute:
169
+
170
+ $ bundle
171
+
172
+ Or install it yourself as:
173
+
174
+ $ gem install ServerPilot
175
+
176
+ ## Usage
177
+
178
+ TODO: Write usage instructions here
179
+
180
+ ## Contributing
181
+
182
+ 1. Fork it ( https://github.com/signalfire/ServerPilot/fork )
183
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
184
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
185
+ 4. Push to the branch (`git push origin my-new-feature`)
186
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ServerPilot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ServerPilot'
8
+ spec.version = ServerPilot::VERSION
9
+ spec.authors = ['Robert Coster']
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
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.required_ruby_version = '~> 2.1'
24
+
25
+ end
@@ -0,0 +1,106 @@
1
+ require 'ServerPilot/version'
2
+ require 'ServerPilot/connection'
3
+
4
+ module ServerPilot
5
+
6
+ class API
7
+
8
+ def initialize(api_client_id, api_key)
9
+
10
+ @sp_client_id = api_client_id
11
+
12
+ @sp_key = api_key
13
+
14
+ end
15
+
16
+ def build_path(action, id = nil)
17
+
18
+ if action === 'ssl'
19
+
20
+ ['/v1', 'apps', id, 'ssl'] * '/'
21
+
22
+ else
23
+
24
+ if id
25
+ ['/v1', action, id] * '/'
26
+ else
27
+ ['/v1', action] * '/'
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+ def method_missing(name, *arguments)
35
+
36
+ #Check if name includes one and only one underscore
37
+ if (name.to_s.include? '_') && (name.to_s.count('_') === 1)
38
+
39
+ #Get the verb to call
40
+ verb = case name.to_s.downcase
41
+ when /^get/ then 'get'
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
81
+
82
+ end
83
+
84
+ end
85
+
86
+ #Create a new connection
87
+ connection = ServerPilot::Connection.new(@sp_client_id, @sp_key)
88
+
89
+ #Execute the command via the connection and return the results
90
+ connection.execute verb, path, params
91
+
92
+ else
93
+ #Raise an exception based on the verb used is not correct
94
+ raise ArgumentError, 'Unsupported verb, functions should begin get_ post_ or delete_', caller
95
+ end
96
+
97
+ else
98
+ #Raise an exception based on the name of the function being incorrect
99
+ raise ArgumentError, 'Multiple underscores not allowed in function call', caller
100
+ end
101
+
102
+ end
103
+
104
+ end
105
+
106
+ end
@@ -0,0 +1,69 @@
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
@@ -0,0 +1,3 @@
1
+ module ServerPilot
2
+ VERSION = '0.0.3'
3
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ServerPilot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Robert Coster
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: An API client gem to allow interaction from Ruby with the ServerPilot.io
42
+ API
43
+ email:
44
+ - rob@signalfire.co.uk
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - ServerPilot.gemspec
55
+ - lib/ServerPilot.rb
56
+ - lib/ServerPilot/connection.rb
57
+ - lib/ServerPilot/version.rb
58
+ homepage: http://www.signalfire.co.uk
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '2.1'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: ServerPilot
82
+ test_files: []