mite-rb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ pkg
3
+ doc
4
+ .DS_Store
5
+ debug.rb
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,25 @@
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 = "mite-rb"
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
+ Jeweler::GemcutterTasks.new
23
+ rescue LoadError
24
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
25
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 1
4
+ :patch: 0
@@ -0,0 +1,9 @@
1
+ class Mite::Customer < Mite::Base
2
+ def time_entries(options = {})
3
+ Mite::TimeEntry.find(:all, :params => options.update(:customer_id => id))
4
+ end
5
+
6
+ def projects(options = {})
7
+ Mite::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
+ Mite::TimeEntry.find(:all, :params => options.update(:project_id => id))
5
+ end
6
+
7
+ def customer
8
+ @customer ||= Mite::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
+ Mite::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 ||= Mite::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 ||= Mite::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
+ Mite::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 Mite::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
+ Mite::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
+ Mite::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.mite.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'
data/mite-rb.gemspec ADDED
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{mite-rb}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Sebastian Munz"]
12
+ s.date = %q{2009-10-15}
13
+ s.description = %q{The official ruby library for interacting with the RESTful mite.api.}
14
+ s.email = %q{sebastian@yo.lk}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.textile"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "CHANGES.txt",
22
+ "LICENSE",
23
+ "README.textile",
24
+ "Rakefile",
25
+ "VERSION.yml",
26
+ "lib/mite-rb.rb",
27
+ "lib/mite/customer.rb",
28
+ "lib/mite/project.rb",
29
+ "lib/mite/service.rb",
30
+ "lib/mite/time_entry.rb",
31
+ "lib/mite/time_entry_group.rb",
32
+ "lib/mite/tracker.rb",
33
+ "lib/mite/user.rb",
34
+ "mite-rb.gemspec"
35
+ ]
36
+ s.homepage = %q{http://github.com/yolk/mite-rb}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.5}
40
+ s.summary = %q{The official ruby library for interacting with the RESTful API of mite, a sleek time tracking webapp.}
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.3.2"])
48
+ s.add_runtime_dependency(%q<activeresource>, [">= 2.3.2"])
49
+ else
50
+ s.add_dependency(%q<activesupport>, [">= 2.3.2"])
51
+ s.add_dependency(%q<activeresource>, [">= 2.3.2"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<activesupport>, [">= 2.3.2"])
55
+ s.add_dependency(%q<activeresource>, [">= 2.3.2"])
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mite-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastian Munz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-15 00:00:00 +02: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
+ - .gitignore
46
+ - CHANGES.txt
47
+ - LICENSE
48
+ - README.textile
49
+ - Rakefile
50
+ - VERSION.yml
51
+ - lib/mite-rb.rb
52
+ - lib/mite/customer.rb
53
+ - lib/mite/project.rb
54
+ - lib/mite/service.rb
55
+ - lib/mite/time_entry.rb
56
+ - lib/mite/time_entry_group.rb
57
+ - lib/mite/tracker.rb
58
+ - lib/mite/user.rb
59
+ - mite-rb.gemspec
60
+ has_rdoc: true
61
+ homepage: http://github.com/yolk/mite-rb
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --charset=UTF-8
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.3.5
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: The official ruby library for interacting with the RESTful API of mite, a sleek time tracking webapp.
88
+ test_files: []
89
+