kmayer-highrise 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.mkdn CHANGED
@@ -1,9 +1,17 @@
1
- # Highrise
1
+ # Highrise (0.8.0)
2
2
 
3
3
  ## What
4
4
 
5
5
  [Highrise][h] is a gem that provides an easy way to use the [Highrise API][api].
6
6
 
7
+ This gem provides a set of classes to access available information on [Highrise][h].
8
+
9
+ These are the list of classes:
10
+
11
+ Comment, Company, Email, Group, Case, Membership, Note, Person, Subject, Tag, Task and User.
12
+
13
+ All these classes are inherited of ActiveResouce::Base. For more informations see the [ActiveResouce][ar] documentation.
14
+
7
15
  ## Installing
8
16
 
9
17
  gem install kmayer-highrise
@@ -19,51 +27,60 @@
19
27
 
20
28
  require 'rubygems'
21
29
  require 'highrise'
30
+
22
31
  Highrise::Base.site = 'http://your_api:login@your_site.highrisehq.com/'
23
32
 
24
- ## Usage
33
+ or
25
34
 
26
- This gem provides a set of classes to access all available informations on [Highrise][h].
35
+ Highrise::Base.site = 'http://your_site.highrisehq.com'
36
+ Highrise::Base.user = 'api-auth-token'
27
37
 
28
- These are the list of classes:
38
+ and, if you want caching(!)
29
39
 
30
- Comment, Company, Email, Group, Case, Membership, Note, Person, Subject, Tag, Task and User.
40
+ Highrise::Base.connection.cache_store= <your normal ActiveSupport::Caching options>
41
+
42
+ ## Usage
31
43
 
32
- All these classes are inherited of ActiveResouce::Base. For more informations see the ActiveResouce documentation.
44
+ @tags = Highrise::Tag.find(:all)
45
+
46
+ @people = Highrise::Person.find_all_across_pages(:params => {:tag_id => 12345})
47
+
48
+ @person.tag!("VIP")
33
49
 
34
50
  ## License
35
51
 
36
52
  This code is free to be used under the terms of the [MIT license][mit].
37
53
 
38
- ## Contact
39
-
40
- Comments are welcome. Send your feedback through [this page][co]
54
+ ## Bugs, Issues, Kudos and Catcalls
41
55
 
42
- ## Authors
43
-
44
- [Marcos Tapajós][mt]
56
+ Comments are welcome. Send your feedback through the [issue tracker on GitHub][i]
45
57
 
46
58
  ## Contributors
47
59
 
60
+ * [Marcos Tapajós][mt]
48
61
  * [Nicolas Bianco][nb]
49
62
  * [Luis Gustavo][lg]
50
63
  * [Thiago Lelis][tl]
51
64
  * [Ken Mayer][km]
52
65
 
53
- ## Shameless advertisement
54
-
55
- (From the original author) This plugin is brought to you by [Improve It][ii].
66
+ ## Special Thanks
56
67
 
57
- [![Improve It][logo]][ii]
68
+ [Rails Envy Podcast Episode #77][re] for mentioning
69
+ [How to Cache Anything With ActiveSupport][rh] on the very *day* I started writing the cache code. Thank you, Rein
70
+ for writing an excellent tutorial and [posting your source][e] on GitHub.
58
71
 
59
- [logo]:http://www.improveit.com.br/images/logo/logo_improve_it_screen.gif "Improve It"
72
+ [ar]: http://api.rubyonrails.org/classes/ActiveResource/Base.html
60
73
  [mt]: http://www.improveit.com.br/en/company/tapajos
61
74
  [ii]: http://www.improveit.com.br/en
62
75
  [co]: http://github.com/kmayer
63
76
  [mit]:http://www.opensource.org/licenses/mit-license.php
64
77
  [h]: http://www.highrisehq.com/
78
+ [i]: http://github.com/kmayer/highrise/issues
65
79
  [km]: http://github.com/kmayer
66
80
  [lg]: http://github.com/luisbebop
67
81
  [nb]: http://github.com/slainer86
68
82
  [tl]: http://github.com/ThiagoLelis
69
- [api]: http://developer.37signals.com/highrise
83
+ [api]: http://developer.37signals.com/highrise
84
+ [re]: http://www.railsenvy.com/2009/4/29/rails-envy-podcast-episode-077-04-29-2009
85
+ [rh]: http://reinh.com/blog/2009/04/27/how-to-cache-anything-with-activesupport.html
86
+ [e]: http://github.com/primedia/endeca/tree/master
data/Rakefile CHANGED
@@ -27,9 +27,13 @@ Configure by adding the following:
27
27
  require 'highrise'
28
28
  Highrise::Base.site = 'http://your_site.highrisehq.com/'
29
29
  Highrise::Base.user = 'your_api_auth_token'q
30
+ Highrise::Base.connection.cache_store = :memory_store # for caching
30
31
  }
31
32
  gemspec.authors = ["Marcos Tapajós", "Ken Mayer"]
32
- gemspec.add_dependency('activeresource', '>=2.2.2')
33
+ gemspec.add_dependency('activeresource', '>=2.2')
34
+ gemspec.add_dependency('activesupport', '>=2.1')
35
+ gemspec.add_dependency('curb')
36
+ gemspec.add_dependency('hpricot')
33
37
  end
34
38
  rescue LoadError
35
39
  puts "Jeweler not available. Install it with: sudo gem install jeweler -s http://gems.github.com"
@@ -41,5 +45,5 @@ task :default => :spec
41
45
  desc "Run all specs"
42
46
  Spec::Rake::SpecTask.new do |t|
43
47
  t.spec_files = FileList['spec/**/*_spec.rb']
44
- t.spec_opts = ['--options', 'spec.opts']
48
+ t.spec_opts = ['--options', 'spec/spec.opts']
45
49
  end
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
+ :patch: 0
2
3
  :major: 0
3
- :minor: 7
4
- :patch: 1
4
+ :minor: 8
@@ -0,0 +1,31 @@
1
+ #
2
+ # Example of extending a class when you need to synthesize an attribute.
3
+ #
4
+ # Adds Highrise::Person.{phone,fax,email} to the Person class inside your
5
+ # module
6
+ #
7
+
8
+ module MyModule
9
+ include Highrise
10
+
11
+ Highrise::Person.class_eval do
12
+ class << self
13
+ def lookup(id, list, item, location)
14
+ module_eval <<-EOT
15
+ def #{id}
16
+ contact_data.#{list}.each do |i|
17
+ return i.#{item}.strip if i.location == "#{location}"
18
+ end
19
+ ''
20
+ end
21
+ EOT
22
+ end
23
+
24
+ private :lookup
25
+ end
26
+
27
+ lookup(:phone, 'phone_numbers', 'number', 'Work')
28
+ lookup(:fax, 'phone_numbers', 'number', 'Fax')
29
+ lookup(:email, 'email_addresses', 'address', 'Work')
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ require 'highrise'
2
+ require 'pp'
3
+
4
+ Highrise::Base.site = 'https://yoursite.highrisehq.com'
5
+ Highrise::Base.user = 'xxx'
6
+ Highrise::Base.connection.cache_store = :memory_store
7
+
8
+ @tags = Highrise::Tag.find(:all)
9
+
10
+ pp @tags
data/lib/cachable.rb ADDED
@@ -0,0 +1,65 @@
1
+ require 'digest/sha1'
2
+
3
+ # Caching is a way to speed up slow ActiveResource queries by keeping the result of
4
+ # an ActiveResource request around to be reused by subequest requests. Caching is
5
+ # turned off by default.
6
+ #
7
+ # == Usage
8
+ #
9
+ # require 'lib/cachable'
10
+ #
11
+ # module CachedResource
12
+ # class Base < ActiveResource::Base
13
+ # end
14
+ # include Cachable
15
+ # end
16
+ #
17
+ # == Caching stores
18
+ #
19
+ # All the caching stores from ActiveSupport::Cache are available to be used
20
+ # as backends for caching. See the Rails rdoc for more information on
21
+ # these stores
22
+ #
23
+ # Configuration examples ('off' is the default):
24
+ #
25
+ # CachedResource.connection.cache_store = :memory_store
26
+ # CachedResource.connection.cache_store = :file_store, "/path/to/cache/directory"
27
+ # CachedResource.connection.cache_store = :drb_store, "druby://localhost:9192"
28
+ # CachedResource.connection.cache_store = :mem_cache_store, "localhost"
29
+ # CachedResource.connection.cache_store = MyOwnStore.new("parameter")
30
+ #
31
+ # Note: To ensure that caching is turned off, set CachedResource.connection.cache_store = nil
32
+
33
+ module Cachable
34
+ def self.included(base)
35
+ ActiveResource::Connection.alias_method_chain :get, :cache
36
+ end
37
+ ActiveResource::Connection.class_eval do
38
+ def cache_store
39
+ @cache_store ||= nil
40
+ end
41
+
42
+ def cache_store=(store_option)
43
+ @cache_store = store_option.nil? ? nil : ActiveSupport::Cache.lookup_store(store_option)
44
+ end
45
+
46
+ def is_caching?
47
+ !@cache_store.nil?
48
+ end
49
+
50
+ private
51
+
52
+ def get_with_cache(path, headers = {})
53
+ return get_without_cache(path, headers) unless is_caching?
54
+ fetch(path) { get_without_cache(path, headers) }
55
+ end
56
+
57
+ def cache_key(*args)
58
+ Digest::SHA1.hexdigest args.to_s
59
+ end
60
+
61
+ def fetch(args, &block)
62
+ cache_store.fetch(cache_key(args), &block).dup
63
+ end
64
+ end
65
+ end
data/lib/highrise/base.rb CHANGED
@@ -1,4 +1,7 @@
1
+ require 'lib/cachable'
2
+
1
3
  module Highrise
2
4
  class Base < ActiveResource::Base
3
5
  end
4
- end
6
+ include Cachable
7
+ end
@@ -1,3 +1,8 @@
1
+ require 'hpricot'
2
+ require 'iconv'
3
+ require 'curb'
4
+ require 'uri'
5
+
1
6
  class Curly < ActiveSupport::BasicObject
2
7
  attr_reader :uri
3
8
 
data/lib/highrise.rb CHANGED
@@ -1,17 +1,13 @@
1
- require 'rubygems'
2
1
  require 'active_resource'
3
- require 'uri'
4
- require 'curb'
5
- gem 'activesupport', '>= 2.1'
2
+ require 'activesupport'
6
3
  require 'active_support/basic_object'
7
- require 'hpricot'
8
- require 'iconv'
9
4
 
5
+ require File.dirname(__FILE__) + '/highrise/base'
6
+ require File.dirname(__FILE__) + '/highrise/version'
10
7
  require File.dirname(__FILE__) + '/highrise/pagination'
11
8
  require File.dirname(__FILE__) + '/highrise/curly'
12
9
  require File.dirname(__FILE__) + '/highrise/curlhelper'
13
10
  require File.dirname(__FILE__) + '/highrise/taggable'
14
- require File.dirname(__FILE__) + '/highrise/base'
15
11
  require File.dirname(__FILE__) + '/highrise/subject'
16
12
  require File.dirname(__FILE__) + '/highrise/comment'
17
13
  require File.dirname(__FILE__) + '/highrise/company'
@@ -24,4 +20,3 @@ require File.dirname(__FILE__) + '/highrise/person'
24
20
  require File.dirname(__FILE__) + '/highrise/task'
25
21
  require File.dirname(__FILE__) + '/highrise/user'
26
22
  require File.dirname(__FILE__) + '/highrise/tag'
27
- require File.dirname(__FILE__) + '/highrise/version'
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::Base do
4
4
 
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Highrise::Base, "class configuration" do
4
+ before(:each) do
5
+ Highrise::Base.site = 'http://example.com.i:3000'
6
+ @connection = Highrise::Base.connection
7
+ end
8
+
9
+ it "should tell us if caching is active" do
10
+ @connection.cache_store = :memory_store
11
+ @connection.is_caching?.should == true
12
+ end
13
+
14
+ it "should tell us if caching is not active" do
15
+ @connection.cache_store = nil
16
+ @connection.is_caching?.should == false
17
+ end
18
+ end
19
+
20
+ describe Highrise::Base do
21
+ before(:all) do
22
+ Highrise::Base.site = 'http://example.com.i:3000'
23
+ @connection = Highrise::Base.connection
24
+ @connection.cache_store = :memory_store
25
+ end
26
+
27
+ after(:all) do
28
+ @connection.cache_store = nil
29
+ end
30
+
31
+ before(:each) do
32
+ @thing = Highrise::Base.new
33
+ @key = :key
34
+ @connection.should_receive(:cache_key).and_return(@key)
35
+ end
36
+
37
+ context "when a cached response is available" do
38
+ before(:each) do
39
+ @connection.cache_store.write(@key, @thing.attributes)
40
+ end
41
+
42
+ it "should NOT make a request to the RESTful server" do
43
+ ActiveResource::Connection.should_not_receive(:get_without_cache)
44
+ Highrise::Base.find(1)
45
+ end
46
+
47
+ it "should read from the cache" do
48
+ Highrise::Base.find(2).should == @thing
49
+ end
50
+ end
51
+
52
+ context "when a cached response is NOT available" do
53
+ before(:each) do
54
+ @connection.cache_store.delete(@key)
55
+ end
56
+
57
+ it "SHOULD perform an ARes request" do
58
+ @connection.should_receive(:get_without_cache).and_return(@thing.attributes)
59
+ Highrise::Base.find(3)
60
+ end
61
+
62
+ it "should cache the response using the caching key" do
63
+ @connection.should_receive(:get_without_cache).and_return(@thing.attributes)
64
+ Highrise::Base.find(4)
65
+ @connection.cache_store.read(@key).should == @thing.attributes
66
+ end
67
+ end
68
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::Comment do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::Company do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::CurlHelper do
4
4
  before do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Curly do
4
4
  before do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::Email do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::Group do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::Kase do
4
4
 
@@ -12,7 +12,7 @@ describe Highrise::Kase do
12
12
 
13
13
  describe ".close!" do
14
14
 
15
- it "should set close date anda save" do
15
+ it "should set close date and save" do
16
16
  time = Time.parse("Wed Jan 14 15:43:11 -0200 2009")
17
17
  Time.should_receive(:now).and_return(time)
18
18
  @kase.should_receive(:closed_at=).with(time.utc)
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::Membership do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::Note do
4
4
 
@@ -1,7 +1,10 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::Pagination do
4
4
 
5
- it "should be tested"
6
-
5
+ it "should be tested" do
6
+ Highrise::Person.should_receive(:find).with(:all,{:params=>{:n=>0}}).and_return(["people"])
7
+ Highrise::Person.should_receive(:find).with(:all,{:params=>{:n=>1}}).and_return([])
8
+ Highrise::Person.find_all_across_pages.should == ["people"]
9
+ end
7
10
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::Person do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::Subject do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::Tag do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::Task do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::User do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Highrise::VERSION do
4
4
  it "should return a version string" do
data/spec/spec.opts ADDED
@@ -0,0 +1,7 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
7
+ -rubygems
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../lib/highrise'
2
+
3
+ def turn_methods_public(classe, method_name = nil)
4
+ if method_name
5
+ classe.class_eval do
6
+ public method_name
7
+ end
8
+ else
9
+ turn_all_methods_public classe
10
+ end
11
+ end
12
+
13
+ def turn_all_methods_public(classe)
14
+ classe.class_eval do
15
+ private_instance_methods.each { |instance_method| public instance_method }
16
+ private_methods.each { |method| public_class_method method }
17
+ protected_instance_methods.each { |instance_method| public instance_method }
18
+ protected_methods.each { |method| public_class_method method }
19
+ end
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kmayer-highrise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Marcos Tapaj\xC3\xB3s"
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-04-30 00:00:00 -07:00
13
+ date: 2009-05-01 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -21,9 +21,39 @@ dependencies:
21
21
  requirements:
22
22
  - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: 2.2.2
24
+ version: "2.2"
25
25
  version:
26
- description: "Based on the original API module from DHH, http://developer.37signals.com/highrise/, this gem is a cleaned up, tested version of the same. Contributors have added support for tags which are not supported by the API directly Configure by adding the following: require 'highrise' Highrise::Base.site = 'http://your_site.highrisehq.com/' Highrise::Base.user = 'your_api_auth_token'q"
26
+ - !ruby/object:Gem::Dependency
27
+ name: activesupport
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "2.1"
35
+ version:
36
+ - !ruby/object:Gem::Dependency
37
+ name: curb
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: hpricot
48
+ type: :runtime
49
+ version_requirement:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ description: "Based on the original API module from DHH, http://developer.37signals.com/highrise/, this gem is a cleaned up, tested version of the same. Contributors have added support for tags which are not supported by the API directly Configure by adding the following: require 'highrise' Highrise::Base.site = 'http://your_site.highrisehq.com/' Highrise::Base.user = 'your_api_auth_token'q Highrise::Base.connection.cache_store = :memory_store # for caching"
27
57
  email: kmayer@bitwrangler.com
28
58
  executables: []
29
59
 
@@ -35,6 +65,9 @@ files:
35
65
  - README.mkdn
36
66
  - Rakefile
37
67
  - VERSION.yml
68
+ - examples/extending.rb
69
+ - examples/sample.rb
70
+ - lib/cachable.rb
38
71
  - lib/highrise.rb
39
72
  - lib/highrise/base.rb
40
73
  - lib/highrise/comment.rb
@@ -55,6 +88,7 @@ files:
55
88
  - lib/highrise/user.rb
56
89
  - lib/highrise/version.rb
57
90
  - spec/highrise/base_spec.rb
91
+ - spec/highrise/cachable_spec.rb
58
92
  - spec/highrise/comment_spec.rb
59
93
  - spec/highrise/companies/16883216.html
60
94
  - spec/highrise/company_spec.rb
@@ -73,6 +107,8 @@ files:
73
107
  - spec/highrise/task_spec.rb
74
108
  - spec/highrise/user_spec.rb
75
109
  - spec/highrise/version_spec.rb
110
+ - spec/spec.opts
111
+ - spec/spec_helper.rb
76
112
  has_rdoc: true
77
113
  homepage: http://github.com/kmayer/highrise
78
114
  post_install_message:
@@ -101,6 +137,7 @@ specification_version: 3
101
137
  summary: Ruby wrapper around Highrise API
102
138
  test_files:
103
139
  - spec/highrise/base_spec.rb
140
+ - spec/highrise/cachable_spec.rb
104
141
  - spec/highrise/comment_spec.rb
105
142
  - spec/highrise/company_spec.rb
106
143
  - spec/highrise/curlhelper_spec.rb
@@ -117,3 +154,6 @@ test_files:
117
154
  - spec/highrise/task_spec.rb
118
155
  - spec/highrise/user_spec.rb
119
156
  - spec/highrise/version_spec.rb
157
+ - spec/spec_helper.rb
158
+ - examples/extending.rb
159
+ - examples/sample.rb