adn-cli 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+ task :default => :spec
6
+
7
+ Rake::TestTask.new(:spec) do |t|
8
+ t.test_files = FileList['spec/**/*_spec.rb']
9
+ end
@@ -8,6 +8,8 @@ Gem::Specification.new do |gem|
8
8
  gem.summary = %q{Command line client for App.net}
9
9
  gem.homepage = "https://github.com/adn-rb/adn-cli"
10
10
 
11
+ gem.required_ruby_version = '>= 1.9.2'
12
+
11
13
  gem.files = `git ls-files`.split($\)
12
14
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
15
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
@@ -15,6 +17,6 @@ Gem::Specification.new do |gem|
15
17
  gem.require_paths = ["lib"]
16
18
  gem.version = ADN::CLI::VERSION
17
19
 
18
- gem.add_runtime_dependency('adn', '~> 0.3.4')
20
+ gem.add_runtime_dependency('adn', '~> 0.3.5')
19
21
  gem.add_runtime_dependency('ansi', '~> 1.4.3')
20
22
  end
@@ -8,6 +8,7 @@ require 'ansi/table'
8
8
 
9
9
  require_relative "cli/version"
10
10
  require_relative "cli/global_stream"
11
+ require_relative "cli/unified_stream"
11
12
  require_relative "auth"
12
13
 
13
14
  trap("INT"){ exit }
@@ -21,8 +22,14 @@ module ADN
21
22
  end
22
23
 
23
24
  def initialize
24
- if ARGV.empty? && STDIN.tty?
25
- GlobalStream.start
25
+ if STDIN.tty?
26
+ if ["-u", "--unified"].include?(ARGV.first)
27
+ UnifiedStream.start
28
+ elsif ["-g", "--global"].include?(ARGV.first) || ARGV.empty?
29
+ GlobalStream.start
30
+ else
31
+ puts "Unknown parameters: #{ARGV.inspect}"
32
+ end
26
33
  else
27
34
  send_post $stdin.read.strip
28
35
  end
@@ -1,36 +1,11 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'yaml'
3
+ require_relative 'terminal_stream'
4
4
 
5
5
  module ADN
6
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
7
+ class GlobalStream < TerminalStream
8
+ def get_stream
34
9
  params = {
35
10
  count: 10,
36
11
  include_directed_posts: 1,
@@ -41,42 +16,6 @@ module ADN
41
16
 
42
17
  ADN::API::Post.global_stream(params)
43
18
  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
19
  end
81
20
  end
82
21
  end
@@ -0,0 +1,82 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'yaml'
4
+
5
+ module ADN
6
+ class CLI
7
+ class TerminalStream
8
+ include ANSI::Code
9
+ include ANSI::Terminal
10
+
11
+ def self.start
12
+ stream = new(ADN::User.me)
13
+ loop { stream.show sleep: 4 }
14
+ rescue SocketError
15
+ exit
16
+ end
17
+
18
+ def initialize(user)
19
+ @user = user
20
+ end
21
+
22
+
23
+ def show(options)
24
+ get_stream.tap do |r|
25
+ show_posts(r)
26
+ update_since_id(r)
27
+ end
28
+
29
+ sleep options[:sleep]
30
+ end
31
+
32
+ def get_stream
33
+ raise NoMethodError, "Should be implemented by child class"
34
+ end
35
+
36
+ private
37
+
38
+ def update_since_id(response)
39
+ if response['data'].any?
40
+ @since_id = response['data'].first['id']
41
+ end
42
+ end
43
+
44
+ def show_posts(response)
45
+ response['data'].reverse.each do |p|
46
+ puts line + post_heading(p) + colorized_text(p)
47
+ puts p['annotations'].to_yaml.ansi(:black) if p['annotations'].any?
48
+ end
49
+ end
50
+
51
+ def post_heading(p)
52
+ heading_line "#{p['user']['username']}".ansi(:blue) +
53
+ " (#{p['user']['name'].strip})".ansi(:yellow),
54
+ p['id'].ansi(:black)
55
+ end
56
+
57
+ def heading_line(left,right)
58
+ spaces = terminal_width - unansi(left + right).length
59
+ "#{left}#{" " * spaces}#{right}\n"
60
+ end
61
+
62
+ def colorized_text(p)
63
+ text_color = p['user']['follows_you'] ? :cyan : :white
64
+ text_color = :green if p['user']['you_follow']
65
+ text_color = :magenta if p['user']['id'] == @user.user_id
66
+
67
+ p['entities']['mentions'].tap do |mentions|
68
+ if mentions.any? &&
69
+ mentions.map { |m| m['id'] }.include?(@user.user_id)
70
+ text_color = :red
71
+ end
72
+ end
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
@@ -0,0 +1,21 @@
1
+ # encoding: UTF-8
2
+
3
+ require_relative 'terminal_stream'
4
+
5
+ module ADN
6
+ class CLI
7
+ class UnifiedStream < TerminalStream
8
+ def get_stream
9
+ params = {
10
+ count: 10,
11
+ include_directed_posts: 1,
12
+ include_annotations: 1
13
+ }
14
+
15
+ params[:since_id] = @since_id unless @since_id.nil?
16
+
17
+ ADN::API::Post.unified_stream(params)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -2,6 +2,9 @@
2
2
 
3
3
  module ADN
4
4
  class CLI
5
- VERSION = "0.0.5"
5
+ MAJOR = 0
6
+ MINOR = 0
7
+ TINY = 6
8
+ VERSION = [MAJOR, MINOR, TINY].join('.')
6
9
  end
7
10
  end
@@ -0,0 +1,16 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'minitest/spec'
4
+ require 'minitest/autorun'
5
+
6
+ begin
7
+ require 'minitest/pride'
8
+ rescue LoadError
9
+ puts "Install the minitest gem if you want colored output"
10
+ end
11
+
12
+ require "find"
13
+
14
+ %w{./lib}.each do |load_path|
15
+ Find.find(load_path) { |f| require f if f.match(/\.rb$/) }
16
+ end
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.5
4
+ version: 0.0.6
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-10 00:00:00.000000000 Z
13
+ date: 2012-10-23 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: 0.3.4
22
+ version: 0.3.5
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: 0.3.4
30
+ version: 0.3.5
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: ansi
33
33
  requirement: !ruby/object:Gem::Requirement
@@ -63,8 +63,11 @@ files:
63
63
  - lib/adn/auth.rb
64
64
  - lib/adn/cli.rb
65
65
  - lib/adn/cli/global_stream.rb
66
+ - lib/adn/cli/terminal_stream.rb
67
+ - lib/adn/cli/unified_stream.rb
66
68
  - lib/adn/cli/version.rb
67
69
  - public/index.html
70
+ - spec/spec_helper.rb
68
71
  homepage: https://github.com/adn-rb/adn-cli
69
72
  licenses: []
70
73
  post_install_message:
@@ -76,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
79
  requirements:
77
80
  - - ! '>='
78
81
  - !ruby/object:Gem::Version
79
- version: '0'
82
+ version: 1.9.2
80
83
  required_rubygems_version: !ruby/object:Gem::Requirement
81
84
  none: false
82
85
  requirements:
@@ -89,5 +92,5 @@ rubygems_version: 1.8.24
89
92
  signing_key:
90
93
  specification_version: 3
91
94
  summary: Command line client for App.net
92
- test_files: []
93
- has_rdoc:
95
+ test_files:
96
+ - spec/spec_helper.rb