superbot-cloud 0.1.9 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5bd835b5b98790f2f3781fa2ff283288e549a3bff592d56bc088fd70261297b
4
- data.tar.gz: d7d43561f6b36cd25e4ff4b166c4f6cfd3e7f920ac14965a138a1998c483b463
3
+ metadata.gz: 95f7b0130f9adf8531a841cda20fa97ad78431b6d7b11109b8fe06fc79a1acc3
4
+ data.tar.gz: 197fd5861fd0cac3ce1350099ca69dca9821f82dcda6ed884897e2e21e1e9365
5
5
  SHA512:
6
- metadata.gz: 4d7a961ce5eb71bd5d87bc953f5745bca6be8b4eff9f5d5065a25f47340cd69769189f4e6a676ee95de3438522c98ee438fd1b5182b71afc1f8ac7f394d54f3f
7
- data.tar.gz: aade2c3fd1d8eda888b39bc4f25b2a5caf29cdbcd187d381b0ed7b0c65a5f89059d9d5746d224a6d56939e4719043c6f551e6674aba1db7beee01ca40d478565
6
+ metadata.gz: 53c8e647210dd13dbb28bfc3c4fa13afd22846c81640fd30c26ae71d9ce3795d17f3cc573e3ae6a21a240f1a3a6147144e4b9592ebd42517392d5dd094c50965
7
+ data.tar.gz: 92123bbb7f3178bf75dc33d60c221b77dfd872ae2f231414bcfc063040c050b8e2104d436a3a5b5c50d4b719354f9d64b608586a4f0fe591dd54130178dd2a33
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superbot-cloud (0.1.9)
4
+ superbot-cloud (0.1.11)
5
5
  marcel (= 0.3.3)
6
6
  multipart-post (= 2.0.0)
7
7
 
@@ -60,13 +60,13 @@ GEM
60
60
  rack-protection (= 2.0.3)
61
61
  tilt (~> 2.0)
62
62
  sinatra-silent (0.0.1)
63
- superbot (0.1.13)
63
+ superbot (0.1.14)
64
64
  clamp (= 1.2.1)
65
65
  kommando (~> 0.1)
66
66
  launchy (= 2.4.3)
67
67
  sinatra (= 2.0.3)
68
68
  sinatra-silent (= 0.0.1)
69
- superbot-cloud (~> 0.1.4)
69
+ superbot-cloud (~> 0.1.9)
70
70
  zaru (= 0.2.0)
71
71
  tilt (2.0.8)
72
72
  unicode-display_width (1.4.0)
@@ -15,7 +15,8 @@ module Superbot
15
15
 
16
16
  begin
17
17
  Superbot::Cloud::Api.request(:token)
18
- puts "Logged in as #{Superbot::Cloud.credentials[:email]}"
18
+ user_creds = Superbot::Cloud.credentials
19
+ puts "Logged in as #{user_creds[:username]} (#{user_creds[:email]})"
19
20
  rescue SystemExit => e
20
21
  abort unless e.message == 'Invalid credentials'
21
22
  proceed_to_login
@@ -34,20 +35,37 @@ module Superbot
34
35
  end
35
36
 
36
37
  def web_login
37
- Superbot::Cloud::WebLogin.run!
38
- Launchy.open(cloud_login_uri)
39
-
40
- puts "Your browser has been opened to visit:"
41
- puts cloud_login_uri
42
- puts ""
43
- puts "Press enter to exit"
44
- $stdin.gets
38
+ web = Superbot::Cloud::WebLogin.new
39
+ web.run_async_after_running!
40
+ open_cloud_login_uri
41
+ handle_keyboard_interrupt
42
+ wait_for_login(web)
45
43
  end
46
44
 
47
- def cloud_login_uri
48
- URI.parse(Superbot::Cloud::LOGIN_URI).tap do |uri|
45
+ def open_cloud_login_uri
46
+ cloud_login_uri = URI.parse(Superbot::Cloud::LOGIN_URI).tap do |uri|
49
47
  uri.query = URI.encode_www_form(redirect_uri: 'http://localhost:4567/login')
50
48
  end.to_s
49
+
50
+ Launchy.open(cloud_login_uri)
51
+ puts "Your browser has been opened to visit:", cloud_login_uri
52
+ puts
53
+ end
54
+
55
+ def handle_keyboard_interrupt
56
+ trap "SIGINT" do
57
+ puts
58
+ puts "Command killed by keyboard interrupt"
59
+ exit 130
60
+ end
61
+ end
62
+
63
+ def wait_for_login(web)
64
+ loop do
65
+ break unless web.running?
66
+
67
+ sleep 0.1
68
+ end
51
69
  end
52
70
  end
53
71
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Superbot
4
4
  module Cloud
5
- VERSION = "0.1.9"
5
+ VERSION = "0.1.11"
6
6
  end
7
7
  end
@@ -14,10 +14,12 @@ module Superbot
14
14
  set :silent_webrick, true
15
15
  set :silent_access_log, false
16
16
  server_settings[:Silent] = true
17
+ instance = self
17
18
 
18
19
  get "/login" do
19
20
  credentials = request.params.slice('username', 'email', 'token')
20
21
  Superbot::Cloud.save_credentials(credentials)
22
+ instance.quit!
21
23
  redirect "#{Superbot::Cloud::LOGIN_URI}/success?username=#{Superbot::Cloud.credentials[:username]}"
22
24
  end
23
25
  end
@@ -28,9 +30,23 @@ module Superbot
28
30
  end
29
31
 
30
32
  def run!
33
+ @sinatra.run_async!
34
+ end
35
+
36
+ def running?
37
+ @sinatra.running?
38
+ end
39
+
40
+ def run_async_after_running!
31
41
  Thread.new do
32
42
  @sinatra.run!
33
43
  end
44
+
45
+ loop do
46
+ break if running?
47
+
48
+ sleep 0.001
49
+ end
34
50
  end
35
51
  end
36
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superbot-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Superbots