kmayer-highrise 0.13.0 → 1.0.1

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.
@@ -1,4 +1,4 @@
1
- # Highrise (0.12.0)
1
+ # Highrise (1.0)
2
2
 
3
3
  ## What is it?
4
4
 
@@ -14,10 +14,8 @@ All these classes are inherited from ActiveResouce::Base. Refer to the [ActiveRe
14
14
 
15
15
  ### Dependencies
16
16
 
17
- * ActiveResorce >= 2.2.2
17
+ * ActiveResorce >= 2.1
18
18
  * ActiveSupport >= 2.1
19
- * Curb
20
- * Hpricot
21
19
 
22
20
  ### Configure your key
23
21
 
@@ -33,7 +31,7 @@ or
33
31
 
34
32
  and, if you want [caching][c]:
35
33
 
36
- Highrise::Base.connection.cache_store= <your normal ActiveSupport::Caching options>
34
+ Highrise::Base.cache_store= <your normal ActiveSupport::Caching options>
37
35
 
38
36
  If you are using this in a Rails application, putting this code in a config/initializers/highrise.rb
39
37
  file is recommended. See config_initializers_highrise.rb in the examples/ directory.
data/Rakefile CHANGED
@@ -27,10 +27,8 @@ Highrise::Base.site = 'http://your_site.highrisehq.com/'
27
27
  Highrise::Base.user = 'your_api_auth_token'
28
28
  }
29
29
  gemspec.authors = ["Marcos Tapajós", "Ken Mayer"]
30
- gemspec.add_dependency('activeresource', '>=2.2')
31
- gemspec.add_dependency('activesupport', '>=2.1')
32
- gemspec.add_dependency('curb')
33
- gemspec.add_dependency('hpricot')
30
+ gemspec.add_dependency('activeresource', '>= 2.1')
31
+ gemspec.add_dependency('activesupport', '>= 2.1')
34
32
  end
35
33
  rescue LoadError
36
34
  puts "Jeweler not available. Install it with: sudo gem install jeweler -s http://gems.github.com"
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 13
3
- :patch: 0
4
- :major: 0
2
+ :minor: 0
3
+ :patch: 1
4
+ :major: 1
@@ -7,6 +7,6 @@ if Rails.env != 'test' then
7
7
  Highrise::Base.site = 'https://my_fancy_auth_token@example.com.i'
8
8
  end
9
9
  # The cache store can be anything that ActiveSupport can handle
10
- Highrise::Base.connection.cache_store = ActiveSupport::Cache.lookup_store :mem_cache_store
11
- Highrise::Base.connection.store_options = { :expires_in => 60.seconds }
10
+ Highrise::Base.cache_store = ActiveSupport::Cache.lookup_store :mem_cache_store
11
+ Highrise::Base.store_options = { :expires_in => 60.seconds }
12
12
  end
@@ -3,7 +3,7 @@ require 'pp'
3
3
 
4
4
  Highrise::Base.site = 'https://yoursite.highrisehq.com'
5
5
  Highrise::Base.user = 'xxx'
6
- Highrise::Base.connection.cache_store = :memory_store
6
+ Highrise::Base.cache_store = :memory_store
7
7
 
8
8
  @tags = Highrise::Tag.find(:all)
9
9
 
@@ -1,12 +1,15 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{highrise}
5
- s.version = "0.13.0"
8
+ s.version = "1.0.1"
6
9
 
7
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
11
  s.authors = ["Marcos Tapaj\303\263s", "Ken Mayer"]
9
- s.date = %q{2009-05-29}
12
+ s.date = %q{2009-09-02}
10
13
  s.description = %q{
11
14
  Based on the original API module from DHH, http://developer.37signals.com/highrise/, this
12
15
  gem is a cleaned up, tested version of the same. Contributors have added support for tags
@@ -40,8 +43,6 @@ Highrise::Base.user = 'your_api_auth_token'
40
43
  "lib/highrise/base.rb",
41
44
  "lib/highrise/comment.rb",
42
45
  "lib/highrise/company.rb",
43
- "lib/highrise/curlhelper.rb",
44
- "lib/highrise/curly.rb",
45
46
  "lib/highrise/email.rb",
46
47
  "lib/highrise/group.rb",
47
48
  "lib/highrise/kase.rb",
@@ -57,17 +58,13 @@ Highrise::Base.user = 'your_api_auth_token'
57
58
  "spec/cachable_spec.rb",
58
59
  "spec/highrise/base_spec.rb",
59
60
  "spec/highrise/comment_spec.rb",
60
- "spec/highrise/companies/16883216.html",
61
61
  "spec/highrise/company_spec.rb",
62
- "spec/highrise/curlhelper_spec.rb",
63
- "spec/highrise/curly_spec.rb",
64
62
  "spec/highrise/email_spec.rb",
65
63
  "spec/highrise/group_spec.rb",
66
64
  "spec/highrise/kase_spec.rb",
67
65
  "spec/highrise/membership_spec.rb",
68
66
  "spec/highrise/note_spec.rb",
69
67
  "spec/highrise/pagination_spec.rb",
70
- "spec/highrise/people/16887003.html",
71
68
  "spec/highrise/person_spec.rb",
72
69
  "spec/highrise/subject_spec.rb",
73
70
  "spec/highrise/tag_spec.rb",
@@ -80,15 +77,13 @@ Highrise::Base.user = 'your_api_auth_token'
80
77
  s.homepage = %q{http://github.com/kmayer/highrise}
81
78
  s.rdoc_options = ["--charset=UTF-8"]
82
79
  s.require_paths = ["lib"]
83
- s.rubygems_version = %q{1.3.3}
80
+ s.rubygems_version = %q{1.3.5}
84
81
  s.summary = %q{Ruby wrapper around Highrise API}
85
82
  s.test_files = [
86
83
  "spec/cachable_spec.rb",
87
84
  "spec/highrise/base_spec.rb",
88
85
  "spec/highrise/comment_spec.rb",
89
86
  "spec/highrise/company_spec.rb",
90
- "spec/highrise/curlhelper_spec.rb",
91
- "spec/highrise/curly_spec.rb",
92
87
  "spec/highrise/email_spec.rb",
93
88
  "spec/highrise/group_spec.rb",
94
89
  "spec/highrise/kase_spec.rb",
@@ -111,20 +106,14 @@ Highrise::Base.user = 'your_api_auth_token'
111
106
  s.specification_version = 3
112
107
 
113
108
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
114
- s.add_runtime_dependency(%q<activeresource>, [">= 2.2"])
109
+ s.add_runtime_dependency(%q<activeresource>, [">= 2.1"])
115
110
  s.add_runtime_dependency(%q<activesupport>, [">= 2.1"])
116
- s.add_runtime_dependency(%q<curb>, [">= 0"])
117
- s.add_runtime_dependency(%q<hpricot>, [">= 0"])
118
111
  else
119
- s.add_dependency(%q<activeresource>, [">= 2.2"])
112
+ s.add_dependency(%q<activeresource>, [">= 2.1"])
120
113
  s.add_dependency(%q<activesupport>, [">= 2.1"])
121
- s.add_dependency(%q<curb>, [">= 0"])
122
- s.add_dependency(%q<hpricot>, [">= 0"])
123
114
  end
124
115
  else
125
- s.add_dependency(%q<activeresource>, [">= 2.2"])
116
+ s.add_dependency(%q<activeresource>, [">= 2.1"])
126
117
  s.add_dependency(%q<activesupport>, [">= 2.1"])
127
- s.add_dependency(%q<curb>, [">= 0"])
128
- s.add_dependency(%q<hpricot>, [">= 0"])
129
118
  end
130
119
  end
@@ -9,9 +9,7 @@
9
9
  #
10
10
  # module CachedResource
11
11
  # class Base < ActiveResource::Base
12
- # end
13
- # class ActiveResource::Connection
14
- # include Cachable
12
+ # include ::Cachable
15
13
  # end
16
14
  # end
17
15
  #
@@ -23,14 +21,14 @@
23
21
  # these stores
24
22
  #
25
23
  # === Configuration examples ('off' is the default):
26
- # CachedResource.connection.cache_store = ActiveSupport::Cache.lookup_store :memory_store
27
- # CachedResource.connection.cache_store = ActiveSupport::Cache.lookup_store :file_store, "/path/to/cache/directory"
28
- # CachedResource.connection.cache_store = ActiveSupport::Cache.lookup_store :drb_store, "druby://localhost:9192"
29
- # CachedResource.connection.cache_store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost"
30
- # CachedResource.connection.cache_store = MyOwnStore.new("parameter")
24
+ # CachedResource.cache_store = ActiveSupport::Cache.lookup_store :memory_store
25
+ # CachedResource.cache_store = ActiveSupport::Cache.lookup_store :file_store, "/path/to/cache/directory"
26
+ # CachedResource.cache_store = ActiveSupport::Cache.lookup_store :drb_store, "druby://localhost:9192"
27
+ # CachedResource.cache_store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost"
28
+ # CachedResource.cache_store = MyOwnStore.new("parameter")
31
29
  #
32
30
  # === If you are using a store that has write options, you can set them
33
- # CachedResource.connection.store_options = { :expires_in => 60.seconds }
31
+ # CachedResource.store_options = { :expires_in => 60.seconds }
34
32
  #
35
33
  # Note: To ensure that caching is turned off, set CachedResource.connection.cache_store = nil
36
34
  #
@@ -38,13 +36,16 @@
38
36
 
39
37
  module Cachable
40
38
  def self.included(base)
39
+ base.extend ClassMethods
41
40
  base.class_eval do
42
- include InstanceMethods
43
- alias_method_chain :get, :cache
41
+ class << self
42
+ alias_method_chain :find_every, :cache
43
+ alias_method_chain :find_single, :cache
44
+ end
44
45
  end
45
46
  end
46
47
 
47
- module InstanceMethods
48
+ module ClassMethods
48
49
  attr_writer :cache_store, :store_options
49
50
 
50
51
  def cache_store
@@ -61,9 +62,19 @@ module Cachable
61
62
 
62
63
  private
63
64
 
64
- def get_with_cache(path, headers = {})
65
- return get_without_cache(path, headers) unless is_caching?
66
- fetch(path) { get_without_cache(path, headers) }
65
+ # A little hacky -- we need to intercept the finds, but not get too deep inside the connection
66
+ def find_every_with_cache(options)
67
+ return find_every_without_cache(options) unless is_caching?
68
+ prefix_options, query_options = split_options(options[:params])
69
+ path = collection_path(prefix_options, query_options)
70
+ fetch(path) { find_every_without_cache(options)}
71
+ end
72
+
73
+ def find_single_with_cache(scope, options)
74
+ return find_single_without_cache(scope, options) unless is_caching?
75
+ prefix_options, query_options = split_options(options[:params])
76
+ path = element_path(scope, prefix_options, query_options)
77
+ fetch(path) { find_single_without_cache(scope, options)}
67
78
  end
68
79
 
69
80
  def cache_key(*args)
@@ -1,11 +1,7 @@
1
1
  require 'active_resource'
2
- require 'activesupport'
3
- require 'active_support/basic_object'
4
2
 
5
3
  require File.dirname(__FILE__) + '/highrise/base'
6
4
  require File.dirname(__FILE__) + '/highrise/pagination'
7
- require File.dirname(__FILE__) + '/highrise/curly'
8
- require File.dirname(__FILE__) + '/highrise/curlhelper'
9
5
  require File.dirname(__FILE__) + '/highrise/taggable'
10
6
  require File.dirname(__FILE__) + '/highrise/subject'
11
7
  require File.dirname(__FILE__) + '/highrise/comment'
@@ -2,8 +2,6 @@ require File.dirname(__FILE__) + '/../cachable'
2
2
 
3
3
  module Highrise
4
4
  class Base < ActiveResource::Base
5
- end
6
- class ActiveResource::Connection
7
- include Cachable
5
+ include ::Cachable
8
6
  end
9
7
  end
@@ -15,6 +15,12 @@ module Highrise
15
15
  "#{first_name rescue ''} #{last_name rescue ''}".strip
16
16
  end
17
17
 
18
+ def address
19
+ contact_data.addresses.first
20
+ end
21
+
22
+ def web_address
23
+ contact_data.web_addresses.first
24
+ end
18
25
  end
19
-
20
26
  end
@@ -1,33 +1,17 @@
1
1
  module Highrise
2
- module Taggable
3
-
4
- # thanks for the user Inka, http://forum.37signals.com/highrise/forums/15/topics/1312?page=2
5
-
2
+ module Taggable
3
+ def tags
4
+ self.get(:tags)
5
+ end
6
6
  def tag!(tag_name)
7
7
  self.post(:tags, :name => tag_name) unless tag_name.blank?
8
- end
9
-
8
+ end
10
9
  def untag!(tag_name)
11
- to_delete = self.tags.find{|t| t.name==tag_name} unless tag_name.blank?
12
- self.untag_id!(to_delete.id) unless to_delete.nil?
13
- end
14
-
10
+ to_delete = self.tags.find{|t| t['name'] == tag_name} unless tag_name.blank?
11
+ self.untag_id!(to_delete['id']) unless to_delete.nil?
12
+ end
15
13
  def untag_id!(tag_id)
16
14
  self.delete("tags/#{tag_id}")
17
15
  end
18
-
19
- def tags
20
- tags = []
21
- get_document.search("#show_tags a").each{ |a|
22
- tags << Highrise::Tag.new(:id => a['href'].gsub(/.*\//, ''), :name => a.inner_html) if a['class'] == "grey tag"
23
- }
24
- tags
25
- end
26
-
27
- def get_document
28
- @curl_helper ||= CurlHelper.new
29
- @doc = @curl_helper.get_document_from_id("#{self.class.collection_name}/#{self.id}")
30
- end
31
-
32
16
  end
33
17
  end
@@ -3,44 +3,42 @@ require File.dirname(__FILE__) + '/spec_helper'
3
3
  describe Highrise::Base, "class configuration" do
4
4
  before(:each) do
5
5
  Highrise::Base.site = 'http://example.com.i:3000'
6
- @connection = Highrise::Base.connection
7
6
  end
8
7
 
9
8
  it "should tell us if caching is active" do
10
- @connection.cache_store = ActiveSupport::Cache.lookup_store :memory_store
11
- @connection.is_caching?.should == true
9
+ Highrise::Base.cache_store = ActiveSupport::Cache.lookup_store :memory_store
10
+ Highrise::Base.is_caching?.should == true
12
11
  end
13
12
 
14
13
  it "should tell us if caching is not active" do
15
- @connection.cache_store = nil
16
- @connection.is_caching?.should == false
14
+ Highrise::Base.cache_store = nil
15
+ Highrise::Base.is_caching?.should == false
17
16
  end
18
17
  end
19
18
 
20
19
  describe Highrise::Base do
21
20
  before(:all) do
22
21
  Highrise::Base.site = 'http://example.com.i:3000'
23
- @connection = Highrise::Base.connection
24
- @connection.cache_store = ActiveSupport::Cache.lookup_store :memory_store
22
+ Highrise::Base.cache_store = ActiveSupport::Cache.lookup_store :memory_store
25
23
  end
26
24
 
27
25
  after(:all) do
28
- @connection.cache_store = :none
26
+ Highrise::Base.cache_store = :none
29
27
  end
30
28
 
31
29
  before(:each) do
32
30
  @thing = Highrise::Base.new
33
31
  @key = :key
34
- @connection.stub!(:cache_key).and_return(@key)
32
+ Highrise::Base.stub!(:cache_key).and_return(@key)
35
33
  end
36
34
 
37
35
  context "when a cached response is available" do
38
36
  before(:each) do
39
- @connection.cache_store.write(@key, @thing.attributes)
37
+ Highrise::Base.cache_store.write(@key, @thing)
40
38
  end
41
39
 
42
40
  it "should NOT make a request to the RESTful server" do
43
- ActiveResource::Connection.should_not_receive(:get_without_cache)
41
+ Highrise::Base.should_not_receive(:find_single_without_cache)
44
42
  Highrise::Base.find(1)
45
43
  end
46
44
 
@@ -51,18 +49,18 @@ describe Highrise::Base do
51
49
 
52
50
  context "when a cached response is NOT available" do
53
51
  before(:each) do
54
- @connection.cache_store.delete(@key)
52
+ Highrise::Base.cache_store.delete(@key)
55
53
  end
56
54
 
57
55
  it "SHOULD perform an ARes request" do
58
- @connection.should_receive(:get_without_cache).and_return(@thing.attributes)
56
+ Highrise::Base.should_receive(:find_single_without_cache).and_return(@thing)
59
57
  Highrise::Base.find(1)
60
58
  end
61
59
 
62
60
  it "should cache the response using the caching key" do
63
- @connection.should_receive(:get_without_cache).and_return(@thing.attributes)
61
+ Highrise::Base.should_receive(:find_single_without_cache).and_return(@thing)
64
62
  Highrise::Base.find(1)
65
- @connection.cache_store.read(@key).should == @thing.attributes
63
+ Highrise::Base.cache_store.read(@key).should == @thing
66
64
  end
67
65
  end
68
66
  end
@@ -4,11 +4,11 @@ describe Highrise::Company do
4
4
 
5
5
  before(:each) do
6
6
  Highrise::Base.site = 'http://example.com.i:3000'
7
- @company = Highrise::Company.new
7
+ @company = Highrise::Company.new(:id => 1)
8
8
  returning @tags = [] do
9
- @tags << Highrise::Tag.new(:id => "414578", :name => "cliente")
10
- @tags << Highrise::Tag.new(:id => "414580", :name => "ged")
11
- @tags << Highrise::Tag.new(:id => "414579", :name => "iepc")
9
+ @tags << {'id' => "414578", 'name' => "cliente"}
10
+ @tags << {'id' => "414580", 'name' => "ged"}
11
+ @tags << {'id' => "414579", 'name' => "iepc"}
12
12
  end
13
13
  end
14
14
 
@@ -39,8 +39,7 @@ describe Highrise::Company do
39
39
  describe ".tags" do
40
40
 
41
41
  it "should return an array of all tags for that company." do
42
- file_path = File.dirname(__FILE__) + "/companies/16883216.html"
43
- @company.stub!(:get_document).and_return(Hpricot(File.open(file_path,"r"){|f| f.read}))
42
+ @company.should_receive(:get).with(:tags).and_return(@tags)
44
43
  @company.tags.should == @tags
45
44
  end
46
45
 
@@ -49,7 +48,7 @@ describe Highrise::Company do
49
48
  describe "tag!(tag_name)" do
50
49
 
51
50
  it "should create a tag for this company." do
52
- @company.should_receive(:post).with(:tags, :name => "client" ).at_least(1).times.and_return(true)
51
+ @company.should_receive(:post).with(:tags, :name => "client" ).and_return(true)
53
52
  @company.tag!("client").should be_true
54
53
  end
55
54
 
@@ -58,9 +57,8 @@ describe Highrise::Company do
58
57
  describe "untag!(tag_name)" do
59
58
 
60
59
  it "should delete a tag for this company." do
61
- file_path = File.dirname(__FILE__) + "/companies/16883216.html"
62
- @company.stub!(:get_document).and_return(Hpricot(File.open(file_path,"r"){|f| f.read}))
63
- @company.should_receive(:delete).with("tags/414578").at_least(1).times.and_return(true)
60
+ @company.should_receive(:get).with(:tags).and_return(@tags)
61
+ @company.should_receive(:delete).with("tags/414578").and_return(true)
64
62
  @company.untag!("cliente").should be_true
65
63
  end
66
64
 
@@ -4,10 +4,10 @@ describe Highrise::Person do
4
4
 
5
5
  before(:each) do
6
6
  Highrise::Base.site = 'http://example.com.i:3000'
7
- @person = Highrise::Person.new
7
+ @person = Highrise::Person.new(:id => 1)
8
8
  returning @tags = [] do
9
- @tags << Highrise::Tag.new(:id => "414578", :name => "cliente")
10
- @tags << Highrise::Tag.new(:id => "414587", :name => "walk")
9
+ @tags << {'id' => "414578", 'name' => "cliente"}
10
+ @tags << {'id' => "414587", 'name' => "walk"}
11
11
  end
12
12
  end
13
13
 
@@ -53,8 +53,7 @@ describe Highrise::Person do
53
53
  describe ".tags" do
54
54
 
55
55
  it "should return an array of all tags for that user." do
56
- file_path = File.dirname(__FILE__) + "/people/16887003.html"
57
- @person.stub!(:get_document).and_return(Hpricot(File.open(file_path,"r"){|f| f.read}))
56
+ @person.should_receive(:get).with(:tags).and_return(@tags)
58
57
  @person.tags.should == @tags
59
58
  end
60
59
 
@@ -63,7 +62,7 @@ describe Highrise::Person do
63
62
  describe "tag!(tag_name)" do
64
63
 
65
64
  it "should create a tag for this user." do
66
- @person.should_receive(:post).with(:tags, :name => "Forum_User" ).at_least(1).times.and_return(true)
65
+ @person.should_receive(:post).with(:tags, :name => "Forum_User" ).and_return(true)
67
66
  @person.tag!("Forum_User").should be_true
68
67
  end
69
68
 
@@ -72,9 +71,8 @@ describe Highrise::Person do
72
71
  describe "untag!(tag_name)" do
73
72
 
74
73
  it "should delete a tag for this user." do
75
- file_path = File.dirname(__FILE__) + "/people/16887003.html"
76
- @person.stub!(:get_document).and_return(Hpricot(File.open(file_path,"r"){|f| f.read}))
77
- @person.should_receive(:delete).with("tags/414578").at_least(1).times.and_return(true)
74
+ @person.should_receive(:get).with(:tags).and_return(@tags)
75
+ @person.should_receive(:delete).with("tags/414578").and_return(true)
78
76
  @person.untag!("cliente").should be_true
79
77
  end
80
78