ryandotsmith-asf-soap-adapter 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/.document +5 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +125 -0
  4. data/Rakefile +63 -0
  5. data/VERSION +1 -0
  6. data/asf-soap-adapter.gemspec +300 -0
  7. data/asf-soap-adapter.pptx +0 -0
  8. data/deploy +6 -0
  9. data/lib/active_record/connection_adapters/activesalesforce.rb +36 -0
  10. data/lib/active_record/connection_adapters/activesalesforce_adapter.rb +919 -0
  11. data/lib/active_record/connection_adapters/asf_active_record.rb +40 -0
  12. data/lib/active_record/connection_adapters/boxcar_command.rb +66 -0
  13. data/lib/active_record/connection_adapters/column_definition.rb +95 -0
  14. data/lib/active_record/connection_adapters/entity_definition.rb +59 -0
  15. data/lib/active_record/connection_adapters/id_resolver.rb +84 -0
  16. data/lib/active_record/connection_adapters/recording_binding.rb +93 -0
  17. data/lib/active_record/connection_adapters/relationship_definition.rb +81 -0
  18. data/lib/active_record/connection_adapters/result_array.rb +31 -0
  19. data/lib/active_record/connection_adapters/sid_authentication_filter.rb +57 -0
  20. data/lib/activerecord-activesalesforce-adapter.rb +1 -0
  21. data/lib/asf-soap-adapter.rb +34 -0
  22. data/lib/salesforce/account.rb +28 -0
  23. data/lib/salesforce/account_feed.rb +27 -0
  24. data/lib/salesforce/apex_log.rb +28 -0
  25. data/lib/salesforce/asset.rb +27 -0
  26. data/lib/salesforce/asset_feed.rb +27 -0
  27. data/lib/salesforce/campaign.rb +27 -0
  28. data/lib/salesforce/campaign_feed.rb +27 -0
  29. data/lib/salesforce/case.rb +27 -0
  30. data/lib/salesforce/case_feed.rb +27 -0
  31. data/lib/salesforce/case_team_member.rb +28 -0
  32. data/lib/salesforce/case_team_role.rb +28 -0
  33. data/lib/salesforce/chatter_feed.rb +291 -0
  34. data/lib/salesforce/contact.rb +27 -0
  35. data/lib/salesforce/contact_feed.rb +29 -0
  36. data/lib/salesforce/contract.rb +27 -0
  37. data/lib/salesforce/contract_feed.rb +27 -0
  38. data/lib/salesforce/entity_subscription.rb +27 -0
  39. data/lib/salesforce/feed_comment.rb +27 -0
  40. data/lib/salesforce/feed_post.rb +27 -0
  41. data/lib/salesforce/feed_tracked_change.rb +27 -0
  42. data/lib/salesforce/file_writer.rb +61 -0
  43. data/lib/salesforce/group.rb +28 -0
  44. data/lib/salesforce/group_member.rb +28 -0
  45. data/lib/salesforce/lead.rb +27 -0
  46. data/lib/salesforce/lead_feed.rb +27 -0
  47. data/lib/salesforce/news_feed.rb +27 -0
  48. data/lib/salesforce/opportunity.rb +27 -0
  49. data/lib/salesforce/opportunity_feed.rb +27 -0
  50. data/lib/salesforce/organization.rb +27 -0
  51. data/lib/salesforce/product2.rb +27 -0
  52. data/lib/salesforce/product2_feed.rb +27 -0
  53. data/lib/salesforce/sf_base.rb +94 -0
  54. data/lib/salesforce/sf_utility.rb +214 -0
  55. data/lib/salesforce/solution.rb +27 -0
  56. data/lib/salesforce/solution_feed.rb +27 -0
  57. data/lib/salesforce/solution_history.rb +28 -0
  58. data/lib/salesforce/task.rb +28 -0
  59. data/lib/salesforce/task_feed.rb +28 -0
  60. data/lib/salesforce/user.rb +27 -0
  61. data/lib/salesforce/user_feed.rb +27 -0
  62. data/lib/salesforce/user_profile_feed.rb +27 -0
  63. data/lib/salesforce/user_role.rb +28 -0
  64. data/ryandotsmith-asf-soap-adapter.gemspec +301 -0
  65. data/test/asf-soap-adapter-rails-app/README +243 -0
  66. data/test/asf-soap-adapter-rails-app/Rakefile +10 -0
  67. data/test/asf-soap-adapter-rails-app/app/controllers/adapter_homes_controller.rb +83 -0
  68. data/test/asf-soap-adapter-rails-app/app/controllers/application_controller.rb +10 -0
  69. data/test/asf-soap-adapter-rails-app/app/helpers/adapter_homes_helper.rb +2 -0
  70. data/test/asf-soap-adapter-rails-app/app/helpers/application_helper.rb +3 -0
  71. data/test/asf-soap-adapter-rails-app/app/models/adapter_home.rb +2 -0
  72. data/test/asf-soap-adapter-rails-app/app/views/adapter_homes/edit.html.erb +24 -0
  73. data/test/asf-soap-adapter-rails-app/app/views/adapter_homes/index.html.erb +24 -0
  74. data/test/asf-soap-adapter-rails-app/app/views/adapter_homes/new.html.erb +23 -0
  75. data/test/asf-soap-adapter-rails-app/app/views/adapter_homes/show.html.erb +18 -0
  76. data/test/asf-soap-adapter-rails-app/app/views/layouts/adapter_homes.html.erb +17 -0
  77. data/test/asf-soap-adapter-rails-app/config/boot.rb +110 -0
  78. data/test/asf-soap-adapter-rails-app/config/database.yml +30 -0
  79. data/test/asf-soap-adapter-rails-app/config/environment.rb +44 -0
  80. data/test/asf-soap-adapter-rails-app/config/environments/development.rb +17 -0
  81. data/test/asf-soap-adapter-rails-app/config/environments/production.rb +28 -0
  82. data/test/asf-soap-adapter-rails-app/config/environments/salesforce-default-realm.rb +30 -0
  83. data/test/asf-soap-adapter-rails-app/config/environments/test.rb +28 -0
  84. data/test/asf-soap-adapter-rails-app/config/initializers/backtrace_silencers.rb +7 -0
  85. data/test/asf-soap-adapter-rails-app/config/initializers/cookie_verification_secret.rb +7 -0
  86. data/test/asf-soap-adapter-rails-app/config/initializers/inflections.rb +10 -0
  87. data/test/asf-soap-adapter-rails-app/config/initializers/mime_types.rb +5 -0
  88. data/test/asf-soap-adapter-rails-app/config/initializers/new_rails_defaults.rb +21 -0
  89. data/test/asf-soap-adapter-rails-app/config/initializers/session_store.rb +15 -0
  90. data/test/asf-soap-adapter-rails-app/config/locales/en.yml +5 -0
  91. data/test/asf-soap-adapter-rails-app/config/routes.rb +46 -0
  92. data/test/asf-soap-adapter-rails-app/db/development.sqlite3 +0 -0
  93. data/test/asf-soap-adapter-rails-app/db/migrate/20101107202112_create_adapter_homes.rb +15 -0
  94. data/test/asf-soap-adapter-rails-app/db/schema.rb +22 -0
  95. data/test/asf-soap-adapter-rails-app/db/seeds.rb +7 -0
  96. data/test/asf-soap-adapter-rails-app/db/test.sqlite3 +0 -0
  97. data/test/asf-soap-adapter-rails-app/log/development.log +51 -0
  98. data/test/asf-soap-adapter-rails-app/log/salesforce-default-realm.log +928 -0
  99. data/test/asf-soap-adapter-rails-app/nbproject/private/config.properties +0 -0
  100. data/test/asf-soap-adapter-rails-app/nbproject/private/private.properties +3 -0
  101. data/test/asf-soap-adapter-rails-app/nbproject/private/private.xml +4 -0
  102. data/test/asf-soap-adapter-rails-app/nbproject/private/rake-d.txt +94 -0
  103. data/test/asf-soap-adapter-rails-app/nbproject/project.properties +5 -0
  104. data/test/asf-soap-adapter-rails-app/nbproject/project.xml +9 -0
  105. data/test/asf-soap-adapter-rails-app/public/404.html +30 -0
  106. data/test/asf-soap-adapter-rails-app/public/422.html +30 -0
  107. data/test/asf-soap-adapter-rails-app/public/500.html +30 -0
  108. data/test/asf-soap-adapter-rails-app/public/favicon.ico +0 -0
  109. data/test/asf-soap-adapter-rails-app/public/images/rails.png +0 -0
  110. data/test/asf-soap-adapter-rails-app/public/javascripts/application.js +2 -0
  111. data/test/asf-soap-adapter-rails-app/public/javascripts/controls.js +963 -0
  112. data/test/asf-soap-adapter-rails-app/public/javascripts/dragdrop.js +973 -0
  113. data/test/asf-soap-adapter-rails-app/public/javascripts/effects.js +1128 -0
  114. data/test/asf-soap-adapter-rails-app/public/javascripts/prototype.js +4320 -0
  115. data/test/asf-soap-adapter-rails-app/public/robots.txt +5 -0
  116. data/test/asf-soap-adapter-rails-app/public/stylesheets/scaffold.css +54 -0
  117. data/test/asf-soap-adapter-rails-app/script/about +4 -0
  118. data/test/asf-soap-adapter-rails-app/script/console +3 -0
  119. data/test/asf-soap-adapter-rails-app/script/dbconsole +3 -0
  120. data/test/asf-soap-adapter-rails-app/script/destroy +3 -0
  121. data/test/asf-soap-adapter-rails-app/script/generate +3 -0
  122. data/test/asf-soap-adapter-rails-app/script/performance/benchmarker +3 -0
  123. data/test/asf-soap-adapter-rails-app/script/performance/profiler +3 -0
  124. data/test/asf-soap-adapter-rails-app/script/plugin +3 -0
  125. data/test/asf-soap-adapter-rails-app/script/runner +3 -0
  126. data/test/asf-soap-adapter-rails-app/script/server +3 -0
  127. data/test/asf-soap-adapter-rails-app/test/performance/browsing_test.rb +9 -0
  128. data/test/asf-soap-adapter-rails-app/test/test_helper.rb +44 -0
  129. data/test/asf-soap-adapter-rails-app/test/test_keys.rb +4 -0
  130. data/test/asf-soap-adapter-rails-app/test/unit/adapter_home_test.rb +8 -0
  131. data/test/asf-soap-adapter-rails-app/test/unit/helpers/adapter_homes_helper_test.rb +4 -0
  132. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/account_feed_test.rb +16 -0
  133. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/account_test.rb +66 -0
  134. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/apex_log_test.rb +10 -0
  135. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/asset_feed_test.rb +14 -0
  136. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/asset_test.rb +13 -0
  137. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/campaign_feed_test.rb +13 -0
  138. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/campaign_test.rb +13 -0
  139. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/case_feed_test.rb +13 -0
  140. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/case_team_member_test.rb +10 -0
  141. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/case_team_role.rb +10 -0
  142. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/case_test.rb +13 -0
  143. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/chatter_feed_test.rb +53 -0
  144. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/contact_feed_test.rb +13 -0
  145. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/contact_test.rb +14 -0
  146. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/contract_feed_test.rb +13 -0
  147. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/contract_test.rb +13 -0
  148. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/entity_subscription_test.rb +13 -0
  149. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/feed_comment_test.rb +9 -0
  150. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/feed_post_test.rb +10 -0
  151. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/feed_tracked_change_test.rb +9 -0
  152. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/group_member_test.rb +10 -0
  153. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/group_test.rb +24 -0
  154. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/lead_feed_test.rb +13 -0
  155. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/lead_test.rb +40 -0
  156. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/news_feed_test.rb +13 -0
  157. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/opportunity_feed_test.rb +13 -0
  158. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/opportunity_test.rb +13 -0
  159. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/organization_test.rb +8 -0
  160. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/product2_feed_test.rb +13 -0
  161. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/product2_test.rb +13 -0
  162. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/salesforce_base_test.rb +10 -0
  163. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/solution_feed_test.rb +13 -0
  164. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/solution_history_test.rb +10 -0
  165. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/solution_test.rb +14 -0
  166. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/task_feed_test.rb +10 -0
  167. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/task_test.rb +10 -0
  168. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/user_feed_test.rb +13 -0
  169. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/user_profile_feed_test.rb +11 -0
  170. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/user_role_test.rb +10 -0
  171. data/test/asf-soap-adapter-rails-app/test/unit/salesforce/user_test.rb +48 -0
  172. data/test/basic_test.rb +204 -0
  173. data/test/config.yml +5 -0
  174. data/test/helper.rb +10 -0
  175. data/test/recorded_test_case.rb +87 -0
  176. data/test/simple_test.rb +96 -0
  177. data/test/tests_without_rail.rb +65 -0
  178. metadata +401 -0
@@ -0,0 +1,291 @@
1
+ require 'logger'
2
+ module Salesforce
3
+ # ==This is the abstract to the 'XXXFeed' table in Salesforce Chatter
4
+ #
5
+ # Note: FeedPost cannot be directly queried. It must go through its parent. For example:
6
+ # <i>SELECT Id, Type, FeedPost.Body FROM AccountFeed WHERE ParentId = AccountId ORDER BY CreatedDate DESC</i>
7
+ #
8
+ # SalesObject's 3 digits code for the KeyPrefix:
9
+ # ID Prefix Entity Type
10
+ # 001 Account
11
+ # 006 Opportunity
12
+ # 003 Contact
13
+ # 00Q Lead
14
+ # 701 Campaign
15
+ # 00V Campaign Member
16
+ # 00D Organization
17
+ # 005 User
18
+ # 00E Profile
19
+ # 00N Custom Field Definition
20
+ #
21
+ # 0D5 FeedItem (post by everyone)
22
+ # 0F7 FeedPost (post made by this user)
23
+ # See: http://eng.genius.com/blog/2009/05/17/salesforcecom-api-gotchas-2/
24
+ class ChatterFeed
25
+ def initialize
26
+ #### define @logger
27
+ # http://ruby-doc.org/core/classes/@logger.html
28
+ # TODO use a log file, rather than Standout
29
+ @logger = Logger.new(STDOUT)
30
+ #@logger.level = @logger::WARN
31
+ end
32
+
33
+ #fields do
34
+ # timestamps
35
+ #end
36
+
37
+ BASE_FRAG = "Id, CreatedDate, Type, CreatedBy.Name, CreatedBy.Id"
38
+
39
+ FEEDPOST_WITH_CONTENT_DATA_FRAG = <<-HERE
40
+ FeedPost.Id, FeedPost.FeedItemId, FeedPost.ParentId, FeedPost.Type,
41
+ FeedPost.CreatedById, FeedPost.CreatedDate, FeedPost.SystemModStamp,
42
+ FeedPost.Title, FeedPost.Body, FeedPost.LinkUrl,
43
+ FeedPost.ContentData, FeedPost.ContentFileName, FeedPost.ContentDescription,
44
+ FeedPost.ContentType, FeedPost.ContentSize
45
+ HERE
46
+
47
+ FEEDPOST_WITHOUT_CONTENT_DATA_FRAG = <<-HERE
48
+ FeedPost.Id, FeedPost.FeedItemId, FeedPost.ParentId, FeedPost.Type,
49
+ FeedPost.CreatedById, FeedPost.CreatedDate, FeedPost.SystemModStamp,
50
+ FeedPost.Title, FeedPost.Body, FeedPost.LinkUrl, FeedPost.ContentSize
51
+ HERE
52
+
53
+ CREATOR_FRAG = "CreatedBy.FirstName, CreateBy.LastName, CreatedBy.Id"
54
+
55
+ FEED_TRACKED_CHANGE_FRAG = <<-HERE
56
+ Select Id, FieldName, OldValue, NewValue From FeedTrackedChanges
57
+ ORDER BY Id Desc
58
+ HERE
59
+
60
+ FEED_COMMENT_FRAG = <<-HERE
61
+ Select Id, CommentBody, CreatedDate, CreatedBy.Id, CreatedBy.FirstName,
62
+ CreatedBy.LastName FROM FeedComments ORDER BY CreatedDate
63
+ HERE
64
+
65
+ # find all chatter feeds based on object_type, query_string, and given binding
66
+ def search_chatter_feeds(object_type, query_string, binding, limit=100)
67
+ return get_all_chatter_feeds_with_attachments(nil, object_type, binding, 'no-attachment-for-search', limit, false, query_string)
68
+ end
69
+
70
+ # 1. It does not return the attached file.
71
+ # 2. See get_all_feed_posts_with_attachments(object_id, object_type, binding, directory_name, limit=100, get_attachment=true, query_string=nil)
72
+ # 7. returns Ruby Array of matching records
73
+ def get_all_chatter_feeds_without_attachments(object_id, object_type, binding, directory_name, limit=100)
74
+ return get_all_chatter_feeds_with_attachments(object_id, object_type, binding, directory_name, limit, false, nil)
75
+ end
76
+
77
+ # 1. It returns the attached file.
78
+ # 2. <b>'object_id'</b> corresponds to the 'parent_id' column in the 'XXXFeed' table
79
+ # 3. <b>'object_type'</b> can be one of the followings
80
+ # Account, Asset, Campaign, Case, Lead, Contact, Contract, Opportunity,
81
+ # Product2, Solution, User
82
+ # **Note**: UserProfileFeed and NewsFeed are special cases.
83
+ # UserProfileFeed -> select ... from UserProfileFeed with Userid='userid'
84
+ # NewsFeed -> select ... from NewsFeed where parentid = 'userid'
85
+ # 4. <b>'binding'</b> can be passed in directly or using the inherited binding from the
86
+ # 'Salesforce::SfBase' base class.
87
+ # 5. <b>'directory_name</b> is the directory in 'public/tmp' for saving the attachment
88
+ # 6. <b>'limit</b> is the number of records to return
89
+ # 7. <b>'get_attachment'</b> is a boolean flag, true gets the attachment,
90
+ # false does not get the attachment
91
+ # 8. <b>query_string</b> is used to search against the Salesforce. Note, if "object_id' is specified, query_string is ignored.
92
+ # 8. returns Ruby Array of matching records
93
+ # 9. TODO add conditions, e.g.
94
+ # search -> where FeedPost.CreatedDate > 2007-08-06T03:23:00.000Z and FeedPost.Body like '%post%'
95
+ # pagination ->
96
+
97
+ def get_all_chatter_feeds_with_attachments(object_id, object_type, binding, directory_name, limit=100, get_attachment=true, query_string=nil)
98
+ begin
99
+ #e.g. select Id, type, FeedPost.body from UserProfileFeed WITH UserId = '005A0000000S8aIIAS'
100
+ if !object_id.nil?
101
+ qstring = <<-HERE
102
+ SELECT #{BASE_FRAG}, #{FEEDPOST_WITHOUT_CONTENT_DATA_FRAG},
103
+ (#{FEED_TRACKED_CHANGE_FRAG}), (#{FEED_COMMENT_FRAG} LIMIT #{limit})
104
+ FROM #{object_type}Feed where parentid = \'#{object_id}\'
105
+ ORDER BY CreatedDate DESC limit #{limit}
106
+ HERE
107
+ elsif !query_string.nil?
108
+ # this is more like a search....
109
+ qstring = <<-HERE
110
+ SELECT #{BASE_FRAG}, #{FEEDPOST_WITHOUT_CONTENT_DATA_FRAG},
111
+ (#{FEED_TRACKED_CHANGE_FRAG}), (#{FEED_COMMENT_FRAG} LIMIT #{limit})
112
+ FROM #{object_type}Feed where FeedPost.Body like \'%#{query_string}%\'
113
+ ORDER BY CreatedDate DESC limit #{limit}
114
+ HERE
115
+ else
116
+ qstring = <<-HERE
117
+ SELECT #{BASE_FRAG}, #{FEEDPOST_WITHOUT_CONTENT_DATA_FRAG},
118
+ (#{FEED_TRACKED_CHANGE_FRAG}), (#{FEED_COMMENT_FRAG} LIMIT #{limit})
119
+ FROM #{object_type}Feed ORDER BY CreatedDate DESC limit #{limit}
120
+ HERE
121
+ end
122
+
123
+
124
+ @logger.info('qstring: ' + qstring)
125
+ # Note, if query FeedPost.ContentData, Salesforce only returns 1 entry at
126
+ # a time, you will get a 'queryLocator', which can be used by calling
127
+ # 'queryMore(queryLocator)'
128
+
129
+ feed_results = Array.new
130
+
131
+ results = binding.query(:queryString => qstring)
132
+ if results.queryResponse.result.records.is_a?(Hash)
133
+ # User has made only one feedpost
134
+ feed = Hash.new
135
+ feed = results.queryResponse.result.records
136
+ if (!feed.FeedPost.nil?) && (feed.FeedPost.ContentSize.to_i > 0)
137
+ feed = get_single_chatter_feed_with_attachment(feed.FeedPost.Id, feed[:type], binding, directory_name)
138
+ end
139
+ feed_results << feed
140
+ elsif results.queryResponse.result.records.is_a?(Array)
141
+ results.queryResponse.result.records.each do |an_feed_entry|
142
+ if (an_feed_entry.is_a?(Hash))
143
+ if (an_feed_entry[:Type] == "TrackedChange")
144
+ # This is a TrackedChange Feed, the FeedPost Body is nil
145
+ feed = Hash.new
146
+ feed = an_feed_entry
147
+ feed_results << feed
148
+ elsif (!an_feed_entry.FeedPost.nil?) && (an_feed_entry.FeedPost.ContentSize.to_i > 0) && (get_attachment)
149
+ # This signifies that:
150
+ # 1. results.queryResponse.result.records.FeedPost.Type is of "ContentPost"
151
+ # 2. results.queryResponse.result.records.FeedPost.type should be of "FeedPost"
152
+ an_entry_with_attachment = get_single_chatter_feed_with_attachment(an_feed_entry.FeedPost.Id, an_feed_entry[:type], binding, directory_name)
153
+ feed_results << an_entry_with_attachment
154
+ else
155
+ feed = Hash.new
156
+ feed = an_feed_entry
157
+ feed_results << feed
158
+ end
159
+ else
160
+ @logger.info "Result #{object_id} has a results.queryResponse that is either not a valid Hash, or with nil FeedPost."
161
+ end
162
+ end
163
+ end
164
+
165
+ #if there are more entries, query it again and show it all
166
+ while results.queryResponse.result.done.to_s.upcase != 'TRUE'
167
+ results = binding.queryMore(:queryString => results.queryResponse.result.queryLocator)
168
+ if results.queryResponse.result.records.is_a?(Hash)
169
+ # User has made only one feedpost
170
+ feed = Hash.new
171
+ feed = results.queryResponse.result.records
172
+ if (!feed.FeedPost.nil?) && (feed.FeedPost.ContentSize.to_i > 0)
173
+ feed = get_single_chatter_feed_with_attachment(feed.FeedPost.Id, feed[:type], binding, directory_name)
174
+ end
175
+ feed_results << feed
176
+ elsif results.queryResponse.result.records.is_a?(Array)
177
+ results.queryResponse.result.records.each do |an_feed_entry|
178
+ if (an_feed_entry.is_a?(Hash))
179
+ if (an_feed_entry[:Type] == "TrackedChange")
180
+ # This is a TrackedChange Feed, the FeedPost Body is nil
181
+ feed = Hash.new
182
+ feed = an_feed_entry
183
+ feed_results << feed
184
+ # check to see if it has attachments
185
+ elsif (!an_feed_entry.FeedPost.nil?) && (an_feed_entry.FeedPost.ContentSize.to_i > 0) && (get_attachment)
186
+ # This signifies that:
187
+ # 1. results.queryResponse.result.records.FeedPost.Type is of "ContentPost"
188
+ # 2. results.queryResponse.result.records.FeedPost.type should be of "FeedPost"
189
+ an_entry_with_attachment = get_single_chatter_feed_with_attachment(an_feed_entry.FeedPost.Id, an_feed_entry[:type], binding, directory_name)
190
+ feed_results << an_entry_with_attachment
191
+ else
192
+ feed = Hash.new
193
+ feed = an_feed_entry
194
+ feed_results << feed
195
+ end
196
+
197
+ else
198
+ @logger.info "Result #{object_id} has a results.queryResponse that is either an invalid Hash or a nil FeedPost."
199
+ end
200
+ end
201
+ end
202
+ end
203
+
204
+ return feed_results
205
+ rescue Exception => exception
206
+ @logger.info 'get_all_feed_posts_with_attachments: ' + exception.message
207
+ return feed_results
208
+ end
209
+ end
210
+
211
+ # 1. Returns a single feed with attachment.
212
+ # 2. <b>'feedpost_id</b> is the id corresponding to this feedpost
213
+ # 3. <b>'feed_type'</b> can be one of the followings
214
+ # Account, Asset, Campaign, Case, Lead, Contact, Contract, Opportunity,
215
+ # Product2, Solution, User
216
+ # **Note**: UserProfileFeed and NewsFeed are not included here, as they
217
+ # are special cases.
218
+ # 4. <b>'binding'</b> can be passed in directly or using the inherited binding from the
219
+ # 'Salesforce::SfBase' base class.
220
+ # 5. <b>'directory_name</b> is the directory in 'public/tmp' for saving the attachment
221
+ # 6. <b>'limit'</b> is the number of feed comments to retrieve at a time
222
+ def get_single_chatter_feed_with_attachment(feedpost_id, feed_type, binding, directory_name, limit=100)
223
+ begin
224
+ expanded_qstring = <<-HERE
225
+ SELECT #{BASE_FRAG}, #{FEEDPOST_WITH_CONTENT_DATA_FRAG},
226
+ (#{FEED_TRACKED_CHANGE_FRAG}), (#{FEED_COMMENT_FRAG} LIMIT #{limit})
227
+ FROM #{feed_type} where FeedPost.Id= \'#{feedpost_id}\' ORDER BY CreatedDate DESC Limit 1
228
+ HERE
229
+
230
+ @logger.info('expanded_string: ' + expanded_qstring)
231
+ deep_result = binding.query(:queryString => expanded_qstring)
232
+
233
+ ######### queryMore does not work on FeedPost with Content.##########
234
+ # locator = deep_result.queryResponse.result.queryLocator
235
+ # while !locator.nil?
236
+ # query_again = binding.queryMore(:queryLocator => locator)
237
+ # locator = query_again.queryMoreResponse.result.queryLocator
238
+ # end
239
+ #####################################################################
240
+
241
+ if !deep_result.Fault.nil?
242
+ raise ChatterFeedError.new(@logger, deep_result.Fault.faultstring.to_s)
243
+ end
244
+ if !deep_result.queryResponse.result.records.FeedComments.nil? && deep_result.queryResponse.result.records.FeedComments[:size].to_i > 1
245
+ # There are more than one feed comments. Therefore, search again without content-data.
246
+ # This is done, because having ContentData in the query string, it will only return only the 1st record of the feed comments.
247
+ qstring_without_content_data = <<-HERE
248
+ SELECT #{BASE_FRAG},
249
+ (#{FEED_TRACKED_CHANGE_FRAG}), (#{FEED_COMMENT_FRAG} LIMIT 20)
250
+ FROM #{feed_type} where FeedPost.Id= \'#{feedpost_id}\' ORDER BY CreatedDate DESC Limit 1
251
+ HERE
252
+ result_without_content_data = binding.query(:queryString => qstring_without_content_data)
253
+ list_of_feed_comments = result_without_content_data.queryResponse.result.records.FeedComments
254
+ deep_result.queryResponse.result.records.FeedComments[:records] = list_of_feed_comments[:records]
255
+ end
256
+
257
+ filename = deep_result.queryResponse.result.records.FeedPost.ContentFileName
258
+ filesize = deep_result.queryResponse.result.records.FeedPost.ContentSize
259
+ filedata = deep_result.queryResponse.result.records.FeedPost.ContentData
260
+ result_with_attachment = deep_result.queryResponse.result.records
261
+
262
+ local_file_name = nil
263
+
264
+ if filename.nil?
265
+ # remote filename is nil, do not write the local file
266
+ @logger.info("remote filename is nil, do not write the local file.")
267
+ else
268
+ # Downloaded files are put in the subdirectory matching each session-id in the /public/tmp directory.
269
+ # creates dir, if it does not exists
270
+ file_writer = Salesforce::FileWriter.new
271
+ local_file_name = file_writer.do_write_file(filename, filesize, filedata, directory_name)
272
+ result_with_attachment.FeedPost.store(:Attachment, local_file_name)
273
+ end
274
+
275
+ return result_with_attachment
276
+ end
277
+ rescue Exception => exception
278
+ @logger.info "Cannot create the file: " + exception.message
279
+ result_with_attachment.FeedPost[:attachment] = nil
280
+ return result_with_attachment
281
+ end
282
+
283
+
284
+ end
285
+
286
+ class ChatterFeedError < RuntimeError
287
+ def initialize(logger, message)
288
+ super(logger, message)
289
+ end
290
+ end
291
+ end
@@ -0,0 +1,27 @@
1
+ =begin
2
+ asf-soap-adapter
3
+ Copyright 2010 Raymond Gao
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ =end
17
+
18
+ # Salesforce package contains convenience classes for mapping Salesforce objects into
19
+ # ActiveRecord objects. The SfBase is the mother of all other objects. Additionally,
20
+ # SfUtitlity class provides several useful methods for manipulating SF objects.
21
+ module Salesforce
22
+ # See http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_list.htm
23
+ # For complete list of Salesforce Standard Objects in V20.
24
+ class Contact < SfBase
25
+ set_table_name 'contacts'
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ =begin
2
+ asf-soap-adapter
3
+ Copyright 2010 Raymond Gao
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ =end
17
+
18
+ # Salesforce package contains convenience classes for mapping Salesforce objects into
19
+ # ActiveRecord objects. The SfBase is the mother of all other objects. Additionally,
20
+ # SfUtitlity class provides several useful methods for manipulating SF objects.
21
+ module Salesforce
22
+ # See http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_list.htm
23
+ # For complete list of Salesforce Standard Objects in V20.
24
+ class ContactFeed < SfBase
25
+ set_table_name 'contact_feeds'
26
+ # Below is not necessary. Auto built by ActiveSalesforce-Adapter gem, albeit a little slow.
27
+ #belongs_to :parent, :class_name => "Contact"
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ =begin
2
+ asf-soap-adapter
3
+ Copyright 2010 Raymond Gao
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ =end
17
+
18
+ # Salesforce package contains convenience classes for mapping Salesforce objects into
19
+ # ActiveRecord objects. The SfBase is the mother of all other objects. Additionally,
20
+ # SfUtitlity class provides several useful methods for manipulating SF objects.
21
+ module Salesforce
22
+ # See http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_list.htm
23
+ # For complete list of Salesforce Standard Objects in V20.
24
+ class Contract < SfBase
25
+ set_table_name 'contracts'
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ =begin
2
+ asf-soap-adapter
3
+ Copyright 2010 Raymond Gao
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ =end
17
+
18
+ # Salesforce package contains convenience classes for mapping Salesforce objects into
19
+ # ActiveRecord objects. The SfBase is the mother of all other objects. Additionally,
20
+ # SfUtitlity class provides several useful methods for manipulating SF objects.
21
+ module Salesforce
22
+ # See http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_list.htm
23
+ # For complete list of Salesforce Standard Objects in V20.
24
+ class ContractFeed < SfBase
25
+ set_table_name 'contract_feeds'
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ =begin
2
+ asf-soap-adapter
3
+ Copyright 2010 Raymond Gao
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ =end
17
+
18
+ # Salesforce package contains convenience classes for mapping Salesforce objects into
19
+ # ActiveRecord objects. The SfBase is the mother of all other objects. Additionally,
20
+ # SfUtitlity class provides several useful methods for manipulating SF objects.
21
+ module Salesforce
22
+ # See http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_list.htm
23
+ # For complete list of Salesforce Standard Objects in V20.
24
+ class EntitySubscription < SfBase
25
+ set_table_name 'entity_subscriptions'
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ =begin
2
+ asf-soap-adapter
3
+ Copyright 2010 Raymond Gao
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ =end
17
+
18
+ # Salesforce package contains convenience classes for mapping Salesforce objects into
19
+ # ActiveRecord objects. The SfBase is the mother of all other objects. Additionally,
20
+ # SfUtitlity class provides several useful methods for manipulating SF objects.
21
+ module Salesforce
22
+ # See http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_list.htm
23
+ # For complete list of Salesforce Standard Objects in V20.
24
+ class FeedComment < SfBase
25
+ set_table_name 'feed_comments'
26
+ end
27
+ end