aboutsummaryrefslogtreecommitdiffstats
path: root/core/boot
diff options
context:
space:
mode:
authorToshiaki Asai <toshi.alternative@gmail.com>2015-09-25 03:49:32 +0900
committerToshiaki Asai <toshi.alternative@gmail.com>2015-09-25 03:49:32 +0900
commit6f4fdffb90565a0efdb18516a9277d429ec4d6fe (patch)
tree77551bd5d8fd5bba1446181de9614744b3304c41 /core/boot
parentc587aa1287b2f9544ac3187c2d914546e60c727a (diff)
downloadmikutter-6f4fdffb90565a0efdb18516a9277d429ec4d6fe.tar.gz
コマンドからアカウントを登録できるサブコマンド「account」を実装 refs #765
Diffstat (limited to 'core/boot')
-rw-r--r--core/boot/option.rb2
-rw-r--r--core/boot/shell/account.rb36
2 files changed, 37 insertions, 1 deletions
diff --git a/core/boot/option.rb b/core/boot/option.rb
index a896738c..a3346839 100644
--- a/core/boot/option.rb
+++ b/core/boot/option.rb
@@ -46,6 +46,7 @@ module Mopt
puts " generate [plugin_slug] generate plugin template at ~/.mikutter/plugin/"
puts " spec [directory] generate plugin spec. ex) mikutter spec ~/.mikutter/plugin/test"
puts " makepot generate .pot file all plugins."
+ puts " account Register new Twitter account."
exit }
opt.parse!(ARGV)
@@ -65,4 +66,3 @@ module Mopt
end
end
-
diff --git a/core/boot/shell/account.rb b/core/boot/shell/account.rb
new file mode 100644
index 00000000..8c51abf3
--- /dev/null
+++ b/core/boot/shell/account.rb
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+
+miquire :boot, 'delayer'
+miquire :lib, 'mikutwitter'
+miquire :core, 'service', 'plugin'
+
+puts "Register new account."
+
+twitter = MikuTwitter.new
+twitter.consumer_key = Environment::TWITTER_CONSUMER_KEY
+twitter.consumer_secret = Environment::TWITTER_CONSUMER_SECRET
+request_token = twitter.request_oauth_token
+
+puts "1) Access #{request_token.authorize_url}"
+puts "2) Login twitter."
+puts "3) Input PIN code."
+
+print "PIN code>"
+pin = STDIN.gets.chomp
+processing = true
+access_token = request_token.get_access_token(oauth_token: request_token.token,
+ oauth_verifier: pin)
+Service.add_service(access_token.token, access_token.secret).next{ |service|
+ puts "Account @#{service.user_obj.idname} registered."
+ processing = false
+}.trap { |err|
+ puts "Account register failed."
+ puts err
+ processing = false
+ abort
+}
+
+while processing
+ Delayer.run
+ sleep 0.1
+end