dobedobedo 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dobedobedo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Kevin Poorman
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Dobedobedo
2
+
3
+ Dobedobedo is a Do.com client for ruby. It's in its early stages and currently supports basic crud on:
4
+ * comments
5
+ * projects
6
+ * notes
7
+ * tasks
8
+
9
+ But does not currently support creation of:
10
+ * workspaces
11
+ * users
12
+ * alerts
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ gem 'dobedobedo'
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install dobedobedo
27
+
28
+ ## Usage
29
+
30
+ Dobedobedo is modeled on the notion of establishing a secure connection and establishing model objects that reflect your do.com workspaces, projects, tasks, comments, etc. As such, usage is pretty simple.
31
+
32
+ require 'dobedobedo' # please do this with the bundler.
33
+ include Dobedobedo # gives you access to the top level models.
34
+
35
+ connection = Dobedobedo::Connection.new(:client_id => 'Your Client Id', :client_secret => 'Your Client Secret', :username => 'Your Email Address', :password => 'Your Passsord Here')
36
+ workspace = connection.by_name('workspace name here') #by_name is an alias to find_workspace_by_name
37
+ projects = workspace.projects #array of Dobedobedo::Project objects reflecting each of the projects
38
+ projects.first.tasks #array of task objects from the first project in the workspace
39
+
40
+ task = projects.first.tasks.first
41
+ task.name = 'new name'
42
+ task.update
43
+ #updated task!
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dobedobedo/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "dobedobedo"
8
+ gem.version = Dobedobedo::VERSION
9
+ gem.authors = ["Kevin Poorman"]
10
+ gem.email = ["kjp@brightleafsoftware.com"]
11
+ gem.description = %q{Interact with Do.com}
12
+ gem.summary = %q{Gem interacts with Do.com}
13
+ gem.homepage = ""
14
+
15
+ gem.add_dependency "oauth2"
16
+ gem.add_dependency "bundler"
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ["lib"]
21
+ end
data/lib/dobedobedo.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "bundler"
2
+ require "oauth2"
3
+ require "json"
4
+ require "dobedobedo/connection"
5
+ require "dobedobedo/workspace"
6
+ require "dobedobedo/project"
7
+ require "dobedobedo/task"
8
+ require "dobedobedo/note"
9
+ require "dobedobedo/alert"
10
+ require "dobedobedo/comment"
11
+ require "dobedobedo/objToJson"
12
+ require "dobedobedo/version"
13
+ #Bundler.require(:default, :development)
14
+ module Dobedobedo
15
+
16
+
17
+
18
+ end
@@ -0,0 +1,20 @@
1
+ module Dobedobedo
2
+ class Alert
3
+ attr_reader :token
4
+
5
+ def initialize(token, h={})
6
+ @token = token
7
+ unless h.nil?
8
+ h.each do |k,v|
9
+ Alert.send(:attr_accessor, k.to_sym)
10
+ self.send("#{k}=".to_sym, v)
11
+ end
12
+ end
13
+ end
14
+
15
+ def mark_read
16
+ @token.put("/alerts/#{@id}", :body => {:is_read => "true"}.to_json)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module Dobedobedo
2
+ module Auth
3
+ require 'oauth2'
4
+
5
+ def login
6
+ @client = OAuth2::Client.new(:client_id,
7
+ :client_secret,
8
+ :site => :site_url,
9
+ :token_url => :tokenurl,
10
+ :authorization_url => :authurl)
11
+
12
+ @token = @client.password.get_token(:username, :password)
13
+ end
14
+
15
+ end
16
+ end
17
+
@@ -0,0 +1,14 @@
1
+ module Dobedobedo
2
+ class Comment
3
+
4
+ def initialize(token, h={})
5
+ @token = token
6
+ unless h.nil?
7
+ h.each do |k,v|
8
+ Comment.send(:attr_accessor, k.to_sym)
9
+ self.send("#{k}=".to_sym, v)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,42 @@
1
+ module Dobedobedo
2
+ class Connection
3
+ # include Dobedobedo::Workspace
4
+
5
+ attr_accessor :client_id, :client_secret, :username, :password
6
+ attr_reader :client, :token
7
+ SITE_URL = "https://www.do.com"
8
+ TOKEN_URL = "/oauth2/token"
9
+ AUTHORIZATION_URL = "/oauth2/authorize"
10
+ GET_WORKSPACE_LIST = '/workspaces'
11
+
12
+ def initialize(config = {})
13
+ @client_id = config[:client_id] unless config[:client_id].nil?
14
+ @client_secret = config[:client_secret] unless config[:client_secret].nil?
15
+ @username = config[:username] unless config[:username].nil?
16
+ @password = config[:password] unless config[:password].nil?
17
+
18
+ raise "Failed to set client id and client secret in constructor" if (@client_id.nil? || @client_secret.nil?)
19
+
20
+ @client = OAuth2::Client.new(@client_id,
21
+ @client_secret,
22
+ :site => SITE_URL,
23
+ :token_url => TOKEN_URL,
24
+ :authorization_url => AUTHORIZATION_URL)
25
+
26
+ raise "Failed to create client" if @client.nil?
27
+
28
+ @token = @client.password.get_token(@username, @password)
29
+ end
30
+
31
+ def workspaces
32
+ @token.get(GET_WORKSPACE_LIST).parsed.map {|w| Dobedobedo::Workspace.new(@token, w)}
33
+ end
34
+
35
+ def find_workspace_by_name(name)
36
+ workspaces.select {|x| x.name == name}.first
37
+ end
38
+
39
+ alias :by_name :find_workspace_by_name
40
+
41
+ end
42
+ end
@@ -0,0 +1,37 @@
1
+ module Dobedobedo
2
+ class Note
3
+ require "dobedobedo/objToJson"
4
+ include ::Dobedobedo::ObjToJson
5
+ attr_reader :token
6
+
7
+ def initialize(token, workspace_id, h={})
8
+ @token = token
9
+ @workspace_id = workspace_id
10
+ if h.empty?
11
+ h = token.post("/workspaces/#{workspace_id}/notes").parsed
12
+ end
13
+ h.each do |k,v|
14
+ Note.send(:attr_accessor, k.to_sym)
15
+ self.send("#{k}=".to_sym, v)
16
+ end
17
+ end
18
+
19
+ def self.get(token, workspace_id, note_id)
20
+ Note.new(token, workspace_id, token.get("/workspaces/#{workspace_id}/notes/#{note_id}").parsed)
21
+ end
22
+
23
+ def self.create(token, workspace_id)
24
+ Note.new(token, workspace_id, token.post("/workspaces/#{workspace_id}/notes").parsed)
25
+ end
26
+
27
+ def update()
28
+ @token.put("/workspaces/#{@workspace_id}/notes/#{@id}", :body => self.objToJson)
29
+ end
30
+ # alias :update :save
31
+
32
+ def delete()
33
+ @token.delete("/workspaces/#{@workspace_id}/notes/#{@id}")
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ module Dobedobedo
2
+ module ObjToJson
3
+
4
+ # modified from http://stackoverflow.com/questions/1684588/how-to-do-ruby-object-serialization-using-json
5
+ def objToJson
6
+ h = {}
7
+ instance_variables.each do |e|
8
+ #next unless [@workspace_id, @id, @lock_version, @name, @description, @due_at, @closed_at, @created_at, @updated_at, @comments_count, @timed, @accepted, @recurrence, @deleted, @closed].include? e.to_sym
9
+ next if [:@token].include? e.to_sym
10
+ o = instance_variable_get e.to_sym
11
+ h[e[1..-1]] = (o.respond_to? :objToJson) ? o.objToJson : o;
12
+ end
13
+ h
14
+ end
15
+
16
+ # def to_json(*a)
17
+ # objToJson.to_json(*a)
18
+ # end
19
+
20
+ def obj_to_json
21
+ retval = {}
22
+ instance_variables.each do |ivar|
23
+ i = instance_variable_get ivar.to_sym
24
+ propname = ivar[1..-1]
25
+ next if %w{token lock_version accepted deleted closed recurrence timed closed_at due_at type goal comments_count updated_at workspace_id assignee created_at comments user creator requestor followers attachments attachments_count notes contacts}.include? propname
26
+ retval[propname] = (i.respond_to? :obj_to_json) ? i.obj_to_json : i;
27
+ end
28
+ retval.to_json
29
+ end
30
+
31
+ def obj_to_json2
32
+ {:id=>@id, :name => @name, :description => @description}
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,41 @@
1
+ module Dobedobedo
2
+ class Project
3
+ require "dobedobedo/objToJson"
4
+ include ::Dobedobedo::ObjToJson
5
+ attr_reader :token
6
+
7
+ def initialize(token, workspace_id, h={})
8
+ @token = token
9
+ @workspace_id = workspace_id
10
+ if h.nil?
11
+ h = token.post("/workspaces/#{workspace_id}/projects").parsed
12
+ end
13
+ h.each do |k,v|
14
+ Project.send(:attr_accessor, k.to_sym)
15
+ self.send("#{k}=".to_sym, v)
16
+ end
17
+
18
+ end
19
+
20
+ def self.get(token, workspace_id, project_id)
21
+ Project.new(token, workspace_id, token.get("/workspaces/#{workspace_id}/projects/#{project_id}").parsed)
22
+ end
23
+
24
+ def self.create(token, workspace_id, create_data)
25
+ Project.new(token, workspace_id, token.post("/workspaces/#{workspace_id}/projects", :body => create_data.to_json ).parsed)
26
+ end
27
+
28
+ def tasks
29
+ @token.get("/workspaces/#{@workspace_id}/projects/#{@id}/tasks").parsed.map {|t| Dobedobedo::Task.new(@token, @id, t)}
30
+ end
31
+
32
+ def update()
33
+ @token.put("/workspaces/#{@workspace_id}/projects/#{@id}", :body => self.objToJson)
34
+ end
35
+
36
+ def delete()
37
+ @token.delete("/workspaces/#{@workspace_id}/projects/#{@id}")
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,37 @@
1
+ module Dobedobedo
2
+ class Task
3
+ require "dobedobedo/objToJson"
4
+ include ::Dobedobedo::ObjToJson
5
+ attr_reader :token
6
+
7
+ def initialize(token, workspace_id, project_id=nil, h={})
8
+ @token = token
9
+ @workspace_id = workspace_id
10
+ if h.empty?
11
+ if project_id.nil?
12
+ h = token.post("/workspaces/#{workspace_id}/tasks").parsed
13
+ else
14
+ h = token.post("/workspaces/#{workspace_id}/projects/project_id/tasks").parsed
15
+ end
16
+ end
17
+ h.each do |k,v|
18
+ Task.send(:attr_accessor, k.to_sym)
19
+ self.send("#{k}=".to_sym, v)
20
+ end
21
+ end
22
+
23
+ def comments
24
+ @token.get("/workspaces/#{workspace_id}/tasks/#{id}/comments").parsed.map {|n| Dobedobedo::Comment.new(@token, n)}
25
+ end
26
+
27
+ def update()
28
+ payload = {:name => @name, :description => @description, :closed => @closed, :deleted => @deleted}
29
+ @token.put("/workspaces/#{@workspace_id}/tasks/#{@id}", :body => payload)
30
+ end
31
+
32
+ def delete()
33
+ @token.delete("/workspaces/#{@workspace_id}/tasks/#{@id}")
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,16 @@
1
+ module Dobedobedo
2
+ class User
3
+ require "dobedobedo/objToJson"
4
+ include ::Dobedobedo::ObjToJson
5
+ attr_reader :token
6
+
7
+ def initialize(token, workspace_id, h)
8
+ @token = token
9
+ @workspace_id = workspace_id
10
+ h.each do |k,v|
11
+ User.send(:attr_accessor, k.to_sym)
12
+ self.send("#{k}=".to_sym, v)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Dobedobedo
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,39 @@
1
+ module Dobedobedo
2
+ class Workspace
3
+ attr_reader :token
4
+
5
+ def initialize(token, h={})
6
+ @token = token
7
+ unless h.nil?
8
+ h.each do |k,v|
9
+ Workspace.send(:attr_accessor, k.to_sym)
10
+ self.send("#{k}=".to_sym, v)
11
+ end
12
+ end
13
+ end
14
+
15
+ def projects
16
+ @token.get("/workspaces/#{@id}/projects").parsed.map {|p| Dobedobedo::Project.new(@token, @id, p)}
17
+ end
18
+
19
+ def find_project_by_name(name)
20
+ projects.select {|x| x.name == name}.first
21
+ end
22
+
23
+ def tasks
24
+ @token.get("/workspaces/#{@id}/tasks").parsed.map {|t| Dobedobedo::Task.new(@token, @id, t)}
25
+ end
26
+
27
+ def notes
28
+ @token.get("/workspaces/#{@id}/notes").parsed.map {|n| Dobedobedo::Note.new(@token, n)}
29
+ end
30
+
31
+ def alerts
32
+ @token.get("/workspaces/#{@id}/alerts").parsed.map {|a| Dobedobedo::Alert.new(@token, a)}
33
+ end
34
+
35
+ def users
36
+ @token.get("/workspaces/#{@id}/users").parsed.map {|u| Dobedobedo::User.new(@token, @id, u)}
37
+ end
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dobedobedo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kevin Poorman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: oauth2
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Interact with Do.com
47
+ email:
48
+ - kjp@brightleafsoftware.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - dobedobedo.gemspec
59
+ - lib/dobedobedo.rb
60
+ - lib/dobedobedo/alert.rb
61
+ - lib/dobedobedo/auth.rb
62
+ - lib/dobedobedo/comment.rb
63
+ - lib/dobedobedo/connection.rb
64
+ - lib/dobedobedo/note.rb
65
+ - lib/dobedobedo/objToJson.rb
66
+ - lib/dobedobedo/project.rb
67
+ - lib/dobedobedo/task.rb
68
+ - lib/dobedobedo/user.rb
69
+ - lib/dobedobedo/version.rb
70
+ - lib/dobedobedo/workspace.rb
71
+ homepage: ''
72
+ licenses: []
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.24
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Gem interacts with Do.com
95
+ test_files: []