gridcli 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -40,11 +40,31 @@ To update all messages / likes / dislikes / etc, run:
40
40
  grid update
41
41
 
42
42
  == Searching
43
- You can search any type (or all types) for something. Will eventually use Chronic to allow users to specify when to search.
44
- grid search <like|dislike|message|status|all> "ruby gem"
43
+ You can search any type (or all types) for something.
44
+ grid search <like|dislike|message|status|all> "ruby gem" [<when>]
45
45
 
46
- = To Do
46
+ The <when> parameter is free form text and can be a range ("x to y"). For instance:
47
+ grid search like "chronic" today
48
+ grid search like "chronic" yesterday
49
+ grid search message "chronic" "two weeks ago to today"
50
+ grid search all "the grid" "1 month ago to last week"
51
+
52
+ == Listing Posts
53
+ You can list any type (or all types) of posts.
54
+ grid list <like|dislike|message|status|all> [<when>]
55
+
56
+ The <when> parameter is free form text and can be a range ("x to y"). For instance:
57
+ grid list like today
58
+ grid list like yesterday
59
+ grid list message "two weeks ago to today"
60
+ grid list all "1 month ago to last week"
61
+
62
+ == Blocking Users
63
+ To block another user:
47
64
  grid block <user>
48
- grid list likes [<count>]
65
+
66
+ This will "unfriend" them and they will no longer see your posts.
67
+
68
+
49
69
 
50
70
 
data/gridcli.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.version = GridCLI::VERSION
7
7
  s.authors = ["Brian Muller"]
8
8
  s.email = ["bamuller@gmail.com"]
9
- s.homepage = ""
9
+ s.homepage = "http://gridcli.com"
10
10
  s.summary = "A command line interface to The Grid: Social Networking, Web 0.2"
11
11
  s.description = "A command line interface to The Grid: Social Networking, Web 0.2"
12
12
  s.rubyforge_project = "gridcli"
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
16
  s.require_paths = ["lib"]
17
17
  s.add_dependency("activeresource", ">= 3.0.10")
18
+ s.add_dependency("chronic", ">= 0.6.4")
18
19
  s.bindir = "bin"
19
20
  s.executables << "grid"
20
21
  end
@@ -1,4 +1,5 @@
1
1
  require 'optparse'
2
+ require 'chronic'
2
3
 
3
4
  module GridCLI
4
5
  class BaseCommand
@@ -25,6 +26,19 @@ module GridCLI
25
26
  exit
26
27
  end
27
28
 
29
+ def parse_dates(datestring)
30
+ dates = [nil, nil]
31
+ return dates if datestring.nil? or datestring.strip == ""
32
+
33
+ # get start / end parts
34
+ parts = datestring.downcase.split(' to ')
35
+ parts << parts.first if parts.length == 1
36
+
37
+ dates[0] = (parts[0].nil? or parts[0].strip == "") ? nil : Chronic.parse(parts[0], :context => :past)
38
+ dates[1] = (parts.length < 2 or parts[1].strip == "") ? nil : Chronic.parse(parts[1], :context => :past)
39
+ dates.map { |d| d.nil? ? nil : Date.parse(d.to_s) }
40
+ end
41
+
28
42
  def parse_opts(args)
29
43
  begin
30
44
  @optp.parse(args)
@@ -0,0 +1,28 @@
1
+ module GridCLI
2
+ class BlockCommand < BaseCommand
3
+ def initialize
4
+ super "block", "Block a user from further communication"
5
+ end
6
+
7
+ def usage
8
+ super "<username>"
9
+ end
10
+
11
+ def run(args)
12
+ # handle options
13
+ usage if args.length == 0
14
+ username = args.shift
15
+ parse_opts args
16
+
17
+ begin
18
+ log "Trying to block '#{username}'"
19
+ Blockage.new(:username => username).save
20
+ puts "User '#{username}' blocked"
21
+ rescue ActiveResource::ResourceNotFound
22
+ puts "Sorry, can't find a user with name '#{username}'"
23
+ end
24
+ end
25
+ end
26
+
27
+ Runner.register "block", BlockCommand
28
+ end
@@ -0,0 +1,25 @@
1
+ module GridCLI
2
+ class ListCommand < BaseCommand
3
+ def initialize
4
+ super "list", "List posts of a particular kind or all posts"
5
+ end
6
+
7
+ def usage
8
+ super "<like|dislike|message|status|all> [<since time>][ to <end time>]"
9
+ end
10
+
11
+ def run(args)
12
+ usage if args.length == 0
13
+ type = args.shift
14
+ usage if not [ 'like', 'dislike', 'status', 'message', 'all' ].include? type
15
+ period = (args.length > 0 and not args.first.start_with? '-') ? args.shift : nil
16
+ dates = parse_dates period
17
+ parse_opts args
18
+
19
+ log "Showing #{type} posts in range #{dates.first || 'first'} - #{dates.last || 'last'}"
20
+ GridCLI.storage.list(type, dates[0], dates[1])
21
+ end
22
+ end
23
+
24
+ Runner.register "list", ListCommand
25
+ end
@@ -5,7 +5,7 @@ module GridCLI
5
5
  end
6
6
 
7
7
  def usage
8
- super "<like|dislike|message|status|all> <query> [<since time>]"
8
+ super "<like|dislike|message|status|all> <query> [<since time>][ to <end time>]"
9
9
  end
10
10
 
11
11
  def run(args)
@@ -13,10 +13,12 @@ module GridCLI
13
13
  type = args.shift
14
14
  usage if not [ 'like', 'dislike', 'status', 'message', 'all' ].include? type
15
15
  query = args.shift
16
- dates = (args.length > 0 and not args.first.start_with? '-') ? args.shift : nil
16
+ period = (args.length > 0 and not args.first.start_with? '-') ? args.shift : nil
17
+ dates = parse_dates period
17
18
  parse_opts args
18
-
19
- GridCLI.storage.search(type, query, dates)
19
+
20
+ log "Showing #{type} posts in range #{dates.first || 'first'} - #{dates.last || 'last'}"
21
+ GridCLI.storage.search(type, query, dates[0], dates[1])
20
22
  end
21
23
  end
22
24
 
@@ -20,12 +20,13 @@ module GridCLI
20
20
  puts "There was an error updating your messages."
21
21
  return
22
22
  end
23
-
23
+
24
+ log "Saving #{posts.length} posts."
24
25
  save posts
25
26
  end
26
27
 
27
28
  def save(posts)
28
- if posts.nil? or posts.length == 0
29
+ if posts.length == 0
29
30
  puts "Up to date."
30
31
  else
31
32
  posts.each { |p| puts "#{p.to_s}\n\n" }
@@ -0,0 +1,4 @@
1
+ module GridCLI
2
+ class Blockage < BaseResource
3
+ end
4
+ end
@@ -1,9 +1,15 @@
1
+ require 'active_resource'
2
+
1
3
  module GridCLI
2
4
  class Runner
3
5
  def self.run(args)
4
6
  cmd = args.shift
5
7
  cmd = "help" if not @@cmds.has_key? cmd
6
- @@cmds[cmd].new.run(args)
8
+ begin
9
+ @@cmds[cmd].new.run(args)
10
+ rescue ActiveResource::UnauthorizedAccess
11
+ puts "Sorry gridder, your username or auth token is invalid."
12
+ end
7
13
  end
8
14
 
9
15
  def self.register(name, klass)
@@ -8,7 +8,11 @@ module GridCLI
8
8
  raise "Not implemented"
9
9
  end
10
10
 
11
- def search(type, query, dates)
11
+ def search(type, query, state_date, end_date)
12
+ raise "Not implemented"
13
+ end
14
+
15
+ def list(type, start_date, end_date)
12
16
  raise "Not implemented"
13
17
  end
14
18
  end
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require 'date'
2
3
 
3
4
  module GridCLI
4
5
  class FileStorage < StorageBase
@@ -40,13 +41,59 @@ module GridCLI
40
41
  @handles[path]
41
42
  end
42
43
 
43
- def search(type, query, dates)
44
- types = (type == "all") ? @types : [type]
44
+ def years(type)
45
+ Dir.glob(File.join(@basedir, type, '*')).map { |f| File.basename(f) }
46
+ end
47
+
48
+ def months(type, year)
49
+ Dir.glob(File.join(@basedir, type, year, '*')).map { |f| File.basename(f) }
50
+ end
51
+
52
+ def dates(type, year, month)
53
+ Dir.glob(File.join(@basedir, type, year, month, '*')).map { |f| File.basename(f) }
54
+ end
55
+
56
+ def min_date(type)
57
+ year = years(type).sort.first
58
+ month = months(type, year).sort.first
59
+ date = dates(type, year, month).sort.first.split('.').first
60
+ Date.new year.to_i, month.to_i, date.to_i
61
+ end
62
+
63
+ def max_date(type)
64
+ year = years(type).sort.last
65
+ month = months(type, year).sort.last
66
+ date = dates(type, year, month).sort.last.split('.').first
67
+ Date.new year.to_i, month.to_i, date.to_i
68
+ end
69
+
70
+ def has_type?(type)
71
+ Dir.glob(File.join(@basedir, type, "*")).length > 0
72
+ end
73
+
74
+ def files(type, start_date, end_date)
75
+ types = (type.strip == "all") ? @types : [type]
45
76
  types.each { |t|
46
- path = File.join(@basedir, t)
77
+ next unless has_type?(t)
78
+ dates = [start_date || min_date(t), end_date || max_date(t)]
79
+ dates.min.upto(dates.max) { |d|
80
+ path = File.join(@basedir, t, d.year.to_s, d.month.to_s, d.day.to_s + ".json")
81
+ yield path if File.exists? path
82
+ }
83
+ }
84
+ end
85
+
86
+ def search(type, query, start_date, end_date)
87
+ files(type, start_date, end_date) { |path|
47
88
  system "grep -R \"#{query}\" #{path}"
48
89
  }
49
90
  end
50
91
 
92
+ def list(type, start_date, end_date)
93
+ files(type, start_date, end_date) { |path|
94
+ system "cat #{path}"
95
+ }
96
+ end
97
+
51
98
  end
52
99
  end
@@ -1,3 +1,3 @@
1
1
  module GridCLI
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/gridcli.rb CHANGED
@@ -23,6 +23,7 @@ require 'gridcli/commands/signup'
23
23
  require 'gridcli/commands/help'
24
24
  require 'gridcli/commands/profile'
25
25
  require 'gridcli/commands/befriend'
26
+ require 'gridcli/commands/block'
26
27
  require 'gridcli/commands/friends'
27
28
  require 'gridcli/commands/message'
28
29
  require 'gridcli/commands/status'
@@ -30,9 +31,11 @@ require 'gridcli/commands/like'
30
31
  require 'gridcli/commands/dislike'
31
32
  require 'gridcli/commands/update'
32
33
  require 'gridcli/commands/search'
34
+ require 'gridcli/commands/list'
33
35
 
34
36
  require 'gridcli/resources/base'
35
37
  require 'gridcli/resources/user'
36
38
  require 'gridcli/resources/friendship'
37
39
  require 'gridcli/resources/post'
40
+ require 'gridcli/resources/blockage'
38
41
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gridcli
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Muller
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-02 00:00:00 -04:00
18
+ date: 2011-10-03 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -34,6 +34,22 @@ dependencies:
34
34
  version: 3.0.10
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: chronic
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 15
46
+ segments:
47
+ - 0
48
+ - 6
49
+ - 4
50
+ version: 0.6.4
51
+ type: :runtime
52
+ version_requirements: *id002
37
53
  description: "A command line interface to The Grid: Social Networking, Web 0.2"
38
54
  email:
39
55
  - bamuller@gmail.com
@@ -55,10 +71,12 @@ files:
55
71
  - lib/gridcli.rb
56
72
  - lib/gridcli/commands/base.rb
57
73
  - lib/gridcli/commands/befriend.rb
74
+ - lib/gridcli/commands/block.rb
58
75
  - lib/gridcli/commands/dislike.rb
59
76
  - lib/gridcli/commands/friends.rb
60
77
  - lib/gridcli/commands/help.rb
61
78
  - lib/gridcli/commands/like.rb
79
+ - lib/gridcli/commands/list.rb
62
80
  - lib/gridcli/commands/message.rb
63
81
  - lib/gridcli/commands/profile.rb
64
82
  - lib/gridcli/commands/search.rb
@@ -67,6 +85,7 @@ files:
67
85
  - lib/gridcli/commands/update.rb
68
86
  - lib/gridcli/config.rb
69
87
  - lib/gridcli/resources/base.rb
88
+ - lib/gridcli/resources/blockage.rb
70
89
  - lib/gridcli/resources/friendship.rb
71
90
  - lib/gridcli/resources/post.rb
72
91
  - lib/gridcli/resources/user.rb
@@ -75,7 +94,7 @@ files:
75
94
  - lib/gridcli/storage/files.rb
76
95
  - lib/gridcli/version.rb
77
96
  has_rdoc: true
78
- homepage: ""
97
+ homepage: http://gridcli.com
79
98
  licenses: []
80
99
 
81
100
  post_install_message: