mite-rb 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,5 +1,20 @@
1
1
  = mite-rb Changelog
2
2
 
3
+ == Version 0.2.0 (not completed)
4
+
5
+ * Added singleton resources account and myself (current authenticated user)
6
+ * Removed depreciated undo method
7
+ * Do not require rubygems
8
+ * Added Method to validate the connection to mite
9
+
10
+ == Version 0.1.0
11
+
12
+ * Use absolute classes to prevent collision with other classes
13
+
14
+ == Version 0.0.3
15
+
16
+ * Fixed wrong domain_name (old one for testung removed)
17
+
3
18
  == Version 0.0.2
4
19
 
5
20
  * Added tracker-resource and methods on time_entry
data/README.textile CHANGED
@@ -2,14 +2,18 @@ The official ruby library for interacting with the "RESTful API":http://mite.yo.
2
2
 
3
3
  h3. Install
4
4
 
5
- As a ruby gem from github:
5
+ As a ruby gem from gemcutter:
6
6
 
7
- sudo gem install yolk-mite-rb -s http://gems.github.com
7
+ sudo gem install mite-rb -s http://gemcutter.org
8
8
 
9
9
  mite-rb requires activeresource and activesupport gems in a current version (2.3.2) to be installed.
10
10
 
11
11
  h3. Documentation
12
12
 
13
+ You should read the complete mite.api documentation at http://mite.yo.lk/en/api
14
+
15
+ h4. Authenticate
16
+
13
17
  The first thing you need to set is the account name. This is the same as the web address (subdomain) for your account. For example if you use mite from the domain demo.mite.yo.lk:
14
18
 
15
19
  Mite.account = 'demo'
@@ -24,7 +28,19 @@ or, use your api key:
24
28
 
25
29
  Mite.key = 'cdfeasdaabcdefgssaeabcdefg'
26
30
 
27
- You should read the complete mite.api documentation at http://mite.yo.lk/en/api
31
+ h4. Validate connection
32
+
33
+ You can validate the connection/authentication with
34
+
35
+ Mite.validate
36
+
37
+ This will return true when the connection is valid and false if not.
38
+
39
+ Use
40
+
41
+ Mite.validate!
42
+
43
+ and mite-rb will raise an exception with further details when the connection is not valid.
28
44
 
29
45
  h4. Project
30
46
 
@@ -61,10 +77,5 @@ Deleting a project
61
77
 
62
78
  project = Mite::Project.find(1209)
63
79
  project.destroy
64
-
65
- Restore a destroyed project
66
- (will only work for aprox. 12 hours after the object was destroyed)
67
-
68
- project = Mite::Project.undo_destroy(1209)
69
80
 
70
81
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 1
3
+ :minor: 2
4
4
  :patch: 0
@@ -0,0 +1,3 @@
1
+ class Mite::Account < Mite::SingletonBase
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class Mite::Myself < Mite::SingletonBase
2
+
3
+ end
data/lib/mite/user.rb CHANGED
@@ -1,19 +1,8 @@
1
1
  class Mite::User < Mite::Base
2
2
 
3
+ include Mite::NoWriteAccess
4
+
3
5
  def time_entries(options = {})
4
6
  Mite::TimeEntry.find(:all, :params => options.update(:user_id => id))
5
7
  end
6
-
7
- def save
8
- raise Error, "Cannot modify users over mite.api"
9
- end
10
-
11
- def create
12
- raise Error, "Cannot create users over mite.api"
13
- end
14
-
15
- def destroy
16
- raise Error, "Cannot destroy users over mite.api"
17
- end
18
-
19
8
  end
data/lib/mite-rb.rb CHANGED
@@ -1,6 +1,3 @@
1
- $:.unshift(File.dirname(__FILE__))
2
-
3
- require 'rubygems'
4
1
  require 'activesupport'
5
2
  require 'activeresource'
6
3
 
@@ -43,23 +40,53 @@ module Mite
43
40
  def resources
44
41
  @resources ||= []
45
42
  end
43
+
44
+ # Validates connection
45
+ # returns true when valid false when not
46
+ def validate
47
+ validate! rescue false
48
+ end
49
+
50
+ # Same as validate_connection
51
+ # but raises http-error when connection is invalid
52
+ def validate!
53
+ !!Mite::Account.find
54
+ end
46
55
  end
47
56
 
48
57
  self.host_format = '%s://%s%s'
49
58
  self.domain_format = '%s.mite.yo.lk'
50
59
  self.protocol = 'http'
51
60
  self.port = ''
61
+
62
+ class MethodNotAvaible < StandardError; end
63
+
64
+ module NoWriteAccess
65
+ def save
66
+ raise MethodNotAvaible, "Cannot save #{self.class.name} over mite.api"
67
+ end
68
+
69
+ def create
70
+ raise MethodNotAvaible, "Cannot save #{self.class.name} over mite.api"
71
+ end
52
72
 
73
+ def destroy
74
+ raise MethodNotAvaible, "Cannot save #{self.class.name} over mite.api"
75
+ end
76
+ end
77
+
53
78
  class Base < ActiveResource::Base
54
79
  class << self
55
80
 
56
81
  def inherited(base)
57
- Mite.resources << base
58
- class << base
59
- attr_accessor :site_format
82
+ unless base == Mite::SingletonBase
83
+ Mite.resources << base
84
+ class << base
85
+ attr_accessor :site_format
86
+ end
87
+ base.site_format = '%s'
88
+ base.timeout = 20
60
89
  end
61
- base.site_format = '%s'
62
- base.timeout = 20
63
90
  super
64
91
  end
65
92
 
@@ -75,31 +102,51 @@ module Mite
75
102
  def last(options={})
76
103
  find_every(options).last
77
104
  end
78
-
79
- # Undo destroy action on the resource with the ID in the +id+ parameter.
80
- def undo_destroy(id)
81
- returning(self.new(:id => id)) { |res| res.undo_destroy }
82
- end
83
105
  end
106
+ end
107
+
108
+ class SingletonBase < Base
109
+ include NoWriteAccess
84
110
 
85
- # Undo destroy action.
86
- def undo_destroy
87
- path = element_path(prefix_options).sub(/\.([\w]+)/, '/undo_delete.\1')
88
-
89
- returning connection.post(path, "", self.class.headers) do |response|
90
- load_attributes_from_response(response)
111
+ class << self
112
+ def collection_name
113
+ element_name
114
+ end
115
+
116
+ def element_path(id, prefix_options = {}, query_options = nil)
117
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
118
+ "#{prefix(prefix_options)}#{collection_name}.#{format.extension}#{query_string(query_options)}"
119
+ end
120
+
121
+ def collection_path(prefix_options = {}, query_options = nil)
122
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
123
+ "#{prefix(prefix_options)}#{collection_name}.#{format.extension}#{query_string(query_options)}"
91
124
  end
92
125
  end
93
-
126
+
127
+ def find
128
+ super(1)
129
+ end
130
+
131
+ alias_method :first, :find
132
+ alias_method :last, :find
133
+
134
+ # Prevent collection methods
135
+ def all
136
+ raise MethodNotAvaible, "Method not supported on #{self.class.name}"
137
+ end
94
138
  end
95
139
 
96
- class Error < StandardError; end
97
140
  end
98
141
 
142
+ $:.unshift(File.dirname(__FILE__))
143
+
99
144
  require 'mite/customer'
100
145
  require 'mite/project'
101
146
  require 'mite/service'
102
147
  require 'mite/time_entry'
103
148
  require 'mite/time_entry_group'
104
149
  require 'mite/tracker'
105
- require 'mite/user'
150
+ require 'mite/user'
151
+ require 'mite/myself'
152
+ require 'mite/account'
data/mite-rb.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mite-rb}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sebastian Munz"]
12
- s.date = %q{2009-10-15}
12
+ s.date = %q{2009-11-05}
13
13
  s.description = %q{The official ruby library for interacting with the RESTful mite.api.}
14
14
  s.email = %q{sebastian@yo.lk}
15
15
  s.extra_rdoc_files = [
@@ -24,7 +24,9 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "VERSION.yml",
26
26
  "lib/mite-rb.rb",
27
+ "lib/mite/account.rb",
27
28
  "lib/mite/customer.rb",
29
+ "lib/mite/myself.rb",
28
30
  "lib/mite/project.rb",
29
31
  "lib/mite/service.rb",
30
32
  "lib/mite/time_entry.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mite-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Munz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-15 00:00:00 +02:00
12
+ date: 2009-11-05 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -49,7 +49,9 @@ files:
49
49
  - Rakefile
50
50
  - VERSION.yml
51
51
  - lib/mite-rb.rb
52
+ - lib/mite/account.rb
52
53
  - lib/mite/customer.rb
54
+ - lib/mite/myself.rb
53
55
  - lib/mite/project.rb
54
56
  - lib/mite/service.rb
55
57
  - lib/mite/time_entry.rb