dgate 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +8 -0
- data/README.md +25 -0
- data/Rakefile +1 -0
- data/bin/dgate +256 -0
- data/dgate.gemspec +27 -0
- data/lib/dgate.rb +4 -0
- data/lib/dgate/version.rb +3 -0
- metadata +120 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Copyright (C) 2014 DeployGate All rights reserved.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
4
|
+
|
5
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
6
|
+
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
8
|
+
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# dgate
|
2
|
+
|
3
|
+
A command-line interface for DeployGate
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dgate'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dgate
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Push/Update an application:
|
22
|
+
|
23
|
+
$ dgate push [package file path]
|
24
|
+
|
25
|
+
See https://deploygate.com/docs/cli for more information.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/dgate
ADDED
@@ -0,0 +1,256 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'dgate'
|
4
|
+
require 'optparse'
|
5
|
+
require 'optparse/shellwords'
|
6
|
+
require 'net/http'
|
7
|
+
require 'json'
|
8
|
+
require 'httpclient'
|
9
|
+
require 'rbconfig'
|
10
|
+
|
11
|
+
API_BASE_URL = "https://deploygate.com"
|
12
|
+
SETTING_FILE = ENV["HOME"] + "/.dgate"
|
13
|
+
$settings = {
|
14
|
+
'name' => "",
|
15
|
+
'token' => ""
|
16
|
+
}
|
17
|
+
|
18
|
+
def new_client
|
19
|
+
client = HTTPClient.new(agent_name: "dgate/#{Dgate::VERSION}")
|
20
|
+
return client
|
21
|
+
end
|
22
|
+
|
23
|
+
def post_request(path,params)
|
24
|
+
url = API_BASE_URL + path
|
25
|
+
client = new_client
|
26
|
+
extheaders = []
|
27
|
+
api_token = $settings['token']
|
28
|
+
unless api_token.nil?
|
29
|
+
extheaders.push(['AUTHORIZATION',api_token])
|
30
|
+
end
|
31
|
+
res = client.post(url,params,extheaders)
|
32
|
+
return nil unless res.status_code == 200
|
33
|
+
res_object = JSON.parse(res.body)
|
34
|
+
if res_object['error'] == true
|
35
|
+
raise res_object['because'] || "error"
|
36
|
+
end
|
37
|
+
return res_object['results']
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_request(path,params)
|
41
|
+
url = API_BASE_URL + path
|
42
|
+
client = new_client
|
43
|
+
extheaders = []
|
44
|
+
api_token = $settings['token']
|
45
|
+
unless api_token.nil?
|
46
|
+
extheaders.push(['AUTHORIZATION',api_token])
|
47
|
+
end
|
48
|
+
#params = {'token' => api_token}
|
49
|
+
res = client.get(url,params,extheaders)
|
50
|
+
return nil unless res.status_code == 200
|
51
|
+
res_object = JSON.parse(res.body)
|
52
|
+
return nil if res_object['error'] == true
|
53
|
+
return res_object['results']
|
54
|
+
end
|
55
|
+
|
56
|
+
def openable?
|
57
|
+
RbConfig::CONFIG['host_os'].include?('darwin')
|
58
|
+
end
|
59
|
+
|
60
|
+
def do_save_settings
|
61
|
+
data = JSON.generate($settings)
|
62
|
+
file = open(SETTING_FILE,"w+")
|
63
|
+
file.print data
|
64
|
+
file.close
|
65
|
+
end
|
66
|
+
|
67
|
+
def do_load_settings
|
68
|
+
return nil unless File.exist?(SETTING_FILE)
|
69
|
+
file = open(SETTING_FILE)
|
70
|
+
data = file.read
|
71
|
+
file.close
|
72
|
+
$settings = JSON.parse(data)
|
73
|
+
end
|
74
|
+
|
75
|
+
def do_create_session
|
76
|
+
$stdout.sync = true
|
77
|
+
print "Email: "
|
78
|
+
email = $stdin.gets.chop
|
79
|
+
system "stty -echo"
|
80
|
+
print "Password: "
|
81
|
+
password = $stdin.gets.chop
|
82
|
+
print "\n"
|
83
|
+
system "stty echo"
|
84
|
+
login_res = {};
|
85
|
+
begin
|
86
|
+
login_res = post_request(
|
87
|
+
'/api/sessions',{
|
88
|
+
'email' => email,
|
89
|
+
'password' => password
|
90
|
+
})
|
91
|
+
rescue => e
|
92
|
+
print "Invalid email or password.\n"
|
93
|
+
return false
|
94
|
+
end
|
95
|
+
$settings['token'] = login_res['api_token']
|
96
|
+
$settings['name'] = login_res['name']
|
97
|
+
do_save_settings
|
98
|
+
return true
|
99
|
+
end
|
100
|
+
|
101
|
+
def do_check_session
|
102
|
+
check_res = get_request('/api/sessions/user',{})
|
103
|
+
if check_res.nil?
|
104
|
+
print "Your session was expired or invalid.\n"
|
105
|
+
exit unless do_create_session
|
106
|
+
check_res = get_request('/api/sessions/user',{})
|
107
|
+
end
|
108
|
+
$settings['name'] = check_res['name']
|
109
|
+
return true
|
110
|
+
end
|
111
|
+
|
112
|
+
def do_push_file
|
113
|
+
message = $message || ''
|
114
|
+
file_path = nil
|
115
|
+
target_user = nil
|
116
|
+
if ARGV[2].nil?
|
117
|
+
target_user = $settings['name']
|
118
|
+
file_path = ARGV[1]
|
119
|
+
else
|
120
|
+
target_user = ARGV[1]
|
121
|
+
file_path = ARGV[2]
|
122
|
+
end
|
123
|
+
if file_path.nil? || !File.exist?(file_path)
|
124
|
+
print "target file is not found.\n"
|
125
|
+
exit
|
126
|
+
end
|
127
|
+
push_res = nil
|
128
|
+
open(file_path) do |file|
|
129
|
+
begin
|
130
|
+
push_res = post_request(
|
131
|
+
sprintf("/api/users/%s/apps",target_user),
|
132
|
+
{ :file => file , :message => message}
|
133
|
+
)
|
134
|
+
rescue => e
|
135
|
+
if e.message == 'file'
|
136
|
+
print "Failed, This file is not app binary.\n"
|
137
|
+
elsif e.message == 'permit'
|
138
|
+
print "Failed, You don't have permit to upload.\n"
|
139
|
+
elsif e.message == 'blank'
|
140
|
+
print "Failed, Target file is not selected.\n"
|
141
|
+
elsif e.message == 'limit'
|
142
|
+
print "Failed, You reach limit of current plan.\nPlease upgrade DeployGate Plan :)\n"
|
143
|
+
else
|
144
|
+
puts e.message
|
145
|
+
end
|
146
|
+
exit
|
147
|
+
end
|
148
|
+
end
|
149
|
+
if push_res.nil?
|
150
|
+
print "Sorry, push operation was faild.\n"
|
151
|
+
exit
|
152
|
+
end
|
153
|
+
web_url = API_BASE_URL + push_res['path']
|
154
|
+
#if first app, start to share.
|
155
|
+
if push_res['revision'] == 1 && push_res['os_name'].downcase == 'android'
|
156
|
+
share_res = nil
|
157
|
+
begin
|
158
|
+
share_res = post_request(
|
159
|
+
sprintf(
|
160
|
+
"/api/users/%s/apps/%s/share",
|
161
|
+
target_user,push_res['package_name']),{}
|
162
|
+
)
|
163
|
+
rescue
|
164
|
+
print "Faild to change permission of your app.\n"
|
165
|
+
exit
|
166
|
+
end
|
167
|
+
if !share_res['secret'].nil?
|
168
|
+
web_url += sprintf("?key=%s",share_res['secret'])
|
169
|
+
end
|
170
|
+
else
|
171
|
+
if !push_res['secret'].nil?
|
172
|
+
web_url += sprintf("?key=%s",push_res['secret'])
|
173
|
+
end
|
174
|
+
end
|
175
|
+
print "Push app file successful!\n"
|
176
|
+
print "\n"
|
177
|
+
print "Name :\t\t" + push_res['name'] + "\n"
|
178
|
+
print "Owner :\t\t" + push_res['user']['name'] + "\n"
|
179
|
+
print "Package :\t" + push_res['package_name'] + "\n"
|
180
|
+
print "Revision :\t" + push_res['revision'].to_s + "\n"
|
181
|
+
print "URL :\t\t" + web_url
|
182
|
+
print "\n\n"
|
183
|
+
if((!$open_with_browser.nil? || push_res['revision'] == 1) && openable?)
|
184
|
+
system "open " + web_url
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
### options
|
189
|
+
parser = OptionParser.new do |option|
|
190
|
+
Version = Dgate::VERSION
|
191
|
+
option.banner = "Usage: dgate <subcommand> [<args>] [<options>]"
|
192
|
+
option.separator("")
|
193
|
+
option.separator("Commands:")
|
194
|
+
option.separator(" push push or update app")
|
195
|
+
option.separator(" logout logout or change account")
|
196
|
+
option.separator("")
|
197
|
+
option.separator("Options:")
|
198
|
+
|
199
|
+
option.on('-m', '--message=MESSAGE', '(push) optional message of this push') { |message| $message = message }
|
200
|
+
option.on('-o', '--[no-]open', TrueClass, '(push) open with browser (Mac OS only)') { $open_with_browser = true }
|
201
|
+
|
202
|
+
option.separator("")
|
203
|
+
option.separator("Examples:")
|
204
|
+
option.separator(" Push/Update app to your own")
|
205
|
+
option.separator(" $ dgate push <app_file_path>")
|
206
|
+
option.separator("")
|
207
|
+
option.separator(" Push/Update app to inviter who invited your as developer")
|
208
|
+
option.separator(" $ dgate push <owner_name> <app_file_path>")
|
209
|
+
option.separator("")
|
210
|
+
option.separator(" Push/Update app to group with message and open it in browser after push")
|
211
|
+
option.separator(" $ dgate push <group_name> <app_file_path> -m 'develop build' -o")
|
212
|
+
option.separator("")
|
213
|
+
option.separator(" Change account or logout")
|
214
|
+
option.separator(" $ dgate logout")
|
215
|
+
|
216
|
+
begin
|
217
|
+
option.parse!
|
218
|
+
rescue => err
|
219
|
+
$stderr.puts err
|
220
|
+
$stderr.puts option
|
221
|
+
exit 1
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
#### main
|
226
|
+
do_load_settings
|
227
|
+
command = ARGV[0]
|
228
|
+
|
229
|
+
if command.nil?
|
230
|
+
$stderr.puts "Please set dgate command."
|
231
|
+
$stderr.puts parser
|
232
|
+
exit
|
233
|
+
end
|
234
|
+
|
235
|
+
# logout
|
236
|
+
if command == 'logout'
|
237
|
+
$settings['token'] = ''
|
238
|
+
do_save_settings
|
239
|
+
print "Session is deleted.\n"
|
240
|
+
exit
|
241
|
+
end
|
242
|
+
|
243
|
+
# login
|
244
|
+
if $settings['token'].nil? || $settings['token'] == ""
|
245
|
+
do_create_session
|
246
|
+
else
|
247
|
+
do_check_session
|
248
|
+
end
|
249
|
+
|
250
|
+
if command == 'push'
|
251
|
+
if ARGV[1].nil?
|
252
|
+
print "Please set target app file.\n"
|
253
|
+
exit
|
254
|
+
end
|
255
|
+
do_push_file
|
256
|
+
end
|
data/dgate.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dgate/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dgate"
|
8
|
+
spec.version = Dgate::VERSION
|
9
|
+
spec.authors = ["deploygate"]
|
10
|
+
spec.email = ["contact@deploygate.com"]
|
11
|
+
spec.description = %q{You can push or update apps to DeployGate in your terminal.}
|
12
|
+
spec.summary = %q{A command-line interface for DeployGate}
|
13
|
+
spec.homepage = "https://deploygate.com"
|
14
|
+
spec.license = "Apache-2.0"
|
15
|
+
|
16
|
+
spec.add_dependency 'json', '~> 1.7.4'
|
17
|
+
spec.add_dependency 'httpclient', '~> 2.2.5'
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
|
22
|
+
spec.files = `git ls-files`.split($/)
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
24
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
end
|
data/lib/dgate.rb
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dgate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- deploygate
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-07-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.7.4
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.7.4
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: httpclient
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.2.5
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.2.5
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: You can push or update apps to DeployGate in your terminal.
|
79
|
+
email:
|
80
|
+
- contact@deploygate.com
|
81
|
+
executables:
|
82
|
+
- dgate
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- bin/dgate
|
92
|
+
- dgate.gemspec
|
93
|
+
- lib/dgate.rb
|
94
|
+
- lib/dgate/version.rb
|
95
|
+
homepage: https://deploygate.com
|
96
|
+
licenses:
|
97
|
+
- Apache-2.0
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 1.8.23
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: A command-line interface for DeployGate
|
120
|
+
test_files: []
|