yolk-mite-rb 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt ADDED
@@ -0,0 +1,11 @@
1
+ = mite-rb Changelog
2
+
3
+ == Version 0.0.2
4
+
5
+ * Added tracker-resource and methods on time_entry
6
+ * Fixed tiny datetimebug
7
+ * Dependency of activeresource 2.3.2 and activesupport 2.3.2
8
+
9
+ == Version 0.0.1
10
+
11
+ * Initial Version
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Yolk Sebastian Munz & Julia Soergel GbR
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,70 @@
1
+ The official ruby library for interacting with the "RESTful API":http://mite.yo.lk/en/api of "mite":http://mite.yo.lk/en, a sleek time tracking webapp.
2
+
3
+ h3. Install
4
+
5
+ As a ruby gem from github:
6
+
7
+ sudo gem install yolk-mite-rb -s http://gems.github.com
8
+
9
+ mite-rb requires activeresource and activesupport gems in a current version (2.3.2) to be installed.
10
+
11
+ h3. Documentation
12
+
13
+ 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
+
15
+ Mite.account = 'demo'
16
+
17
+ Then, you should set the authentication. You can either use your login credentials (email and password) with HTTP Basic Authentication or your mite.api key. In both cases you must enable the mite.api in your user settings.
18
+
19
+ With basic authentication:
20
+
21
+ Mite.authenticate('rick@techno-weenie.net', 'spacemonkey')
22
+
23
+ or, use your api key:
24
+
25
+ Mite.key = 'cdfeasdaabcdefgssaeabcdefg'
26
+
27
+ You should read the complete mite.api documentation at http://mite.yo.lk/en/api
28
+
29
+ h4. Project
30
+
31
+ Find all active projects of the current account
32
+
33
+ Mite::Project.all
34
+
35
+ Find single project by ID
36
+
37
+ Mite::Project.find(1209)
38
+
39
+ Creating a Project
40
+
41
+ project = Mite::Project.new(:name => 'Playing with the mite.api')
42
+ project.save
43
+
44
+ or
45
+
46
+ project = Mite::Project.create(:name => 'Playing with the mite.api')
47
+
48
+ Updating a Project
49
+
50
+ project = Mite::Project.find(1209)
51
+ project.name = "mite.api"
52
+ project.customer = Mite::Customer.find(384)
53
+ project.save
54
+
55
+ Get the customer of an project
56
+
57
+ project = Mite::Project.find(1209)
58
+ project.customer
59
+
60
+ Deleting a project
61
+
62
+ project = Mite::Project.find(1209)
63
+ 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
+
70
+
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ task :default => [:spec]
2
+
3
+ $gem_name = "mite-rb"
4
+
5
+ desc "Run specs"
6
+ task :spec do
7
+ sh "spec spec/* --format specdoc --color"
8
+ end
9
+
10
+ begin
11
+ require 'jeweler'
12
+ Jeweler::Tasks.new do |s|
13
+ s.name = $gem_name
14
+ s.summary = "The official ruby library for interacting with the RESTful API of mite, a sleek time tracking webapp."
15
+ s.email = "sebastian@yo.lk"
16
+ s.homepage = "http://github.com/yolk/mite-rb"
17
+ s.description = "The official ruby library for interacting with the RESTful mite.api."
18
+ s.authors = ["Sebastian Munz"]
19
+ s.add_dependency(%q<activesupport>, [">= 2.3.2"])
20
+ s.add_dependency(%q<activeresource>, [">= 2.3.2"])
21
+ end
22
+ rescue LoadError
23
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
24
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 0
3
+ :patch: 2
4
+ :major: 0
@@ -0,0 +1,9 @@
1
+ class Mite::Customer < Mite::Base
2
+ def time_entries(options = {})
3
+ TimeEntry.find(:all, :params => options.update(:customer_id => id))
4
+ end
5
+
6
+ def projects(options = {})
7
+ Project.find(:all, :params => options.update(:customer_id => id))
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ class Mite::Project < Mite::Base
2
+
3
+ def time_entries(options = {})
4
+ TimeEntry.find(:all, :params => options.update(:project_id => id))
5
+ end
6
+
7
+ def customer
8
+ @customer ||= Customer.find(customer_id) unless customer_id.blank?
9
+ end
10
+
11
+ def customer=(customer)
12
+ self.customer_id = customer ? customer.id : nil
13
+ @customer = customer
14
+ end
15
+
16
+ end
@@ -0,0 +1,7 @@
1
+ class Mite::Service < Mite::Base
2
+
3
+ def time_entries(options = {})
4
+ TimeEntry.find(:all, :params => options.update(:service_id => id))
5
+ end
6
+
7
+ end
@@ -0,0 +1,54 @@
1
+ class Mite::TimeEntry < Mite::Base
2
+
3
+ def service
4
+ @service ||= Service.find(service_id) unless service_id.blank?
5
+ end
6
+
7
+ def service=(service)
8
+ self.service_id = service ? service.id : nil
9
+ @service = service
10
+ end
11
+
12
+ def project
13
+ @project ||= Project.find(project_id) unless project_id.blank?
14
+ end
15
+
16
+ def project=(project)
17
+ self.project_id = project ? project.id : nil
18
+ @project = project
19
+ end
20
+
21
+ def customer
22
+ @customer ||= begin
23
+ p = project
24
+ p.customer unless p.blank?
25
+ end
26
+ end
27
+
28
+ def tracking?
29
+ !!attributes["tracker"]
30
+ end
31
+
32
+ def start_tracker
33
+ attributes["tracker"] = Mite::Tracker.start(id) || nil
34
+ end
35
+
36
+ def stop_tracker
37
+ Mite::Tracker.stop if tracking?
38
+ end
39
+
40
+ def load(attr)
41
+ super(attr)
42
+ if attributes["tracking"]
43
+ attributes["tracker"] = Mite::Tracker.new.load(attributes.delete("tracking").attributes)
44
+ end
45
+ self
46
+ end
47
+
48
+ class << self
49
+ def find_every(options={})
50
+ return super(options) if !options[:params] || !options[:params][:group_by]
51
+ TimeEntryGroup.all(options)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,36 @@
1
+ class Mite::TimeEntryGroup < Mite::Base
2
+ self.collection_name = "time_entries"
3
+
4
+ attr_accessor :time_entries_params
5
+
6
+ class << self
7
+ def find_every(options={})
8
+ return TimeEntry.all(options) if !options[:params] || !options[:params][:group_by]
9
+
10
+ returning super(options) do |records|
11
+ records.each do |record|
12
+ if record.attributes["time_entries_params"]
13
+ record.time_entries_params = record.attributes.delete("time_entries_params").attributes.stringify_keys
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ def time_entries(options={})
21
+ return [] unless time_entries_params.is_a?(Hash)
22
+
23
+ empty_result = false
24
+
25
+ options[:params] ||= {}
26
+ options[:params].stringify_keys!
27
+ options[:params].merge!(time_entries_params) do |key, v1, v2|
28
+ empty_result = (v1 != v2)
29
+ v2
30
+ end
31
+
32
+ return [] if empty_result
33
+
34
+ TimeEntry.all(options)
35
+ end
36
+ end
@@ -0,0 +1,34 @@
1
+ class Mite::Tracker < Mite::Base
2
+
3
+ self.collection_name = "tracker"
4
+
5
+ def self.current
6
+ tracking_time_entry = connection.get(collection_path, headers)["tracking_time_entry"]
7
+ tracking_time_entry ? instantiate_record(tracking_time_entry) : nil
8
+ end
9
+
10
+ def self.start(time_entry_or_id)
11
+ id = time_entry_or_id.is_a?(Mite::TimeEntry) ? time_entry_or_id.id : time_entry_or_id
12
+ self.new(:id => id).start
13
+ end
14
+
15
+ def self.stop
16
+ tracker = current
17
+ tracker ? tracker.stop : false
18
+ end
19
+
20
+ def start
21
+ response = connection.put(element_path(prefix_options), encode, self.class.headers)
22
+ load(self.class.format.decode(response.body)["tracking_time_entry"])
23
+ response.is_a?(Net::HTTPSuccess) ? self : false
24
+ end
25
+
26
+ def stop
27
+ connection.delete(element_path, self.class.headers).is_a?(Net::HTTPSuccess) ? self : false
28
+ end
29
+
30
+ def time_entry
31
+ Mite::TimeEntry.find(id)
32
+ end
33
+
34
+ end
data/lib/mite/user.rb ADDED
@@ -0,0 +1,19 @@
1
+ class Mite::User < Mite::Base
2
+
3
+ def time_entries(options = {})
4
+ TimeEntry.find(:all, :params => options.update(:user_id => id))
5
+ 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
+ end
data/lib/mite-rb.rb ADDED
@@ -0,0 +1,105 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'rubygems'
4
+ require 'activesupport'
5
+ require 'activeresource'
6
+
7
+ # The official ruby library for interacting with the RESTful API of mite,
8
+ # a sleek time tracking webapp.
9
+
10
+ module Mite
11
+
12
+ class << self
13
+ attr_accessor :email, :password, :host_format, :domain_format, :protocol, :port
14
+ attr_reader :account, :key
15
+
16
+ # Sets the account name, and updates all resources with the new domain.
17
+ def account=(name)
18
+ resources.each do |klass|
19
+ klass.site = klass.site_format % (host_format % [protocol, domain_format % name, ":#{port}"])
20
+ end
21
+ @account = name
22
+ end
23
+
24
+ # Sets up basic authentication credentials for all resources.
25
+ def authenticate(user, password)
26
+ resources.each do |klass|
27
+ klass.user = user
28
+ klass.password = password
29
+ end
30
+ @user = user
31
+ @password = password
32
+ true
33
+ end
34
+
35
+ # Sets the mite.api key for all resources.
36
+ def key=(value)
37
+ resources.each do |klass|
38
+ klass.headers['X-MiteApiKey'] = value
39
+ end
40
+ @key = value
41
+ end
42
+
43
+ def resources
44
+ @resources ||= []
45
+ end
46
+ end
47
+
48
+ self.host_format = '%s://%s%s'
49
+ self.domain_format = '%s.test.yo.lk'
50
+ self.protocol = 'http'
51
+ self.port = ''
52
+
53
+ class Base < ActiveResource::Base
54
+ class << self
55
+
56
+ def inherited(base)
57
+ Mite.resources << base
58
+ class << base
59
+ attr_accessor :site_format
60
+ end
61
+ base.site_format = '%s'
62
+ base.timeout = 20
63
+ super
64
+ end
65
+
66
+ # Common shortcuts known from ActiveRecord
67
+ def all(options={})
68
+ find_every(options)
69
+ end
70
+
71
+ def first(options={})
72
+ find_every(options).first
73
+ end
74
+
75
+ def last(options={})
76
+ find_every(options).last
77
+ 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
+ end
84
+
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)
91
+ end
92
+ end
93
+
94
+ end
95
+
96
+ class Error < StandardError; end
97
+ end
98
+
99
+ require 'mite/customer'
100
+ require 'mite/project'
101
+ require 'mite/service'
102
+ require 'mite/time_entry'
103
+ require 'mite/time_entry_group'
104
+ require 'mite/tracker'
105
+ require 'mite/user'
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yolk-mite-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Sebastian Munz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-21 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activeresource
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.2
34
+ version:
35
+ description: The official ruby library for interacting with the RESTful mite.api.
36
+ email: sebastian@yo.lk
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.textile
44
+ files:
45
+ - CHANGES.txt
46
+ - LICENSE
47
+ - README.textile
48
+ - Rakefile
49
+ - VERSION.yml
50
+ - lib/mite-rb.rb
51
+ - lib/mite/customer.rb
52
+ - lib/mite/project.rb
53
+ - lib/mite/service.rb
54
+ - lib/mite/time_entry.rb
55
+ - lib/mite/time_entry_group.rb
56
+ - lib/mite/tracker.rb
57
+ - lib/mite/user.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/yolk/mite-rb
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --charset=UTF-8
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.2.0
81
+ signing_key:
82
+ specification_version: 2
83
+ summary: The official ruby library for interacting with the RESTful API of mite, a sleek time tracking webapp.
84
+ test_files: []
85
+