tapajos-highrise 0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.mkdn ADDED
@@ -0,0 +1,54 @@
1
+ # Highrise
2
+
3
+ ## What
4
+
5
+ Highrise is a gem that provides an easy way to use the Highrise API.
6
+
7
+ ## Installing
8
+
9
+ gem install tapajos-highrise
10
+
11
+ ## Dependencies
12
+
13
+ * ActiveResorce
14
+
15
+ ## Configure your key.
16
+
17
+ require 'rubygens'
18
+ require 'highrise'
19
+ Highrise::Base.site = "http://your_api:login@your_site.highrisehq.com/"
20
+
21
+ ## Usage
22
+
23
+ This gem provides a set of classes to access all available informations on Highrise.
24
+
25
+ These are the list of classes:
26
+
27
+ Comment, Company, Email, Group, Note, Membership, Person, Subject, Task and User.
28
+
29
+ All these classes are inherited of ActiveResouce::Base. For more informations see the ActiveResouce documentation.
30
+
31
+ ## License
32
+
33
+ This code is free to be used under the terms of the [MIT license][mit].
34
+
35
+ ## Contact
36
+
37
+ Comments are welcome. Send your feedback through [this page][co]
38
+
39
+ ## Authors
40
+
41
+ [Marcos Tapajós][mt]
42
+
43
+ ## Shameless advertisement
44
+
45
+ This plugin is brought to you by [Improve It][ii].
46
+
47
+ [![Improve It][logo]][ii]
48
+
49
+ [logo]: http://www.improveit.com.br/images/logo/logo_improve_it_screen.gif "Improve It"
50
+
51
+ [mt]: http://www.improveit.com.br/en/company/tapajos
52
+ [ii]: http://www.improveit.com.br/en
53
+ [co]: http://www.improveit.com.br/en/contact
54
+ [mit]: http://www.opensource.org/licenses/mit-license.php
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rake'
2
+ require 'rubygems'
3
+ require 'rake/rdoctask'
4
+ require 'rake/testtask'
5
+ require 'spec/rake/spectask'
6
+ require "date"
7
+ require "fileutils"
8
+ require "rubygems"
9
+ require "rake/gempackagetask"
10
+
11
+ VERSION = "0.6"
12
+
13
+ highrise_gemspec = Gem::Specification.new do |s|
14
+ s.name = "highrise"
15
+ s.version = VERSION
16
+ s.platform = Gem::Platform::RUBY
17
+ s.has_rdoc = true
18
+ s.extra_rdoc_files = ["README.mkdn"]
19
+ s.summary = "Find awesome stuff"
20
+ s.description = s.summary
21
+ s.authors = ["Marcos Tapajós"]
22
+ s.email = "tapajos@improveit.com.br"
23
+ s.homepage = "http://www.improveit.com.br/en/company/tapajos"
24
+ s.require_path = "lib"
25
+ s.autorequire = "highrise"
26
+ s.files = %w(README.mkdn Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
27
+ end
28
+
29
+ Rake::GemPackageTask.new(highrise_gemspec) do |pkg|
30
+ pkg.gem_spec = highrise_gemspec
31
+ end
32
+
33
+ namespace :gem do
34
+ namespace :spec do
35
+ desc "Update highrise.gemspec"
36
+ task :generate do
37
+ File.open("highrise.gemspec", "w") do |f|
38
+ f.puts(highrise_gemspec.to_ruby)
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ desc "Instal gem"
45
+ task :install => :package do
46
+ sh %{sudo gem install --local pkg/highrise-#{VERSION}}
47
+ end
48
+
49
+ desc 'Default: run unit tests.'
50
+ task :default => :spec
51
+
52
+ desc "Run all specs"
53
+ Spec::Rake::SpecTask.new do |t|
54
+ t.spec_files = FileList['spec/**/*_spec.rb']
55
+ t.spec_opts = ['--options', 'spec.opts']
56
+ end
@@ -0,0 +1,4 @@
1
+ module Highrise
2
+ class Base < ActiveResource::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Highrise
2
+ class Comment < Base
3
+ end
4
+ end
@@ -0,0 +1,13 @@
1
+ module Highrise
2
+ class Company < Subject
3
+ include Pagination
4
+
5
+ def self.find_all_across_pages_since(time)
6
+ find_all_across_pages(:params => { :since => time.to_s(:db).gsub(/[^\d]/, '') })
7
+ end
8
+
9
+ def people
10
+ Person.find(:all, :from => "/companies/#{id}/people.xml")
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module Highrise
2
+ class Email < Base
3
+ include Pagination
4
+
5
+ def comments
6
+ Comment.find(:all, :from => "/emails/#{email_id}/comments.xml")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ module Highrise
2
+ class Group < Base
3
+ end
4
+ end
@@ -0,0 +1,8 @@
1
+ module Highrise
2
+ class Kase < Subject
3
+ def close!
4
+ self.closed_at = Time.now.utc
5
+ save
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ module Highrise
2
+ class Membership < Base
3
+ end
4
+ end
@@ -0,0 +1,9 @@
1
+ module Highrise
2
+ class Note < Base
3
+ include Pagination
4
+
5
+ def comments
6
+ Comment.find(:all, :from => "/notes/#{id}/comments.xml")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ module Highrise
2
+ module Pagination
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def find_all_across_pages(options = {})
9
+ records = []
10
+ each(options) { |record| records << record }
11
+ records
12
+ end
13
+
14
+ def each(options = {})
15
+ options[:params] ||= {}
16
+ options[:params][:n] = 0
17
+
18
+ loop do
19
+ if (records = self.find(:all, options)).any?
20
+ records.each { |record| yield record }
21
+ options[:params][:n] += records.size
22
+ else
23
+ break # no people included on that page, thus no more people total
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ module Highrise
2
+ class Person < Subject
3
+ include Pagination
4
+
5
+ def self.find_all_across_pages_since(time)
6
+ find_all_across_pages(:params => { :since => time.to_s(:db).gsub(/[^\d]/, '') })
7
+ end
8
+
9
+ def company
10
+ Company.find(company_id) if company_id
11
+ end
12
+
13
+ def name
14
+ "#{first_name} #{last_name}".strip
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module Highrise
2
+ class Subject < Base
3
+ def notes
4
+ Note.find_all_across_pages(:from => "/#{self.class.collection_name}/#{id}/notes.xml")
5
+ end
6
+
7
+ def emails
8
+ Email.find_all_across_pages(:from => "/#{self.class.collection_name}/#{id}/emails.xml")
9
+ end
10
+
11
+ def upcoming_tasks
12
+ Task.find(:all, :from => "/#{self.class.collection_name}/#{id}/tasks.xml")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Highrise
2
+ class Task < Base
3
+ # find(:all, :from => :upcoming)
4
+ # find(:all, :from => :assigned)
5
+ # find(:all, :from => :completed)
6
+
7
+ def complete!
8
+ load_attributes_from_response(post(:complete))
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Highrise
2
+ class User < Base
3
+ def join(group)
4
+ Membership.create(:user_id => id, :group_id => group.id)
5
+ end
6
+ end
7
+ end
data/lib/highrise.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'active_resource'
3
+ require File.dirname(__FILE__) + '/highrise/pagination'
4
+ require File.dirname(__FILE__) + '/highrise/base'
5
+ require File.dirname(__FILE__) + '/highrise/subject'
6
+ require File.dirname(__FILE__) + '/highrise/comment'
7
+ require File.dirname(__FILE__) + '/highrise/company'
8
+ require File.dirname(__FILE__) + '/highrise/email'
9
+ require File.dirname(__FILE__) + '/highrise/group'
10
+ require File.dirname(__FILE__) + '/highrise/kase'
11
+ require File.dirname(__FILE__) + '/highrise/membership'
12
+ require File.dirname(__FILE__) + '/highrise/note'
13
+ require File.dirname(__FILE__) + '/highrise/person'
14
+ require File.dirname(__FILE__) + '/highrise/task'
15
+ require File.dirname(__FILE__) + '/highrise/user'
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Highrise::Base do
4
+
5
+ before(:each) do
6
+ @base = Highrise::Base.new
7
+ end
8
+
9
+ it "should be instance of ActiveResource::Base" do
10
+ @base.kind_of?(ActiveResource::Base).should be_true
11
+ end
12
+
13
+ end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Highrise::Comment do
4
+
5
+ before(:each) do
6
+ @comment = Highrise::Comment.new
7
+ end
8
+
9
+ it "should be instance of Highrise::Base" do
10
+ @comment.kind_of?(Highrise::Base).should be_true
11
+ end
12
+
13
+
14
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Highrise::Company do
4
+
5
+ before(:each) do
6
+ @company = Highrise::Company.new
7
+ end
8
+
9
+ it "should be instance of Highrise::Base" do
10
+ @company.kind_of?(Highrise::Base).should be_true
11
+ end
12
+
13
+ describe ".find_all_across_pages_since" do
14
+
15
+ it "should delegate to find_all_across_pages with correct params" do
16
+ time = Time.parse("Wed Jan 14 15:43:11 -0200 2009")
17
+ Highrise::Company.should_receive(:find_all_across_pages).with({:params=>{:since=>"20090114154311"}}).and_return("result")
18
+ Highrise::Company.find_all_across_pages_since(time).should == "result"
19
+ end
20
+
21
+ end
22
+
23
+ describe "people" do
24
+
25
+ it "should delegate to Highrise::Person.find with correct params" do
26
+ @company.should_receive(:id).and_return(1)
27
+ Highrise::Person.should_receive(:find).with(:all, {:from=>"/companies/1/people.xml"}).and_return("people")
28
+ @company.people.should == "people"
29
+ end
30
+
31
+ end
32
+
33
+
34
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Highrise::Email do
4
+
5
+ before(:each) do
6
+ @mail = Highrise::Email.new
7
+ end
8
+
9
+ it "should be instance of Highrise::Base" do
10
+ @mail.kind_of?(Highrise::Base).should be_true
11
+ end
12
+
13
+ describe "comments" do
14
+
15
+ it "should delegate to Highrise::Comment.find with correct params" do
16
+ @mail.should_receive(:email_id).and_return(1)
17
+ Highrise::Comment.should_receive(:find).with(:all, {:from=>"/emails/1/comments.xml"}).and_return("comments")
18
+ @mail.comments.should == "comments"
19
+ end
20
+
21
+ end
22
+
23
+
24
+
25
+ end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Highrise::Group do
4
+
5
+ before(:each) do
6
+ @group = Highrise::Group.new
7
+ end
8
+
9
+ it "should be instance of Highrise::Base" do
10
+ @group.kind_of?(Highrise::Base).should be_true
11
+ end
12
+
13
+
14
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Highrise::Kase do
4
+
5
+ before(:each) do
6
+ @kase = Highrise::Kase.new
7
+ end
8
+
9
+ it "should be instance of Highrise::Subject" do
10
+ @kase.kind_of?(Highrise::Subject).should be_true
11
+ end
12
+
13
+ describe ".close!" do
14
+
15
+ it "should set close date anda save" do
16
+ time = Time.parse("Wed Jan 14 15:43:11 -0200 2009")
17
+ Time.should_receive(:now).and_return(time)
18
+ @kase.should_receive(:closed_at=).with(time.utc)
19
+ @kase.should_receive(:save)
20
+ @kase.close!
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Highrise::Membership do
4
+
5
+ before(:each) do
6
+ @member = Highrise::Membership.new
7
+ end
8
+
9
+ it "should be instance of Highrise::Base" do
10
+ @member.kind_of?(Highrise::Base).should be_true
11
+ end
12
+
13
+
14
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Highrise::Note do
4
+
5
+ before(:each) do
6
+ @note = Highrise::Note.new
7
+ end
8
+
9
+ it "should be instance of Highrise::Base" do
10
+ @note.kind_of?(Highrise::Base).should be_true
11
+ end
12
+
13
+ describe "comments" do
14
+
15
+ it "should delegate to Highrise::Comment.find with correct params" do
16
+ @note.should_receive(:id).and_return(1)
17
+ Highrise::Comment.should_receive(:find).with(:all, {:from=>"/notes/1/comments.xml"}).and_return("comments")
18
+ @note.comments.should == "comments"
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Highrise::Pagination do
4
+
5
+ it "should be tested"
6
+
7
+ end
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Highrise::Person do
4
+
5
+ before(:each) do
6
+ @person = Highrise::Person.new
7
+ end
8
+
9
+ it "should be instance of Highrise::Subject" do
10
+ @person.kind_of?(Highrise::Subject).should be_true
11
+ end
12
+
13
+ describe ".find_all_across_pages_since" do
14
+
15
+ it "should delegate to find_all_across_pages with correct params" do
16
+ time = Time.parse("Wed Jan 14 15:43:11 -0200 2009")
17
+ Highrise::Person.should_receive(:find_all_across_pages).with({:params=>{:since=>"20090114154311"}}).and_return("result")
18
+ Highrise::Person.find_all_across_pages_since(time).should == "result"
19
+ end
20
+
21
+ end
22
+
23
+ describe ".company" do
24
+
25
+ it "should return nil when doesn't have company_id" do
26
+ @person.should_receive(:company_id).and_return(nil)
27
+ @person.company.should be_nil
28
+ end
29
+
30
+ it "should delegate to Highrise::Company when have company_id" do
31
+ @person.should_receive(:company_id).at_least(2).times.and_return(1)
32
+ Highrise::Company.should_receive(:find).with(1).and_return("company")
33
+ @person.company.should == "company"
34
+ end
35
+
36
+ end
37
+
38
+ describe ".name" do
39
+
40
+ it "should concat fist_name with last_name and strip" do
41
+ @person.should_receive(:first_name).and_return("Marcos")
42
+ @person.should_receive(:last_name).and_return("Tapajós ")
43
+ @person.name.should == "Marcos Tapajós"
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Highrise::Subject do
4
+
5
+ before(:each) do
6
+ @subject = Highrise::Subject.new
7
+ end
8
+
9
+ it "should be instance of Highrise::Base" do
10
+ @subject.kind_of?(Highrise::Base).should be_true
11
+ end
12
+
13
+ describe ".notes" do
14
+
15
+ it "should delegate to Highrise::Note with correct params" do
16
+ @subject.should_receive(:id).and_return(1)
17
+ Highrise::Note.should_receive(:find_all_across_pages).with({:from=>"/subjects/1/notes.xml"}).and_return("notes")
18
+ @subject.notes.should == "notes"
19
+ end
20
+
21
+ end
22
+
23
+ describe ".emails" do
24
+
25
+ it "should delegate to Highrise::Email with correct params" do
26
+ @subject.should_receive(:id).and_return(1)
27
+ Highrise::Email.should_receive(:find_all_across_pages).with({:from=>"/subjects/1/emails.xml"}).and_return("emails")
28
+ @subject.emails.should == "emails"
29
+ end
30
+
31
+ end
32
+
33
+ describe ".upcoming_tasks" do
34
+
35
+ it "should delegate to Highrise::Task with correct params" do
36
+ @subject.should_receive(:id).and_return(1)
37
+ Highrise::Task.should_receive(:find).with(:all, {:from=>"/subjects/1/tasks.xml"}).and_return("tasks")
38
+ @subject.upcoming_tasks.should == "tasks"
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Highrise::Task do
4
+
5
+ before(:each) do
6
+ @task = Highrise::Task.new
7
+ end
8
+
9
+ it "should be instance of Highrise::Base" do
10
+ @task.kind_of?(Highrise::Base).should be_true
11
+ end
12
+
13
+ describe ".complete!" do
14
+
15
+ it "should delegate to load_attributes_from_response" do
16
+ @task.should_receive(:load_attributes_from_response).with("post")
17
+ @task.should_receive(:post).with(:complete).and_return("post")
18
+ @task.complete!
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Highrise::User do
4
+
5
+ before(:each) do
6
+ @user = Highrise::User.new
7
+ end
8
+
9
+ it "should be instance of Highrise::Base" do
10
+ @user.kind_of?(Highrise::Base).should be_true
11
+ end
12
+
13
+ def join(group)
14
+ Membership.create(:user_id => id, :group_id => group.id)
15
+ end
16
+
17
+ describe ".joind" do
18
+
19
+ it "should delegate to Highrise::Membership.create" do
20
+ group_mock = mock("group")
21
+ group_mock.should_receive(:id).and_return(2)
22
+ @user.should_receive(:id).and_return(1)
23
+ Highrise::Membership.should_receive(:create).with({:user_id=>1, :group_id=>2})
24
+ @user.join(group_mock)
25
+ end
26
+
27
+ end
28
+
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tapajos-highrise
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.6"
5
+ platform: ruby
6
+ authors:
7
+ - "Marcos Tapaj\xC3\xB3s"
8
+ autorequire: highrise
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-14 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Find awesome stuff
17
+ email: tapajos@improveit.com.br
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.mkdn
24
+ files:
25
+ - README.mkdn
26
+ - Rakefile
27
+ - lib/highrise
28
+ - lib/highrise/base.rb
29
+ - lib/highrise/comment.rb
30
+ - lib/highrise/company.rb
31
+ - lib/highrise/email.rb
32
+ - lib/highrise/group.rb
33
+ - lib/highrise/kase.rb
34
+ - lib/highrise/membership.rb
35
+ - lib/highrise/note.rb
36
+ - lib/highrise/pagination.rb
37
+ - lib/highrise/person.rb
38
+ - lib/highrise/subject.rb
39
+ - lib/highrise/task.rb
40
+ - lib/highrise/user.rb
41
+ - lib/highrise.rb
42
+ - spec/highrise
43
+ - spec/highrise/base_spec.rb
44
+ - spec/highrise/comment_spec.rb
45
+ - spec/highrise/company_spec.rb
46
+ - spec/highrise/email_spec.rb
47
+ - spec/highrise/group_spec.rb
48
+ - spec/highrise/kase_spec.rb
49
+ - spec/highrise/membership_spec.rb
50
+ - spec/highrise/note_spec.rb
51
+ - spec/highrise/pagination_spec.rb
52
+ - spec/highrise/person_spec.rb
53
+ - spec/highrise/subject_spec.rb
54
+ - spec/highrise/task_spec.rb
55
+ - spec/highrise/user_spec.rb
56
+ has_rdoc: true
57
+ homepage: http://www.improveit.com.br/en/company/tapajos
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.2.0
79
+ signing_key:
80
+ specification_version: 2
81
+ summary: Find awesome stuff
82
+ test_files: []
83
+