locum 0.0.1
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 +7 -0
- data/.gitignore +24 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +20 -0
- data/Rakefile +2 -0
- data/bin/locum +11 -0
- data/lib/locum/api.rb +37 -0
- data/lib/locum/api_error.rb +3 -0
- data/lib/locum/auth.rb +34 -0
- data/lib/locum/cli.rb +88 -0
- data/lib/locum/config.rb +10 -0
- data/lib/locum/config_builder.rb +17 -0
- data/lib/locum/ping.rb +11 -0
- data/lib/locum/projects.rb +10 -0
- data/lib/locum/version.rb +3 -0
- data/lib/locum.rb +6 -0
- data/locum.gemspec +28 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc68875fb645fd43a73b8f837756809570adaf49
|
4
|
+
data.tar.gz: 193f8b1ad7b8bafe21090701fe334da06cfd0bfd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 131f42630ef4346d45bfe8495992a26b1ab0d6778d9784421ef9328f1f63789bece3f63aa4f4166931177dc8f39891eeb62d30ae0ba2bedff900c44bfe12e0bd
|
7
|
+
data.tar.gz: 104cedb4d2996d0d853b0a56b4ea976e1e066d18d242c94ac193be430a2377965fcaf2f0b61bef5c8b17c021846c82978cd69416e6426522049270bbb82726a0
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
/.idea
|
24
|
+
.locum
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Vasily Shmelev
|
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,20 @@
|
|
1
|
+
# Locum
|
2
|
+
|
3
|
+
Gem предоставляет командный интерфейс (CLI) для панели управления хостинга
|
4
|
+
Locum.ru. Gem находится в ранней разработке, любые пожелания приветствуются.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
$ gem install locum
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
$ locum help
|
13
|
+
|
14
|
+
## Contributing
|
15
|
+
|
16
|
+
1. Fork it ( https://github.com/[my-github-username]/locum/fork )
|
17
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
18
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
19
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
20
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/locum
ADDED
data/lib/locum/api.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'json'
|
3
|
+
require 'net/http'
|
4
|
+
require 'locum/config'
|
5
|
+
|
6
|
+
module Locum::Api
|
7
|
+
HOST = ENV['DEV'] ? 'localhost:3000' : 'locum.ru'
|
8
|
+
SCHEMA = ENV['DEV'] ? 'http' : 'https'
|
9
|
+
API_VERSION = 1
|
10
|
+
|
11
|
+
API = "#{SCHEMA}://#{HOST}/api/v#{API_VERSION}/".freeze
|
12
|
+
|
13
|
+
def self.api
|
14
|
+
API
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.call(method, params = {}, tokenized = true)
|
18
|
+
token = tokenized ? self.token : nil
|
19
|
+
uri = URI("#{API}#{method}")
|
20
|
+
res = Net::HTTP.post_form(
|
21
|
+
uri,
|
22
|
+
{ :token => token }.merge(params)
|
23
|
+
)
|
24
|
+
|
25
|
+
result = JSON.parse(res.body.to_s)
|
26
|
+
|
27
|
+
if result['result'] == 'error'
|
28
|
+
raise ApiError, result['status']
|
29
|
+
end
|
30
|
+
|
31
|
+
result
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.token
|
35
|
+
Locum::Config.get.token
|
36
|
+
end
|
37
|
+
end
|
data/lib/locum/auth.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'locum/api'
|
3
|
+
|
4
|
+
class Locum::Auth
|
5
|
+
attr_accessor :login, :password
|
6
|
+
|
7
|
+
def initialize(login, password)
|
8
|
+
@login = login
|
9
|
+
@password = password
|
10
|
+
end
|
11
|
+
|
12
|
+
def persist_token
|
13
|
+
res = Locum::Api.call(:get_token, { login: @login, password: password }, false)
|
14
|
+
if res['result'] == 'ok'
|
15
|
+
@token = res['token']
|
16
|
+
store_token
|
17
|
+
|
18
|
+
return @token
|
19
|
+
else
|
20
|
+
raise ApiError, res['status']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def store_token
|
25
|
+
begin
|
26
|
+
config = Locum::ConfigBuilder.load
|
27
|
+
rescue
|
28
|
+
config = Locum::Config.new
|
29
|
+
end
|
30
|
+
|
31
|
+
config.token = @token
|
32
|
+
Locum::ConfigBuilder.save(config)
|
33
|
+
end
|
34
|
+
end
|
data/lib/locum/cli.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'thor'
|
3
|
+
require 'highline/import'
|
4
|
+
require 'locum'
|
5
|
+
|
6
|
+
class Locum::CLI < Thor
|
7
|
+
|
8
|
+
desc 'init', 'Получает token для работы с сервисом'
|
9
|
+
option :login
|
10
|
+
option :password
|
11
|
+
|
12
|
+
def init
|
13
|
+
cn.say("\nНастройка интерфейса командной строки locum.ru\n\n")
|
14
|
+
|
15
|
+
login = options[:login] || cn.ask('login: ')
|
16
|
+
password = options[:password] || cn.ask('пароль: ') { |q| q.echo = false }
|
17
|
+
|
18
|
+
s_out "Получаем токен https://locum.ru"
|
19
|
+
|
20
|
+
authenticator = Locum::Auth.new(login, password)
|
21
|
+
|
22
|
+
authenticator.persist_token
|
23
|
+
|
24
|
+
s_in "Токен получен\n\n"
|
25
|
+
|
26
|
+
cn.say <<EOFBLOCK
|
27
|
+
Авторизационный токен для доступа к вашим проектам сохранен в
|
28
|
+
текущем каталоге в файле <%= color('.locum', BOLD) %>.
|
29
|
+
Возможно, вы не хотите, чтобы этот токен попал в систему контроля
|
30
|
+
версий. В этом случае вам нужно добавить исключение в ваш .gitignore
|
31
|
+
или его аналог.
|
32
|
+
|
33
|
+
Выданный токен можно отозвать в любой момент через панель управления
|
34
|
+
хостингом.
|
35
|
+
|
36
|
+
Интерфейс командной строки настроен, используйте команду
|
37
|
+
<%= color('locum help', BOLD) %> для получения списка возможных действий и справки.
|
38
|
+
|
39
|
+
EOFBLOCK
|
40
|
+
|
41
|
+
rescue ApiError => e
|
42
|
+
display_error(e)
|
43
|
+
end
|
44
|
+
|
45
|
+
desc 'ping', 'Проверка связи с API'
|
46
|
+
|
47
|
+
def ping
|
48
|
+
s_out "PING"
|
49
|
+
|
50
|
+
ping = Locum::Ping.new
|
51
|
+
ping.call
|
52
|
+
|
53
|
+
s_in "PONG login: #{ping.login} till #{ping.valid}\n\n"
|
54
|
+
|
55
|
+
rescue ApiError => e
|
56
|
+
display_error(e)
|
57
|
+
end
|
58
|
+
|
59
|
+
desc 'projects', 'Список проектов'
|
60
|
+
|
61
|
+
def projects
|
62
|
+
projects = Locum::Projects.new
|
63
|
+
projects.call
|
64
|
+
|
65
|
+
projects.projects.each {|p| say(" * #{p['name']} (##{p['id']} #{p['type']})") }
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def display_error e
|
72
|
+
cn = HighLine.new
|
73
|
+
cn.say("\n<%= color('Произошла ошибка:', RED) %> #{e.message}")
|
74
|
+
end
|
75
|
+
|
76
|
+
def cn
|
77
|
+
@cn ||= HighLine.new
|
78
|
+
end
|
79
|
+
|
80
|
+
def s_out(s)
|
81
|
+
cn.say("\n<%= color('->', GREEN) %> #{s}")
|
82
|
+
end
|
83
|
+
|
84
|
+
def s_in(s)
|
85
|
+
cn.say("<%= color('<-', CYAN) %> #{s}")
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
data/lib/locum/config.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'yaml'
|
3
|
+
require 'locum/config'
|
4
|
+
|
5
|
+
module Locum::ConfigBuilder
|
6
|
+
CONFIG_FILE = '.locum'.freeze
|
7
|
+
|
8
|
+
def self.load
|
9
|
+
YAML.load_file(CONFIG_FILE)
|
10
|
+
rescue Errno::ENOENT
|
11
|
+
raise Errno::ENOENT, 'Не найден файл конфигурации. Запустите locum init, чтобы его создать'
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.save(config)
|
15
|
+
File.write(CONFIG_FILE, YAML.dump(config))
|
16
|
+
end
|
17
|
+
end
|
data/lib/locum/ping.rb
ADDED
data/lib/locum.rb
ADDED
data/locum.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'locum/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "locum"
|
8
|
+
spec.version = Locum::VERSION
|
9
|
+
spec.authors = ["Vasily Shmelev"]
|
10
|
+
spec.email = ["sleephunter@gmail.com"]
|
11
|
+
spec.summary = %q{Locum.ru maintenance interface}
|
12
|
+
# spec.description = %q{TODO: Write a longer description. Optional.}
|
13
|
+
spec.homepage = "https://github.com/locumru/locum"
|
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.6"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
23
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "highline", "~> 1.6"
|
26
|
+
spec.add_runtime_dependency "thor", "~> 0.19"
|
27
|
+
spec.add_runtime_dependency "json", "~> 1.8"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: locum
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vasily Shmelev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-14 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
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.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: highline
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.6'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: thor
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.19'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.19'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: json
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.8'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.8'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- sleephunter@gmail.com
|
100
|
+
executables:
|
101
|
+
- locum
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/locum
|
111
|
+
- lib/locum.rb
|
112
|
+
- lib/locum/api.rb
|
113
|
+
- lib/locum/api_error.rb
|
114
|
+
- lib/locum/auth.rb
|
115
|
+
- lib/locum/cli.rb
|
116
|
+
- lib/locum/config.rb
|
117
|
+
- lib/locum/config_builder.rb
|
118
|
+
- lib/locum/ping.rb
|
119
|
+
- lib/locum/projects.rb
|
120
|
+
- lib/locum/version.rb
|
121
|
+
- locum.gemspec
|
122
|
+
homepage: https://github.com/locumru/locum
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.2.2
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Locum.ru maintenance interface
|
146
|
+
test_files: []
|
147
|
+
has_rdoc:
|