dynamics_crm 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +104 -0
- data/Rakefile +9 -0
- data/dynamics_crm.gemspec +28 -0
- data/lib/dynamics_crm/client.rb +295 -0
- data/lib/dynamics_crm/metadata/attribute_metadata.rb +42 -0
- data/lib/dynamics_crm/metadata/entity_metadata.rb +24 -0
- data/lib/dynamics_crm/metadata/retrieve_all_entities_response.rb +21 -0
- data/lib/dynamics_crm/metadata/retrieve_attribute_response.rb +16 -0
- data/lib/dynamics_crm/metadata/retrieve_entity_response.rb +17 -0
- data/lib/dynamics_crm/metadata/xml_document.rb +39 -0
- data/lib/dynamics_crm/response/create_result.rb +15 -0
- data/lib/dynamics_crm/response/execute_result.rb +26 -0
- data/lib/dynamics_crm/response/result.rb +78 -0
- data/lib/dynamics_crm/response/retrieve_multiple_result.rb +38 -0
- data/lib/dynamics_crm/response/retrieve_result.rb +20 -0
- data/lib/dynamics_crm/version.rb +3 -0
- data/lib/dynamics_crm/xml/attributes.rb +163 -0
- data/lib/dynamics_crm/xml/column_set.rb +34 -0
- data/lib/dynamics_crm/xml/criteria.rb +54 -0
- data/lib/dynamics_crm/xml/entity.rb +61 -0
- data/lib/dynamics_crm/xml/entity_reference.rb +56 -0
- data/lib/dynamics_crm/xml/fault.rb +42 -0
- data/lib/dynamics_crm/xml/fetch_expression.rb +27 -0
- data/lib/dynamics_crm/xml/message_builder.rb +222 -0
- data/lib/dynamics_crm/xml/message_parser.rb +68 -0
- data/lib/dynamics_crm/xml/orders.rb +36 -0
- data/lib/dynamics_crm/xml/page_info.rb +38 -0
- data/lib/dynamics_crm/xml/query.rb +38 -0
- data/lib/dynamics_crm.rb +46 -0
- data/spec/fixtures/associate_response.xml +17 -0
- data/spec/fixtures/create_response.xml +19 -0
- data/spec/fixtures/delete_response.xml +16 -0
- data/spec/fixtures/disassociate_response.xml +17 -0
- data/spec/fixtures/fetch_xml_response.xml +120 -0
- data/spec/fixtures/receiver_fault.xml +27 -0
- data/spec/fixtures/request_security_token_response.xml +62 -0
- data/spec/fixtures/retrieve_account_all_columns.xml +402 -0
- data/spec/fixtures/retrieve_all_entities.xml +614 -0
- data/spec/fixtures/retrieve_attribute_identifier_response.xml +117 -0
- data/spec/fixtures/retrieve_attribute_picklist_response.xml +1097 -0
- data/spec/fixtures/retrieve_attribute_response.xml +126 -0
- data/spec/fixtures/retrieve_entity_response.xml +671 -0
- data/spec/fixtures/retrieve_multiple_result.xml +67 -0
- data/spec/fixtures/sender_fault.xml +34 -0
- data/spec/fixtures/update_response.xml +16 -0
- data/spec/fixtures/who_am_i_result.xml +35 -0
- data/spec/lib/client_spec.rb +230 -0
- data/spec/lib/metadata/entity_metadata_spec.rb +24 -0
- data/spec/lib/metadata/retrieve_all_entities_response_spec.rb +26 -0
- data/spec/lib/metadata/retrieve_attribute_response_spec.rb +65 -0
- data/spec/lib/metadata/retrieve_entity_response_spec.rb +24 -0
- data/spec/lib/response/execute_result_spec.rb +20 -0
- data/spec/lib/response/retrieve_multiple_spec.rb +34 -0
- data/spec/lib/response/retrieve_result_spec.rb +67 -0
- data/spec/lib/xml/attributes_spec.rb +39 -0
- data/spec/lib/xml/column_set_spec.rb +19 -0
- data/spec/lib/xml/entity_reference_spec.rb +47 -0
- data/spec/lib/xml/entity_spec.rb +63 -0
- data/spec/lib/xml/fault_spec.rb +41 -0
- data/spec/lib/xml/query_spec.rb +43 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/fixture_helpers.rb +14 -0
- metadata +240 -0
@@ -0,0 +1,222 @@
|
|
1
|
+
module DynamicsCRM
|
2
|
+
module XML
|
3
|
+
module MessageBuilder
|
4
|
+
|
5
|
+
def uuid
|
6
|
+
SecureRandom.uuid
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_current_time
|
10
|
+
Time.now.utc.strftime '%Y-%m-%dT%H:%M:%SZ'
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_tomorrow_time
|
14
|
+
(Time.now.utc + (24*60*60)).strftime '%Y-%m-%dT%H:%M:%SZ'
|
15
|
+
end
|
16
|
+
|
17
|
+
# Select the right region for your CRM
|
18
|
+
# The region can be pulled from the Organization WSDL
|
19
|
+
#
|
20
|
+
# urn:crmna:dynamics.com - North America
|
21
|
+
# urn:crmemea:dynamics.com - Europe, the Middle East and Africa
|
22
|
+
# urn:crmapac:dynamics.com - Asia Pacific
|
23
|
+
def build_ocp_request(username, password)
|
24
|
+
%Q{
|
25
|
+
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
|
26
|
+
xmlns:a="http://www.w3.org/2005/08/addressing"
|
27
|
+
xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
|
28
|
+
<s:Header>
|
29
|
+
<a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
|
30
|
+
<a:MessageID>urn:uuid:#{uuid()}</a:MessageID>
|
31
|
+
<a:ReplyTo>
|
32
|
+
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
|
33
|
+
</a:ReplyTo>
|
34
|
+
<a:To s:mustUnderstand="1">#{Client::LOGIN_URL}</a:To>
|
35
|
+
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
36
|
+
<u:Timestamp u:Id="_0">
|
37
|
+
<u:Created>#{get_current_time}</u:Created>
|
38
|
+
<u:Expires>#{get_tomorrow_time}</u:Expires>
|
39
|
+
</u:Timestamp>
|
40
|
+
<o:UsernameToken u:Id="uuid-cdb639e6-f9b0-4c01-b454-0fe244de73af-1">
|
41
|
+
<o:Username>#{username}</o:Username>
|
42
|
+
<o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">
|
43
|
+
#{password}
|
44
|
+
</o:Password>
|
45
|
+
</o:UsernameToken>
|
46
|
+
</o:Security>
|
47
|
+
</s:Header>
|
48
|
+
<s:Body>
|
49
|
+
<t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
|
50
|
+
<wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
|
51
|
+
<a:EndpointReference>
|
52
|
+
<a:Address>#{Client::REGION}</a:Address>
|
53
|
+
</a:EndpointReference>
|
54
|
+
</wsp:AppliesTo>
|
55
|
+
<t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
|
56
|
+
</t:RequestSecurityToken>
|
57
|
+
</s:Body>
|
58
|
+
</s:Envelope>
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def build_envelope(action, &block)
|
64
|
+
%Q{
|
65
|
+
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
|
66
|
+
#{build_header(action)}
|
67
|
+
<s:Body>
|
68
|
+
#{yield}
|
69
|
+
</s:Body>
|
70
|
+
</s:Envelope>
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def build_header(action)
|
75
|
+
|
76
|
+
caller_id = @caller_id ? %Q{<CallerId xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">#{@caller_id}</CallerId>} : ""
|
77
|
+
|
78
|
+
%Q{
|
79
|
+
<s:Header>
|
80
|
+
<a:Action s:mustUnderstand="1">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/#{action}</a:Action>
|
81
|
+
#{caller_id}
|
82
|
+
<a:MessageID>
|
83
|
+
urn:uuid:#{uuid()}
|
84
|
+
</a:MessageID>
|
85
|
+
<a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>
|
86
|
+
<a:To s:mustUnderstand="1">
|
87
|
+
#{@organization_endpoint}
|
88
|
+
</a:To>
|
89
|
+
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
90
|
+
<u:Timestamp u:Id="_0">
|
91
|
+
<u:Created>#{get_current_time}</u:Created>
|
92
|
+
<u:Expires>#{get_tomorrow_time}</u:Expires>
|
93
|
+
</u:Timestamp>
|
94
|
+
<EncryptedData Id="Assertion0" Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#">
|
95
|
+
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"></EncryptionMethod>
|
96
|
+
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
|
97
|
+
<EncryptedKey>
|
98
|
+
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"></EncryptionMethod>
|
99
|
+
<ds:KeyInfo Id="keyinfo">
|
100
|
+
<wsse:SecurityTokenReference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
101
|
+
<wsse:KeyIdentifier EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier">
|
102
|
+
#{@key_identifier}
|
103
|
+
</wsse:KeyIdentifier>
|
104
|
+
</wsse:SecurityTokenReference>
|
105
|
+
</ds:KeyInfo>
|
106
|
+
<CipherData>
|
107
|
+
<CipherValue>
|
108
|
+
#{@security_token0}
|
109
|
+
</CipherValue>
|
110
|
+
</CipherData>
|
111
|
+
</EncryptedKey>
|
112
|
+
</ds:KeyInfo>
|
113
|
+
<CipherData>
|
114
|
+
<CipherValue>
|
115
|
+
#{@security_token1}
|
116
|
+
</CipherValue>
|
117
|
+
</CipherData>
|
118
|
+
</EncryptedData>
|
119
|
+
</o:Security>
|
120
|
+
</s:Header>
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
def create_request(entity)
|
125
|
+
build_envelope('Create') do
|
126
|
+
%Q{<Create xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
127
|
+
#{entity.to_xml}
|
128
|
+
</Create>}
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def update_request(entity)
|
133
|
+
build_envelope('Update') do
|
134
|
+
%Q{<Update xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
135
|
+
#{entity.to_xml}
|
136
|
+
</Update>}
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# Tag name case MATTERS!
|
141
|
+
def retrieve_request(entity_name, guid, columns)
|
142
|
+
build_envelope('Retrieve') do
|
143
|
+
%Q{<Retrieve xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
|
144
|
+
<entityName>#{entity_name}</entityName>
|
145
|
+
<id>#{guid}</id>
|
146
|
+
#{columns.to_xml}
|
147
|
+
</Retrieve>}
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def retrieve_multiple_request(object)
|
152
|
+
request = build_envelope('RetrieveMultiple') do
|
153
|
+
%Q{
|
154
|
+
<RetrieveMultiple xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
|
155
|
+
#{object.to_xml}
|
156
|
+
</RetrieveMultiple>
|
157
|
+
}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
# Tag name case MATTERS!
|
162
|
+
def delete_request(entity_name, guid)
|
163
|
+
build_envelope('Delete') do
|
164
|
+
%Q{<Delete xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
|
165
|
+
<entityName>#{entity_name}</entityName>
|
166
|
+
<id>#{guid}</id>
|
167
|
+
</Delete>}
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def associate_request(entity_name, id, relationship, relationship_entities=[])
|
172
|
+
modify_association("Associate", entity_name, id, relationship, relationship_entities)
|
173
|
+
end
|
174
|
+
|
175
|
+
def disassociate_request(entity_name, id, relationship, relationship_entities=[])
|
176
|
+
modify_association("Disassociate", entity_name, id, relationship, relationship_entities)
|
177
|
+
end
|
178
|
+
|
179
|
+
def modify_association(action, entity_name, id, relationship, relationship_entities=[])
|
180
|
+
entities_xml = ""
|
181
|
+
relationship_entities.each do |ref|
|
182
|
+
entities_xml << ref.to_xml(namespace: "b")
|
183
|
+
end
|
184
|
+
|
185
|
+
build_envelope(action) do
|
186
|
+
%Q{<#{action} xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts">
|
187
|
+
<entityName i:type="string">#{entity_name}</entityName>
|
188
|
+
<entityId xmlns:q10="http://schemas.microsoft.com/2003/10/Serialization/" i:type="q10:guid">#{id}</entityId>
|
189
|
+
<relationship i:type="b:Relationship">
|
190
|
+
<b:PrimaryEntityRole>Referenced</b:PrimaryEntityRole>
|
191
|
+
<b:SchemaName i:type="string">#{relationship}</b:SchemaName>
|
192
|
+
</relationship>
|
193
|
+
<relatedEntities i:type="b:EntityReferenceCollection">#{entities_xml}</relatedEntities>
|
194
|
+
</#{action}>}
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def execute_request(action, parameters={})
|
199
|
+
|
200
|
+
# Default namespace is /crm/2011/Contracts
|
201
|
+
ns_alias = "b"
|
202
|
+
# Metadata Service calls are under the /xrm/2011/Contracts schema.
|
203
|
+
if ["RetrieveAllEntities", "RetrieveEntityMetadata", "RetrieveEntity", "RetrieveAttribute", "RetrieveMultiple"].include?(action)
|
204
|
+
ns_alias = 'a'
|
205
|
+
end
|
206
|
+
|
207
|
+
parameters_xml = XML::Parameters.new(parameters)
|
208
|
+
build_envelope('Execute') do
|
209
|
+
%Q{<Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
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}
|
212
|
+
<a:RequestId i:nil="true" />
|
213
|
+
<a:RequestName>#{action}</a:RequestName>
|
214
|
+
</request>
|
215
|
+
</Execute>}
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
# MessageBuilder
|
221
|
+
end
|
222
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'rexml/document'
|
3
|
+
|
4
|
+
module DynamicsCRM
|
5
|
+
module XML
|
6
|
+
module MessageParser
|
7
|
+
|
8
|
+
def self.parse_key_value_pairs(parent_element)
|
9
|
+
h = {}
|
10
|
+
# Get namespace alias (letter) for child elements.
|
11
|
+
namespace_alias = parent_element.attributes.keys.first || "c"
|
12
|
+
parent_element.each_element do |key_value_pair|
|
13
|
+
|
14
|
+
key_element = key_value_pair.elements["#{namespace_alias}:key"]
|
15
|
+
key = key_element.text
|
16
|
+
value_element = key_value_pair.elements["#{namespace_alias}:value"]
|
17
|
+
value = value_element.text
|
18
|
+
begin
|
19
|
+
|
20
|
+
case value_element.attributes["type"]
|
21
|
+
when "b:OptionSetValue"
|
22
|
+
# Nested value. Appears to always be an integer.
|
23
|
+
value = value_element.elements.first.text.to_i
|
24
|
+
when "d:boolean"
|
25
|
+
value = (value == "true")
|
26
|
+
when "d:decimal"
|
27
|
+
value = value.to_f
|
28
|
+
when "d:dateTime"
|
29
|
+
value = Time.parse(value)
|
30
|
+
when "b:EntityReference"
|
31
|
+
entity_ref = {}
|
32
|
+
value_element.each_element do |child|
|
33
|
+
entity_ref[child.name] = child.text
|
34
|
+
end
|
35
|
+
value = entity_ref
|
36
|
+
when "b:EntityCollection"
|
37
|
+
collection = []
|
38
|
+
value_element.elements["b:Entities"].elements.each do |entity_xml|
|
39
|
+
collection << XML::Entity.from_xml(entity_xml)
|
40
|
+
end
|
41
|
+
value = collection
|
42
|
+
when "d:EntityMetadata", /^d:\w*AttributeMetadata$/
|
43
|
+
value = value_element
|
44
|
+
when "d:ArrayOfEntityMetadata"
|
45
|
+
value = value_element.get_elements("d:EntityMetadata")
|
46
|
+
when "d:ArrayOfAttributeMetadata"
|
47
|
+
value = value_element.get_elements("d:AttributeMetadata")
|
48
|
+
when "b:Money"
|
49
|
+
# Nested value.
|
50
|
+
value = value_element.elements.first.text.to_f
|
51
|
+
when "d:int"
|
52
|
+
value = value.to_i
|
53
|
+
when "d:string", "d:guid"
|
54
|
+
# nothing
|
55
|
+
end
|
56
|
+
rescue => e
|
57
|
+
# In case there's an error during type conversion.
|
58
|
+
puts e.message
|
59
|
+
end
|
60
|
+
|
61
|
+
h[key] = value
|
62
|
+
end
|
63
|
+
h
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module DynamicsCRM
|
2
|
+
module XML
|
3
|
+
# Represents Orders XML element.
|
4
|
+
class Orders
|
5
|
+
|
6
|
+
attr_accessor :attribute_name, :order_type
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@order_type = 0
|
10
|
+
end
|
11
|
+
|
12
|
+
# Using Entity vs entity causes the error: Value cannot be null.
|
13
|
+
# <Order> can be repeated multiple times
|
14
|
+
# orderType: 0 (Ascending) or 1 (Descending)
|
15
|
+
def to_xml
|
16
|
+
%Q{
|
17
|
+
<a:Orders>
|
18
|
+
<a:Order>
|
19
|
+
<a:attributeName>#{attribute_name}</a:attributeName>
|
20
|
+
<a:orderType>#{order_type}</a:orderType>
|
21
|
+
</a:Order>
|
22
|
+
</a:Orders>
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_hash
|
27
|
+
{
|
28
|
+
:attribute_name => attribute_name,
|
29
|
+
:order_type => order_type
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
# Orders
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module DynamicsCRM
|
2
|
+
module XML
|
3
|
+
|
4
|
+
class PageInfo
|
5
|
+
|
6
|
+
attr_accessor :count, :page_number, :paging_cookie, :return_total_record_count
|
7
|
+
def initialize
|
8
|
+
@count = 20
|
9
|
+
@page_number = 1
|
10
|
+
@paging_cookie = nil
|
11
|
+
@return_total_record_count = false
|
12
|
+
end
|
13
|
+
|
14
|
+
# Using Entity vs entity causes the error: Value cannot be null.
|
15
|
+
def to_xml
|
16
|
+
%Q{
|
17
|
+
<b:PageInfo>
|
18
|
+
<b:Count>#{count}</b:Count>
|
19
|
+
<b:PageNumber>#{page_number}</b:PageNumber>
|
20
|
+
<b:PagingCookie i:nil="true" />
|
21
|
+
<b:ReturnTotalRecordCount>false</b:ReturnTotalRecordCount>
|
22
|
+
</b:PageInfo>
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_hash
|
27
|
+
{
|
28
|
+
:count => count,
|
29
|
+
:page_number => page_number,
|
30
|
+
:paging_cookie => paging_cookie,
|
31
|
+
:return_total_record_count => return_total_record_count
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
# PageInfo
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module DynamicsCRM
|
2
|
+
module XML
|
3
|
+
# Represents Query XML fragment.
|
4
|
+
class Query
|
5
|
+
|
6
|
+
attr_accessor :columns, :criteria, :entity_name
|
7
|
+
|
8
|
+
def initialize(entity_name)
|
9
|
+
@entity_name = entity_name
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_xml(options={})
|
13
|
+
namespace = options[:namespace] ? options[:namespace] : "b"
|
14
|
+
|
15
|
+
column_set = ColumnSet.new(columns)
|
16
|
+
@criteria ||= Criteria.new
|
17
|
+
|
18
|
+
xml = %Q{
|
19
|
+
#{column_set.to_xml(namespace: namespace, camel_case: true)}
|
20
|
+
#{@criteria.to_xml(namespace: namespace)}
|
21
|
+
<#{namespace}:Distinct>false</#{namespace}:Distinct>
|
22
|
+
<#{namespace}:EntityName>#{entity_name}</#{namespace}:EntityName>
|
23
|
+
<#{namespace}:LinkEntities />
|
24
|
+
<#{namespace}:Orders />
|
25
|
+
}
|
26
|
+
|
27
|
+
if options[:exclude_root].nil?
|
28
|
+
xml = %Q{<query i:type="b:QueryExpression" xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
29
|
+
#{xml}
|
30
|
+
</query>}
|
31
|
+
end
|
32
|
+
return xml
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
# Query
|
37
|
+
end
|
38
|
+
end
|
data/lib/dynamics_crm.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "dynamics_crm/version"
|
2
|
+
# CRM
|
3
|
+
require "dynamics_crm/xml/message_builder"
|
4
|
+
require 'dynamics_crm/xml/message_parser'
|
5
|
+
require "dynamics_crm/xml/fault"
|
6
|
+
require "dynamics_crm/xml/attributes"
|
7
|
+
require "dynamics_crm/xml/column_set"
|
8
|
+
require "dynamics_crm/xml/criteria"
|
9
|
+
require "dynamics_crm/xml/query"
|
10
|
+
require "dynamics_crm/xml/fetch_expression"
|
11
|
+
require "dynamics_crm/xml/entity"
|
12
|
+
require "dynamics_crm/xml/entity_reference"
|
13
|
+
require "dynamics_crm/response/result"
|
14
|
+
require "dynamics_crm/response/retrieve_result"
|
15
|
+
require "dynamics_crm/response/retrieve_multiple_result"
|
16
|
+
require "dynamics_crm/response/create_result"
|
17
|
+
require "dynamics_crm/response/execute_result"
|
18
|
+
# Metadata
|
19
|
+
require "dynamics_crm/metadata/xml_document"
|
20
|
+
require "dynamics_crm/metadata/entity_metadata"
|
21
|
+
require "dynamics_crm/metadata/attribute_metadata"
|
22
|
+
require "dynamics_crm/metadata/retrieve_all_entities_response"
|
23
|
+
require "dynamics_crm/metadata/retrieve_entity_response"
|
24
|
+
require "dynamics_crm/metadata/retrieve_attribute_response"
|
25
|
+
# Client
|
26
|
+
require "dynamics_crm/client"
|
27
|
+
|
28
|
+
require 'bigdecimal'
|
29
|
+
require 'base64'
|
30
|
+
require "rexml/document"
|
31
|
+
require 'mimemagic'
|
32
|
+
require 'curl'
|
33
|
+
|
34
|
+
module DynamicsCRM
|
35
|
+
|
36
|
+
class StringUtil
|
37
|
+
def self.underscore(str)
|
38
|
+
str.gsub(/::/, '/').
|
39
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
40
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
41
|
+
tr("-", "_").
|
42
|
+
downcase
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
|
2
|
+
<s:Header>
|
3
|
+
<a:Action s:mustUnderstand="1">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/AssociateResponse
|
4
|
+
</a:Action>
|
5
|
+
<a:RelatesTo>urn:uuid:2df2ff28-b16e-4684-bb58-d96b432dc8cc</a:RelatesTo>
|
6
|
+
<ActivityId CorrelationId="9395279d-8e7c-4053-ad55-b99c84aa8fde" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId>
|
7
|
+
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
8
|
+
<u:Timestamp u:Id="_0">
|
9
|
+
<u:Created>2014-03-03T17:39:31.032Z</u:Created>
|
10
|
+
<u:Expires>2014-03-03T17:44:31.032Z</u:Expires>
|
11
|
+
</u:Timestamp>
|
12
|
+
</o:Security>
|
13
|
+
</s:Header>
|
14
|
+
<s:Body>
|
15
|
+
<AssociateResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services"/>
|
16
|
+
</s:Body>
|
17
|
+
</s:Envelope>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
|
3
|
+
<s:Header>
|
4
|
+
<a:Action s:mustUnderstand="1">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/CreateResponse</a:Action>
|
5
|
+
<a:RelatesTo>urn:uuid:db950b07-cc15-4da9-ba78-807295cda52d</a:RelatesTo>
|
6
|
+
<ActivityId CorrelationId="93787a70-d770-4cb0-9a08-526b4543f5bc" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId>
|
7
|
+
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
8
|
+
<u:Timestamp u:Id="_0">
|
9
|
+
<u:Created>2014-02-28T20:19:19.007Z</u:Created>
|
10
|
+
<u:Expires>2014-02-28T20:24:19.007Z</u:Expires>
|
11
|
+
</u:Timestamp>
|
12
|
+
</o:Security>
|
13
|
+
</s:Header>
|
14
|
+
<s:Body>
|
15
|
+
<CreateResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
|
16
|
+
<CreateResult>c4944f99-b5a0-e311-b64f-6c3be5a87df0</CreateResult>
|
17
|
+
</CreateResponse>
|
18
|
+
</s:Body>
|
19
|
+
</s:Envelope>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
|
2
|
+
<s:Header>
|
3
|
+
<a:Action s:mustUnderstand="1">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/DeleteResponse</a:Action>
|
4
|
+
<a:RelatesTo>urn:uuid:c92ec99b-3093-4856-85dc-c46d6aad5bcc</a:RelatesTo>
|
5
|
+
<ActivityId CorrelationId="700b5b17-bbdb-4769-bba0-bb76513e1695" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId>
|
6
|
+
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
7
|
+
<u:Timestamp u:Id="_0">
|
8
|
+
<u:Created>2014-02-28T20:24:33.196Z</u:Created>
|
9
|
+
<u:Expires>2014-02-28T20:29:33.196Z</u:Expires>
|
10
|
+
</u:Timestamp>
|
11
|
+
</o:Security>
|
12
|
+
</s:Header>
|
13
|
+
<s:Body>
|
14
|
+
<DeleteResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services"/>
|
15
|
+
</s:Body>
|
16
|
+
</s:Envelope>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
|
2
|
+
<s:Header>
|
3
|
+
<a:Action s:mustUnderstand="1">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/DisassociateResponse
|
4
|
+
</a:Action>
|
5
|
+
<a:RelatesTo>urn:uuid:be010af5-f3c7-4f90-9a86-2360dbf1d43e</a:RelatesTo>
|
6
|
+
<ActivityId CorrelationId="88cb28d4-340f-49b9-a8b3-8b34992df052" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId>
|
7
|
+
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
8
|
+
<u:Timestamp u:Id="_0">
|
9
|
+
<u:Created>2014-03-03T17:39:31.120Z</u:Created>
|
10
|
+
<u:Expires>2014-03-03T17:44:31.120Z</u:Expires>
|
11
|
+
</u:Timestamp>
|
12
|
+
</o:Security>
|
13
|
+
</s:Header>
|
14
|
+
<s:Body>
|
15
|
+
<DisassociateResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services"/>
|
16
|
+
</s:Body>
|
17
|
+
</s:Envelope>
|
@@ -0,0 +1,120 @@
|
|
1
|
+
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
|
2
|
+
<s:Header>
|
3
|
+
<a:Action s:mustUnderstand="1">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/ExecuteResponse
|
4
|
+
</a:Action>
|
5
|
+
<a:RelatesTo>urn:uuid:cf266ae7-0139-40dd-bdaa-c64765d16a1f</a:RelatesTo>
|
6
|
+
<ActivityId CorrelationId="5c0bd162-f7d9-4059-a709-a7e8b7bbaa04" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId>
|
7
|
+
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
8
|
+
<u:Timestamp u:Id="_0">
|
9
|
+
<u:Created>2014-03-13T23:31:44.643Z</u:Created>
|
10
|
+
<u:Expires>2014-03-13T23:36:44.643Z</u:Expires>
|
11
|
+
</u:Timestamp>
|
12
|
+
</o:Security>
|
13
|
+
</s:Header>
|
14
|
+
<s:Body>
|
15
|
+
<ExecuteResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
|
16
|
+
<ExecuteResult i:type="b:RetrieveMultipleResponse" xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
17
|
+
<b:ResponseName>RetrieveMultiple</b:ResponseName>
|
18
|
+
<b:Results xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
|
19
|
+
<b:KeyValuePairOfstringanyType>
|
20
|
+
<c:key>EntityCollection</c:key>
|
21
|
+
<c:value i:type="b:EntityCollection">
|
22
|
+
<b:Entities>
|
23
|
+
<b:Entity>
|
24
|
+
<b:Attributes>
|
25
|
+
<b:KeyValuePairOfstringanyType>
|
26
|
+
<c:key>new_tinderboxdocumentid</c:key>
|
27
|
+
<c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">9c27cf91-ada3-e311-b64f-6c3be5a87df0</c:value>
|
28
|
+
</b:KeyValuePairOfstringanyType>
|
29
|
+
<b:KeyValuePairOfstringanyType>
|
30
|
+
<c:key>new_name</c:key>
|
31
|
+
<c:value i:type="d:string" xmlns:d="http://www.w3.org/2001/XMLSchema">6 orders of Product SKU JJ202</c:value>
|
32
|
+
</b:KeyValuePairOfstringanyType>
|
33
|
+
<b:KeyValuePairOfstringanyType>
|
34
|
+
<c:key>createdon</c:key>
|
35
|
+
<c:value i:type="d:dateTime" xmlns:d="http://www.w3.org/2001/XMLSchema">2014-03-04T14:59:23Z</c:value>
|
36
|
+
</b:KeyValuePairOfstringanyType>
|
37
|
+
</b:Attributes>
|
38
|
+
<b:EntityState i:nil="true"/>
|
39
|
+
<b:FormattedValues>
|
40
|
+
<b:KeyValuePairOfstringstring>
|
41
|
+
<c:key>createdon</c:key>
|
42
|
+
<c:value>3/4/2014 6:59 AM</c:value>
|
43
|
+
</b:KeyValuePairOfstringstring>
|
44
|
+
</b:FormattedValues>
|
45
|
+
<b:Id>9c27cf91-ada3-e311-b64f-6c3be5a87df0</b:Id>
|
46
|
+
<b:LogicalName>new_tinderboxdocument</b:LogicalName>
|
47
|
+
<b:RelatedEntities/>
|
48
|
+
</b:Entity>
|
49
|
+
<b:Entity>
|
50
|
+
<b:Attributes>
|
51
|
+
<b:KeyValuePairOfstringanyType>
|
52
|
+
<c:key>new_tinderboxdocumentid</c:key>
|
53
|
+
<c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">0b534c29-f5aa-e311-b64f-6c3be5a87df0</c:value>
|
54
|
+
</b:KeyValuePairOfstringanyType>
|
55
|
+
<b:KeyValuePairOfstringanyType>
|
56
|
+
<c:key>new_name</c:key>
|
57
|
+
<c:value i:type="d:string" xmlns:d="http://www.w3.org/2001/XMLSchema">6 orders of Product SKU JJ202</c:value>
|
58
|
+
</b:KeyValuePairOfstringanyType>
|
59
|
+
<b:KeyValuePairOfstringanyType>
|
60
|
+
<c:key>createdon</c:key>
|
61
|
+
<c:value i:type="d:dateTime" xmlns:d="http://www.w3.org/2001/XMLSchema">2014-03-13T21:19:29Z</c:value>
|
62
|
+
</b:KeyValuePairOfstringanyType>
|
63
|
+
</b:Attributes>
|
64
|
+
<b:EntityState i:nil="true"/>
|
65
|
+
<b:FormattedValues>
|
66
|
+
<b:KeyValuePairOfstringstring>
|
67
|
+
<c:key>createdon</c:key>
|
68
|
+
<c:value>3/13/2014 2:19 PM</c:value>
|
69
|
+
</b:KeyValuePairOfstringstring>
|
70
|
+
</b:FormattedValues>
|
71
|
+
<b:Id>0b534c29-f5aa-e311-b64f-6c3be5a87df0</b:Id>
|
72
|
+
<b:LogicalName>new_tinderboxdocument</b:LogicalName>
|
73
|
+
<b:RelatedEntities/>
|
74
|
+
</b:Entity>
|
75
|
+
<b:Entity>
|
76
|
+
<b:Attributes>
|
77
|
+
<b:KeyValuePairOfstringanyType>
|
78
|
+
<c:key>new_tinderboxdocumentid</c:key>
|
79
|
+
<c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">107a6fbc-f4aa-e311-af52-6c3be5a8ad70</c:value>
|
80
|
+
</b:KeyValuePairOfstringanyType>
|
81
|
+
<b:KeyValuePairOfstringanyType>
|
82
|
+
<c:key>new_name</c:key>
|
83
|
+
<c:value i:type="d:string" xmlns:d="http://www.w3.org/2001/XMLSchema">6 orders of Product SKU JJ202</c:value>
|
84
|
+
</b:KeyValuePairOfstringanyType>
|
85
|
+
<b:KeyValuePairOfstringanyType>
|
86
|
+
<c:key>createdon</c:key>
|
87
|
+
<c:value i:type="d:dateTime" xmlns:d="http://www.w3.org/2001/XMLSchema">2014-03-13T21:16:27Z</c:value>
|
88
|
+
</b:KeyValuePairOfstringanyType>
|
89
|
+
</b:Attributes>
|
90
|
+
<b:EntityState i:nil="true"/>
|
91
|
+
<b:FormattedValues>
|
92
|
+
<b:KeyValuePairOfstringstring>
|
93
|
+
<c:key>createdon</c:key>
|
94
|
+
<c:value>3/13/2014 2:16 PM</c:value>
|
95
|
+
</b:KeyValuePairOfstringstring>
|
96
|
+
</b:FormattedValues>
|
97
|
+
<b:Id>107a6fbc-f4aa-e311-af52-6c3be5a8ad70</b:Id>
|
98
|
+
<b:LogicalName>new_tinderboxdocument</b:LogicalName>
|
99
|
+
<b:RelatedEntities/>
|
100
|
+
</b:Entity>
|
101
|
+
</b:Entities>
|
102
|
+
<b:EntityName>new_tinderboxdocument</b:EntityName>
|
103
|
+
<b:MinActiveRowVersion>-1</b:MinActiveRowVersion>
|
104
|
+
<b:MoreRecords>false</b:MoreRecords>
|
105
|
+
<b:PagingCookie><cookie page="1"><new_name last="Test Proposal"
|
106
|
+
first="6 orders of Product SKU JJ202"
|
107
|
+
/><new_tinderboxdocumentid
|
108
|
+
last="{B4F20991-D399-E311-AD92-6C3BE5A8AD70}"
|
109
|
+
first="{9C27CF91-ADA3-E311-B64F-6C3BE5A87DF0}"
|
110
|
+
/></cookie>
|
111
|
+
</b:PagingCookie>
|
112
|
+
<b:TotalRecordCount>-1</b:TotalRecordCount>
|
113
|
+
<b:TotalRecordCountLimitExceeded>false</b:TotalRecordCountLimitExceeded>
|
114
|
+
</c:value>
|
115
|
+
</b:KeyValuePairOfstringanyType>
|
116
|
+
</b:Results>
|
117
|
+
</ExecuteResult>
|
118
|
+
</ExecuteResponse>
|
119
|
+
</s:Body>
|
120
|
+
</s:Envelope>
|