twsh 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/README.md +3 -0
- data/lib/myun2/twitter/authenticate.rb +24 -0
- data/lib/myun2/twitter_shell.rb +2 -0
- data/lib/myun2/twitter_shell/authorize.rb +33 -0
- data/lib/myun2/twitter_shell/client.rb +17 -0
- data/lib/myun2/twitter_shell/consumer_key.rb +6 -0
- data/lib/myun2/twitter_shell/login.rb +21 -0
- data/lib/myun2/twitter_shell/ls.rb +27 -0
- data/lib/myun2/twitter_shell/profile.rb +50 -0
- data/lib/myun2/twitter_shell/shell.rb +33 -0
- data/lib/myun2/twitter_shell/version.rb +5 -0
- data/lib/twsh.rb +4 -0
- data/twsh.gemspec +27 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6e127e033d14eb425e9e2267f5869ed50d177b33
|
4
|
+
data.tar.gz: 12d7627fd8af3490e8a8f438528f15c4abbc824e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a7a0c41448262a7929f025b038511811e86d1e168a0af0cc5f8c883ac4ea875f8e687c2c4a9444b6cad787b6758a77e7a87df13893207c8d863c15a2c8b574c
|
7
|
+
data.tar.gz: 715a284939f4e550dd0cb50685328ccb7a2f5a7fc97fcf1d0ee2f9351d68c44bf4801e54a7b9939844877b4130d4780b4d806798c4b2b9ff90be11de821f37e0
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'twitter_oauth'
|
2
|
+
|
3
|
+
module Myun2
|
4
|
+
class Twitter
|
5
|
+
class Authenticate
|
6
|
+
attr_reader :client, :authorize_url, :access_token
|
7
|
+
|
8
|
+
def initialize(params)
|
9
|
+
@client = TwitterOAuth::Client.new(params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def request_authorize_url
|
13
|
+
@token = client.authentication_request_token(oauth_callback: 'oob')
|
14
|
+
@authorize_url = @token.authorize_url
|
15
|
+
end
|
16
|
+
|
17
|
+
def authorize(pin_code)
|
18
|
+
@access_token = client.authorize(
|
19
|
+
@token.token, @token.secret, oauth_verifier: pin_code)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'myun2/twitter/authenticate'
|
2
|
+
|
3
|
+
module Myun2
|
4
|
+
class TwitterShell
|
5
|
+
class Authorize
|
6
|
+
attr_reader :pin, :access_token
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
puts "* Requesting Authorize URL ..."
|
10
|
+
auth_url = request_authorize_url
|
11
|
+
puts " Please access and please input PIN code."
|
12
|
+
puts auth_url
|
13
|
+
print "PIN> "
|
14
|
+
read_pin && authorize
|
15
|
+
end
|
16
|
+
|
17
|
+
def request_authorize_url
|
18
|
+
@auth = Myun2::Twitter::Authenticate.new(
|
19
|
+
consumer_key: TWITTER_CONSUMER_KEY,
|
20
|
+
consumer_secret: TWITTER_CONSUMER_SECRET)
|
21
|
+
@auth.request_authorize_url
|
22
|
+
end
|
23
|
+
|
24
|
+
def read_pin
|
25
|
+
@pin = gets.chomp
|
26
|
+
end
|
27
|
+
|
28
|
+
def authorize
|
29
|
+
@access_token = @auth.authorize(@pin)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'twitter_oauth'
|
2
|
+
require 'myun2/twitter_shell/consumer_key'
|
3
|
+
|
4
|
+
module Myun2
|
5
|
+
class TwitterShell
|
6
|
+
class Client < TwitterOAuth::Client
|
7
|
+
def initialize(params)
|
8
|
+
super(
|
9
|
+
consumer_key: Myun2::TwitterShell::TWITTER_CONSUMER_KEY,
|
10
|
+
consumer_secret: Myun2::TwitterShell::TWITTER_CONSUMER_SECRET,
|
11
|
+
token: params[:access_token],
|
12
|
+
secret: params[:access_token_secret],
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'myun2/twitter_shell/authorize'
|
2
|
+
|
3
|
+
module Myun2
|
4
|
+
class TwitterShell
|
5
|
+
class Login
|
6
|
+
def initialize(*params)
|
7
|
+
new_login
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def new_login
|
12
|
+
access_token = Authorize.new.access_token
|
13
|
+
profile = Profile.new(
|
14
|
+
access_token: access_token.token,
|
15
|
+
access_token_secret: access_token.secret,
|
16
|
+
)
|
17
|
+
profile.save
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'twitter'
|
2
|
+
|
3
|
+
module Myun2
|
4
|
+
class TwitterShell
|
5
|
+
class Ls
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
def initialize(client, *params)
|
9
|
+
@client = client
|
10
|
+
format(home_timeline).each do |tweet| puts tweet end
|
11
|
+
end
|
12
|
+
|
13
|
+
def home_timeline
|
14
|
+
client.home_timeline
|
15
|
+
end
|
16
|
+
|
17
|
+
def format(timeline)
|
18
|
+
timeline.map do |t|
|
19
|
+
u = t["user"]
|
20
|
+
user_name = u["name"]
|
21
|
+
text = t["text"]
|
22
|
+
"<#{user_name}>: #{text[0..30]}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Myun2
|
2
|
+
class TwitterShell
|
3
|
+
class Profile
|
4
|
+
attr_reader :data
|
5
|
+
|
6
|
+
class Loader
|
7
|
+
def self.load(path)
|
8
|
+
return unless File.exist?(path)
|
9
|
+
r = {}
|
10
|
+
open(path).each do |line|
|
11
|
+
key, value = line.chomp.split "="
|
12
|
+
r[key.to_sym] = value
|
13
|
+
end
|
14
|
+
r
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(params = {})
|
19
|
+
@data = params
|
20
|
+
end
|
21
|
+
|
22
|
+
def save
|
23
|
+
Dir.mkdir profile_root_dir unless File.exist?(profile_root_dir)
|
24
|
+
|
25
|
+
open(profile_path, "w") do |f|
|
26
|
+
@data.each do |key,value|
|
27
|
+
f.puts key.to_s + "=" + value.to_s
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.load(path = nil)
|
33
|
+
return unless data = Loader.load(path || default_profile_path)
|
34
|
+
new(data)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.profile_root_dir
|
38
|
+
File.expand_path('~/.twsh')
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.default_profile_path
|
42
|
+
File.join(profile_root_dir, 'profile')
|
43
|
+
end
|
44
|
+
|
45
|
+
def profile_path
|
46
|
+
@profile_path ||= Profile.default_profile_path
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'shell_base'
|
2
|
+
require 'myun2/twitter_shell/profile'
|
3
|
+
require 'myun2/twitter_shell/client'
|
4
|
+
require 'myun2/twitter_shell/ls'
|
5
|
+
|
6
|
+
module Myun2
|
7
|
+
class TwitterShell
|
8
|
+
class Shell < ShellBase
|
9
|
+
attr_reader :client
|
10
|
+
|
11
|
+
def initialize(*params)
|
12
|
+
if @profile = Profile.load
|
13
|
+
@client = Client.new(@profile.data)
|
14
|
+
else
|
15
|
+
puts "Please first login"
|
16
|
+
end
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def ls(*params)
|
21
|
+
Ls.new(client, *params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def prompt
|
25
|
+
"twsh:$ "
|
26
|
+
end
|
27
|
+
|
28
|
+
def login(*params)
|
29
|
+
Login.new(*params)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/twsh.rb
ADDED
data/twsh.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 'myun2/twitter_shell/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "twsh"
|
8
|
+
spec.version = Myun2::TwitterShell::VERSION
|
9
|
+
spec.authors = ["myun2"]
|
10
|
+
spec.email = ["myun2@nwhite.info"]
|
11
|
+
|
12
|
+
spec.summary = "Twitter command line shell."
|
13
|
+
spec.description = "Twitter command line shell."
|
14
|
+
spec.homepage = "https://github.com/myun2/twitter-sh"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "twitter", "~> 5.14.0"
|
23
|
+
spec.add_dependency "twitter_oauth", "~> 0.4.0"
|
24
|
+
spec.add_dependency "shell-base", "~> 0.2.1"
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twsh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- myun2
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: twitter
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.14.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.14.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: twitter_oauth
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.4.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.4.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: shell-base
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.2.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description: Twitter command line shell.
|
84
|
+
email:
|
85
|
+
- myun2@nwhite.info
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- Gemfile
|
91
|
+
- README.md
|
92
|
+
- lib/myun2/twitter/authenticate.rb
|
93
|
+
- lib/myun2/twitter_shell.rb
|
94
|
+
- lib/myun2/twitter_shell/authorize.rb
|
95
|
+
- lib/myun2/twitter_shell/client.rb
|
96
|
+
- lib/myun2/twitter_shell/consumer_key.rb
|
97
|
+
- lib/myun2/twitter_shell/login.rb
|
98
|
+
- lib/myun2/twitter_shell/ls.rb
|
99
|
+
- lib/myun2/twitter_shell/profile.rb
|
100
|
+
- lib/myun2/twitter_shell/shell.rb
|
101
|
+
- lib/myun2/twitter_shell/version.rb
|
102
|
+
- lib/twsh.rb
|
103
|
+
- twsh.gemspec
|
104
|
+
homepage: https://github.com/myun2/twitter-sh
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.4.5
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Twitter command line shell.
|
128
|
+
test_files: []
|