morale 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,9 +1,8 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gem 'rake', '0.8.7'
4
- gem 'httparty', '0.7.8'
4
+ gem 'morale-client'
5
5
  gem 'json', '1.4.6'
6
- gem 'crack', '0.1.8'
7
6
  gem 'thor', '0.14.6'
8
7
  gem 'hirb'
9
8
 
data/Gemfile.lock CHANGED
@@ -24,6 +24,9 @@ GEM
24
24
  httparty (0.7.8)
25
25
  crack (= 0.1.8)
26
26
  json (1.4.6)
27
+ morale-client (0.0.1)
28
+ httparty (~> 0.7.8)
29
+ json (~> 1.4.6)
27
30
  rake (0.8.7)
28
31
  rspec (2.6.0)
29
32
  rspec-core (~> 2.6.0)
@@ -44,12 +47,11 @@ PLATFORMS
44
47
 
45
48
  DEPENDENCIES
46
49
  aruba (= 0.3.6)
47
- crack (= 0.1.8)
48
50
  cucumber (= 1.0.6)
49
51
  diff-lcs (= 1.1.3)
50
52
  hirb
51
- httparty (= 0.7.8)
52
53
  json (= 1.4.6)
54
+ morale-client
53
55
  rake (= 0.8.7)
54
56
  rspec (= 2.6.0)
55
57
  thor (= 0.14.6)
@@ -3,7 +3,7 @@ require 'morale/credentials_store'
3
3
 
4
4
  module Morale
5
5
  class Account
6
- include Morale::Platform
6
+ include Morale::IO
7
7
 
8
8
  class << self
9
9
  include Morale::CredentialsStore
@@ -82,7 +82,7 @@ module Morale
82
82
  password = running_on_windows? ? ask_for_secret_on_windows : ask_for_secret
83
83
  api_key = Morale::Client.authorize(user, password, @subdomain).api_key
84
84
 
85
- say "Invalid email/password combination or API key was not generated." if api_key.nil?
85
+ say "Invalid email/password combination or API key was not generated." if api_key.empty?
86
86
 
87
87
  [@subdomain, api_key]
88
88
  end
@@ -7,7 +7,6 @@ require 'morale/commands/ticket'
7
7
 
8
8
  module Morale
9
9
  class Command < Thor
10
- include Morale::Platform
11
10
 
12
11
  desc "login", "Signs a user in using their email address and password. Stores the users API key locally to use for access later."
13
12
  def login
@@ -6,7 +6,7 @@ require 'morale/authorization'
6
6
  module Morale::Commands
7
7
  class Account
8
8
  class << self
9
- include Morale::Platform
9
+ include Morale::IO
10
10
 
11
11
  def list(email="", change=false)
12
12
  accounts = Morale::Client.accounts(email) unless email.nil? || email.empty?
@@ -5,7 +5,7 @@ require 'morale/authorization'
5
5
  module Morale::Commands
6
6
  class Project
7
7
  class << self
8
- include Morale::Platform
8
+ include Morale::IO
9
9
 
10
10
  def list(change=false)
11
11
  begin
@@ -7,7 +7,7 @@ require 'hirb'
7
7
  module Morale::Commands
8
8
  class Ticket
9
9
  class << self
10
- include Morale::Platform
10
+ include Morale::IO
11
11
  include Morale::Flow
12
12
 
13
13
  def command(command)
@@ -1,10 +1,12 @@
1
1
  require 'morale/storage'
2
2
  require 'morale/platform'
3
+ require 'morale/io'
3
4
 
4
5
  module Morale
5
6
  module CredentialsStore
6
7
  include Morale::Storage
7
8
  include Morale::Platform
9
+ include Morale::IO
8
10
 
9
11
  attr_accessor :credentials
10
12
 
@@ -1,13 +1,5 @@
1
1
  module Morale
2
- module Platform
3
- def home_directory
4
- running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
5
- end
6
-
7
- def running_on_windows?
8
- RUBY_PLATFORM =~ /mswin32|mingw32/
9
- end
10
-
2
+ module IO
11
3
  def say(message="", color=nil, force_new_line=(message.to_s !~ /( |\t)$/))
12
4
  message = message.to_s
13
5
  message = set_color(message, color) if color
data/lib/morale.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Morale
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
4
4
 
5
5
  require 'morale/command'
data/morale.gemspec CHANGED
@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
5
5
  s.rubygems_version = '1.3.5'
6
6
 
7
7
  s.name = 'morale'
8
- s.version = '1.0.0'
9
- s.date = '2011-10-26'
8
+ s.version = '1.1.0'
9
+ s.date = '2011-12-12'
10
10
  s.rubyforge_project = 'morale'
11
11
 
12
12
  s.summary = "Command line interface to create & manage tickets on Morale."
@@ -20,10 +20,10 @@ Gem::Specification.new do |s|
20
20
  s.executables = ["morale"]
21
21
 
22
22
  s.rdoc_options = ["--charset=UTF-8"]
23
- s.extra_rdoc_files = %w[README.md LICENSE]
23
+ s.extra_rdoc_files = %w[README.md]
24
24
 
25
+ s.add_dependency('morale-client', "~> 0.0.1")
25
26
  s.add_dependency('hirb', "~> 0.5.0")
26
- s.add_dependency('httparty', "~> 0.7.8")
27
27
  s.add_dependency('json', "~> 1.4.6")
28
28
  s.add_dependency('thor', "~> 0.14.6")
29
29
 
@@ -36,7 +36,6 @@ Gem::Specification.new do |s|
36
36
  s.files = %w[
37
37
  Gemfile
38
38
  Gemfile.lock
39
- LICENSE
40
39
  README.md
41
40
  Rakefile
42
41
  bin/morale
@@ -50,22 +49,17 @@ Gem::Specification.new do |s|
50
49
  lib/morale.rb
51
50
  lib/morale/account.rb
52
51
  lib/morale/authorization.rb
53
- lib/morale/client.rb
54
52
  lib/morale/command.rb
55
53
  lib/morale/commands/account.rb
56
54
  lib/morale/commands/authorization.rb
57
55
  lib/morale/commands/project.rb
58
56
  lib/morale/commands/ticket.rb
59
- lib/morale/connection_store.rb
60
57
  lib/morale/credentials_store.rb
61
58
  lib/morale/flow.rb
62
- lib/morale/platform.rb
63
- lib/morale/storage.rb
59
+ lib/morale/io.rb
64
60
  morale.gemspec
65
61
  spec/morale/account_spec.rb
66
- spec/morale/client_spec.rb
67
62
  spec/morale/command_spec.rb
68
- spec/morale/connection_store_spec.rb
69
63
  spec/morale/credentials_store_spec.rb
70
64
  spec/morale/storage_spec.rb
71
65
  spec/spec_helper.rb
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
+ - 1
7
8
  - 0
8
- - 0
9
- version: 1.0.0
9
+ version: 1.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brilliant Fantastic
@@ -14,11 +14,11 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-10-26 00:00:00 -04:00
17
+ date: 2011-12-12 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: hirb
21
+ name: morale-client
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  requirements:
@@ -26,13 +26,13 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
28
  - 0
29
- - 5
30
29
  - 0
31
- version: 0.5.0
30
+ - 1
31
+ version: 0.0.1
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- name: httparty
35
+ name: hirb
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  requirements:
@@ -40,9 +40,9 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  segments:
42
42
  - 0
43
- - 7
44
- - 8
45
- version: 0.7.8
43
+ - 5
44
+ - 0
45
+ version: 0.5.0
46
46
  type: :runtime
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
@@ -81,11 +81,9 @@ extensions: []
81
81
 
82
82
  extra_rdoc_files:
83
83
  - README.md
84
- - LICENSE
85
84
  files:
86
85
  - Gemfile
87
86
  - Gemfile.lock
88
- - LICENSE
89
87
  - README.md
90
88
  - Rakefile
91
89
  - bin/morale
@@ -99,22 +97,17 @@ files:
99
97
  - lib/morale.rb
100
98
  - lib/morale/account.rb
101
99
  - lib/morale/authorization.rb
102
- - lib/morale/client.rb
103
100
  - lib/morale/command.rb
104
101
  - lib/morale/commands/account.rb
105
102
  - lib/morale/commands/authorization.rb
106
103
  - lib/morale/commands/project.rb
107
104
  - lib/morale/commands/ticket.rb
108
- - lib/morale/connection_store.rb
109
105
  - lib/morale/credentials_store.rb
110
106
  - lib/morale/flow.rb
111
- - lib/morale/platform.rb
112
- - lib/morale/storage.rb
107
+ - lib/morale/io.rb
113
108
  - morale.gemspec
114
109
  - spec/morale/account_spec.rb
115
- - spec/morale/client_spec.rb
116
110
  - spec/morale/command_spec.rb
117
- - spec/morale/connection_store_spec.rb
118
111
  - spec/morale/credentials_store_spec.rb
119
112
  - spec/morale/storage_spec.rb
120
113
  - spec/spec_helper.rb
data/LICENSE DELETED
File without changes
data/lib/morale/client.rb DELETED
@@ -1,84 +0,0 @@
1
- require 'httparty'
2
- require 'json'
3
- require 'morale/account'
4
- require 'morale/connection_store'
5
-
6
- module Morale
7
- class Client
8
- class Unauthorized < RuntimeError; end
9
- class NotFound < RuntimeError; end
10
-
11
- include HTTParty
12
- extend Morale::ConnectionStore
13
-
14
- format :json
15
-
16
- API_VERSION = 'v1'
17
-
18
- attr_accessor :api_key
19
- attr_reader :subdomain
20
-
21
- def self.authorize(user, password, subdomain)
22
- client = new(subdomain)
23
- client.unauthorize
24
- client.api_key = client.class.post('/in', :body => { :email => user, :password => password })["api_key"]
25
- return client
26
- end
27
-
28
- def self.accounts(user)
29
- client = new
30
- client.unauthorize
31
- response = client.class.get("/accounts", :query => { :email => user })
32
- raise Unauthorized if response.code == 401
33
- raise NotFound if response.code == 404
34
- response
35
- end
36
-
37
- def accounts
38
- authorize
39
- response = self.class.get("/accounts", :query => { :api_key => @api_key })
40
- raise Unauthorized if response.code == 401
41
- raise NotFound if response.code == 404
42
- response
43
- end
44
-
45
- def initialize(subdomain="", api_key="")
46
- @api_key = api_key
47
- @subdomain = subdomain
48
- self.class.default_options[:base_uri] = HTTParty.normalize_base_uri("#{subdomain}#{"." unless subdomain.nil? || subdomain.empty?}#{self.class.base_url}/api/#{API_VERSION}")
49
- end
50
-
51
- def projects
52
- authorize
53
- response = self.class.get('/projects')
54
- raise Unauthorized if response.code == 401
55
- raise NotFound if response.code == 404
56
- response
57
- end
58
-
59
- def tickets(options={})
60
- authorize
61
- response = self.class.get("/projects/#{options[:project_id]}/tickets")
62
- raise Unauthorized if response.code == 401
63
- raise NotFound if response.code == 404
64
- response
65
- end
66
-
67
- def ticket(project_id, command)
68
- authorize
69
- response = self.class.post("/projects/#{project_id}/tickets", :body => { :command => command })
70
- raise Unauthorized if response.code == 401
71
- raise NotFound if response.code == 404
72
- response
73
- end
74
-
75
- def authorize
76
- self.class.basic_auth @subdomain, @api_key
77
- end
78
-
79
- def unauthorize
80
- self.class.basic_auth nil, nil
81
- end
82
-
83
- end
84
- end
@@ -1,58 +0,0 @@
1
- require 'morale/storage'
2
- require 'morale/platform'
3
-
4
- module Morale
5
- module ConnectionStore
6
- include Morale::Storage
7
- include Morale::Platform
8
-
9
- def base_url
10
- if @base_url.nil?
11
- @base_url = read_connection
12
- if @base_url.nil?
13
- @base_url = default_base_url
14
- self.write_connection
15
- end
16
- end
17
- @base_url
18
- end
19
-
20
- def base_url=(value)
21
- @base_url = value
22
- self.write_connection
23
- end
24
-
25
- def location
26
- ENV['CONNECTION_LOCATION'] || default_location
27
- end
28
-
29
- def location=(value)
30
- ENV['CONNECTION_LOCATION'] = value
31
- end
32
-
33
- def default_location
34
- "#{home_directory}/.morale/connection"
35
- end
36
-
37
- def delete_connection
38
- self.delete
39
- @base_url = nil
40
- end
41
-
42
- def read_connection
43
- connection = self.read
44
- connection.split("\n") if connection
45
- end
46
-
47
- def write_connection
48
- self.write self.base_url
49
- end
50
-
51
- private
52
-
53
- def default_base_url
54
- ENV['DEFAULT_BASE_URL'] || "teammorale.com"
55
- end
56
-
57
- end
58
- end
@@ -1,29 +0,0 @@
1
- module Morale
2
- module Storage
3
-
4
- attr_accessor :location
5
-
6
- def delete
7
- FileUtils.rm_f(location)
8
- end
9
-
10
- def read
11
- File.exists?(location) and File.read(location)
12
- end
13
-
14
- def write(data)
15
- FileUtils.mkdir_p(File.dirname(location))
16
- f = File.open(location, 'w')
17
- f.puts data
18
- f.close
19
- set_permissions
20
- end
21
-
22
- private
23
-
24
- def set_permissions
25
- FileUtils.chmod 0700, File.dirname(location)
26
- FileUtils.chmod 0600, location
27
- end
28
- end
29
- end
@@ -1,119 +0,0 @@
1
- require "spec_helper"
2
- require "json"
3
- require "morale/client"
4
-
5
- describe Morale::Client do
6
- describe "#authorize" do
7
- it "authorizes a user with a valid email address and password" do
8
- api_key = "blah"
9
- stub_request(:post, "http://blah.lvh.me:3000/api/v1/in").to_return(:body => { "api_key" => "#{api_key}" }.to_json)
10
- Morale::Client.authorize(nil, nil, 'blah').api_key.should == api_key
11
- end
12
- end
13
-
14
- describe "#accounts" do
15
- it "displays all the accounts for a specific user based on their email" do
16
- stub_request(:get, "http://lvh.me:3000/api/v1/accounts?email=someone@example.com").to_return(:body =>
17
- [{"account" => {"group_name" => "Shimmy Sham","site_address"=>"shimmy_sham","created_at" => "2011-07-31T21:28:53Z","updated_at" => "2011-07-31T21:28:53Z","plan_id" => 1,"id" => 2}},
18
- {"account" => {"group_name" => "Pumpkin Tarts","site_address"=>"pumpkin_tarts","created_at" => "2011-07-31T21:40:24Z","updated_at" => "2011-07-31T21:40:24Z","plan_id" => 1,"id" => 1}}].to_json)
19
-
20
- accounts = Morale::Client.accounts('someone@example.com')
21
- accounts.count.should == 2
22
- end
23
-
24
- it "displays all the accounts for a specific user based on their api_key" do
25
- stub_request(:get, "http://blah:@blah.lvh.me:3000/api/v1/accounts?api_key=").to_return(:body =>
26
- [{"account" => {"group_name" => "Shimmy Sham","site_address"=>"shimmy_sham","created_at" => "2011-07-31T21:28:53Z","updated_at" => "2011-07-31T21:28:53Z","plan_id" => 1,"id" => 2}},
27
- {"account" => {"group_name" => "Pumpkin Tarts","site_address"=>"pumpkin_tarts","created_at" => "2011-07-31T21:40:24Z","updated_at" => "2011-07-31T21:40:24Z","plan_id" => 1,"id" => 1}}].to_json)
28
-
29
- client = Morale::Client.new('blah')
30
- client.accounts.count.should == 2
31
- client.accounts[0]["account"]["group_name"].should == "Shimmy Sham"
32
- end
33
- end
34
-
35
- describe "#projects" do
36
- it "displays all the projects for a specific account" do
37
- stub_request(:get, "http://blah:@blah.lvh.me:3000/api/v1/projects").to_return(:body =>
38
- [{"project" => {"name" => "Skunk Works","created_at" => "2011-07-31T21:40:24Z","updated_at" => "2011-07-31T21:40:24Z","account_id" => 1,"id" => 1}},
39
- {"project" => {"name" => "Poop Shoot","created_at" => "2011-07-31T21:28:53Z","updated_at" => "2011-07-31T21:28:53Z","account_id" => 1,"id" => 2}}].to_json)
40
- client = Morale::Client.new('blah')
41
- client.projects.count.should == 2
42
- client.projects[0]["project"]["name"].should == "Skunk Works"
43
- client.projects[1]["project"]["id"].should == 2
44
- end
45
-
46
- it "should raise unauthorized if a 401 is received" do
47
- stub_request(:get, "http://blah:@blah.lvh.me:3000/api/v1/projects").to_return(:status => 401)
48
- client = Morale::Client.new('blah')
49
- lambda { client.projects.count }.should raise_error(Morale::Client::Unauthorized)
50
- end
51
- end
52
-
53
- describe "#ticket" do
54
- it "should return a JSON ticket that was created" do
55
- stub_request(:post, "http://blah:123456@blah.lvh.me:3000/api/v1/projects/1/tickets").
56
- with(:body => "command=This%20is%20a%20test%20that%20should%20create%20a%20new%20task%20as%3A%20Lester").
57
- to_return(:body => {
58
- "created_at" => "2011-09-27T02:56:03Z",
59
- "assigned_to" => { "user" => { "first_name" => "Lester", "last_name" => "Tester", "email" => "test@test.com" } },
60
- "title" => "This is a test that should create a new task",
61
- "project_id" => "1",
62
- "priority" => "null",
63
- "archived" => "false",
64
- "id" => "1",
65
- "created_by" => { "user" => { "first_name" => "Lester", "last_name" => "Tester", "email" => "test@test.com" } },
66
- "due_date" => "null",
67
- "identifier" => "1" }.to_json
68
- )
69
- client = Morale::Client.new('blah', '123456')
70
- response = client.ticket(1, "This is a test that should create a new task as: Lester")
71
- response['title'].should == "This is a test that should create a new task"
72
- response['assigned_to']['user']['first_name'].should == "Lester"
73
- response['project_id'].should == "1"
74
- end
75
-
76
- it "should raise unauthorized if a 401 is received" do
77
- stub_request(:post, "http://blah:123456@blah.lvh.me:3000/api/v1/projects/1/tickets").
78
- with(:body => "command=This%20is%20a%20test%20that%20should%20create%20a%20new%20task%20as%3A%20Lester").
79
- to_return(:status => 401)
80
- client = Morale::Client.new('blah', '123456')
81
- lambda { client.ticket('1', "This is a test that should create a new task as: Lester") }.should raise_error(Morale::Client::Unauthorized)
82
- end
83
-
84
- it "should raise notfound if a 404 is received" do
85
- stub_request(:post, "http://blah:123456@blah.lvh.me:3000/api/v1/projects/1/tickets").
86
- with(:body => "command=This%20is%20a%20test%20that%20should%20create%20a%20new%20task%20as%3A%20Lester").
87
- to_return(:status => 404)
88
- client = Morale::Client.new('blah', '123456')
89
- lambda { client.ticket('1', "This is a test that should create a new task as: Lester") }.should raise_error(Morale::Client::NotFound)
90
- end
91
- end
92
-
93
- describe "#tickets" do
94
- it "should return all active tickets when no options are specified" do
95
- stub_request(:get, "http://blah:123456@blah.lvh.me:3000/api/v1/projects/1/tickets").to_return(:body =>
96
- [{"ticket" => {"title" => "This is test #1","created_at" => "2011-07-31T21:40:24Z","updated_at" => "2011-07-31T21:40:24Z","project_id" => 1,"id" => 1,"identifier" => "1","type" => "Task","due_date" => "2011-10-15 16:00:00.000000","priority" => nil,"archived" => "f"}},
97
- {"ticket" => {"title" => "This is test #2","created_at" => "2011-07-31T21:28:53Z","updated_at" => "2011-07-31T21:28:53Z","project_id" => 1,"id" => 2, "identifier" => "2","type" => "Bug","due_date" => nil,"priority" => "2","archived" => "f"}}].to_json)
98
- client = Morale::Client.new('blah', '123456')
99
- response = client.tickets({:project_id => 1})
100
- response.count.should == 2
101
- response[0]["ticket"]["title"].should == "This is test #1"
102
- response[1]["ticket"]["title"].should == "This is test #2"
103
- end
104
-
105
- it "should raise unauthorized if a 401 is received" do
106
- stub_request(:get, "http://blah:123456@blah.lvh.me:3000/api/v1/projects/1/tickets").
107
- to_return(:status => 401)
108
- client = Morale::Client.new('blah', '123456')
109
- lambda { client.tickets({:project_id => 1}) }.should raise_error(Morale::Client::Unauthorized)
110
- end
111
-
112
- it "should raise notfound if a 404 is received" do
113
- stub_request(:get, "http://blah:123456@blah.lvh.me:3000/api/v1/projects/1/tickets").
114
- to_return(:status => 404)
115
- client = Morale::Client.new('blah', '123456')
116
- lambda { client.tickets({ :project_id => 1 }) }.should raise_error(Morale::Client::NotFound)
117
- end
118
- end
119
- end
@@ -1,65 +0,0 @@
1
- require 'spec_helper'
2
- require 'morale/connection_store'
3
-
4
- describe Morale::ConnectionStore do
5
-
6
- class Dummy; end
7
- before (:each) do
8
- @dummy = Dummy.new
9
- @dummy.extend(Morale::ConnectionStore)
10
- end
11
-
12
- after (:each) do
13
- @dummy.delete_connection
14
- end
15
-
16
- describe "#location" do
17
- it "should return the correct location of the connection file" do
18
- @dummy.location.should == "#{ENV['HOME']}/.morale/connection"
19
- end
20
- end
21
-
22
- describe "#base_url" do
23
- it "should store the default base url if it is not set" do
24
- @dummy.base_url.should == "teammorale.com"
25
- File.read(@dummy.location).should =~ /teammorale.com/
26
- end
27
-
28
- it "should return the environment variable for the default base url" do
29
- @dummy.delete_connection
30
- ENV['DEFAULT_BASE_URL'] = "somewhere-else.com"
31
- @dummy.base_url.should == "somewhere-else.com"
32
- end
33
-
34
- it "should store the base url when it is set" do
35
- @dummy.base_url = "somewhere-else.com"
36
- File.read(@dummy.location).should =~ /somewhere-else.com/
37
- end
38
- end
39
-
40
- describe "#delete_connection" do
41
- it "should clear the base_url field" do
42
- ENV['DEFAULT_BASE_URL'] = nil
43
- @dummy.base_url = "Blah!"
44
- @dummy.delete_connection
45
- @dummy.base_url.should == "teammorale.com"
46
- end
47
-
48
- it "should delete the connection file" do
49
- FileUtils.mkdir_p(File.dirname(@dummy.location))
50
- f = File.open(@dummy.location, 'w')
51
- f.puts "Blah!"
52
-
53
- @dummy.delete_connection
54
- File.exists?(@dummy.location).should be_false
55
- end
56
- end
57
-
58
- describe "#write_connection" do
59
- it "should write data to the location of the connection file" do
60
- @dummy.base_url = "Blah!"
61
- @dummy.write_connection
62
- File.read(@dummy.location).should =~ /Blah!/
63
- end
64
- end
65
- end