coop_cli 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +42 -0
- data/bin/coop_cli +106 -0
- data/coop_cli.rdoc +5 -0
- data/lib/coop_cli.rb +33 -0
- metadata +143 -0
data/README.rdoc
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
= coop_cli
|
2
|
+
|
3
|
+
Author:: Warwick Poole (wpoole@gmail.com)
|
4
|
+
https://github.com/warwickp/coop_cli
|
5
|
+
|
6
|
+
A simple cli tool for interacting with Co-op (https://coopapp.com) the group collaboration tool from Harvest (http://www.getharvest.com).
|
7
|
+
|
8
|
+
== License
|
9
|
+
|
10
|
+
MIT bitches.
|
11
|
+
|
12
|
+
== Install
|
13
|
+
|
14
|
+
gem install coop_cli
|
15
|
+
|
16
|
+
|
17
|
+
== Usage
|
18
|
+
|
19
|
+
First, set up your configuration file at ~/.coop_cli (set to chmod 600 on creation) to contain your username, password, group ID and optional (http://coopapp.com/api/statuses) Cobot Key
|
20
|
+
|
21
|
+
coop_cli -u me@me.com -p happypants -g 1234 -k 1234567899003030 initconfig
|
22
|
+
|
23
|
+
Alternatively you can specify/override these at runtime like a pirate.
|
24
|
+
|
25
|
+
Now to post to Co-op as your user:
|
26
|
+
|
27
|
+
coop_cli post "My horse is thirsty @bob"
|
28
|
+
|
29
|
+
Or, pirately:
|
30
|
+
|
31
|
+
coop_cli -u me@me.com -p happypants -g 12345 post "Hey @tim, may I have this dance?"
|
32
|
+
|
33
|
+
Now to post to Co-op as Cobot
|
34
|
+
|
35
|
+
coop_cli post -c "Building on fire. Everyone panic. Thanks."
|
36
|
+
|
37
|
+
Or, pirately:
|
38
|
+
|
39
|
+
coop_cli -k 12344598989723387 post -c "Sharks have escaped. Self destruction in 5 minutes."
|
40
|
+
|
41
|
+
:include:coop_cli.rdoc
|
42
|
+
|
data/bin/coop_cli
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# 1.9 adds realpath to resolve symlinks; 1.8 doesn't
|
3
|
+
# have this method, so we add it so we get resolved symlinks
|
4
|
+
# and compatibility
|
5
|
+
unless File.respond_to? :realpath
|
6
|
+
class File #:nodoc:
|
7
|
+
def self.realpath path
|
8
|
+
return realpath(File.readlink(path)) if symlink?(path)
|
9
|
+
path
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib')
|
14
|
+
require 'rubygems'
|
15
|
+
require 'gli'
|
16
|
+
require 'coop_cli'
|
17
|
+
|
18
|
+
include GLI
|
19
|
+
|
20
|
+
program_desc 'A cli interface to Co-op, the team collaboration tool from Harvest (https://coopapp.com)'
|
21
|
+
|
22
|
+
version CoopCli::VERSION
|
23
|
+
|
24
|
+
config_file '.coop_cli'
|
25
|
+
|
26
|
+
### global options will override config file values if both are specified
|
27
|
+
desc 'Use specified URL for Co-op, allows local testing'
|
28
|
+
default_value 'https://coopapp.com'
|
29
|
+
flag [:b,:baseurl]
|
30
|
+
|
31
|
+
desc 'The numerical ID of your Co-op group (eg: 1234)'
|
32
|
+
flag [:g,:group]
|
33
|
+
|
34
|
+
desc 'Your Co-op username (eg: me@example.com)'
|
35
|
+
flag [:u,:username]
|
36
|
+
|
37
|
+
desc 'Your Co-op password (eg: horseradishburns)'
|
38
|
+
flag [:p,:password]
|
39
|
+
|
40
|
+
desc 'Key to use when posting as Cobot (eg: 12345678910111213)'
|
41
|
+
flag [:k,:key]
|
42
|
+
|
43
|
+
### method options
|
44
|
+
desc "Post a status or a note to a Co-op group (eg: coop_cli post 'eating a cookie, delicious' or: coop_cli post -c '@all meeting at 10am')"
|
45
|
+
arg_name "'status to post to coop'"
|
46
|
+
command :post do |c|
|
47
|
+
c.desc 'Post a note as Cobot instead of your own Co-op user (requires a key)'
|
48
|
+
c.switch [:c,:cobot]
|
49
|
+
|
50
|
+
c.action do |global_options,options,args|
|
51
|
+
|
52
|
+
#====validations
|
53
|
+
raise("You need to specify a status to post. (eg: coop_cli post 'whats for dinner?')") if args.empty?
|
54
|
+
raise("You need to specify a SINGLE status to post. (eg: coop_cli post 'whats for dinner?')") if args.size > 1
|
55
|
+
raise("There is no group for me to use, try using initconfig to set up a config file first") unless global_options[:g]
|
56
|
+
if options[:c]
|
57
|
+
raise("There is no key for me to use") unless global_options[:k]
|
58
|
+
end
|
59
|
+
unless options[:c]
|
60
|
+
raise("There is no username for me to use") unless global_options[:u]
|
61
|
+
raise("There is no password for me to use") unless global_options[:p]
|
62
|
+
end
|
63
|
+
#==END==validations
|
64
|
+
|
65
|
+
#====posting to co-op
|
66
|
+
post_to_coop = CoopCli::Coop.new(global_options[:b])
|
67
|
+
if options[:c] #using a key, no basic auth
|
68
|
+
post_to_coop.post_as_cobot("/groups/#{global_options[:g]}/statuses",args[0],global_options[:k])
|
69
|
+
else
|
70
|
+
post_to_coop.basic_auth(global_options[:u],global_options[:p])
|
71
|
+
post_to_coop.post_as_user("/groups/#{global_options[:g]}/statuses",args[0])
|
72
|
+
end
|
73
|
+
#==END==posting to co-op
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
desc 'List statuses and notes from a Co-op group'
|
78
|
+
arg_name 'Describe arguments to list here'
|
79
|
+
command :list do |c|
|
80
|
+
c.action do |global_options,options,args|
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
pre do |global,command,options,args|
|
86
|
+
# Pre logic here
|
87
|
+
# Return true to proceed; false to abort and not call the
|
88
|
+
# chosen command
|
89
|
+
# Use skips_pre before a command to skip this block
|
90
|
+
# on that command only
|
91
|
+
true
|
92
|
+
end
|
93
|
+
|
94
|
+
post do |global,command,options,args|
|
95
|
+
# Post logic here
|
96
|
+
# Use skips_post before a command to skip this
|
97
|
+
# block on that command only
|
98
|
+
end
|
99
|
+
|
100
|
+
on_error do |exception|
|
101
|
+
# Error logic here
|
102
|
+
# return false to skip default error handling
|
103
|
+
true
|
104
|
+
end
|
105
|
+
|
106
|
+
exit GLI.run(ARGV)
|
data/coop_cli.rdoc
ADDED
data/lib/coop_cli.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module CoopCli
|
2
|
+
require 'httparty'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
VERSION = '0.0.1'
|
6
|
+
|
7
|
+
class Coop
|
8
|
+
include HTTParty
|
9
|
+
|
10
|
+
def initialize(base_uri)
|
11
|
+
self.class.base_uri base_uri
|
12
|
+
end
|
13
|
+
|
14
|
+
def basic_auth(user,pass)
|
15
|
+
self.class.basic_auth user, pass
|
16
|
+
end
|
17
|
+
|
18
|
+
def user_agent
|
19
|
+
"coop_cli (v: #{CoopCli::VERSION})"
|
20
|
+
end
|
21
|
+
|
22
|
+
def post_as_user(path,message)
|
23
|
+
self.class.post(path, :query => { :status => message }, :headers => { "User-Agent" => self.user_agent })
|
24
|
+
end
|
25
|
+
|
26
|
+
def post_as_cobot(path,message,cobotkey)
|
27
|
+
self.class.post(path, :query => { :status => message, :key => cobotkey }, :headers => { "User-Agent" => self.user_agent, "Accept" => "application/json",
|
28
|
+
"Content-Type" => "application/json; charset=utf-8" })
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coop_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Warwick Poole
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-02-18 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: httparty
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: gli
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: json
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
type: :development
|
75
|
+
version_requirements: *id004
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: rdoc
|
78
|
+
prerelease: false
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
type: :development
|
89
|
+
version_requirements: *id005
|
90
|
+
description: A small cli interface to Co-op, the team collaboration tool from Harvest
|
91
|
+
email: wpoole@gmail.com
|
92
|
+
executables:
|
93
|
+
- coop_cli
|
94
|
+
extensions: []
|
95
|
+
|
96
|
+
extra_rdoc_files:
|
97
|
+
- README.rdoc
|
98
|
+
- coop_cli.rdoc
|
99
|
+
files:
|
100
|
+
- bin/coop_cli
|
101
|
+
- lib/coop_cli.rb
|
102
|
+
- README.rdoc
|
103
|
+
- coop_cli.rdoc
|
104
|
+
homepage: https://github.com/warwickp/coop_cli
|
105
|
+
licenses: []
|
106
|
+
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options:
|
109
|
+
- --title
|
110
|
+
- coop_cli
|
111
|
+
- --main
|
112
|
+
- README.rdoc
|
113
|
+
- -ri
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: 3
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
version: "0"
|
135
|
+
requirements: []
|
136
|
+
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 1.8.15
|
139
|
+
signing_key:
|
140
|
+
specification_version: 3
|
141
|
+
summary: cli co-op interface
|
142
|
+
test_files: []
|
143
|
+
|