terminal.com 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +66 -0
- data/bin/terminal.com +160 -0
- data/docs/help.txt +131 -0
- data/lib/terminal.com.rb +385 -0
- data/spec/spec_helper.rb +0 -0
- data/spec/terminal.com_spec.rb +0 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d256dec7f902f6e53bebf75cedb4231ba0123e1b
|
4
|
+
data.tar.gz: 51cc71d632d28a9b840eaf67a7a353363e8f76fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb2b0d8e464a88d836015e20984aa000b8304f5dab8ae783a087324b90f19c49ff9a0b4d7a3a99cc50481e986b5b11a771763f73560ab0820915efa189e9f516
|
7
|
+
data.tar.gz: d06615df3b69e26cf1645ed40bc4081fb18a566c163b520b9142893b44459da3724096ce9daffdec6fef60c738f4e928a76b7780baa57f53265b8d62407aebf5
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# About
|
2
|
+
|
3
|
+
This is a Ruby wrapper for [Terminal.com](https://www.terminal.com) API.
|
4
|
+
|
5
|
+
At the moment all it does is to dump all the [Terminal.com API endpoints](https://www.terminal.com/api/docs) to `Terminal::API` module, from which you can call them pretty much the same way you'd do with curl, just from Ruby.
|
6
|
+
|
7
|
+
In the future there will be more object-oriented abstraction.
|
8
|
+
|
9
|
+
# Usage
|
10
|
+
|
11
|
+
1. Run `gem install terminal.com --development` or put `gem 'terminal.com'` into your Gemfile and run `bundle`. The development option installs coderay, so you get syntax highlighting for JSON on console when using the command-line client.
|
12
|
+
|
13
|
+
2. Get your `user_token` and `access_token` from [your settings](https://www.terminal.com/settings/api).
|
14
|
+
|
15
|
+
![](docs/terminal-com-api-keys.png)
|
16
|
+
|
17
|
+
# Command-Line Client
|
18
|
+
|
19
|
+
Anything you can do from the library can be done through the CLI client. There are two ways how you can use it.
|
20
|
+
|
21
|
+
![](docs/terminal-cli-client.png)
|
22
|
+
|
23
|
+
## Without Configuration
|
24
|
+
|
25
|
+
```bash
|
26
|
+
terminal.com [user_token] [access_token] list_terminals
|
27
|
+
```
|
28
|
+
|
29
|
+
*Note that at the point you have to provide both `user_token` and `access_token` regardless of whether the API endpoint actually needs it. This will be fixed in near future!*
|
30
|
+
|
31
|
+
## With Configuration
|
32
|
+
|
33
|
+
Specifying the credentials every single time can be quite tedious. That's where `terminal.com configure` comes in handy:
|
34
|
+
|
35
|
+
![](docs/terminal-com-configure.png)
|
36
|
+
|
37
|
+
```bash
|
38
|
+
# One time only.
|
39
|
+
terminal.com configure
|
40
|
+
|
41
|
+
# Now you can simply do:
|
42
|
+
terminal.com list_terminals
|
43
|
+
```
|
44
|
+
|
45
|
+
## Options
|
46
|
+
|
47
|
+
```bash
|
48
|
+
terminal.com list_public_snapshots --tag=ruby --featured
|
49
|
+
```
|
50
|
+
|
51
|
+
# Example
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
require 'terminal.com'
|
55
|
+
|
56
|
+
# Let's search featured ruby-related snapshots.
|
57
|
+
Terminal::API.list_public_snapshots(tag: 'ruby', featured: true)
|
58
|
+
# {"snapshots" => [{"title" => "JRuby Stack (example included)", "body" => "JRuby is a 100% Java implementation of the Ruby programming language. This snapshot also includes a working example, its source code and the tools needed to develop JRuby applications.", ...
|
59
|
+
|
60
|
+
# List your Terminals.
|
61
|
+
my_user_token = '...'
|
62
|
+
my_access_token = '...'
|
63
|
+
|
64
|
+
Terminal::API.list_terminals(my_user_token, my_access_token)
|
65
|
+
# {"terminals" => [{"cpu" => "2 (max)", "ram" => "256", "diskspace" => "10", "name" => "Coding Interview: John Doe Jr", ...
|
66
|
+
```
|
data/bin/terminal.com
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# TODO (later): Don't force tokens for methods that don't need them.
|
4
|
+
# TODO (maybe): DBG=ruby/curl/off. Curl would output curl commands.
|
5
|
+
|
6
|
+
############
|
7
|
+
# Helpers. #
|
8
|
+
############
|
9
|
+
|
10
|
+
def log(message)
|
11
|
+
STDERR.puts("\x1B[1;30m~ #{message}\x1B[0m") unless ENV['DBG'] == 'off'
|
12
|
+
end
|
13
|
+
|
14
|
+
def dbg(command, arguments, **options)
|
15
|
+
log "Terminal::API.#{command}(" +
|
16
|
+
("#{arguments.inspect[1..-2]}" unless arguments.empty?).to_s +
|
17
|
+
(", #{options.inspect[1..-2]}" unless options.empty?).to_s +
|
18
|
+
")\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
def try_highlight_syntax(json)
|
22
|
+
CodeRay.scan(json, :json).term
|
23
|
+
rescue
|
24
|
+
json
|
25
|
+
end
|
26
|
+
|
27
|
+
def print_as_json(data)
|
28
|
+
json = JSON.pretty_generate(data)
|
29
|
+
puts try_highlight_syntax(json)
|
30
|
+
end
|
31
|
+
|
32
|
+
def api_call(command, arguments, options)
|
33
|
+
# Ruby **args expansion doesn't work as I expected, that's why the extra if.
|
34
|
+
# pry(main)> def xxx(*args) args; end
|
35
|
+
# pry(main)> xxx(**{})
|
36
|
+
# => [{}]
|
37
|
+
if options
|
38
|
+
dbg command, arguments, options
|
39
|
+
print_as_json Terminal::API.send(command, *arguments, **options)
|
40
|
+
else
|
41
|
+
dbg command, arguments
|
42
|
+
print_as_json Terminal::API.send(command, *arguments)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def usage
|
47
|
+
if File.exist?(File.expand_path('../docs/help.txt', __dir__))
|
48
|
+
# Running locally.
|
49
|
+
puts File.read(File.expand_path('../docs/help.txt', __dir__))
|
50
|
+
else
|
51
|
+
# RubyGems installation.
|
52
|
+
spec = Gem::Specification.find_by_name('terminal.com')
|
53
|
+
puts File.read(File.join(spec.gem_dir, 'docs', 'help.txt'))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
#########
|
58
|
+
# Main. #
|
59
|
+
#########
|
60
|
+
|
61
|
+
require File.expand_path('../../lib/terminal.com', __FILE__)
|
62
|
+
require 'json'
|
63
|
+
|
64
|
+
begin
|
65
|
+
require 'coderay'
|
66
|
+
rescue LoadError
|
67
|
+
log "CodeRay is not installed. Syntax highlighting won't be available."
|
68
|
+
end
|
69
|
+
|
70
|
+
# -h | --help
|
71
|
+
if ARGV.include?('-h') || ARGV.include?('--help')
|
72
|
+
puts usage; exit
|
73
|
+
end
|
74
|
+
|
75
|
+
if ARGV.first == 'configure'
|
76
|
+
puts <<-EOF
|
77
|
+
Welcome to the Terminal.com CLI client.
|
78
|
+
|
79
|
+
We don't want to bother you with asking for credentials every single time,
|
80
|
+
so instead we'll ask you for them now and save them to ~/.terminal.com.json.
|
81
|
+
|
82
|
+
Alright?
|
83
|
+
|
84
|
+
Go to https://www.terminal.com/settings/api
|
85
|
+
|
86
|
+
And:
|
87
|
+
EOF
|
88
|
+
|
89
|
+
print "1. Paste your user token here: "
|
90
|
+
user_token = STDIN.readline.chomp
|
91
|
+
print "2. Generate an access token if you don't have one and paste it here: "
|
92
|
+
access_token = STDIN.readline.chomp
|
93
|
+
|
94
|
+
File.open(File.expand_path('~/.terminal.com.json'), 'w') do |file|
|
95
|
+
file.puts({user_token: user_token, access_token: access_token}.to_json)
|
96
|
+
end
|
97
|
+
|
98
|
+
puts "\nYour tokens were saved to ~/.terminal.com.json."
|
99
|
+
exit
|
100
|
+
end
|
101
|
+
|
102
|
+
# Tokens.
|
103
|
+
# TODO: Add --no-config
|
104
|
+
if File.exist?(File.expand_path('~/.terminal.com.json'))
|
105
|
+
config = JSON.parse(File.read(File.expand_path('~/.terminal.com.json')))
|
106
|
+
user_token, access_token = config.values_at('user_token', 'access_token')
|
107
|
+
|
108
|
+
if user_token.nil?
|
109
|
+
abort("Config file found, but user_token is missing. Add user_token key.")
|
110
|
+
end
|
111
|
+
|
112
|
+
if access_token.nil?
|
113
|
+
abort("Config file found, but access_token is missing. Add access_token key.")
|
114
|
+
end
|
115
|
+
else
|
116
|
+
user_token, access_token = ARGV.shift(2)
|
117
|
+
|
118
|
+
if user_token.nil? || access_token.nil?
|
119
|
+
STDERR.puts("Credentials missing.\n\n")
|
120
|
+
abort usage
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
if ARGV.empty?
|
125
|
+
STDERR.puts("Command missing.\n\n")
|
126
|
+
abort usage
|
127
|
+
else
|
128
|
+
command = ARGV.shift
|
129
|
+
|
130
|
+
unless Terminal::API.respond_to?(command)
|
131
|
+
STDERR.puts("Invalid command '#{command}'.\n\n")
|
132
|
+
abort usage
|
133
|
+
end
|
134
|
+
|
135
|
+
# Not every method requires authentication.
|
136
|
+
method_args = Terminal::API.method(command).parameters.map(&:last)
|
137
|
+
|
138
|
+
if method_args.include?(:options)
|
139
|
+
options = ARGV.reduce(Hash.new) do |buffer, argument|
|
140
|
+
if argument.match(/^--(.+)=(.+)$/)
|
141
|
+
buffer[$1.to_sym] = $2
|
142
|
+
elsif argument.match(/^--no-(.+)$/)
|
143
|
+
buffer[$1.to_sym] = false
|
144
|
+
elsif argument.match(/^--(.+)$/)
|
145
|
+
buffer[$1.to_sym] = true
|
146
|
+
end
|
147
|
+
|
148
|
+
buffer
|
149
|
+
end
|
150
|
+
|
151
|
+
ARGV.delete_if { |argument| argument.start_with?('--') }
|
152
|
+
end
|
153
|
+
|
154
|
+
arguments = []
|
155
|
+
arguments << user_token if method_args.include?(:user_token)
|
156
|
+
arguments << access_token if method_args.include?(:access_token)
|
157
|
+
arguments.push(*ARGV)
|
158
|
+
|
159
|
+
api_call(command, arguments, options)
|
160
|
+
end
|
data/docs/help.txt
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
== Usage ==
|
2
|
+
|
3
|
+
1. Explicit configuration.
|
4
|
+
|
5
|
+
terminal.com [user_token] [access_token] [command]
|
6
|
+
|
7
|
+
2. With a configuration file.
|
8
|
+
|
9
|
+
First run terminal.com configure. This command will
|
10
|
+
save your credentials into ~/.terminal.com.json.
|
11
|
+
{"user_token": "...", "access_token": "..."}
|
12
|
+
|
13
|
+
Then you can run commands like so:
|
14
|
+
|
15
|
+
terminal.com [command]
|
16
|
+
|
17
|
+
== Commands ==
|
18
|
+
|
19
|
+
These are identical to what the API provides.
|
20
|
+
|
21
|
+
# BROWSE SNAPSHOTS & USERS #
|
22
|
+
get_snapshot snapshot_id
|
23
|
+
get_profile username
|
24
|
+
list_public_snapshots [options]
|
25
|
+
--username=value
|
26
|
+
--tag=value
|
27
|
+
--featured
|
28
|
+
--title=value
|
29
|
+
--page=value
|
30
|
+
--perPage=value
|
31
|
+
--sortby=value
|
32
|
+
|
33
|
+
count_public_snapshots [options]
|
34
|
+
--username=value
|
35
|
+
--tag=value
|
36
|
+
--featured
|
37
|
+
--title=value
|
38
|
+
|
39
|
+
# CREATE AND MANAGE TERMINALS #
|
40
|
+
list_terminals user_token access_token
|
41
|
+
get_terminal user_token access_token [options]
|
42
|
+
--container_key=value
|
43
|
+
--subdomain=value
|
44
|
+
|
45
|
+
start_snapshot user_token access_token snapshot_id [options]
|
46
|
+
--cpu=value
|
47
|
+
--ram=value
|
48
|
+
--temporary
|
49
|
+
--name=value
|
50
|
+
--autopause=value
|
51
|
+
--startup_script=value
|
52
|
+
--custom_data=value
|
53
|
+
|
54
|
+
delete_terminal user_token access_token container_key
|
55
|
+
restart_terminal user_token access_token container_key
|
56
|
+
pause_terminal user_token access_token container_key
|
57
|
+
resume_terminal user_token access_token container_key
|
58
|
+
edit_terminal user_token access_token container_key [options]
|
59
|
+
--cpu=value
|
60
|
+
--ram=value
|
61
|
+
--diskspace=value
|
62
|
+
--name=value
|
63
|
+
|
64
|
+
# CREATE AND MANAGE SNAPSHOTS #
|
65
|
+
list_snapshots user_token access_token [options]
|
66
|
+
--username=value
|
67
|
+
--tag=value
|
68
|
+
--featured
|
69
|
+
--title=value
|
70
|
+
--page=value
|
71
|
+
--perPage=value
|
72
|
+
|
73
|
+
count_snapshots user_token access_token [options]
|
74
|
+
--username=value
|
75
|
+
--tag=value
|
76
|
+
--featured
|
77
|
+
--title=value
|
78
|
+
|
79
|
+
delete_snapshot user_token access_token snapshot_id
|
80
|
+
edit_snapshot user_token access_token snapshot_id [options]
|
81
|
+
--body=value
|
82
|
+
--title=value
|
83
|
+
--readme=value
|
84
|
+
--public
|
85
|
+
--custom_data=value
|
86
|
+
|
87
|
+
snapshot_terminal user_token access_token container_key [options]
|
88
|
+
--body=value
|
89
|
+
--title=value
|
90
|
+
--readme=value
|
91
|
+
--public
|
92
|
+
|
93
|
+
# MANAGE TERMINAL ACCESS #
|
94
|
+
add_terminal_links user_token access_token container_key *links
|
95
|
+
remove_terminal_links user_token access_token container_key *links
|
96
|
+
list_terminal_access user_token access_token container_key
|
97
|
+
edit_terminal_access user_token access_token container_key [options]
|
98
|
+
--is_public_list
|
99
|
+
--access_rules=value
|
100
|
+
|
101
|
+
# MANAGE TERMINAL DNS & DOMAINS #
|
102
|
+
get_cname_records user_token access_token
|
103
|
+
add_domain_to_pool user_token access_token domain
|
104
|
+
remove_domain_from_pool user_token access_token domain
|
105
|
+
add_cname_record user_token access_token domain subdomain port
|
106
|
+
remove_cname_record user_token access_token domain
|
107
|
+
|
108
|
+
# MANAGE TERMINAL IDLE SETTINGS #
|
109
|
+
set_terminal_idle_settings user_token access_token container_key action *triggers
|
110
|
+
get_terminal_idle_settings user_token access_token container_key
|
111
|
+
|
112
|
+
# MANAGE USAGE & CREDITS #
|
113
|
+
instance_types
|
114
|
+
instance_price instance_type status (defaults to running)
|
115
|
+
balance user_token access_token
|
116
|
+
balance_added user_token access_token
|
117
|
+
gift user_token access_token email cents
|
118
|
+
burn_history user_token access_token
|
119
|
+
terminal_usage_history user_token access_token
|
120
|
+
burn_state user_token access_token
|
121
|
+
burn_estimates user_token access_token
|
122
|
+
|
123
|
+
# MANAGE SSH PUBLIC KEYS #
|
124
|
+
add_authorized_key_to_terminal user_token access_token container_key publicKey
|
125
|
+
add_authorized_key_to_ssh_proxy user_token access_token name publicKey
|
126
|
+
del_authorized_key_from_ssh_proxy user_token access_token name fingerprint
|
127
|
+
get_authorized_keys_from_ssh_proxy user_token access_token
|
128
|
+
|
129
|
+
# OTHER #
|
130
|
+
who_am_i user_token, access_token
|
131
|
+
request_progress request_id
|
data/lib/terminal.com.rb
ADDED
@@ -0,0 +1,385 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Terminal
|
5
|
+
VERSION = '0.0.1'
|
6
|
+
|
7
|
+
module API
|
8
|
+
extend self
|
9
|
+
|
10
|
+
API_VERSION = 'v0.1'
|
11
|
+
HEADERS = {'Content-Type' => 'application/json'}
|
12
|
+
|
13
|
+
############################
|
14
|
+
# BROWSE SNAPSHOTS & USERS #
|
15
|
+
############################
|
16
|
+
|
17
|
+
# https://www.terminal.com/api/docs#get-snapshot
|
18
|
+
def get_snapshot(snapshot_id)
|
19
|
+
call('/get_snapshot', snapshot_id: snapshot_id)
|
20
|
+
end
|
21
|
+
|
22
|
+
# https://www.terminal.com/api/docs#get-profile
|
23
|
+
def get_profile(username)
|
24
|
+
call('/get_profile', username: username)
|
25
|
+
end
|
26
|
+
|
27
|
+
# https://www.terminal.com/api/docs#list-public-snapshots
|
28
|
+
def list_public_snapshots(**options)
|
29
|
+
ensure_options_validity(options,
|
30
|
+
:username, :tag, :featured, :title, :page, :perPage, :sortby)
|
31
|
+
|
32
|
+
call('/list_public_snapshots', options)
|
33
|
+
end
|
34
|
+
|
35
|
+
# https://www.terminal.com/api/docs#count-public-snapshots
|
36
|
+
def count_public_snapshots(**options)
|
37
|
+
ensure_options_validity(options,
|
38
|
+
:username, :tag, :featured, :title)
|
39
|
+
|
40
|
+
call('/count_public_snapshots', options)
|
41
|
+
end
|
42
|
+
|
43
|
+
###############################
|
44
|
+
# CREATE AND MANAGE TERMINALS #
|
45
|
+
###############################
|
46
|
+
|
47
|
+
# https://www.terminal.com/api/docs#list-terminals
|
48
|
+
def list_terminals(user_token, access_token)
|
49
|
+
call('/list_terminals',
|
50
|
+
user_token: user_token, access_token: access_token)
|
51
|
+
end
|
52
|
+
|
53
|
+
# https://www.terminal.com/api/docs#get-terminal
|
54
|
+
def get_terminal(user_token, access_token, **options)
|
55
|
+
ensure_options_validity(options, :container_key, :subdomain)
|
56
|
+
|
57
|
+
options.merge!(user_token: user_token, access_token: access_token)
|
58
|
+
|
59
|
+
call('/get_terminal', options)
|
60
|
+
end
|
61
|
+
|
62
|
+
# https://www.terminal.com/api/docs#start-snapshot
|
63
|
+
def start_snapshot(user_token, access_token, snapshot_id, **options)
|
64
|
+
ensure_options_validity(options,
|
65
|
+
:cpu, :ram, :temporary, :name, :autopause, :startup_script, :custom_data)
|
66
|
+
|
67
|
+
options.merge!(user_token: user_token, access_token: access_token, snapshot_id: snapshot_id)
|
68
|
+
|
69
|
+
call('/start_snapshot', options)
|
70
|
+
end
|
71
|
+
|
72
|
+
# https://www.terminal.com/api/docs#delete-terminal
|
73
|
+
def delete_terminal(user_token, access_token, container_key)
|
74
|
+
call('/delete_terminal',
|
75
|
+
user_token: user_token, access_token: access_token, container_key: container_key)
|
76
|
+
end
|
77
|
+
|
78
|
+
# https://www.terminal.com/api/docs#restart-terminal
|
79
|
+
def restart_terminal(user_token, access_token, container_key)
|
80
|
+
call('/restart_terminal',
|
81
|
+
user_token: user_token, access_token: access_token, container_key: container_key)
|
82
|
+
end
|
83
|
+
|
84
|
+
# https://www.terminal.com/api/docs#pause-terminal
|
85
|
+
def pause_terminal(user_token, access_token, container_key)
|
86
|
+
call('/pause_terminal',
|
87
|
+
user_token: user_token, access_token: access_token, container_key: container_key)
|
88
|
+
end
|
89
|
+
|
90
|
+
# https://www.terminal.com/api/docs#resume-terminal
|
91
|
+
def resume_terminal(user_token, access_token, container_key)
|
92
|
+
call('/resume_terminal',
|
93
|
+
user_token: user_token, access_token: access_token, container_key: container_key)
|
94
|
+
end
|
95
|
+
|
96
|
+
# https://www.terminal.com/api/docs#edit-terminal
|
97
|
+
def edit_terminal(user_token, access_token, container_key, **options)
|
98
|
+
ensure_options_validity(options,
|
99
|
+
:cpu, :ram, :diskspace, :name)
|
100
|
+
|
101
|
+
options.merge!(user_token: user_token, access_token: access_token, container_key: container_key)
|
102
|
+
|
103
|
+
call('/edit_terminal', options)
|
104
|
+
end
|
105
|
+
|
106
|
+
###############################
|
107
|
+
# CREATE AND MANAGE SNAPSHOTS #
|
108
|
+
###############################
|
109
|
+
|
110
|
+
# https://www.terminal.com/api/docs#list-snapshots
|
111
|
+
def list_snapshots(user_token, access_token, **options)
|
112
|
+
ensure_options_validity(options,
|
113
|
+
:username, :tag, :featured, :title, :page, :perPage)
|
114
|
+
|
115
|
+
options.merge!(user_token: user_token, access_token: access_token)
|
116
|
+
|
117
|
+
call('/list_snapshots', options)
|
118
|
+
end
|
119
|
+
|
120
|
+
# https://www.terminal.com/api/docs#count-snapshots
|
121
|
+
def count_snapshots(user_token, access_token, **options)
|
122
|
+
ensure_options_validity(options,
|
123
|
+
:username, :tag, :featured, :title)
|
124
|
+
|
125
|
+
options.merge!(user_token: user_token, access_token: access_token)
|
126
|
+
|
127
|
+
call('/count_snapshots', options)
|
128
|
+
end
|
129
|
+
|
130
|
+
# https://www.terminal.com/api/docs#delete-snapshot
|
131
|
+
def delete_snapshot(user_token, access_token, snapshot_id)
|
132
|
+
call('/delete_snapshot',
|
133
|
+
user_token: user_token,
|
134
|
+
access_token: access_token,
|
135
|
+
snapshot_id: snapshot_id)
|
136
|
+
end
|
137
|
+
|
138
|
+
# https://www.terminal.com/api/docs#edit-snapshot
|
139
|
+
def edit_snapshot(user_token, access_token, snapshot_id, **options)
|
140
|
+
ensure_options_validity(options,
|
141
|
+
:body, :title, :readme, :tags, :public, :custom_data)
|
142
|
+
|
143
|
+
options.merge!(user_token: user_token, access_token: access_token, snapshot_id: snapshot_id)
|
144
|
+
|
145
|
+
call('/edit_snapshot', options)
|
146
|
+
end
|
147
|
+
|
148
|
+
# https://www.terminal.com/api/docs#snapshot-terminal
|
149
|
+
def snapshot_terminal(user_token, access_token, container_key, **options)
|
150
|
+
ensure_options_validity(options,
|
151
|
+
:body, :title, :readme, :tags, :public)
|
152
|
+
|
153
|
+
options.merge!(user_token: user_token, access_token: access_token, container_key: container_key)
|
154
|
+
|
155
|
+
call('/snapshot_terminal', options)
|
156
|
+
end
|
157
|
+
|
158
|
+
##########################
|
159
|
+
# MANAGE TERMINAL ACCESS #
|
160
|
+
##########################
|
161
|
+
|
162
|
+
# https://www.terminal.com/api/docs#add-terminal-links
|
163
|
+
def add_terminal_links(user_token, access_token, container_key, *links)
|
164
|
+
call('/add_terminal_links',
|
165
|
+
user_token: user_token,
|
166
|
+
access_token: access_token,
|
167
|
+
container_key: container_key,
|
168
|
+
links: links)
|
169
|
+
end
|
170
|
+
|
171
|
+
# https://www.terminal.com/api/docs#remove-terminal-links
|
172
|
+
def remove_terminal_links(user_token, access_token, container_key, *links)
|
173
|
+
call('/remove_terminal_links',
|
174
|
+
user_token: user_token,
|
175
|
+
access_token: access_token,
|
176
|
+
container_key: container_key,
|
177
|
+
links: links)
|
178
|
+
end
|
179
|
+
|
180
|
+
# https://www.terminal.com/api/docs#list-terminal-access
|
181
|
+
def list_terminal_access(user_token, access_token, container_key)
|
182
|
+
call('/list_terminal_access',
|
183
|
+
user_token: user_token,
|
184
|
+
access_token: access_token,
|
185
|
+
container_key: container_key)
|
186
|
+
end
|
187
|
+
|
188
|
+
# https://www.terminal.com/api/docs#edit-terminal-access
|
189
|
+
def edit_terminal_access(user_token, access_token, container_key, **options)
|
190
|
+
ensure_options_validity(options, :is_public_list, :access_rules)
|
191
|
+
|
192
|
+
options.merge!(user_token: user_token, access_token: access_token, container_key: container_key)
|
193
|
+
|
194
|
+
call('/edit_terminal_access', options)
|
195
|
+
end
|
196
|
+
|
197
|
+
#################################
|
198
|
+
# MANAGE TERMINAL DNS & DOMAINS #
|
199
|
+
#################################
|
200
|
+
|
201
|
+
# https://www.terminal.com/api/docs#get-cname-records
|
202
|
+
def get_cname_records(user_token, access_token)
|
203
|
+
call('/get_cname_records',
|
204
|
+
user_token: user_token, access_token: access_token)
|
205
|
+
end
|
206
|
+
|
207
|
+
# https://www.terminal.com/api/docs#add-domain-to-pool
|
208
|
+
def add_domain_to_pool(user_token, access_token, domain)
|
209
|
+
call('/add_domain_to_pool',
|
210
|
+
user_token: user_token, access_token: access_token, domain: domain)
|
211
|
+
end
|
212
|
+
|
213
|
+
# https://www.terminal.com/api/docs#remove-domain-from-pool
|
214
|
+
def remove_domain_from_pool(user_token, access_token, domain)
|
215
|
+
call('/remove_domain_from_pool',
|
216
|
+
user_token: user_token, access_token: access_token, domain: domain)
|
217
|
+
end
|
218
|
+
|
219
|
+
# https://www.terminal.com/api/docs#add-cname-record
|
220
|
+
def add_cname_record(user_token, access_token, domain, subdomain, port)
|
221
|
+
call('/add_cname_record',
|
222
|
+
user_token: user_token,
|
223
|
+
access_token: access_token,
|
224
|
+
domain: domain,
|
225
|
+
subdomain: subdomain,
|
226
|
+
port: port)
|
227
|
+
end
|
228
|
+
|
229
|
+
# https://www.terminal.com/api/docs#remove-cname-record
|
230
|
+
def remove_cname_record(user_token, access_token, domain)
|
231
|
+
call('/remove_cname_record',
|
232
|
+
user_token: user_token,
|
233
|
+
access_token: access_token,
|
234
|
+
domain: domain)
|
235
|
+
end
|
236
|
+
|
237
|
+
#################################
|
238
|
+
# MANAGE TERMINAL IDLE SETTINGS #
|
239
|
+
#################################
|
240
|
+
|
241
|
+
# https://www.terminal.com/api/docs#set-terminal-idle-settings
|
242
|
+
def set_terminal_idle_settings(user_token, access_token, container_key, action, *triggers)
|
243
|
+
call('/set_terminal_idle_settings',
|
244
|
+
user_token: user_token,
|
245
|
+
access_token: access_token,
|
246
|
+
container_key: container_key,
|
247
|
+
action: action,
|
248
|
+
triggers: triggers)
|
249
|
+
end
|
250
|
+
|
251
|
+
# https://www.terminal.com/api/docs#get-terminal-idle-settings
|
252
|
+
def get_terminal_idle_settings(user_token, access_token, container_key)
|
253
|
+
call('/get_terminal_idle_settings',
|
254
|
+
user_token: user_token,
|
255
|
+
access_token: access_token,
|
256
|
+
container_key: container_key)
|
257
|
+
end
|
258
|
+
|
259
|
+
##########################
|
260
|
+
# MANAGE USAGE & CREDITS #
|
261
|
+
##########################
|
262
|
+
|
263
|
+
# https://www.terminal.com/api/docs#instance-types
|
264
|
+
def instance_types
|
265
|
+
call('/instance_types', Hash.new)
|
266
|
+
end
|
267
|
+
|
268
|
+
# https://www.terminal.com/api/docs#instance-price
|
269
|
+
def instance_price(instance_type, status = 'running')
|
270
|
+
call('/instance_price', instance_type: instance_type, status: status)
|
271
|
+
end
|
272
|
+
|
273
|
+
# https://www.terminal.com/api/docs#balance
|
274
|
+
def balance(user_token, access_token)
|
275
|
+
call('/balance', user_token: user_token, access_token: access_token)
|
276
|
+
end
|
277
|
+
|
278
|
+
# https://www.terminal.com/api/docs#balance-added
|
279
|
+
def balance_added(user_token, access_token)
|
280
|
+
call('/balance_added', user_token: user_token, access_token: access_token)
|
281
|
+
end
|
282
|
+
|
283
|
+
# https://www.terminal.com/api/docs#gift
|
284
|
+
def gift(user_token, access_token, email, cents)
|
285
|
+
call('/gift',
|
286
|
+
user_token: user_token,
|
287
|
+
access_token: access_token,
|
288
|
+
email: email,
|
289
|
+
cents: cents)
|
290
|
+
end
|
291
|
+
|
292
|
+
# https://www.terminal.com/api/docs#burn-history
|
293
|
+
def burn_history(user_token, access_token)
|
294
|
+
call('/burn_history', user_token: user_token, access_token: access_token)
|
295
|
+
end
|
296
|
+
|
297
|
+
# https://www.terminal.com/api/docs#terminal-usage-history
|
298
|
+
def terminal_usage_history(user_token, access_token)
|
299
|
+
call('/terminal_usage_history', user_token: user_token, access_token: access_token)
|
300
|
+
end
|
301
|
+
|
302
|
+
# https://www.terminal.com/api/docs#burn-state
|
303
|
+
def burn_state(user_token, access_token)
|
304
|
+
call('/burn_state', user_token: user_token, access_token: access_token)
|
305
|
+
end
|
306
|
+
|
307
|
+
# https://www.terminal.com/api/docs#burn-estimates
|
308
|
+
def burn_estimates(user_token, access_token)
|
309
|
+
call('/burn_estimates', user_token: user_token, access_token: access_token)
|
310
|
+
end
|
311
|
+
|
312
|
+
##########################
|
313
|
+
# MANAGE SSH PUBLIC KEYS #
|
314
|
+
##########################
|
315
|
+
|
316
|
+
# https://www.terminal.com/api/docs#add-authorized-key-to-terminal
|
317
|
+
def add_authorized_key_to_terminal(user_token, access_token, container_key, publicKey)
|
318
|
+
call('/add_authorized_key_to_terminal',
|
319
|
+
user_token: user_token,
|
320
|
+
access_token: access_token,
|
321
|
+
container_key: container_key,
|
322
|
+
publicKey: publicKey)
|
323
|
+
end
|
324
|
+
|
325
|
+
# https://www.terminal.com/api/docs#add-authorized-key-to-ssh-proxy
|
326
|
+
def add_authorized_key_to_ssh_proxy(user_token, access_token, name, publicKey)
|
327
|
+
call('/add_authorized_key_to_ssh_proxy',
|
328
|
+
user_token: user_token,
|
329
|
+
access_token: access_token,
|
330
|
+
name: name,
|
331
|
+
publicKey: publicKey)
|
332
|
+
end
|
333
|
+
|
334
|
+
# https://www.terminal.com/api/docs#del-authorized-key-from-ssh-proxy
|
335
|
+
def del_authorized_key_from_ssh_proxy(user_token, access_token, name, fingerprint)
|
336
|
+
call('/del_authorized_key_from_ssh_proxy',
|
337
|
+
user_token: user_token,
|
338
|
+
access_token: access_token,
|
339
|
+
name: name,
|
340
|
+
fingerprint: fingerprint)
|
341
|
+
end
|
342
|
+
|
343
|
+
# https://www.terminal.com/api/docs#get-authorized-keys-from-ssh-proxy
|
344
|
+
def get_authorized_keys_from_ssh_proxy(user_token, access_token)
|
345
|
+
call('/get_authorized_keys_from_ssh_proxy',
|
346
|
+
user_token: user_token, access_token: access_token)
|
347
|
+
end
|
348
|
+
|
349
|
+
#########
|
350
|
+
# OTHER #
|
351
|
+
#########
|
352
|
+
|
353
|
+
# https://www.terminal.com/api/docs#who-am-i
|
354
|
+
def who_am_i(user_token, access_token)
|
355
|
+
call('/who_am_i', user_token: user_token, access_token: access_token)
|
356
|
+
end
|
357
|
+
|
358
|
+
# https://www.terminal.com/api/docs#request-progress
|
359
|
+
def request_progress(request_id)
|
360
|
+
call('/request_progress', request_id: request_id)
|
361
|
+
end
|
362
|
+
|
363
|
+
private
|
364
|
+
def request
|
365
|
+
@request ||= Net::HTTP.new('api.terminal.com')
|
366
|
+
end
|
367
|
+
|
368
|
+
def call(path, data)
|
369
|
+
path = "/#{API_VERSION}#{path}"
|
370
|
+
response = request.post(path, data.to_json, HEADERS)
|
371
|
+
status = response.code.to_i
|
372
|
+
return JSON.parse(response.body) if status == 200
|
373
|
+
|
374
|
+
raise "Unexpected status: #{response.inspect}"
|
375
|
+
end
|
376
|
+
|
377
|
+
def ensure_options_validity(options, *valid_keys)
|
378
|
+
unrecognised_options = (options.keys - valid_keys)
|
379
|
+
|
380
|
+
unless unrecognised_options.empty?
|
381
|
+
raise ArgumentError.new("Unrecognised options: #{unrecognised_options}")
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
data/spec/spec_helper.rb
ADDED
File without changes
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: terminal.com
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James C Russell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: coderay
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
description: The official Terminal.com Ruby + CLI client.
|
28
|
+
email: james@cloudlabs.io
|
29
|
+
executables:
|
30
|
+
- terminal.com
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- bin/terminal.com
|
36
|
+
- docs/help.txt
|
37
|
+
- lib/terminal.com.rb
|
38
|
+
- spec/spec_helper.rb
|
39
|
+
- spec/terminal.com_spec.rb
|
40
|
+
homepage: http://github.com/botanicus/terminal.com
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.2.2
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: The official Terminal.com Ruby + CLI client
|
64
|
+
test_files: []
|