gridcli 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ree-1.8.7-2011.03@gridcli
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gridcli.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,41 @@
1
+ = gridcli -- A command line interface to The Grid
2
+
3
+ The Grid is a command line social network that is always in offline mode.
4
+
5
+ To install:
6
+ gem install gridcli
7
+
8
+ == Signup
9
+ To create account (writes username/auth token to ~/.grid/config):
10
+ grid signup <username>
11
+
12
+ == Profile
13
+ To show your profile:
14
+ grid profile
15
+
16
+ To update your profile:
17
+ grid profile [--github-username <username>] [--name <name>]
18
+
19
+ To show someone else's profile:
20
+ grid profile <username>
21
+
22
+ == Friending
23
+ To add a friend:
24
+ grid befriend <username> [--message|-m <message>]
25
+
26
+ To list your friends:
27
+ grid friends
28
+
29
+ == Messaging
30
+ To send a message to a list of users:
31
+ grid message <username>[,<username>,...] [<subject>] <body>
32
+
33
+ To send a status update, like, or dislike to your friends:
34
+ grid status <status message>
35
+ grid like <like message>
36
+ grid dislike <dislike message>
37
+
38
+ = To Do
39
+ grid list likes [<count>]
40
+ grid search <type | 'all'> "ruby gem" yesterday
41
+ grid update
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/grid ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'gridcli'
4
+
5
+ GridCLI::Runner.run ARGV.clone
data/gridcli.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "gridcli/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "gridcli"
6
+ s.version = GridCLI::VERSION
7
+ s.authors = ["Brian Muller"]
8
+ s.email = ["bamuller@gmail.com"]
9
+ s.homepage = ""
10
+ s.summary = "A command line interface to The Grid: Social Networking, Web 0.2"
11
+ s.description = "A command line interface to The Grid: Social Networking, Web 0.2"
12
+ s.rubyforge_project = "gridcli"
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+ s.add_dependency("activeresource", ">= 3.0.10")
18
+ s.bindir = "bin"
19
+ s.executables << "grid"
20
+ end
@@ -0,0 +1,41 @@
1
+ require 'optparse'
2
+
3
+ module GridCLI
4
+ class BaseCommand
5
+ attr_accessor :cmd, :desc
6
+
7
+ def initialize(cmd, desc, default_opts = nil)
8
+ @config = GridCLI.config
9
+ @cmd = cmd
10
+ @desc = desc
11
+ @opts = default_opts || {}
12
+ @optp = OptionParser.new { |opts|
13
+ opts.on("-v", "--verbose", "Run verbosely") { |v| @opts[:verbose] = v }
14
+ }
15
+ end
16
+
17
+ def add_option(*args)
18
+ @optp.on(*args) { |u| yield u }
19
+ end
20
+
21
+ def usage(cmd_opts=nil)
22
+ cmd_opts ||= ""
23
+ @optp.banner = "Usage: grid #{@cmd} #{cmd_opts} [options]"
24
+ puts @optp
25
+ exit
26
+ end
27
+
28
+ def parse_opts(args)
29
+ begin
30
+ @optp.parse(args)
31
+ rescue
32
+ usage
33
+ end
34
+ end
35
+
36
+ def log(msg)
37
+ return unless @opts[:verbose]
38
+ puts "[debug]: #{msg}"
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,35 @@
1
+ module GridCLI
2
+ class BefriendCommand < BaseCommand
3
+ def initialize
4
+ super "befriend", "Request friendship with someone"
5
+ add_option("--message message", "-m message", "Add a person message to the request.") { |m|
6
+ @opts[:message] = m
7
+ }
8
+ end
9
+
10
+ def usage
11
+ super "<username>"
12
+ end
13
+
14
+ def run(args)
15
+ # handle options
16
+ usage if args.length == 0
17
+ username = args.shift
18
+ parse_opts args
19
+
20
+ begin
21
+ log "Trying to create new friendship with '#{username}'"
22
+ Friendship.new(:username => username).save
23
+ puts "Friendship request sent."
24
+ rescue ActiveResource::ForbiddenAccess
25
+ puts "Looks like '#{username}' doesn't want to be your friend."
26
+ rescue ActiveResource::ResourceConflict
27
+ puts "You are already friends with '#{username}'"
28
+ rescue ActiveResource::ResourceNotFound
29
+ puts "Sorry, can't find a user with name '#{username}'"
30
+ end
31
+ end
32
+ end
33
+
34
+ Runner.register "befriend", BefriendCommand
35
+ end
@@ -0,0 +1,29 @@
1
+ module GridCLI
2
+ class DislikeCommand < BaseCommand
3
+ def initialize
4
+ super "dislike", "Dislike something."
5
+ end
6
+
7
+ def usage
8
+ super "<dislike>"
9
+ end
10
+
11
+ def run(args)
12
+ usage if args.length == 0
13
+ body = args.shift
14
+ parse_opts args
15
+
16
+ begin
17
+ log "Trying to send a dislike '#{body}' to your friends"
18
+ post = Post.create :body => body, :recipients => "friends", :posttype => 'dislike'
19
+ rescue ActiveResource::ClientError
20
+ puts "There was an error sending your dislike. Please make sure it's not empty."
21
+ return
22
+ end
23
+
24
+ puts post
25
+ end
26
+ end
27
+
28
+ Runner.register "dislike", DislikeCommand
29
+ end
@@ -0,0 +1,32 @@
1
+ module GridCLI
2
+ class FriendsCommand < BaseCommand
3
+ def initialize
4
+ super "friends", "List your friends or the friends of a friend"
5
+ end
6
+
7
+ def usage
8
+ super "[<username>]"
9
+ end
10
+
11
+ def run(args)
12
+ # handle options
13
+ username = @config['username'] if args.length == 0
14
+ parse_opts args
15
+
16
+ begin
17
+ log "Getting all friends of '#{username}'"
18
+ friends = Friendship.find(:all, :params => { :id => username })
19
+ friends.each { |f|
20
+ puts f
21
+ }
22
+ puts "You have no friends :(" if friends.length == 0
23
+ rescue ActiveResource::ForbiddenAccess
24
+ puts "Looks like '#{username}' isn't one of your friends."
25
+ rescue ActiveResource::ResourceNotFound
26
+ puts "Sorry, can't find a user with name '#{username}'"
27
+ end
28
+ end
29
+ end
30
+
31
+ Runner.register "friends", FriendsCommand
32
+ end
@@ -0,0 +1,24 @@
1
+ module GridCLI
2
+ class HelpCommand < BaseCommand
3
+ def initialize
4
+ super "help", "Show available commands"
5
+ end
6
+
7
+ def run(args)
8
+ if args.length > 0
9
+ cmd = Runner.command(args.first)
10
+ cmd.new.usage if not cmd.nil?
11
+ end
12
+
13
+ puts "Usage: grid <cmd>\n\nAvailable commands:\n\n"
14
+ Runner.commands.each { |klass|
15
+ inst = klass.new
16
+ puts "\t#{inst.cmd}\t\t#{inst.desc}"
17
+ }
18
+ puts "\n\nTo get the options for any individual command, use:"
19
+ puts "\tgrid help <cmd>\n\n"
20
+ end
21
+ end
22
+
23
+ Runner.register "help", HelpCommand
24
+ end
@@ -0,0 +1,29 @@
1
+ module GridCLI
2
+ class LikeCommand < BaseCommand
3
+ def initialize
4
+ super "like", "Like something."
5
+ end
6
+
7
+ def usage
8
+ super "<like>"
9
+ end
10
+
11
+ def run(args)
12
+ usage if args.length == 0
13
+ body = args.shift
14
+ parse_opts args
15
+
16
+ begin
17
+ log "Trying to send a like '#{body}' to your friends"
18
+ post = Post.create :body => body, :recipients => "friends", :posttype => 'like'
19
+ rescue ActiveResource::ClientError
20
+ puts "There was an error sending your like. Please make sure it's not empty."
21
+ return
22
+ end
23
+
24
+ puts post
25
+ end
26
+ end
27
+
28
+ Runner.register "like", LikeCommand
29
+ end
@@ -0,0 +1,35 @@
1
+ module GridCLI
2
+ class MessageCommand < BaseCommand
3
+ def initialize
4
+ super "message", "Send a message to a friend or group of friends."
5
+ end
6
+
7
+ def usage
8
+ super "<username>[,<username>,...] [<subject>] <body>"
9
+ end
10
+
11
+ def run(args)
12
+ usage if args.length < 2
13
+ recipients = args.shift
14
+ if args.length > 1 and not args[1].start_with?('-')
15
+ subject = args.shift
16
+ else
17
+ subject = args.first.slice(0,30) + "..."
18
+ end
19
+ body = args.shift
20
+ parse_opts args
21
+
22
+ begin
23
+ log "Trying to send a message '#{subject}' to '#{recipients}'"
24
+ post = Post.create :subject => subject, :body => body, :recipients => recipients, :posttype => 'message'
25
+ rescue ActiveResource::ClientError
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
+ return
28
+ end
29
+
30
+ puts post
31
+ end
32
+ end
33
+
34
+ Runner.register "message", MessageCommand
35
+ end
@@ -0,0 +1,46 @@
1
+ module GridCLI
2
+ class ProfileCommand < BaseCommand
3
+ def initialize
4
+ super "profile", "Show profile information for other users or update own profile", { :update => false }
5
+ add_option("--github-user username", "Set your username on github") { |u|
6
+ @opts[:github_username] = u
7
+ @opts[:update] = true
8
+ }
9
+ add_option("--name fullname", "Set your full name") { |u|
10
+ @opts[:name] = u
11
+ @opts[:update] = true
12
+ }
13
+ end
14
+
15
+ def usage
16
+ super "[username]"
17
+ end
18
+
19
+ def run(args)
20
+ username = (args.length == 0 || args.first.start_with?('-')) ? @config['username'] : args.shift
21
+ parse_opts args
22
+
23
+ begin
24
+ log "Trying to find user with name '#{username}'"
25
+ user = User.find(username)
26
+ rescue ActiveResource::ResourceNotFound
27
+ puts "Sorry, username '#{username}' does not exist."
28
+ return
29
+ rescue ActiveResource::ClientError
30
+ puts "Sorry, you cannot see the profile for '#{username}'"
31
+ return
32
+ end
33
+
34
+ # if we're supposed to update, do so
35
+ if @opts[:update]
36
+ [:github_username, :name].each { |n| user.send("#{n.to_s}=", @opts[n]) }
37
+ user.id = username
38
+ user.save
39
+ end
40
+
41
+ puts user
42
+ end
43
+ end
44
+
45
+ Runner.register "profile", ProfileCommand
46
+ end
@@ -0,0 +1,31 @@
1
+ module GridCLI
2
+ class SignupCommand < BaseCommand
3
+ def initialize
4
+ super "signup", "Create an account on the grid"
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
+ @config["username"] = username
18
+ @config.save
19
+
20
+ begin
21
+ log "Trying to create new user with name '#{username}'"
22
+ User.new(:username => username, :token => @config['token']).save
23
+ puts "New user created. You are now known as '#{username}'"
24
+ rescue ActiveResource::ClientError
25
+ puts "Sorry, username '#{username}' already exists."
26
+ end
27
+ end
28
+ end
29
+
30
+ Runner.register "signup", SignupCommand
31
+ end
@@ -0,0 +1,29 @@
1
+ module GridCLI
2
+ class StatusCommand < BaseCommand
3
+ def initialize
4
+ super "status", "Send a status update to all friends."
5
+ end
6
+
7
+ def usage
8
+ super "<status>"
9
+ end
10
+
11
+ def run(args)
12
+ usage if args.length == 0
13
+ body = args.shift
14
+ parse_opts args
15
+
16
+ begin
17
+ log "Trying to send a status update '#{body}' to your friends"
18
+ post = Post.create :body => body, :recipients => "friends", :posttype => 'status'
19
+ rescue ActiveResource::ClientError
20
+ puts "There was an error sending your status. Please make sure it's not empty."
21
+ return
22
+ end
23
+
24
+ puts post
25
+ end
26
+ end
27
+
28
+ Runner.register "status", StatusCommand
29
+ end
@@ -0,0 +1,31 @@
1
+ require 'yaml'
2
+
3
+ module GridCLI
4
+ class Config < Hash
5
+ def initialize
6
+ # Initialize the grid config / message dir
7
+ @griddir = File.expand_path(File.join("~", ".grid"))
8
+ Dir.mkdir(@griddir) if not File.exists?(@griddir)
9
+
10
+ # This is a hash, so initialize it, set w/ default config options, then set
11
+ # with any config options in the ~/.grid/config file
12
+ @conffile = File.join(@griddir, "config")
13
+ super
14
+ update default_config
15
+ # if conf file exists, update this obj w/ it's values. Otherwise, create file
16
+ File.exists?(@conffile) ? update(YAML.load_file(@conffile)) : save
17
+ end
18
+
19
+
20
+ def default_config
21
+ {
22
+ 'site' => "http://savorthegrid.com:3000",
23
+ 'token' => rand(36**31).to_s(36)
24
+ }
25
+ end
26
+
27
+ def save
28
+ File.open(@conffile, 'w') { |f| YAML.dump(self, f) }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,12 @@
1
+ module GridCLI
2
+ class BaseResource < ActiveResource::Base
3
+ self.format = :json
4
+ self.site = GridCLI.config['site']
5
+ self.user = GridCLI.config['username']
6
+ self.password = GridCLI.config['token']
7
+
8
+ def to_s
9
+ known_attributes.map { |k| "#{k}:\t#{send(k)}" }.join("\n")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module GridCLI
2
+ class Friendship < BaseResource
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module GridCLI
2
+ class Post < BaseResource
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module GridCLI
2
+ class User < BaseResource
3
+ end
4
+ end
@@ -0,0 +1,22 @@
1
+ module GridCLI
2
+ class Runner
3
+ def self.run(args)
4
+ cmd = args.shift
5
+ cmd = "help" if not @@cmds.has_key? cmd
6
+ @@cmds[cmd].new.run(args)
7
+ end
8
+
9
+ def self.register(name, klass)
10
+ @@cmds ||= {}
11
+ @@cmds[name] = klass
12
+ end
13
+
14
+ def self.command(key)
15
+ @@cmds[key]
16
+ end
17
+
18
+ def self.commands
19
+ @@cmds.values
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module GridCLI
2
+ VERSION = "0.0.1"
3
+ end
data/lib/gridcli.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'active_resource'
2
+
3
+ module GridCLI
4
+ autoload :Config, 'gridcli/config'
5
+
6
+ def self.config
7
+ @config ||= Config.new
8
+ end
9
+ end
10
+
11
+ require 'gridcli/version'
12
+ require 'gridcli/runner'
13
+
14
+ require 'gridcli/commands/base'
15
+ require 'gridcli/commands/signup'
16
+ require 'gridcli/commands/help'
17
+ require 'gridcli/commands/profile'
18
+ require 'gridcli/commands/befriend'
19
+ require 'gridcli/commands/friends'
20
+ require 'gridcli/commands/message'
21
+ require 'gridcli/commands/status'
22
+ require 'gridcli/commands/like'
23
+ require 'gridcli/commands/dislike'
24
+
25
+ require 'gridcli/resources/base'
26
+ require 'gridcli/resources/user'
27
+ require 'gridcli/resources/friendship'
28
+ require 'gridcli/resources/post'
29
+
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gridcli
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Brian Muller
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-02 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activeresource
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 19
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 10
34
+ version: 3.0.10
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: "A command line interface to The Grid: Social Networking, Web 0.2"
38
+ email:
39
+ - bamuller@gmail.com
40
+ executables:
41
+ - grid
42
+ - grid
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - .gitignore
49
+ - .rvmrc
50
+ - Gemfile
51
+ - README.rdoc
52
+ - Rakefile
53
+ - bin/grid
54
+ - gridcli.gemspec
55
+ - lib/gridcli.rb
56
+ - lib/gridcli/commands/base.rb
57
+ - lib/gridcli/commands/befriend.rb
58
+ - lib/gridcli/commands/dislike.rb
59
+ - lib/gridcli/commands/friends.rb
60
+ - lib/gridcli/commands/help.rb
61
+ - lib/gridcli/commands/like.rb
62
+ - lib/gridcli/commands/message.rb
63
+ - lib/gridcli/commands/profile.rb
64
+ - lib/gridcli/commands/signup.rb
65
+ - lib/gridcli/commands/status.rb
66
+ - lib/gridcli/config.rb
67
+ - lib/gridcli/resources/base.rb
68
+ - lib/gridcli/resources/friendship.rb
69
+ - lib/gridcli/resources/post.rb
70
+ - lib/gridcli/resources/user.rb
71
+ - lib/gridcli/runner.rb
72
+ - lib/gridcli/version.rb
73
+ has_rdoc: true
74
+ homepage: ""
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options: []
79
+
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ requirements: []
101
+
102
+ rubyforge_project: gridcli
103
+ rubygems_version: 1.3.7
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: "A command line interface to The Grid: Social Networking, Web 0.2"
107
+ test_files: []
108
+