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,40 @@
1
+ =begin
2
+ ActiveSalesforce
3
+ Copyright 2006 Doug Chasman
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
+ module ActiveSalesforce
19
+
20
+ module ActiveRecord
21
+
22
+ module Mixin
23
+ def self.append_features(base) #:nodoc:
24
+ super
25
+
26
+ base.class_eval do
27
+ class << self
28
+ def set_table_name(value = nil, &block)
29
+ super(value, &block)
30
+
31
+ connection.set_class_for_entity(self, table_name.singularize)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,66 @@
1
+ =begin
2
+ ActiveSalesforce
3
+ Copyright 2006 Doug Chasman
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
+ require 'pp'
19
+
20
+
21
+ module ActiveSalesforce
22
+ module BoxcarCommand
23
+
24
+ class Base
25
+ attr_reader :verb, :args
26
+
27
+ def initialize(connection, verb, args)
28
+ @connection = connection
29
+ @verb = verb
30
+ @args = args
31
+ end
32
+
33
+ def after_execute(result)
34
+ end
35
+ end
36
+
37
+
38
+ class Insert < Base
39
+ def initialize(connection, sobject, idproxy)
40
+ super(connection, :create, sobject)
41
+ @idproxy = idproxy
42
+ end
43
+
44
+ def after_execute(result)
45
+ id = result[:id]
46
+ @idproxy << id if id
47
+ end
48
+ end
49
+
50
+
51
+ class Update < Base
52
+ def initialize(connection, sobject)
53
+ super(connection, :update, sobject)
54
+ end
55
+ end
56
+
57
+
58
+ class Delete < Base
59
+ def initialize(connection, ids)
60
+ super(connection, :delete, ids)
61
+ end
62
+ end
63
+
64
+
65
+ end
66
+ end
@@ -0,0 +1,95 @@
1
+ =begin
2
+ ActiveSalesforce
3
+ Copyright 2006 Doug Chasman
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
+ require 'pp'
19
+ require 'active_record/connection_adapters/abstract_adapter'
20
+
21
+
22
+ module ActiveRecord
23
+ module StringHelper
24
+ def column_nameize(s)
25
+ s.underscore
26
+ end
27
+ end
28
+
29
+ module ConnectionAdapters
30
+ class SalesforceColumn < Column
31
+ include StringHelper
32
+
33
+ attr_reader :api_name, :custom, :label, :createable, :updateable, :reference_to
34
+
35
+ def initialize(field)
36
+ @api_name = field[:name]
37
+ @custom = field[:custom] == "true"
38
+ @name = column_nameize(@api_name)
39
+ @type = get_type(field[:type])
40
+ @limit = field[:length]
41
+ @label = field[:label]
42
+ @name_field = field[:nameField] == "true"
43
+
44
+ @text = [:string, :text].include? @type
45
+ @number = [:float, :integer].include? @type
46
+
47
+ @createable = field[:createable] == "true"
48
+ @updateable = field[:updateable] == "true"
49
+
50
+ if field[:type] =~ /reference/i
51
+ @reference_to = field[:referenceTo]
52
+ @one_to_many = false
53
+ @cascade_delete = false
54
+
55
+ @name = @name.chop.chop << "id__c" if @custom
56
+ end
57
+ end
58
+
59
+ def is_name?
60
+ @name_field
61
+ end
62
+
63
+ def get_type(field_type)
64
+ case field_type
65
+ when /int/i
66
+ :integer
67
+ when /currency|percent/i
68
+ :float
69
+ when /datetime/i
70
+ :datetime
71
+ when /date/i
72
+ :date
73
+ when /id|string|textarea/i
74
+ :text
75
+ when /phone|fax|email|url/i
76
+ :string
77
+ when /blob|binary/i
78
+ :binary
79
+ when /boolean/i
80
+ :boolean
81
+ when /picklist/i
82
+ :text
83
+ when /reference/i
84
+ :text
85
+ end
86
+ end
87
+
88
+ def human_name
89
+ @label
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+ end
@@ -0,0 +1,59 @@
1
+ =begin
2
+ ActiveSalesforce
3
+ Copyright 2006 Doug Chasman
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
+ require 'pp'
19
+
20
+
21
+ module ActiveSalesforce
22
+ class EntityDefinition
23
+ attr_reader :name, :asf_class, :columns, :column_name_to_column, :api_name_to_column, :relationships, :key_prefix
24
+
25
+ def initialize(connection, name, asf_class, columns, relationships, custom, key_prefix)
26
+ @connection = connection
27
+ @name = name
28
+ @asf_class = asf_class
29
+ @columns = columns
30
+ @relationships = relationships
31
+ @custom = custom
32
+ @key_prefix = key_prefix
33
+
34
+ @column_name_to_column = {}
35
+ @columns.each { |column| @column_name_to_column[column.name] = column }
36
+
37
+ @api_name_to_column = {}
38
+ @columns.each { |column| @api_name_to_column[column.api_name] = column }
39
+ end
40
+
41
+ def custom?
42
+ @custom
43
+ end
44
+
45
+ def api_name
46
+ @custom ? name + "__c" : name
47
+ end
48
+
49
+ def layouts
50
+ return @layouts if @layouts
51
+
52
+ # Lazy load Layout information
53
+ response = @connection.binding.describeLayout(:sObjectType => api_name)
54
+ @layouts = @connection.get_result(response, :describeLayout)
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,84 @@
1
+ =begin
2
+ ActiveSalesforce
3
+ Copyright 2006 Doug Chasman
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
+ require 'pp'
19
+
20
+
21
+ module ActiveSalesforce
22
+ class IdResolver
23
+ attr_reader :object_type_to_ids
24
+
25
+ def initialize(connection)
26
+ @connection = connection
27
+ @object_type_to_ids = {}
28
+ end
29
+
30
+
31
+ def add(record, columns = nil)
32
+ if columns
33
+ columns = columns.to_a.map { |column_name| record.column_for_attribute(column_name) }
34
+ else
35
+ columns = record.class.columns
36
+ end
37
+
38
+ columns.each do |column|
39
+ reference_to = column.reference_to
40
+ next unless reference_to
41
+
42
+ value = record.send(column.name)
43
+ if value
44
+ ids = @object_type_to_ids[reference_to] ||= Set.new
45
+ ids << value
46
+ end
47
+ end
48
+ end
49
+
50
+
51
+ def resolve
52
+ result = {}
53
+
54
+ @object_type_to_ids.each do |object_type, ids|
55
+ entity_def = @connection.get_entity_def(object_type)
56
+
57
+ fields = (entity_def.columns.reject { |column| not column.is_name? }).map { |column| column.api_name }
58
+
59
+ # DCHASMAN TODO Boxcar into requests of no more than 200 retrieves per request
60
+ puts "Resolving references to #{object_type}"
61
+ field_values = @connection.retrieve_field_values(object_type, fields, ids.to_a, "#{self}.resolve()")
62
+
63
+ field_values.each do |field_value|
64
+ id = field_value.delete(:Id)
65
+ result[id] = field_value
66
+ end
67
+ end
68
+
69
+ result
70
+ end
71
+
72
+
73
+ def serialize
74
+ YAML.dump @object_type_to_ids
75
+ end
76
+
77
+
78
+ def deserialize(source)
79
+ @object_type_to_ids = YAML.load(source)
80
+ end
81
+
82
+ end
83
+
84
+ end
@@ -0,0 +1,93 @@
1
+ =begin
2
+ ActiveSalesforce
3
+ Copyright 2006 Doug Chasman
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
+ require 'yaml'
19
+
20
+
21
+ module ActiveSalesforce
22
+ # This is the main error class used by ActiveSalesforce Adapter.
23
+ class ASFError < RuntimeError
24
+ attr :fault
25
+
26
+ def initialize(logger, message, fault = nil)
27
+ super message
28
+
29
+ @fault = fault
30
+
31
+ logger.debug("\nASFError:\n message='#{message}'\n fault='#{fault}'\n\n")
32
+ end
33
+ end
34
+
35
+ # Error related to creating a binding with the Salesforce Web Services API
36
+ class ASFRecordingBindingError < ASFError
37
+ def initialize(logger, message)
38
+ super(logger, message)
39
+ end
40
+ end
41
+
42
+ # A wrapper for the Salesforce RForce Binding. <em>recording</em> attribute
43
+ # allows you to save web services traffic information for later debug purpose.
44
+ # It is saved to a file which is specified by in the YAML file, e.g. 'database.yml'
45
+ # In production, it should not be used, because it generates a lot of overhead.
46
+ class RecordingBinding < RForce::Binding
47
+
48
+ attr_reader :recorded_responses
49
+
50
+ def initialize(url, sid, recording, recording_source, logger)
51
+ super(url, sid)
52
+
53
+ @recording = recording
54
+ @recorded_responses = {}
55
+ @recording_source = recording_source
56
+ @logger = logger
57
+
58
+ unless @recording
59
+ YAML.load_documents(recording_source) do |recorded_response|
60
+ @recorded_responses.merge!(recorded_response)
61
+ end
62
+ end
63
+ end
64
+
65
+
66
+ #Call a method on the remote server. Arguments can be
67
+ #a hash or (if order is important) an array of alternating
68
+ #keys and values.
69
+ def call_remote(method, args)
70
+ # Blank out username and password
71
+ safe_args = args.inject([]) {|memo, v| memo << ((memo.last == :username or memo.last == :password) ? "" : v) }
72
+ key = "#{method}(#{safe_args.join(':')})"
73
+
74
+ if @recording
75
+ response = super(method, args)
76
+
77
+ unless @recorded_responses[key]
78
+ # track this { key => request } to avoid duplication in the YAML
79
+ @recorded_responses[key] = true
80
+
81
+ YAML.dump({ key => response }, @recording_source)
82
+ end
83
+ else
84
+ response = @recorded_responses[key]
85
+ raise ASFRecordingBindingError.new(@logger, "Unable to find matching response for recorded request '#{key}'") unless response
86
+ end
87
+
88
+ response
89
+ end
90
+
91
+ end
92
+
93
+ end
@@ -0,0 +1,81 @@
1
+ =begin
2
+ ActiveSalesforce
3
+ Copyright 2006 Doug Chasman
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
+ require 'pp'
19
+
20
+
21
+ module ActiveRecord
22
+ module StringHelper
23
+ def column_nameize(s)
24
+ s.underscore
25
+ end
26
+ end
27
+
28
+ module ConnectionAdapters
29
+
30
+ class SalesforceRelationship
31
+ include StringHelper
32
+
33
+ attr_reader :name, :api_name, :custom, :foreign_key, :label, :reference_to, :one_to_many
34
+
35
+ def initialize(source, column = nil)
36
+ if source[:childSObject]
37
+ relationship = source
38
+
39
+ if relationship[:relationshipName]
40
+ @api_name = relationship[:relationshipName]
41
+ @one_to_many = true
42
+ @label = @api_name
43
+ @name = column_nameize(@api_name)
44
+ @custom = false
45
+ else
46
+ @api_name = relationship[:field]
47
+ @one_to_many = relationship[:cascadeDelete] == "true"
48
+ @label = relationship[:childSObject].pluralize
49
+ @custom = relationship[:childSObject].match(/__c$/)
50
+
51
+ name = relationship[:childSObject]
52
+ name = name.chop.chop.chop if custom
53
+
54
+ @name = column_nameize(name.pluralize)
55
+ @name = @name + "__c" if custom
56
+ end
57
+
58
+ @reference_to = relationship[:childSObject]
59
+
60
+ @foreign_key = column_nameize(relationship[:field])
61
+ @foreign_key = @foreign_key.chop.chop << "id__c" if @foreign_key.match(/__c$/)
62
+ else
63
+ field = source
64
+
65
+ @api_name = field[:name]
66
+ @custom = field[:custom] == "true"
67
+
68
+ @api_name = @api_name.chop.chop unless @custom
69
+
70
+ @label = field[:label]
71
+ @reference_to = field[:referenceTo]
72
+ @one_to_many = false
73
+
74
+ @foreign_key = column.name
75
+ @name = column_nameize(@api_name)
76
+ end
77
+ end
78
+ end
79
+
80
+ end
81
+ end