sredder 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +22 -0
- data/Rakefile +1 -0
- data/bin/sredder +4 -0
- data/keys.yml +3 -0
- data/lib/sredder/arg_parser.rb +76 -0
- data/lib/sredder/sredderc.rb +33 -0
- data/lib/sredder/util.rb +19 -0
- data/lib/sredder/version.rb +3 -0
- data/lib/sredder/wrike_auth.rb +74 -0
- data/lib/sredder/wrike_request.rb +32 -0
- data/lib/sredder.rb +86 -0
- data/spec/.gitkeep +0 -0
- data/spec/sample.sredderc +2 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/sredder/arg_parser_spec.rb +82 -0
- data/spec/sredder/sredderc_spec.rb +60 -0
- data/spec/sredder/util_spec.rb +21 -0
- data/spec/sredder/wrike_auth_spec.rb +33 -0
- data/spec/sredder/wrike_request_spec.rb +31 -0
- data/spec/sredder_spec.rb +10 -0
- data/sredder.gemspec +26 -0
- metadata +111 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Matthew Robertson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Sredder
|
2
|
+
|
3
|
+
Sred the gnarl of tracking the wriketious deeds.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Installation via the command line:
|
8
|
+
|
9
|
+
$ gem install sredder, :git => 'git@github.com:CloudClinic/sredder.git'
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
TODO: Write usage instructions here
|
14
|
+
|
15
|
+
## Contributing
|
16
|
+
|
17
|
+
1. Fork it
|
18
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
19
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
20
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
21
|
+
5. Create new Pull Request
|
22
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/sredder
ADDED
data/keys.yml
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'optparse/time'
|
3
|
+
|
4
|
+
module Sredder
|
5
|
+
class ArgParser
|
6
|
+
|
7
|
+
def options
|
8
|
+
@options ||= defaults
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid?
|
12
|
+
options[:date] &&
|
13
|
+
options[:title] &&
|
14
|
+
options[:message] &&
|
15
|
+
options[:hours]
|
16
|
+
end
|
17
|
+
|
18
|
+
# Print the usage and quit
|
19
|
+
def validate!
|
20
|
+
parse(['--help']) unless valid?
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse(args)
|
24
|
+
|
25
|
+
OptionParser.new do |opts|
|
26
|
+
|
27
|
+
opts.banner = "Usage: sredder [options]"
|
28
|
+
|
29
|
+
opts.on("-t", "--title TITLE",
|
30
|
+
"The TITLE field to add to the wrike task") do |title|
|
31
|
+
options[:title] = title
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on("-m", "--message MESSAGE",
|
35
|
+
"The MESSAGE field to add to the wrike task") do |message|
|
36
|
+
options[:message] = message
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("-h", "--hours N", Float, "The number of HOURS spent on the task") do |n|
|
40
|
+
options[:hours] = n
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on("-d", "--date DATE", Time, "The DATE (YY/MM/DD) on which the task was performed (default today)") do |date|
|
44
|
+
options[:date] = Util.time_stamp(date)
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on("-f", "--folder FOLDER", "The wrike FOLDER in which to place the task (default #{defaults[:folder]})") do |folder|
|
48
|
+
options[:folder] = folder
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on_tail("--help", "Show this message") do
|
52
|
+
puts opts
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on_tail("--version", "Show version") do
|
57
|
+
puts Sredder::VERSION
|
58
|
+
exit
|
59
|
+
end
|
60
|
+
|
61
|
+
end.parse(args)
|
62
|
+
|
63
|
+
options
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def defaults
|
69
|
+
{
|
70
|
+
:folder => 'Programming',
|
71
|
+
:date => Util.time_stamp
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Sredder
|
2
|
+
|
3
|
+
class Sredderc
|
4
|
+
|
5
|
+
attr_accessor :token, :secret
|
6
|
+
attr_reader :file_path
|
7
|
+
|
8
|
+
def initialize(path = '~/.sredderc')
|
9
|
+
@file_path = File.expand_path(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def exists?
|
13
|
+
File.exists?(file_path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def load
|
17
|
+
if exists?
|
18
|
+
params = File.read(file_path).split
|
19
|
+
self.secret = params[0]
|
20
|
+
self.token = params[1]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def save
|
25
|
+
File.open(file_path, 'w') do |f|
|
26
|
+
f.puts(secret)
|
27
|
+
f.puts(token)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/sredder/util.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Sredder
|
2
|
+
|
3
|
+
module Util
|
4
|
+
|
5
|
+
# Wrike expects this "yyyy-MM-dd'T'HH:mm.ss"
|
6
|
+
def self.time_stamp(time = Time.now)
|
7
|
+
time.strftime('%Y-%m-%d %R.00')
|
8
|
+
end
|
9
|
+
|
10
|
+
# just block execution until the user hits ENTER
|
11
|
+
def self.wait_for_input
|
12
|
+
puts 'Press ENTER to continue...'
|
13
|
+
sleep 4
|
14
|
+
gets
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'oauth'
|
2
|
+
require 'forwardable'
|
3
|
+
|
4
|
+
module Sredder
|
5
|
+
|
6
|
+
WRIKE_OAUTH_OPTIONS = {
|
7
|
+
:site => 'https://www.wrike.com',
|
8
|
+
:authorize_path => '/rest/auth/authorize',
|
9
|
+
:access_token_path => '/rest/auth/access_token',
|
10
|
+
:request_token_path => '/rest/auth/request_token'
|
11
|
+
}
|
12
|
+
|
13
|
+
class WrikeAuth
|
14
|
+
|
15
|
+
extend Forwardable
|
16
|
+
|
17
|
+
attr_accessor :sredderc
|
18
|
+
attr_writer :consumer
|
19
|
+
|
20
|
+
def_delegators :sredderc, :token, :token=, :secret, :secret=
|
21
|
+
|
22
|
+
def initialize(sredderc = Sredderc.new)
|
23
|
+
@sredderc = sredderc
|
24
|
+
@sredderc.load
|
25
|
+
end
|
26
|
+
|
27
|
+
def run_oauth_procedure
|
28
|
+
@request_token = consumer.get_request_token
|
29
|
+
puts 'Sredder is about to open your browser too complete the oauth protocol.'
|
30
|
+
puts 'Please return to the terminal after you athenticate with write.'
|
31
|
+
|
32
|
+
Util.wait_for_input
|
33
|
+
|
34
|
+
`open #{@request_token.authorize_url}`
|
35
|
+
|
36
|
+
Util.wait_for_input
|
37
|
+
|
38
|
+
store_tokens(@request_token.get_access_token)
|
39
|
+
end
|
40
|
+
|
41
|
+
def authorized?
|
42
|
+
!!token && !!secret
|
43
|
+
end
|
44
|
+
|
45
|
+
def oauth_access_token
|
46
|
+
if @access_token || authorized?
|
47
|
+
@access_token ||= OAuth::AccessToken.new(consumer, secret, token)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def consumer
|
54
|
+
@consumer ||= OAuth::Consumer.new(key, oauth_secret, WRIKE_OAUTH_OPTIONS)
|
55
|
+
end
|
56
|
+
|
57
|
+
def key
|
58
|
+
'119705a437503d196da9eeab675808a4'
|
59
|
+
end
|
60
|
+
|
61
|
+
def oauth_secret
|
62
|
+
'4216face9995a5d6'
|
63
|
+
end
|
64
|
+
|
65
|
+
def store_tokens(access_token)
|
66
|
+
@access_token = access_token
|
67
|
+
self.secret = access_token.token
|
68
|
+
self.token = access_token.secret
|
69
|
+
sredderc.save
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Sredder
|
4
|
+
|
5
|
+
class WrikeRequest
|
6
|
+
|
7
|
+
HEADERS = {
|
8
|
+
'Accept' => 'application/json'
|
9
|
+
}
|
10
|
+
|
11
|
+
attr_reader :access_token
|
12
|
+
attr_accessor :response
|
13
|
+
|
14
|
+
def initialize(access_token)
|
15
|
+
@access_token = access_token
|
16
|
+
end
|
17
|
+
|
18
|
+
def post(url, params)
|
19
|
+
@response = access_token.post(url, params, HEADERS)
|
20
|
+
end
|
21
|
+
|
22
|
+
def success?
|
23
|
+
response && response.is_a?(Net::HTTPSuccess)
|
24
|
+
end
|
25
|
+
|
26
|
+
def json
|
27
|
+
JSON.parse(@response.body)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/lib/sredder.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require "sredder/arg_parser"
|
2
|
+
require "sredder/sredderc"
|
3
|
+
require "sredder/util"
|
4
|
+
require "sredder/version"
|
5
|
+
require "sredder/wrike_auth"
|
6
|
+
require "sredder/wrike_request"
|
7
|
+
|
8
|
+
module Sredder
|
9
|
+
|
10
|
+
def self.run_command(argv)
|
11
|
+
args_parser = ArgParser.new
|
12
|
+
args_parser.parse(argv)
|
13
|
+
args_parser.validate!
|
14
|
+
options = args_parser.options
|
15
|
+
|
16
|
+
access = get_access_token
|
17
|
+
folder_ids = get_folder(access, options[:folder])
|
18
|
+
task_id = create_task(access, options[:title], options[:message], folder_ids)
|
19
|
+
create_timelog(access, options[:date], task_id, options[:hours])
|
20
|
+
end
|
21
|
+
|
22
|
+
# gets an authenticated OAuth access token by loading the
|
23
|
+
# users .sredderc or prompting them to authenticate in their
|
24
|
+
# browser
|
25
|
+
def self.get_access_token
|
26
|
+
auth = WrikeAuth.new
|
27
|
+
auth.run_oauth_procedure unless auth.authorized?
|
28
|
+
auth.oauth_access_token
|
29
|
+
end
|
30
|
+
|
31
|
+
# Fetches the ID of a wrike folder by name. Currently this is
|
32
|
+
# limited to subfolders of "SRED Time Tracking/"
|
33
|
+
def self.get_folder(access, folder)
|
34
|
+
request = WrikeRequest.new(access)
|
35
|
+
request.post('/api/json/v2/wrike.folder.tree', {})
|
36
|
+
regex = Regexp.new(Regexp.escape("SRED Time Tracking/#{folder}"))
|
37
|
+
if request.success?
|
38
|
+
request.json["foldersTree"]["folders"].each_with_object([]) do |folder, arr|
|
39
|
+
arr << folder['id'].to_i if folder['fullPath'] =~ regex
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Create a Wrike task and return its ID
|
45
|
+
def self.create_task(access, title, description, parent_folder_ids)
|
46
|
+
request = WrikeRequest.new(access)
|
47
|
+
request.post('/api/json/v2/wrike.task.add', {
|
48
|
+
title: title,
|
49
|
+
description: description,
|
50
|
+
parents: parent_folder_ids
|
51
|
+
})
|
52
|
+
request.json["task"]["id"] if request.success?
|
53
|
+
end
|
54
|
+
|
55
|
+
# Attaches a timelog entry to a Wrike task
|
56
|
+
def self.create_timelog(access, date, task_id, hours, comment='')
|
57
|
+
request = WrikeRequest.new(access)
|
58
|
+
request.post('/api/json/v2/wrike.timelog.add', {
|
59
|
+
date: date,
|
60
|
+
taskId: task_id,
|
61
|
+
hours: hours,
|
62
|
+
comment: comment
|
63
|
+
})
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
# def self.run_oauth
|
68
|
+
# auth = WrikeAuth.new
|
69
|
+
# auth.run_oauth_procedure unless auth.authorized?
|
70
|
+
|
71
|
+
|
72
|
+
# parents = self.get_folder(auth.oauth_access_token)
|
73
|
+
|
74
|
+
# req = WrikeRequest.new(auth.oauth_access_token)
|
75
|
+
# puts req.post('/api/json/v2/wrike.task.add', {title: 'ermahgerd ruby', description: 'blah blah blah', parents: parents}).body
|
76
|
+
|
77
|
+
# req2 = WrikeRequest.new(auth.oauth_access_token)
|
78
|
+
# puts req2.post('/api/json/v2/wrike.timelog.add', {
|
79
|
+
# date: Util.time_stamp,
|
80
|
+
# taskId: req.json["task"]["id"],
|
81
|
+
# hours: 3.5,
|
82
|
+
# comment: 'lolz'
|
83
|
+
# })
|
84
|
+
# end
|
85
|
+
|
86
|
+
end
|
data/spec/.gitkeep
ADDED
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.before :all do
|
5
|
+
@orig_stderr = $stderr
|
6
|
+
@orig_stdout = $stdout
|
7
|
+
|
8
|
+
# redirect stderr and stdout to /dev/null
|
9
|
+
$stderr = File.new('/dev/null', 'w')
|
10
|
+
$stdout = File.new('/dev/null', 'w')
|
11
|
+
end
|
12
|
+
config.after :all do
|
13
|
+
$stderr = @orig_stderr
|
14
|
+
$stdout = @orig_stdout
|
15
|
+
@orig_stderr = nil
|
16
|
+
@orig_stdout = nil
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../lib/sredder/arg_parser'
|
3
|
+
require_relative '../../lib/sredder/version'
|
4
|
+
require_relative '../../lib/sredder/util'
|
5
|
+
|
6
|
+
describe Sredder::ArgParser do
|
7
|
+
|
8
|
+
let(:parser) { Sredder::ArgParser.new }
|
9
|
+
|
10
|
+
describe 'parse' do
|
11
|
+
|
12
|
+
it 'parses the message' do
|
13
|
+
result = parser.parse(['-m', 'some message'])
|
14
|
+
result[:message].should == 'some message'
|
15
|
+
|
16
|
+
result = parser.parse(['--message', 'some message'])
|
17
|
+
result[:message].should == 'some message'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'parses hours as a double' do
|
21
|
+
result = parser.parse(['-h', '3.5'])
|
22
|
+
result[:hours].should == 3.5
|
23
|
+
|
24
|
+
result = parser.parse(['--hours', '3.5'])
|
25
|
+
result[:hours].should == 3.5
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'parses the date as a time' do
|
29
|
+
time = Time.new(2012, 12, 19)
|
30
|
+
time_str = time.strftime('%y-%m-%d')
|
31
|
+
|
32
|
+
result = parser.parse(['-d', time_str])
|
33
|
+
result[:date].should == Sredder::Util.time_stamp(time)
|
34
|
+
|
35
|
+
result = parser.parse(['--date', time_str])
|
36
|
+
result[:date].should == Sredder::Util.time_stamp(time)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'it can print the help message' do
|
40
|
+
lambda { parser.parse(['--help']) }.should raise_error SystemExit
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'it can print the version number' do
|
44
|
+
lambda { parser.parse(['--version']) }.should raise_error SystemExit
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'sets defaults' do
|
48
|
+
result = parser.parse([])
|
49
|
+
result[:date].should_not be_nil
|
50
|
+
result[:folder].should == 'Programming'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#valid?' do
|
55
|
+
it 'returns false by default' do
|
56
|
+
parser.parse([])
|
57
|
+
parser.valid?.should be_false
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns true if all the options are set' do
|
61
|
+
parser.parse([
|
62
|
+
'-t', 'a title',
|
63
|
+
'-m', 'a message',
|
64
|
+
'-h', '3.5'
|
65
|
+
])
|
66
|
+
parser.valid?.should be_true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#validate!' do
|
71
|
+
it 'system exits if the options are not valid' do
|
72
|
+
parser.stub(:valid? => false)
|
73
|
+
lambda { parser.validate! }.should raise_error SystemExit
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'is a no-op if the options are valid' do
|
77
|
+
parser.stub(:valid? => true)
|
78
|
+
lambda { parser.validate! }.should_not raise_error
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../lib/sredder/sredderc'
|
3
|
+
|
4
|
+
describe Sredder::Sredderc do
|
5
|
+
|
6
|
+
def sample_file
|
7
|
+
File.expand_path('spec/sample.sredderc')
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'initialization' do
|
11
|
+
it 'sets the default file_path' do
|
12
|
+
Sredder::Sredderc.new.file_path.should == File.expand_path('~/.sredderc')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#exists?' do
|
17
|
+
|
18
|
+
it 'returns true if the file exists' do
|
19
|
+
Sredder::Sredderc.new(sample_file).exists?.should be_true
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns false if the file does not exist' do
|
23
|
+
Sredder::Sredderc.new('/some/path').exists?.should be_false
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#load' do
|
29
|
+
|
30
|
+
it 'does not open the file if it does not exists' do
|
31
|
+
File.should_receive(:open).never
|
32
|
+
Sredder::Sredderc.new('/some/path').load
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'loads the token and secret from the file if it exists' do
|
36
|
+
rc = Sredder::Sredderc.new(sample_file)
|
37
|
+
rc.load
|
38
|
+
rc.secret.should == 'secret'
|
39
|
+
rc.token.should == 'token'
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#save' do
|
45
|
+
|
46
|
+
it 'writes the data to the file' do
|
47
|
+
io_stub = stub('io')
|
48
|
+
io_stub.should_receive(:puts).with('secret')
|
49
|
+
io_stub.should_receive(:puts).with('token')
|
50
|
+
File.stub(:open).and_yield(io_stub)
|
51
|
+
|
52
|
+
rc = Sredder::Sredderc.new(sample_file)
|
53
|
+
rc.secret = 'secret'
|
54
|
+
rc.token = 'token'
|
55
|
+
rc.save
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../lib/sredder/util'
|
3
|
+
|
4
|
+
describe Sredder::Util do
|
5
|
+
|
6
|
+
describe '::timestamp' do
|
7
|
+
|
8
|
+
it 'returns the proper format' do
|
9
|
+
time = Time.new(2009, 3, 17, 12, 12)
|
10
|
+
Sredder::Util.time_stamp(time).should == "2009-03-17 12:12.00"
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'it uses Time.now by default' do
|
14
|
+
time = Time.new(2009, 3, 17, 12, 12)
|
15
|
+
Time.stub(:now => time)
|
16
|
+
Sredder::Util.time_stamp.should == "2009-03-17 12:12.00"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../lib/sredder/wrike_auth'
|
3
|
+
require_relative '../../lib/sredder/sredderc'
|
4
|
+
|
5
|
+
describe Sredder::WrikeAuth do
|
6
|
+
|
7
|
+
let(:auth) { Sredder::WrikeAuth.new }
|
8
|
+
|
9
|
+
it 'delegates token= to its sredderc' do
|
10
|
+
auth.token = 'banana'
|
11
|
+
auth.sredderc.token.should == 'banana'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'delegates secret= to its sredderc' do
|
15
|
+
auth.secret = 'banana'
|
16
|
+
auth.sredderc.secret.should == 'banana'
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#authorized?' do
|
20
|
+
|
21
|
+
it 'returns false by default' do
|
22
|
+
auth.authorized?.should be_false
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns true if the token and secret attrs are set' do
|
26
|
+
auth.token = 'blah'
|
27
|
+
auth.secret = 'blah'
|
28
|
+
auth.authorized?.should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../lib/sredder/wrike_request'
|
3
|
+
|
4
|
+
describe Sredder::WrikeRequest do
|
5
|
+
|
6
|
+
describe 'initialization' do
|
7
|
+
it 'accepts the oauth access token as an arg' do
|
8
|
+
access_token = stub('access_token')
|
9
|
+
request = Sredder::WrikeRequest.new(access_token)
|
10
|
+
request.access_token.should == access_token
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#post' do
|
15
|
+
it 'passes parameter and headers to the put of the access token' do
|
16
|
+
access_token = stub('access_token')
|
17
|
+
access_token.should_receive(:post).
|
18
|
+
with('/do_stuff', {}, Sredder::WrikeRequest::HEADERS)
|
19
|
+
request = Sredder::WrikeRequest.new(access_token)
|
20
|
+
request.post('/do_stuff', {})
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'it assigns the response' do
|
24
|
+
access_token = stub('access_token', :post => 'response')
|
25
|
+
request = Sredder::WrikeRequest.new(access_token)
|
26
|
+
request.post('/do_stuff', {})
|
27
|
+
request.response.should == 'response'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/sredder.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sredder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "sredder"
|
8
|
+
gem.version = Sredder::VERSION
|
9
|
+
gem.authors = ["Matthew Robertson"]
|
10
|
+
gem.email = ["matthew@cloudclinic.ca"]
|
11
|
+
gem.description = %q{Sred the gnarl of tracking the wriketious deeds.}
|
12
|
+
|
13
|
+
gem.summary = %q{Track yo time muthafucka}
|
14
|
+
gem.homepage = %q{https://github.com/CloudClinic/sredder}
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency 'oauth'
|
22
|
+
|
23
|
+
gem.add_development_dependency 'rspec'
|
24
|
+
|
25
|
+
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sredder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matthew Robertson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
none: false
|
21
|
+
name: oauth
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
requirement: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ! '>='
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
none: false
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
version_requirements: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
none: false
|
37
|
+
name: rspec
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
none: false
|
46
|
+
description: Sred the gnarl of tracking the wriketious deeds.
|
47
|
+
email:
|
48
|
+
- matthew@cloudclinic.ca
|
49
|
+
executables:
|
50
|
+
- sredder
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- bin/sredder
|
60
|
+
- keys.yml
|
61
|
+
- lib/sredder.rb
|
62
|
+
- lib/sredder/arg_parser.rb
|
63
|
+
- lib/sredder/sredderc.rb
|
64
|
+
- lib/sredder/util.rb
|
65
|
+
- lib/sredder/version.rb
|
66
|
+
- lib/sredder/wrike_auth.rb
|
67
|
+
- lib/sredder/wrike_request.rb
|
68
|
+
- spec/.gitkeep
|
69
|
+
- spec/sample.sredderc
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
- spec/sredder/arg_parser_spec.rb
|
72
|
+
- spec/sredder/sredderc_spec.rb
|
73
|
+
- spec/sredder/util_spec.rb
|
74
|
+
- spec/sredder/wrike_auth_spec.rb
|
75
|
+
- spec/sredder/wrike_request_spec.rb
|
76
|
+
- spec/sredder_spec.rb
|
77
|
+
- sredder.gemspec
|
78
|
+
homepage: https://github.com/CloudClinic/sredder
|
79
|
+
licenses: []
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
none: false
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
none: false
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.8.24
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: Track yo time muthafucka
|
102
|
+
test_files:
|
103
|
+
- spec/.gitkeep
|
104
|
+
- spec/sample.sredderc
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- spec/sredder/arg_parser_spec.rb
|
107
|
+
- spec/sredder/sredderc_spec.rb
|
108
|
+
- spec/sredder/util_spec.rb
|
109
|
+
- spec/sredder/wrike_auth_spec.rb
|
110
|
+
- spec/sredder/wrike_request_spec.rb
|
111
|
+
- spec/sredder_spec.rb
|