deploygate 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjI1OTFhNWJhY2U4ZThhNTNjMWQwM2QyY2Y3Y2EzM2E4NzIzZmU2Yw==
4
+ ZTI5MDhlOGNmOGY1OWRkYzM3OTEwZTc2NjRhOTRjYjNlM2U5YzVmNw==
5
5
  data.tar.gz: !binary |-
6
- NDRhMTRhMWI1Y2Y0ZDQ5YzI0M2Q4NDFjNjllODc3NzAzMjk5MjdlMQ==
6
+ MWUwNTJmNTdiNGY4MWJmMTY2MTUyMzlkZGI5NjQ0NTQxOTJlM2VmNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzhhNzAwZmQxNzM5MjQ5MzdmZjg5YmFmMjIzNGZjZTlmODFhNzQwOTBkNWIz
10
- ZjVlZTdiZjEzNDFlNDVkZmZkZTA5MGU1ODhlNjI1MmVmYWVkYzYzYzBlZTJh
11
- YTcyOGUyNGVhYzhiY2Q2ZTc1ZDMzYzFkNjQ4MzhiZDIwYzA0Y2Y=
9
+ YjkyMmExM2EwMjQwNzk2NWVhMzZjMzhiNDYxNTM1ZDM0ZDE2Mzg5NTZmNTU1
10
+ YmVmZTFhOWI0MWZlZDU0YWIxNTlmOWY3ZDFlYmU3NDZhMjk4MjlkMjA3Njgz
11
+ YmNlNDBlYTNiZWE1MTE0MmE3NDBmOWMwNWZkZmJkYWE3YjExYzc=
12
12
  data.tar.gz: !binary |-
13
- OGQzNWViMDU2ODM2MGIyMzdkODc1Mjg1NmE5YmE3OTAzZTNkNmQwOTcwODJk
14
- ODY4N2IwM2Q1MWM0OGRlYjkyMzUyNTQzYTM1NmUzZDgxYjA4YmRjODNiZTdi
15
- ZDgzYjQ1MjgzMGYzMDMyMTgzOWY3ZGU0ZDg2NzJlNjk4MDJmY2U=
13
+ NDQwODQ1MGRiNDg4N2NjN2RjMmRjZWE4NmMyM2ZmODA1ZjUzM2FiMDBlMThm
14
+ ZjU3MGRhOTM0YTFmOTgzNWQ5ODQ1N2EwZWI2OGE4YTY2Y2Y3MTE4M2Y5NTVj
15
+ NzAxNDhiOTM0ZDY1Y2E0MTNkNjc5NWIyNmQwMThkMmY2YWM1N2M=
@@ -20,7 +20,14 @@ en:
20
20
  user: 'Owner user or organization name'
21
21
  udid: 'UDID to be registered'
22
22
  device_name: 'Device name to be registered'
23
+ distribution_key: 'If you also want to update distribution page, set the last part of the URL of the page'
23
24
  error: 'Commands::AddDevices Error: %{e}'
25
+ server:
26
+ description: 'Start the add-devices server. When added new device automatically run add-devices command.'
27
+ connecting: 'Connecting...'
28
+ start: 'Start add-devices server. Use Ctrl-C to stop.'
29
+ start_build: 'New device has been added. Start add-devices command.'
30
+ finish_build: 'add-devices completed successfully.'
24
31
  logout:
25
32
  description: 'Log out current session'
26
33
  error: 'Commands::Logout Error: %{e}'
data/deploygate.gemspec CHANGED
@@ -34,6 +34,8 @@ POST_INSTALL_MESSAGE
34
34
  spec.add_dependency 'launchy'
35
35
  spec.add_dependency 'locale'
36
36
  spec.add_dependency 'net-ping'
37
+ spec.add_dependency 'socket.io-client-simple'
38
+ spec.add_dependency 'workers'
37
39
 
38
40
  # ios build
39
41
  spec.add_dependency 'gym', '~> 1.7.0'
@@ -0,0 +1,79 @@
1
+ module DeployGate
2
+ class AddDevicesServer
3
+
4
+ def start(token, owner_name, bundle_id, distribution_key, args, options)
5
+ DeployGate::Xcode::MemberCenter.instance
6
+ options.server = false
7
+
8
+ puts I18n.t('command_builder.add_devices.server.connecting')
9
+ res = DeployGate::API::V1::Users::Apps::CliWebsockets.create(token, owner_name, bundle_id, distribution_key)
10
+
11
+ server = res[:webpush_server]
12
+ push_token = res[:push_token]
13
+ action = res[:action]
14
+ if res[:error] || server.blank? || push_token.blank? || action.blank?
15
+ raise res[:message]
16
+ end
17
+
18
+ websocket_setup(server, bundle_id, push_token, action, args, options) do |socket|
19
+ puts HighLine.color(I18n.t('command_builder.add_devices.server.start'), HighLine::GREEN)
20
+
21
+ Workers::PeriodicTimer.new(60) do
22
+ DeployGate::API::V1::Users::Apps::CliWebsockets.heartbeat(token, owner_name, bundle_id, distribution_key, push_token)
23
+ end
24
+
25
+ Signal.trap(:INT){
26
+ socket.disconnect
27
+ exit 0
28
+ }
29
+ end
30
+
31
+ loop do
32
+ sleep 60
33
+ end
34
+ end
35
+
36
+ def self.build(pool, bunlde_id, iphones, args, options)
37
+ iphones.reject! { |iphone| iphone['is_registered'] } # remove udids if already registered
38
+ devices = iphones.map do |iphone|
39
+ udid = iphone['udid']
40
+ device_name= iphone['device_name']
41
+ DeployGate::Xcode::MemberCenters::Device.new(udid, '', device_name)
42
+ end
43
+ return if devices.empty?
44
+
45
+ puts HighLine.color(I18n.t('command_builder.add_devices.server.start_build'), HighLine::GREEN)
46
+ pool.perform do
47
+ DeployGate::Commands::AddDevices.register!(devices)
48
+ DeployGate::Commands::AddDevices.build!(bunlde_id, args, options)
49
+ puts HighLine.color(I18n.t('command_builder.add_devices.server.finish_build'), HighLine::GREEN)
50
+ puts ''
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def websocket_setup(server, bundle_id, push_token, target_action, args, options, &block)
57
+ socket = SocketIO::Client::Simple.connect server
58
+ socket.on :connect do
59
+ socket.emit :subscribe, push_token
60
+ block.call(socket)
61
+ end
62
+
63
+ socket.on :error do
64
+ raise 'Socket Error'
65
+ end
66
+
67
+ pool = Workers::Pool.new(size: 1, on_exception: proc { |e|
68
+ raise e
69
+ })
70
+ socket.on push_token do |push_data|
71
+ return if push_data['action'] != target_action
72
+ data = JSON.parse(push_data['data'])
73
+
74
+ iphones = data['iphones']
75
+ DeployGate::AddDevicesServer.build(pool, bundle_id, iphones, args, options)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -2,7 +2,7 @@ module DeployGate
2
2
  module API
3
3
  module V1
4
4
  class Base
5
- BASE_URL = 'https://deploygate.com'
5
+ BASE_URL = ENV['DG_DEVELOP_URL'] || 'https://deploygate.com'
6
6
  API_BASE_URL = "#{BASE_URL}/api"
7
7
 
8
8
  # @param [String] token
@@ -0,0 +1,42 @@
1
+ module DeployGate::API::V1::Users::Apps
2
+ class CliWebsockets
3
+ ENDPOINT = "/users/%s/platforms/%s/apps/%s/cli_websockets"
4
+
5
+ class << self
6
+ def create(token, name, package_name, distribution_key, platform = 'ios')
7
+ params = {distribution_access_key: distribution_key} unless distribution_key.nil?
8
+ res = DeployGate::API::V1::Base.new(token).post(sprintf(ENDPOINT, name, platform, package_name), params || {})
9
+
10
+ results = {
11
+ error: res['error']
12
+ }
13
+ if results[:error]
14
+ results.merge!(
15
+ {
16
+ message: res['message']
17
+ }
18
+ )
19
+ else
20
+ results.merge!(
21
+ {
22
+ push_token: res['results']['push_token'],
23
+ webpush_server: res['results']['webpush_server'],
24
+ action: res['results']['action']
25
+ }
26
+ )
27
+ end
28
+
29
+ results
30
+ end
31
+
32
+ def heartbeat(token, name, package_name, distribution_key, push_token, platform = 'ios')
33
+ params = {distribution_access_key: distribution_key} unless distribution_key.nil?
34
+ res = DeployGate::API::V1::Base.new(token).get("#{sprintf(ENDPOINT, name, platform, package_name)}/#{push_token}/heartbeat", params || {})
35
+
36
+ {
37
+ error: res['error']
38
+ }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -80,8 +80,10 @@ module DeployGate
80
80
  c.option '--user STRING', String, I18n.t('command_builder.add_devices.user')
81
81
  c.option '--udid STRING', String, I18n.t('command_builder.add_devices.udid')
82
82
  c.option '--device-name STRING', String, I18n.t('command_builder.add_devices.device_name')
83
+ c.option '--distribution-key STRING', String, I18n.t('command_builder.add_devices.distribution_key')
84
+ c.option '--server', I18n.t('command_builder.add_devices.server.description')
83
85
  c.action do |args, options|
84
- options.default :user => nil
86
+ options.default :user => nil, :server => false
85
87
  begin
86
88
  Commands::AddDevices.run(args, options)
87
89
  rescue => e
@@ -15,21 +15,32 @@ module DeployGate
15
15
  session = DeployGate::Session.new()
16
16
  end
17
17
 
18
- owner = options.user || session.name
19
- udid = options.udid
20
- device_name = options.device_name
18
+ owner = options.user || session.name
19
+ udid = options.udid
20
+ device_name = options.device_name
21
+ distribution_key = options.distribution_key
22
+ server = options.server
21
23
 
22
24
  bundle_id = bundle_id(work_dir)
23
25
 
26
+ if server
27
+ run_server(session, owner, bundle_id, distribution_key, args, options)
28
+ else
29
+ device_register(session, owner, udid, device_name, bundle_id, args, options)
30
+ end
31
+ end
32
+
33
+ def run_server(session, owner, bundle_id, distribution_key, args, options)
34
+ DeployGate::AddDevicesServer.new().start(session.token, owner, bundle_id, distribution_key, args, options)
35
+ end
36
+
37
+ def device_register(session, owner, udid, device_name, bundle_id, args, options)
24
38
  if udid.nil? && device_name.nil?
25
39
  devices = fetch_devices(session.token, owner, bundle_id)
26
40
  select_devices = select_devices(devices)
27
41
  not_device if select_devices.empty?
28
42
 
29
- select_devices.each do |device|
30
- device.register!
31
- success_registered_device(device)
32
- end
43
+ register!(devices)
33
44
  else
34
45
  register_udid = udid || HighLine.ask(I18n.t('commands.add_devices.input_udid'))
35
46
  register_device_name = device_name || HighLine.ask(I18n.t('commands.add_devices.input_device_name'))
@@ -37,13 +48,23 @@ module DeployGate
37
48
 
38
49
  puts device.to_s
39
50
  if HighLine.agree(I18n.t('commands.add_devices.device_register_confirm')) {|q| q.default = "y"}
40
- device.register!
41
- success_registered_device(device)
51
+ register!([device])
42
52
  else
43
53
  not_device
44
54
  end
45
55
  end
46
56
 
57
+ build!(bundle_id, args, options)
58
+ end
59
+
60
+ def register!(devices)
61
+ devices.each do |device|
62
+ device.register!
63
+ success_registered_device(device)
64
+ end
65
+ end
66
+
67
+ def build!(bundle_id, args, options)
47
68
  DeployGate::Xcode::MemberCenters::ProvisioningProfile.new(bundle_id).create!
48
69
  team = DeployGate::Xcode::MemberCenter.instance.team
49
70
  DeployGate::Xcode::Export.clean_provisioning_profiles(bundle_id, team)
@@ -1,3 +1,3 @@
1
1
  module DeployGate
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/deploygate.rb CHANGED
@@ -19,6 +19,8 @@ require "rexml/document"
19
19
  require "launchy"
20
20
  require "webrick"
21
21
  require "net/ping"
22
+ require "socket.io-client-simple"
23
+ require "workers"
22
24
 
23
25
  require "i18n"
24
26
  I18n.load_path = Dir[File.join(File.dirname(__FILE__), '../config/locales/*.yml')]
@@ -38,6 +40,7 @@ require "deploygate/api/v1/session"
38
40
  require "deploygate/api/v1/push"
39
41
  require "deploygate/api/v1/user"
40
42
  require "deploygate/api/v1/users/app"
43
+ require "deploygate/api/v1/users/apps/cli_websockets"
41
44
  require "deploygate/command_builder"
42
45
  require "deploygate/commands/login"
43
46
  require "deploygate/commands/logout"
@@ -54,6 +57,7 @@ require "deploygate/deploy"
54
57
  require "deploygate/project"
55
58
  require "deploygate/user"
56
59
  require "deploygate/browser_login"
60
+ require "deploygate/add_devices_server"
57
61
  require "deploygate/xcode/member_center"
58
62
  require "deploygate/xcode/member_centers/app"
59
63
  require "deploygate/xcode/member_centers/provisioning_profile"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deploygate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - deploygate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-21 00:00:00.000000000 Z
11
+ date: 2016-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -206,6 +206,34 @@ dependencies:
206
206
  - - ! '>='
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: socket.io-client-simple
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ! '>='
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ! '>='
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: workers
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :runtime
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ! '>='
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
209
237
  - !ruby/object:Gem::Dependency
210
238
  name: gym
211
239
  requirement: !ruby/object:Gem::Requirement
@@ -338,6 +366,7 @@ files:
338
366
  - config/locales/en.yml
339
367
  - deploygate.gemspec
340
368
  - lib/deploygate.rb
369
+ - lib/deploygate/add_devices_server.rb
341
370
  - lib/deploygate/android/gradle_deploy.rb
342
371
  - lib/deploygate/android/gradle_plugin_installer.rb
343
372
  - lib/deploygate/android/gradle_project.rb
@@ -346,6 +375,7 @@ files:
346
375
  - lib/deploygate/api/v1/session.rb
347
376
  - lib/deploygate/api/v1/user.rb
348
377
  - lib/deploygate/api/v1/users/app.rb
378
+ - lib/deploygate/api/v1/users/apps/cli_websockets.rb
349
379
  - lib/deploygate/browser_login.rb
350
380
  - lib/deploygate/command_builder.rb
351
381
  - lib/deploygate/commands/add_devices.rb