gridcli 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +11 -2
- data/lib/gridcli/commands/dislike.rb +1 -1
- data/lib/gridcli/commands/like.rb +1 -1
- data/lib/gridcli/commands/message.rb +1 -1
- data/lib/gridcli/commands/search.rb +24 -0
- data/lib/gridcli/commands/status.rb +1 -1
- data/lib/gridcli/commands/update.rb +42 -0
- data/lib/gridcli/resources/post.rb +15 -1
- data/lib/gridcli/storage/base.rb +15 -0
- data/lib/gridcli/storage/files.rb +52 -0
- data/lib/gridcli/version.rb +1 -1
- data/lib/gridcli.rb +11 -2
- metadata +7 -3
data/README.rdoc
CHANGED
@@ -35,7 +35,16 @@ To send a status update, like, or dislike to your friends:
|
|
35
35
|
grid like <like message>
|
36
36
|
grid dislike <dislike message>
|
37
37
|
|
38
|
+
== Updating
|
39
|
+
To update all messages / likes / dislikes / etc, run:
|
40
|
+
grid update
|
41
|
+
|
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"
|
45
|
+
|
38
46
|
= To Do
|
47
|
+
grid block <user>
|
39
48
|
grid list likes [<count>]
|
40
|
-
|
41
|
-
|
49
|
+
|
50
|
+
|
@@ -15,7 +15,7 @@ module GridCLI
|
|
15
15
|
|
16
16
|
begin
|
17
17
|
log "Trying to send a dislike '#{body}' to your friends"
|
18
|
-
post = Post.create :body => body, :recipients => "friends", :posttype => 'dislike'
|
18
|
+
post = Post::Dislike.create :body => body, :recipients => "friends", :posttype => 'dislike'
|
19
19
|
rescue ActiveResource::ClientError
|
20
20
|
puts "There was an error sending your dislike. Please make sure it's not empty."
|
21
21
|
return
|
@@ -15,7 +15,7 @@ module GridCLI
|
|
15
15
|
|
16
16
|
begin
|
17
17
|
log "Trying to send a like '#{body}' to your friends"
|
18
|
-
post = Post.create :body => body, :recipients => "friends", :posttype => 'like'
|
18
|
+
post = Post::Like.create :body => body, :recipients => "friends", :posttype => 'like'
|
19
19
|
rescue ActiveResource::ClientError
|
20
20
|
puts "There was an error sending your like. Please make sure it's not empty."
|
21
21
|
return
|
@@ -21,7 +21,7 @@ module GridCLI
|
|
21
21
|
|
22
22
|
begin
|
23
23
|
log "Trying to send a message '#{subject}' to '#{recipients}'"
|
24
|
-
post = Post.create :subject => subject, :body => body, :recipients => recipients, :posttype => 'message'
|
24
|
+
post = Post::Message.create :subject => subject, :body => body, :recipients => recipients, :posttype => 'message'
|
25
25
|
rescue ActiveResource::ClientError
|
26
26
|
puts "There was an error sending your message. Please make sure everyone in your recipient list is a friend, and the message body isn't empty."
|
27
27
|
return
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module GridCLI
|
2
|
+
class SearchCommand < BaseCommand
|
3
|
+
def initialize
|
4
|
+
super "search", "Search posts"
|
5
|
+
end
|
6
|
+
|
7
|
+
def usage
|
8
|
+
super "<like|dislike|message|status|all> <query> [<since time>]"
|
9
|
+
end
|
10
|
+
|
11
|
+
def run(args)
|
12
|
+
usage if args.length < 2
|
13
|
+
type = args.shift
|
14
|
+
usage if not [ 'like', 'dislike', 'status', 'message', 'all' ].include? type
|
15
|
+
query = args.shift
|
16
|
+
dates = (args.length > 0 and not args.first.start_with? '-') ? args.shift : nil
|
17
|
+
parse_opts args
|
18
|
+
|
19
|
+
GridCLI.storage.search(type, query, dates)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Runner.register "search", SearchCommand
|
24
|
+
end
|
@@ -15,7 +15,7 @@ module GridCLI
|
|
15
15
|
|
16
16
|
begin
|
17
17
|
log "Trying to send a status update '#{body}' to your friends"
|
18
|
-
post = Post.create :body => body, :recipients => "friends", :posttype => 'status'
|
18
|
+
post = Post::Status.create :body => body, :recipients => "friends", :posttype => 'status'
|
19
19
|
rescue ActiveResource::ClientError
|
20
20
|
puts "There was an error sending your status. Please make sure it's not empty."
|
21
21
|
return
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module GridCLI
|
2
|
+
class UpdateCommand < BaseCommand
|
3
|
+
def initialize
|
4
|
+
super "update", "Download all messages"
|
5
|
+
end
|
6
|
+
|
7
|
+
def run(args)
|
8
|
+
parse_opts args
|
9
|
+
last_sha = @config['last_sha']
|
10
|
+
|
11
|
+
begin
|
12
|
+
if last_sha.nil?
|
13
|
+
log "Trying to download all messages."
|
14
|
+
posts = Post::Message.find(:all)
|
15
|
+
else
|
16
|
+
log "Trying to download all messages since '#{last_sha}'"
|
17
|
+
posts = Post::Message.find(:all, :params => { :id => last_sha })
|
18
|
+
end
|
19
|
+
rescue ActiveResource::ClientError
|
20
|
+
puts "There was an error updating your messages."
|
21
|
+
return
|
22
|
+
end
|
23
|
+
|
24
|
+
save posts
|
25
|
+
end
|
26
|
+
|
27
|
+
def save(posts)
|
28
|
+
if posts.length == 0
|
29
|
+
puts "Up to date."
|
30
|
+
else
|
31
|
+
posts.each { |p| puts "#{p.to_s}\n\n" }
|
32
|
+
@config['last_sha'] = GridCLI.storage.append(posts)
|
33
|
+
@config.save
|
34
|
+
|
35
|
+
# run again if we got back 300 posts
|
36
|
+
run(args) if posts.length == 300
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
Runner.register "update", UpdateCommand
|
42
|
+
end
|
@@ -1,4 +1,18 @@
|
|
1
1
|
module GridCLI
|
2
|
-
|
2
|
+
module Post
|
3
|
+
class Message < BaseResource
|
4
|
+
self.element_name = "post"
|
5
|
+
end
|
6
|
+
class Like < BaseResource
|
7
|
+
self.element_name = "post"
|
8
|
+
end
|
9
|
+
class Dislike < BaseResource
|
10
|
+
self.element_name = "post"
|
11
|
+
end
|
12
|
+
class Status < BaseResource
|
13
|
+
self.element_name = "post"
|
14
|
+
end
|
3
15
|
end
|
4
16
|
end
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module GridCLI
|
4
|
+
class FileStorage < StorageBase
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
@basedir = File.expand_path(File.join("~", ".grid"))
|
8
|
+
@types = [ 'like', 'dislike', 'status', 'message' ]
|
9
|
+
@types.each { |type|
|
10
|
+
path = File.join(@basedir, type)
|
11
|
+
Dir.mkdir(path) if not File.exists?(path)
|
12
|
+
}
|
13
|
+
@handles = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
# return sha of last post
|
17
|
+
def append(posts)
|
18
|
+
obj = nil
|
19
|
+
posts.each { |post|
|
20
|
+
type = post.known_attributes.first
|
21
|
+
obj = post.send(type)
|
22
|
+
write_post obj, type
|
23
|
+
}
|
24
|
+
obj.sha
|
25
|
+
end
|
26
|
+
|
27
|
+
def write_post(post, type)
|
28
|
+
created_at = Date.parse(post.created_at)
|
29
|
+
json = post.to_json(:root => type) + "\n"
|
30
|
+
open(type, created_at).write json
|
31
|
+
end
|
32
|
+
|
33
|
+
def open(type, date)
|
34
|
+
dir = File.join(@basedir, type, date.year.to_s, date.month.to_s)
|
35
|
+
path = File.join(dir, date.day.to_s + ".json")
|
36
|
+
unless @handles.has_key? path
|
37
|
+
FileUtils.mkdir_p dir
|
38
|
+
@handles[path] = File.open(path, 'a')
|
39
|
+
end
|
40
|
+
@handles[path]
|
41
|
+
end
|
42
|
+
|
43
|
+
def search(type, query, dates)
|
44
|
+
types = (type == "all") ? @types : [type]
|
45
|
+
types.each { |t|
|
46
|
+
path = File.join(@basedir, t)
|
47
|
+
system "grep -R \"#{query}\" #{path}"
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
data/lib/gridcli/version.rb
CHANGED
data/lib/gridcli.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
require 'active_resource'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require 'gridcli/storage/base'
|
4
|
+
require 'gridcli/storage/files'
|
5
|
+
|
6
|
+
require 'gridcli/config'
|
5
7
|
|
8
|
+
module GridCLI
|
6
9
|
def self.config
|
7
10
|
@config ||= Config.new
|
8
11
|
end
|
12
|
+
|
13
|
+
def self.storage
|
14
|
+
@storage ||= FileStorage.new
|
15
|
+
end
|
9
16
|
end
|
10
17
|
|
11
18
|
require 'gridcli/version'
|
@@ -21,6 +28,8 @@ require 'gridcli/commands/message'
|
|
21
28
|
require 'gridcli/commands/status'
|
22
29
|
require 'gridcli/commands/like'
|
23
30
|
require 'gridcli/commands/dislike'
|
31
|
+
require 'gridcli/commands/update'
|
32
|
+
require 'gridcli/commands/search'
|
24
33
|
|
25
34
|
require 'gridcli/resources/base'
|
26
35
|
require 'gridcli/resources/user'
|
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:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian Muller
|
@@ -61,14 +61,18 @@ files:
|
|
61
61
|
- lib/gridcli/commands/like.rb
|
62
62
|
- lib/gridcli/commands/message.rb
|
63
63
|
- lib/gridcli/commands/profile.rb
|
64
|
+
- lib/gridcli/commands/search.rb
|
64
65
|
- lib/gridcli/commands/signup.rb
|
65
66
|
- lib/gridcli/commands/status.rb
|
67
|
+
- lib/gridcli/commands/update.rb
|
66
68
|
- lib/gridcli/config.rb
|
67
69
|
- lib/gridcli/resources/base.rb
|
68
70
|
- lib/gridcli/resources/friendship.rb
|
69
71
|
- lib/gridcli/resources/post.rb
|
70
72
|
- lib/gridcli/resources/user.rb
|
71
73
|
- lib/gridcli/runner.rb
|
74
|
+
- lib/gridcli/storage/base.rb
|
75
|
+
- lib/gridcli/storage/files.rb
|
72
76
|
- lib/gridcli/version.rb
|
73
77
|
has_rdoc: true
|
74
78
|
homepage: ""
|