peterosullivan-highrise 3.0.6 → 3.0.7

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- highrise (3.0.1)
4
+ peterosullivan-highrise (3.0.6)
5
5
  activeresource (~> 3.0)
6
6
 
7
7
  GEM
@@ -41,6 +41,6 @@ PLATFORMS
41
41
 
42
42
  DEPENDENCIES
43
43
  activeresource (~> 3.0)
44
- highrise!
44
+ peterosullivan-highrise!
45
45
  rake (= 0.8.7)
46
46
  rspec (~> 2.0.1)
data/README.md CHANGED
@@ -18,7 +18,7 @@ This fork is very close to the orginal gem. I have added a few features and shor
18
18
  ###Highrise Custom Fields read only (called "subject_datas" in the Highrise API)
19
19
 
20
20
  p = Highrise::Person.find(123)
21
- p.subject_data_fields #{"favourite_color"=>"red"}
21
+ p.subject_data_hash #{"favourite_color"=>"red"}
22
22
  p.field("FavouriteColor") #<Highrise::SubjectData:0xb5e3442c @attributes={"subject_field_label"=>"FavouriteColor", "id"=>12065552, "value"=>"red", "subject_field_id"=>123}, @prefix_options={}>
23
23
  p.favourite_color #"red"
24
24
 
data/lib/highrise.rb CHANGED
@@ -1,24 +1,35 @@
1
- require 'highrise/base'
2
- require 'highrise/pagination'
3
- require 'highrise/taggable'
4
- require 'highrise/searchable'
5
- require 'highrise/subject_data'
6
- require 'highrise/subject'
7
- require 'highrise/comment'
8
- require 'highrise/company'
9
- require 'highrise/email'
10
- require 'highrise/group'
11
- require 'highrise/kase'
12
- require 'highrise/membership'
13
- require 'highrise/note'
14
- require 'highrise/person'
15
- require 'highrise/task'
16
- require 'highrise/user'
17
- require 'highrise/tag'
18
- require 'highrise/deal'
19
- require 'highrise/account'
20
- require 'highrise/deal_category'
21
- require 'highrise/task_category'
22
- require 'highrise/party'
23
- require 'highrise/recording'
1
+ %w[
2
+ base
3
+ version
4
+ rfc822
5
+
6
+ pagination
7
+ taggable
8
+ searchable
9
+ has_subject_data
10
+
11
+ subject
12
+
13
+ comment
14
+ company
15
+ email
16
+ group
17
+ kase
18
+ membership
19
+ note
20
+ person
21
+ task
22
+ user
23
+ tag
24
+ deal
25
+ account
26
+ deal_category
27
+ task_category
28
+ party
29
+ recording
30
+ subject_field
31
+ subject_data
24
32
 
33
+ ].each do |lib|
34
+ require File.join(File.dirname(__FILE__), 'highrise', lib)
35
+ end
data/lib/highrise/base.rb CHANGED
@@ -16,8 +16,13 @@ module Highrise
16
16
  if method.to_s =~ /^find_(all_)?by_([_a-zA-Z]\w*)$/
17
17
  raise ArgumentError, "Dynamic finder method must take an argument." if args.empty?
18
18
  options = args.extract_options!
19
- resources = respond_to?(:find_all_across_pages) ? send(:find_all_across_pages, options) : send(:find, :all)
20
- resources.send($1 == 'all_' ? 'select' : 'detect') { |container| container.send($2) == args.first }
19
+ if respond_to? :search
20
+ resources = search $2 => args.first
21
+ $1 == 'all_' ? resources : resources.first
22
+ else
23
+ resources = respond_to?(:find_all_across_pages) ? find_all_across_pages(options) : find(:all)
24
+ resources.send($1 == 'all_' ? 'select' : 'detect') { |container| container.send($2) == args.first }
25
+ end
21
26
  else
22
27
  super
23
28
  end
@@ -12,4 +12,4 @@ module Highrise
12
12
  'Party'
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -0,0 +1,19 @@
1
+ module Highrise
2
+ module HasSubjectData
3
+
4
+ def subject_data_hash
5
+ if attributes.has_key?(:subject_datas)
6
+ Hash[subject_datas.map(&:attributes).map {|attrs| [attrs[:subject_field_label].to_s.underscore, attrs[:value]] }]
7
+ else
8
+ {}
9
+ end
10
+ end
11
+
12
+ def field(field_name)
13
+ (attributes["subject_datas"] || []).detect do |sd|
14
+ sd.subject_field_label == field_name.to_s
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -38,7 +38,8 @@ module Highrise
38
38
  options[:params][:n] = 0
39
39
 
40
40
  loop do
41
- if (records = self.find(:all, options)).try(:any?)
41
+ records = find(:all, options)
42
+ if records && records.any?
42
43
  records.each { |record| yield record }
43
44
  options[:params][:n] += records.size
44
45
  else
@@ -1,15 +1,9 @@
1
1
  module Highrise
2
2
  class Person < Subject
3
- require 'highrise/rfc822'
4
3
  include Pagination
5
4
  include Taggable
6
5
  include Searchable
7
- include SubjectData::Mixin
8
-
9
- def initialize(*args)
10
- super(*args)
11
- create_subject_fields_accessors
12
- end
6
+ include HasSubjectData
13
7
 
14
8
  def company
15
9
  Company.find(company_id) if company_id
@@ -58,16 +52,5 @@ module Highrise
58
52
  end
59
53
  end
60
54
 
61
- def create_subject_fields_accessors
62
- subject_data_fields.each do |subject_field_name, value|
63
- # for this instance only
64
- singleton_class.instance_eval do
65
- define_method subject_field_name do
66
- value
67
- end
68
- end
69
- end
70
- end
71
-
72
55
  end
73
56
  end
@@ -10,12 +10,13 @@ module Highrise
10
10
  # Available criteria are: city, state, country, zip, phone, email
11
11
  def search(options = {})
12
12
  raise ArgumentError, "cannot convert #{options}:#{options.class} to hash" if options.kind_of?(String)
13
- search_params = options.inject({}) { |h, (k, v)| h["criteria[#{k}]"] = v; h }
14
13
  # This might have to be changed in the future if other non-pagable resources become searchable
15
- if self.respond_to?(:find_all_across_pages)
16
- self.find_all_across_pages(:from => "/#{self.collection_name}/search.xml", :params => search_params)
14
+ options[:kind] ||= collection_name
15
+ find_options = {:from => "/parties/search.xml", :params => options}
16
+ if respond_to?(:find_all_across_pages)
17
+ find_all_across_pages(find_options)
17
18
  else
18
- self.find(:all, {:from => "/#{self.collection_name}/search.xml", :params => search_params})
19
+ find(:all, find_options)
19
20
  end
20
21
  end
21
22
  end
@@ -1,23 +1,5 @@
1
1
  module Highrise
2
2
  class SubjectData < Base
3
-
4
- module Mixin
5
-
6
- def subject_data_fields
7
- if attributes.has_key?(:subject_datas)
8
- Hash[subject_datas.map(&:attributes).map {|attrs| [attrs[:subject_field_label].to_s.underscore, attrs[:value]] }]
9
- else
10
- {}
11
- end
12
- end
13
-
14
- def field(field_name)
15
- (attributes["subject_datas"] || []).detect do |sd|
16
- sd.subject_field_label == field_name.to_s
17
- end
18
- end
19
-
20
- end
21
-
22
3
  end
23
4
  end
5
+
@@ -0,0 +1,5 @@
1
+ module Highrise
2
+ class SubjectField < Base
3
+ end
4
+ end
5
+
@@ -1,3 +1,3 @@
1
1
  module Highrise
2
- VERSION = "3.0.6"
2
+ VERSION = "3.0.7"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peterosullivan-highrise
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 6
10
- version: 3.0.6
9
+ - 7
10
+ version: 3.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Marcos Tapaj\xC3\xB3s"
@@ -100,6 +100,7 @@ files:
100
100
  - lib/highrise/deal_category.rb
101
101
  - lib/highrise/email.rb
102
102
  - lib/highrise/group.rb
103
+ - lib/highrise/has_subject_data.rb
103
104
  - lib/highrise/kase.rb
104
105
  - lib/highrise/membership.rb
105
106
  - lib/highrise/note.rb
@@ -111,6 +112,7 @@ files:
111
112
  - lib/highrise/searchable.rb
112
113
  - lib/highrise/subject.rb
113
114
  - lib/highrise/subject_data.rb
115
+ - lib/highrise/subject_field.rb
114
116
  - lib/highrise/tag.rb
115
117
  - lib/highrise/taggable.rb
116
118
  - lib/highrise/task.rb