adn-cli 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/adn-cli.gemspec +1 -1
- data/lib/adn/auth.rb +2 -1
- data/lib/adn/cli.rb +22 -52
- data/lib/adn/cli/global_stream.rb +82 -0
- data/lib/adn/cli/version.rb +1 -1
- metadata +5 -4
data/adn-cli.gemspec
CHANGED
data/lib/adn/auth.rb
CHANGED
@@ -18,7 +18,8 @@ module ADN
|
|
18
18
|
module Auth
|
19
19
|
TOKEN_FILE = File.expand_path("~/.adn-cli-token")
|
20
20
|
CLIENT_ID = 'bQQrxrhNXGVNrnZ6dTs6LDHfSfUFSX9Q'
|
21
|
-
|
21
|
+
SCOPES = ['stream', 'write_post']
|
22
|
+
AUTH_URL = "https://alpha.app.net/oauth/authenticate?client_id=#{CLIENT_ID}&response_type=token&redirect_uri=http://localhost:9229/authorize/&scope=#{SCOPES.join(',')}"
|
22
23
|
PUBLIC = File.expand_path(File.dirname(__FILE__)) + "/../../public"
|
23
24
|
|
24
25
|
class << self
|
data/lib/adn/cli.rb
CHANGED
@@ -1,77 +1,47 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
+
require 'optparse'
|
4
|
+
|
3
5
|
require 'adn'
|
4
6
|
require 'ansi/core'
|
5
7
|
require 'ansi/table'
|
6
8
|
|
7
9
|
require_relative "cli/version"
|
10
|
+
require_relative "cli/global_stream"
|
8
11
|
require_relative "auth"
|
9
12
|
|
13
|
+
trap("INT"){ exit }
|
14
|
+
|
10
15
|
module ADN
|
11
16
|
class CLI
|
12
|
-
include ANSI::Code
|
13
|
-
|
14
17
|
def self.run
|
15
18
|
ADN::Auth.retrieve_token unless ADN::Auth.has_token?
|
16
|
-
|
19
|
+
ADN.token = ADN::Auth.token
|
20
|
+
new
|
17
21
|
end
|
18
22
|
|
19
|
-
def initialize
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
loop {
|
25
|
-
show_global_feed
|
26
|
-
sleep 4
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
def show_global_feed
|
31
|
-
get_global_feed.tap do |r|
|
32
|
-
show_posts(r)
|
33
|
-
update_since_id(r)
|
23
|
+
def initialize
|
24
|
+
if ARGV.empty? && STDIN.tty?
|
25
|
+
GlobalStream.start
|
26
|
+
else
|
27
|
+
send_post $stdin.read.strip
|
34
28
|
end
|
35
29
|
end
|
36
30
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
params = {
|
41
|
-
count: 10,
|
42
|
-
include_directed_posts: 1
|
43
|
-
}
|
44
|
-
|
45
|
-
params[:since_id] = @since_id unless @since_id.nil?
|
46
|
-
|
47
|
-
ADN::API::Post.global_stream(params)
|
48
|
-
end
|
49
|
-
|
50
|
-
def update_since_id(response)
|
51
|
-
if response['data'].any?
|
52
|
-
@since_id = response['data'].first['id']
|
31
|
+
def send_post(text)
|
32
|
+
if text.length > 256
|
33
|
+
abort ANSI.color(:red) { "Sorry, max 256 chars" }
|
53
34
|
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def show_posts(response)
|
57
|
-
response['data'].reverse.each do |p|
|
58
|
-
line
|
59
35
|
|
60
|
-
|
61
|
-
" (#{p['user']['name'].strip})".ansi(:yellow)
|
36
|
+
data = { text: text }
|
62
37
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
ANSI.unansi(user_str + id_str).length
|
67
|
-
|
68
|
-
puts "#{user_str}#{" " * spaces}#{id_str}\n\n#{p['text']}"
|
69
|
-
end
|
70
|
-
end
|
38
|
+
OptionParser.new do |opts|
|
39
|
+
opts.on("-r ID") { |id| data[:reply_to] = id }
|
40
|
+
end.parse!
|
71
41
|
|
72
|
-
|
73
|
-
|
74
|
-
|
42
|
+
ADN::Post.send_post data
|
43
|
+
rescue OptionParser::ParseError => e
|
44
|
+
abort "Error: #{e}"
|
75
45
|
end
|
76
46
|
end
|
77
47
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module ADN
|
6
|
+
class CLI
|
7
|
+
class GlobalStream
|
8
|
+
include ANSI::Code
|
9
|
+
include ANSI::Terminal
|
10
|
+
|
11
|
+
def self.start
|
12
|
+
gs = new(ADN::User.me)
|
13
|
+
loop { gs.show sleep: 4 }
|
14
|
+
rescue SocketError
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(user)
|
19
|
+
@user = user
|
20
|
+
end
|
21
|
+
|
22
|
+
def show(options)
|
23
|
+
get_global_stream.tap { |r|
|
24
|
+
show_posts(r)
|
25
|
+
update_since_id(r)
|
26
|
+
}
|
27
|
+
|
28
|
+
sleep options[:sleep]
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def get_global_stream
|
34
|
+
params = {
|
35
|
+
count: 10,
|
36
|
+
include_directed_posts: 1,
|
37
|
+
include_annotations: 1
|
38
|
+
}
|
39
|
+
|
40
|
+
params[:since_id] = @since_id unless @since_id.nil?
|
41
|
+
|
42
|
+
ADN::API::Post.global_stream(params)
|
43
|
+
end
|
44
|
+
|
45
|
+
def update_since_id(response)
|
46
|
+
if response['data'].any?
|
47
|
+
@since_id = response['data'].first['id']
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def show_posts(response)
|
52
|
+
response['data'].reverse.each { |p|
|
53
|
+
puts line + post_heading(p) + colorized_text(p)
|
54
|
+
puts p['annotations'].to_yaml.ansi(:black) if p['annotations'].any?
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def post_heading(p)
|
59
|
+
heading_line "#{p['user']['username']}".ansi(:blue) +
|
60
|
+
" (#{p['user']['name'].strip})".ansi(:yellow),
|
61
|
+
p['id'].ansi(:black)
|
62
|
+
end
|
63
|
+
|
64
|
+
def heading_line(left,right)
|
65
|
+
spaces = terminal_width - unansi(left + right).length
|
66
|
+
"#{left}#{" " * spaces}#{right}\n"
|
67
|
+
end
|
68
|
+
|
69
|
+
def colorized_text(p)
|
70
|
+
text_color = p['user']['follows_you'] ? :cyan : :white
|
71
|
+
text_color = :green if p['user']['you_follow']
|
72
|
+
text_color = :magenta if p['user']['id'] == @user.user_id
|
73
|
+
|
74
|
+
ANSI.color(text_color) { p['text'] }
|
75
|
+
end
|
76
|
+
|
77
|
+
def line(char = '_')
|
78
|
+
"#{char * terminal_width}\n".ansi(:black)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/adn/cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adn-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-09-
|
13
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: adn
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 0.3.4
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version:
|
30
|
+
version: 0.3.4
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: ansi
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- bin/adn
|
63
63
|
- lib/adn/auth.rb
|
64
64
|
- lib/adn/cli.rb
|
65
|
+
- lib/adn/cli/global_stream.rb
|
65
66
|
- lib/adn/cli/version.rb
|
66
67
|
- public/index.html
|
67
68
|
homepage: https://github.com/adn-rb/adn-cli
|