dynamics_crm 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed0c1801ab9a78dba2eb01192f0806fdbf9bc4ab
4
- data.tar.gz: 9bb310620e6a7fbdc950487a3a7cb1a57c3e2a9f
3
+ metadata.gz: e726f9c76ea10016d1fcc9de700cc4126c5894c1
4
+ data.tar.gz: 9693bc3f8691b6195c180e97adb21fbe2029b186
5
5
  SHA512:
6
- metadata.gz: 83a6d261729864fd043f39ea3fb33c18c6c73d058d8672612e67b6a170de701184d1a957e04d229bec7c694f98b2f6abf8f9eff64bebc1dd515eb50df04fe221
7
- data.tar.gz: a690903d49cdab46e248569539acc3a47afa9ce275e991b1b10039014bd3b70e764f973206c6be4f3ace790a230c00224013560a7ba6e3d4eec2673cb95ced99
6
+ metadata.gz: 39593d695f63ca92ee16d6b353de089af278bcec8126be15a80172cd238dfa63b491f72ed2137db91d99a6b205c92fa708a61f814d9c2b6cd053f2bef25548d7
7
+ data.tar.gz: a17258a4d2893e5c399b49f3fae697c8647ca912da234201b5219f95bc67d5a8793ab3e73fe18682852f9387be4fe9b1ef3bfde9e6cd75559cb8a127721534d5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 0.3.0 (October 11, 2014)
2
+
3
+ * Merge PR #12 - Adds support for Entity FormattedValues
4
+ * Merge PR #14 - Fix invalid hash key lookup (return nil).
5
+
6
+ ## 0.2.0 (September 17, 2014)
7
+
8
+ * Merged PR #6 - Fix requires
9
+ * Merged PR #7 - Update README
10
+ * Merged PR #8 - Use Ruby Logger
11
+
1
12
  ## 0.1.2 (June 17, 2014)
2
13
 
3
14
  * Fixes associate/disassociate requests
@@ -282,7 +282,7 @@ module DynamicsCRM
282
282
  logger.debug(title)
283
283
  doc = REXML::Document.new(xml)
284
284
  formatter.write(doc.root, logger)
285
- logger.debug
285
+ logger.debug("\n")
286
286
  end
287
287
 
288
288
  def formatter
@@ -2,6 +2,11 @@ module DynamicsCRM
2
2
  module Response
3
3
  class RetrieveResult < Result
4
4
 
5
+ # Returns RetrieveResult response body as an Entity object.
6
+ def entity
7
+ @entity ||= XML::Entity.from_xml(@result_response)
8
+ end
9
+
5
10
  protected
6
11
 
7
12
  # Invoked by Result constructor
@@ -1,3 +1,3 @@
1
1
  module DynamicsCRM
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -71,7 +71,7 @@ module DynamicsCRM
71
71
  end
72
72
 
73
73
  def to_s
74
- self.to_xml
74
+ self.to_hash
75
75
  end
76
76
 
77
77
  def build_xml(key, value, type)
@@ -144,13 +144,19 @@ module DynamicsCRM
144
144
 
145
145
  def self.from_xml(xml_document)
146
146
  hash = MessageParser.parse_key_value_pairs(xml_document)
147
- return Attributes.new(hash)
147
+ if xml_document.name == "FormattedValues"
148
+ return FormattedValues.new(hash)
149
+ elsif xml_document.name == "Parameters"
150
+ return Parameters.new(hash)
151
+ else
152
+ return Attributes.new(hash)
153
+ end
148
154
  end
149
155
 
150
156
  # Allows method-like access to the hash (OpenStruct)
151
157
  def method_missing(method_name, *args, &block)
152
158
  # Return local hash entry if any.
153
- return self[method_name.to_s]
159
+ return self.key?(method_name.to_s) ? self[method_name.to_s] : nil
154
160
  end
155
161
 
156
162
  def respond_to_missing?(method_name, include_private = false)
@@ -160,6 +166,7 @@ module DynamicsCRM
160
166
  end
161
167
 
162
168
  class Parameters < Attributes; end
169
+ class FormattedValues < Attributes; end
163
170
  end
164
171
 
165
172
  end
@@ -14,7 +14,7 @@ module DynamicsCRM
14
14
  def to_xml(options={})
15
15
 
16
16
  inner_xml = %Q{
17
- #{@attributes}
17
+ #{@attributes.is_a?(XML::Attributes) ? @attributes.to_xml : @attributes}
18
18
  <a:EntityState i:nil="true" />
19
19
  <a:FormattedValues xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
20
20
  <a:Id>#{@id}</a:Id>
@@ -33,9 +33,9 @@ module DynamicsCRM
33
33
 
34
34
  def to_hash
35
35
  {
36
- :attributes => attributes.to_hash,
36
+ :attributes => @attributes.to_hash,
37
37
  :entity_state => entity_state,
38
- :formatted_values => formatted_values,
38
+ :formatted_values => (@formatted_values ? @formatted_values.to_hash : nil),
39
39
  :id => @id,
40
40
  :logical_name => @logical_name,
41
41
  :related_entities => related_entities
@@ -52,6 +52,10 @@ module DynamicsCRM
52
52
  if entity.respond_to?(attr_name)
53
53
  if node.name == "Attributes"
54
54
  entity.attributes = XML::Attributes.from_xml(node)
55
+ elsif node.name == "FormattedValues"
56
+ entity.formatted_values = XML::FormattedValues.from_xml(node)
57
+ # Reset to nil if no values were found.
58
+ entity.formatted_values = nil if entity.formatted_values.empty?
55
59
  else
56
60
  entity.send("#{attr_name}=", node.text ? node.text.strip : nil)
57
61
  end
@@ -204,11 +204,11 @@ module DynamicsCRM
204
204
  ns_alias = 'a'
205
205
  end
206
206
 
207
- parameters_xml = XML::Parameters.new(parameters)
207
+ parameters = XML::Parameters.new(parameters)
208
208
  build_envelope('Execute') do
209
209
  %Q{<Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
210
210
  <request i:type="#{ns_alias}:#{action}Request" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">
211
- #{parameters_xml}
211
+ #{parameters.to_xml}
212
212
  <a:RequestId i:nil="true" />
213
213
  <a:RequestName>#{action}</a:RequestName>
214
214
  </request>
@@ -35,17 +35,31 @@ describe DynamicsCRM::Client do
35
35
  end
36
36
 
37
37
  describe "#retrieve" do
38
- it "retrieves object by id" do
39
-
38
+ before(:each) do
40
39
  subject.stub(:post).and_return(fixture("retrieve_account_all_columns"))
40
+ end
41
41
 
42
- result = subject.retrieve("account", "93f0325c-a592-e311-b7f3-6c3be5a8a0c8")
42
+ let(:result) { subject.retrieve("account", "93f0325c-a592-e311-b7f3-6c3be5a8a0c8") }
43
43
 
44
+ it "retrieves object by id and acts as hash" do
44
45
  result.should be_a(DynamicsCRM::Response::RetrieveResult)
45
46
  result.type.should == "account"
46
47
  result.id.should == "93f0325c-a592-e311-b7f3-6c3be5a8a0c8"
47
48
  result.name.should == "Adventure Works (sample)"
48
49
  end
50
+
51
+ it "exposes entity object" do
52
+ entity = result.entity
53
+
54
+ expect(entity).to be_a(DynamicsCRM::XML::Entity)
55
+ expect(entity.attributes).to be_a(DynamicsCRM::XML::Attributes)
56
+ expect(entity.attributes.merged).to eq(false)
57
+ expect(entity.attributes.nothing).to be_nil
58
+
59
+ expect(entity.formatted_values).to be_a(DynamicsCRM::XML::FormattedValues)
60
+ expect(entity.formatted_values.merged).to eq('No')
61
+ expect(entity.formatted_values.nothing).to be_nil
62
+ end
49
63
  end
50
64
 
51
65
  describe "#retrieve_multiple" do
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe DynamicsCRM::XML::MessageBuilder do
4
+
5
+ describe 'execute_request' do
6
+ let(:dummy_class) { Class.new.extend(DynamicsCRM::XML::MessageBuilder) }
7
+
8
+ context "who_am_i" do
9
+ it "generates WhoAmI XML request" do
10
+ xml = dummy_class.execute_request('WhoAmI')
11
+ expect(xml).to include('<request i:type="b:WhoAmIRequest"')
12
+ expect(xml).to include('<a:Parameters xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">')
13
+ end
14
+ end
15
+
16
+ end
17
+
18
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamics_crm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Heth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-17 00:00:00.000000000 Z
11
+ date: 2014-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curb
@@ -183,6 +183,7 @@ files:
183
183
  - spec/lib/xml/entity_reference_spec.rb
184
184
  - spec/lib/xml/entity_spec.rb
185
185
  - spec/lib/xml/fault_spec.rb
186
+ - spec/lib/xml/message_builder_spec.rb
186
187
  - spec/lib/xml/query_spec.rb
187
188
  - spec/spec_helper.rb
188
189
  - spec/support/fixture_helpers.rb
@@ -244,6 +245,7 @@ test_files:
244
245
  - spec/lib/xml/entity_reference_spec.rb
245
246
  - spec/lib/xml/entity_spec.rb
246
247
  - spec/lib/xml/fault_spec.rb
248
+ - spec/lib/xml/message_builder_spec.rb
247
249
  - spec/lib/xml/query_spec.rb
248
250
  - spec/spec_helper.rb
249
251
  - spec/support/fixture_helpers.rb