morale 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,4 +3,6 @@ require 'webmock/cucumber'
3
3
  require 'aruba/cucumber'
4
4
 
5
5
  ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
6
- ENV['CREDENTIALS_LOCATION'] = "credentials"
6
+ ENV['CREDENTIALS_LOCATION'] = "credentials"
7
+ ENV['CONNECTION_LOCATION'] = "connection"
8
+ ENV['DEFAULT_BASE_URL'] = "lvh.me:3000"
data/lib/morale/client.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'httparty'
2
- require "json"
2
+ require 'json'
3
+ require 'morale/account'
4
+ require 'morale/connection_store'
3
5
 
4
6
  module Morale
5
7
  class Client
@@ -7,6 +9,8 @@ module Morale
7
9
  class NotFound < RuntimeError; end
8
10
 
9
11
  include HTTParty
12
+ extend Morale::ConnectionStore
13
+
10
14
  format :json
11
15
 
12
16
  API_VERSION = 'v1'
@@ -41,8 +45,7 @@ module Morale
41
45
  def initialize(subdomain="", api_key="")
42
46
  @api_key = api_key
43
47
  @subdomain = subdomain
44
- #TODO: Save the domain in a config file
45
- self.class.default_options[:base_uri] = HTTParty.normalize_base_uri("#{subdomain}#{"." unless subdomain.nil? || subdomain.empty?}lvh.me:3000/api/#{API_VERSION}")
48
+ self.class.default_options[:base_uri] = HTTParty.normalize_base_uri("#{subdomain}#{"." unless subdomain.nil? || subdomain.empty?}#{self.class.base_url}/api/#{API_VERSION}")
46
49
  end
47
50
 
48
51
  def projects
@@ -0,0 +1,58 @@
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,7 +1,9 @@
1
+ require 'morale/storage'
1
2
  require 'morale/platform'
2
3
 
3
4
  module Morale
4
5
  module CredentialsStore
6
+ include Morale::Storage
5
7
  include Morale::Platform
6
8
 
7
9
  attr_accessor :credentials
@@ -10,32 +12,26 @@ module Morale
10
12
  ENV['CREDENTIALS_LOCATION'] || default_location
11
13
  end
12
14
 
15
+ def location=(value)
16
+ ENV['CREDENTIALS_LOCATION'] = value
17
+ end
18
+
13
19
  def default_location
14
20
  "#{home_directory}/.morale/credentials"
15
21
  end
16
22
 
17
23
  def read_credentials
18
- File.exists?(location) and File.read(location).split("\n")
24
+ creds = self.read
25
+ creds.split("\n") if creds
19
26
  end
20
27
 
21
28
  def write_credentials
22
- FileUtils.mkdir_p(File.dirname(location))
23
- f = File.open(location, 'w')
24
- f.puts self.credentials
25
- f.close
26
- set_credentials_permissions
29
+ self.write self.credentials
27
30
  end
28
31
 
29
32
  def delete_credentials
30
- FileUtils.rm_f(location)
33
+ self.delete
31
34
  @credentials = nil
32
35
  end
33
-
34
- private
35
-
36
- def set_credentials_permissions
37
- FileUtils.chmod 0700, File.dirname(location)
38
- FileUtils.chmod 0600, location
39
- end
40
36
  end
41
37
  end
@@ -0,0 +1,29 @@
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
data/lib/morale.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Morale
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
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 = '0.1.0'
9
- s.date = '2011-09-29'
8
+ s.version = '0.1.1'
9
+ s.date = '2011-09-30'
10
10
  s.rubyforge_project = 'morale'
11
11
 
12
12
  s.summary = "Command line interface to create & manage tickets on Morale."
@@ -56,14 +56,18 @@ Gem::Specification.new do |s|
56
56
  lib/morale/commands/authorization.rb
57
57
  lib/morale/commands/project.rb
58
58
  lib/morale/commands/ticket.rb
59
+ lib/morale/connection_store.rb
59
60
  lib/morale/credentials_store.rb
60
61
  lib/morale/flow.rb
61
62
  lib/morale/platform.rb
63
+ lib/morale/storage.rb
62
64
  morale.gemspec
63
65
  spec/morale/account_spec.rb
64
66
  spec/morale/client_spec.rb
65
67
  spec/morale/command_spec.rb
68
+ spec/morale/connection_store_spec.rb
66
69
  spec/morale/credentials_store_spec.rb
70
+ spec/morale/storage_spec.rb
67
71
  spec/spec_helper.rb
68
72
  ]
69
73
  # = MANIFEST =
@@ -0,0 +1,65 @@
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
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'morale/storage'
3
+
4
+ describe Morale::Storage do
5
+
6
+ class Dummy; end
7
+ before (:each) do
8
+ @dummy = Dummy.new
9
+ @dummy.extend(Morale::Storage)
10
+ @dummy.location = "tmp/morale/store"
11
+ end
12
+
13
+ after (:each) do
14
+ @dummy.delete
15
+ end
16
+
17
+ describe "#delete" do
18
+ it "should delete the file" do
19
+ FileUtils.mkdir_p(File.dirname(@dummy.location))
20
+ f = File.open(@dummy.location, 'w')
21
+ f.puts "Blah!"
22
+
23
+ @dummy.delete
24
+ File.exists?(@dummy.location).should be_false
25
+ end
26
+ end
27
+
28
+ describe "#write" do
29
+ it "should write data to the location of the file" do
30
+ @dummy.write "Blah!"
31
+ File.read(@dummy.location).should =~ /Blah!/
32
+ end
33
+ end
34
+
35
+ describe "#read" do
36
+ it "should read data from the location of the file" do
37
+ FileUtils.mkdir_p(File.dirname(@dummy.location))
38
+ f = File.open(@dummy.location, 'w')
39
+ f.puts "Blah!"
40
+ f.close
41
+ @dummy.read.should =~ /Blah!/
42
+ end
43
+ end
44
+ end
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,11 @@ require "webmock/rspec"
6
6
 
7
7
  require "stringio"
8
8
 
9
+ require "morale/client"
10
+
9
11
  RSpec.configure do |config|
12
+ Morale::Client.base_url = "lvh.me:3000"
13
+
10
14
  def process(stdin_str = '')
11
15
  begin
12
16
  require 'stringio'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brilliant Fantastic
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-09-29 00:00:00 -04:00
17
+ date: 2011-09-30 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -105,14 +105,18 @@ files:
105
105
  - lib/morale/commands/authorization.rb
106
106
  - lib/morale/commands/project.rb
107
107
  - lib/morale/commands/ticket.rb
108
+ - lib/morale/connection_store.rb
108
109
  - lib/morale/credentials_store.rb
109
110
  - lib/morale/flow.rb
110
111
  - lib/morale/platform.rb
112
+ - lib/morale/storage.rb
111
113
  - morale.gemspec
112
114
  - spec/morale/account_spec.rb
113
115
  - spec/morale/client_spec.rb
114
116
  - spec/morale/command_spec.rb
117
+ - spec/morale/connection_store_spec.rb
115
118
  - spec/morale/credentials_store_spec.rb
119
+ - spec/morale/storage_spec.rb
116
120
  - spec/spec_helper.rb
117
121
  has_rdoc: true
118
122
  homepage: http://teammorale.com