pupil 0.3.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ 0.4.0
2
+ ----------------
3
+
4
+ * Added new commandline tool.
5
+ "Eyedrops, the interactive twitter with Pupil"
6
+ * Pupil::Keygen are supported readline.
7
+
1
8
  0.3.3
2
9
  ----------------
3
10
 
data/bin/eyedrops ADDED
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "pupil"
4
+ require "pupil/keygen"
5
+ require "yaml"
6
+ require "fileutils"
7
+ require "readline"
8
+
9
+ class Credentials
10
+ attr_accessor :credentials
11
+
12
+ def initialize(file)
13
+ FileUtils.touch file unless FileTest.exists? file
14
+ @credentials_file = file
15
+ @credentials = YAML.load_file(file)
16
+ end
17
+
18
+ def save
19
+ YAML.dump(@credentials, File.open(@credentials_file, "w"))
20
+ end
21
+
22
+ def create
23
+ token = Pupil::Keygen.new.interactive
24
+ @credentials ||= Hash.new
25
+ @credentials.update({token[:screen_name] => token.reject{|k, v| k == :screen_name }})
26
+ self.save
27
+ return token
28
+ end
29
+ end
30
+
31
+ # Initialize
32
+ home_dir = `echo $HOME`.strip
33
+ eyedrops_dir = File.join(home_dir, ".eyedrops")
34
+ credentials_file = File.join(eyedrops_dir, "credentials")
35
+
36
+ Dir.mkdir eyedrops_dir unless FileTest.exists? eyedrops_dir
37
+ cred = Credentials.new(credentials_file)
38
+
39
+ unless cred.credentials
40
+ cred.create
41
+ end
42
+
43
+ puts "Eyedrops, the interactive twitter with Pupil #{Pupil::VERSION}"
44
+
45
+ num = 1
46
+ cred.credentials.keys.each do |name|
47
+ puts "#{num}. #{name}"
48
+ num += 1
49
+ end
50
+ puts "#{num}. Add Account"
51
+ sel = Readline.readline("Choose account: ", false).to_i
52
+ if sel == cred.credentials.keys.size + 1
53
+ cred.create
54
+ sel = cred.credentials.keys.size
55
+ end
56
+
57
+ puts "Preparing Pupil instance..."
58
+ pupil = Pupil.new(cred.credentials[cred.credentials.keys[sel-1]])
59
+ puts "Signed with @#{cred.credentials.keys[sel-1]}"
60
+
61
+ while(true)
62
+ begin
63
+ line = Readline.readline("eyedrops> ", true)
64
+ break if line =~ /^(exit|quit)$/
65
+
66
+ arr = line.split(" ")
67
+ command = arr.first
68
+ option = arr[1, arr.size]
69
+
70
+ case command.to_sym
71
+ when :help
72
+ puts <<-'EOD'
73
+ ### External Commands ###
74
+ help - Now you typed it.
75
+ exit|quit - Exit eyedrops.
76
+
77
+ ### Examples ###
78
+ eyedrops> puts pupil.profile.id
79
+ 237079012
80
+ => nil
81
+ eyedrops> pupil.timeline :count => 5
82
+ #<Pupil::Status:0x007fafb34b5720>
83
+ #<Pupil::Status:0x007fafb34b56f8>
84
+ #<Pupil::Status:0x007fafb34b56d0>
85
+ #<Pupil::Status:0x007fafb34b56a8>
86
+ #<Pupil::Status:0x007fafb34b5680>
87
+ => nil
88
+ EOD
89
+ else
90
+ result = eval(line)
91
+ puts "=> #{result.inspect}"
92
+ end
93
+ rescue => exception
94
+ puts exception
95
+ end
96
+ end
data/lib/pupil/keygen.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  $LOAD_PATH << File.dirname(File.expand_path(__FILE__)) if RUBY_VERSION >= "1.9.0"
4
+ require "readline"
4
5
  require "essentials"
5
6
  require "base"
6
7
  require "keygen/base"
@@ -30,7 +30,7 @@ class Pupil
30
30
  return {:access_token => access_token.token, :access_token_secret => access_token.secret}
31
31
  end
32
32
 
33
- def pupilkey
33
+ def pupil_key
34
34
  raise MissingRequiredTokens, "Pupil::Keygen#pupilkey require consumer_key, consumer_secret, access_token and access_token_secret" unless @consumer_key || @consumer_secret || @access_token || @access_token_secret
35
35
  return {
36
36
  :consumer_key => @consumer_key,
@@ -41,28 +41,23 @@ class Pupil
41
41
  end
42
42
 
43
43
  def interactive
44
- print "Enter OAuth Consumer Key: " unless @consumer_key
45
- @consumer_key = gets.chomp.strip unless @consumer_key
46
- print "Enter OAuth Consumer Secret: " unless @consumer_secret
47
- @consumer_secret = gets.chomp.strip unless @consumer_secret
44
+ @consumer_key = Readline.readline("Enter OAuth Consumer Key: ", true) unless @consumer_key
45
+ print unless @consumer_secret
46
+ @consumer_secret = Readline.readline("Enter OAuth Consumer Secret: ", true) unless @consumer_secret
48
47
 
49
48
  consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret, :site => 'http://twitter.com')
50
49
 
51
50
  request_token = consumer.get_request_token
52
51
 
53
52
  puts "Access to this URL and approve: #{request_token.authorize_url}"
54
-
55
- print "Enter OAuth Verifier: "
56
- oauth_verifier = gets.chomp.strip
53
+
54
+ oauth_verifier = Readline.readline("Enter OAuth Verifier: ", true)
57
55
 
58
56
  access_token = request_token.get_access_token(:oauth_verifier => oauth_verifier)
59
57
  @access_token = access_token.token
60
58
  @access_token_secret = access_token.secret
61
59
 
62
- puts "Process complete!"
63
- puts "Access token: #{access_token.token}"
64
- puts "Access token secret: #{access_token.secret}"
65
- return {:consumer_key => @consumer_key, :consumer_secret => @consumer_secret, :access_token => access_token.token, :access_token_secret => access_token.secret}
60
+ return {:consumer_key => @consumer_key, :consumer_secret => @consumer_secret, :access_token => access_token.token, :access_token_secret => access_token.secret, :screen_name => access_token.params[:screen_name]}
66
61
  end
67
62
  end
68
63
  end
data/lib/pupil/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Pupil
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pupil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: '0.4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth
16
- requirement: &70336822437800 !ruby/object:Gem::Requirement
16
+ requirement: &70170194408800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70336822437800
24
+ version_requirements: *70170194408800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70336822437220 !ruby/object:Gem::Requirement
27
+ requirement: &70170194408300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70336822437220
35
+ version_requirements: *70170194408300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70336822436600 !ruby/object:Gem::Requirement
38
+ requirement: &70170194407740 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70336822436600
46
+ version_requirements: *70170194407740
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: yard
49
- requirement: &70336822435980 !ruby/object:Gem::Requirement
49
+ requirement: &70170194423220 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70336822435980
57
+ version_requirements: *70170194423220
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &70336822459820 !ruby/object:Gem::Requirement
60
+ requirement: &70170194421440 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,12 +65,12 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70336822459820
68
+ version_requirements: *70170194421440
69
69
  description: The "Lazy" Twitter API Library for Ruby 1.9.x. Easy to use.
70
70
  email:
71
71
  - oame@oameya.com
72
72
  executables:
73
- - hitomi
73
+ - eyedrops
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
@@ -82,7 +82,7 @@ files:
82
82
  - README.ja.md
83
83
  - README.md
84
84
  - Rakefile
85
- - bin/hitomi
85
+ - bin/eyedrops
86
86
  - lib/pupil.rb
87
87
  - lib/pupil/account.rb
88
88
  - lib/pupil/base.rb
data/bin/hitomi DELETED
File without changes