dynamics_crm 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDYyNmExNWY0NTlhOGZmZTA2NzMyYWUzM2U2MjFlNjM2MWIxZGRiNQ==
4
+ ZGMyMDk3OTNlNDA1Y2VkNzllZWJlMzc1NGExNDEwNzNiYTc4OTBjZQ==
5
5
  data.tar.gz: !binary |-
6
- NmNiMjM2OGMxNGYxMTcyNmE2MTg5YjUxMjkwZmQ2Yzc5ZWFkNGY4OQ==
6
+ ZDU2ZGVlMzE2YzAwNzk4YmMzZDA1ZWQ1OGYxMWJlNmIxZDg4Nzc3Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDJkMTRhM2YxZjgxYmJmZWRkODlhZjE3YzZhOTQzNjZhNTJhNzgwZTk5NzE5
10
- Mzk1MjJmZTIxZThjYjQyN2MwYTAwZmI2YTVhMTQyYzVkNjU0M2FlOTAyMjAw
11
- MTc4NjQ5MjM1YzE1YTg2ZmFhODYwN2M1MzBjODZiNzdmNmM2NjQ=
9
+ ZWYyZDM0NGFjNzJiYmRhYmNhZDAwMmQzYTBjNWQzY2YwMWVjYWI2YWEwZmRl
10
+ NGJkZDFkYTljZjUwNzVmZGQxMTdjYTE2YmUzNDBhMDE3N2RiZTY0ZWUzNzcx
11
+ NTIzYTg2YmIzNjJmZDJiZDYxMzhiZGUxNjZkZGQ2NTcyMTQxN2U=
12
12
  data.tar.gz: !binary |-
13
- MjgyOGVjMzA5ZDI2YzI3MGFkYzdkN2EwZjg5OTJiZjJhMzAwMmVmYTBjM2U1
14
- ZTAwMjM3Mjg2MThiMzRmMjk1N2NlZWFhOTkwY2Q5MmE5N2YzZjliMjA1MWVj
15
- OTYwOGUwNjc2OTdmMjQ3MjIxZGI1YjA4MTM2NTYxZDlhNWYyNmI=
13
+ MzEwYTk0ZmY4OGRlYjBiODIwZGExNDJkOTI3ODRiNWM0YjQ5YzUxYWVhZDQ4
14
+ NmQ0ZjY3NjVmY2Y0OTljYWQ0N2ZiYWM2MmYwY2E4Mzg4MGVjMzUyOGUzNzhi
15
+ NzgxYTk4ZWFkZmEyOGJmMjhjYmRiYjRjNTg2YjZjM2UwNjRhODI=
data/dynamics_crm.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency 'curb', '~> 0.8', '>= 0.8.5'
22
22
  spec.add_runtime_dependency 'mimemagic', '~> 0.2', '>= 0.2.1'
23
+ #spec.add_runtime_dependency 'nokogiri', '~> 1.5', '>= 1.5.10'
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.3"
25
26
  spec.add_development_dependency 'rake', '~> 10.1'
@@ -0,0 +1,14 @@
1
+ module DynamicsCRM
2
+ module Model
3
+ class Entity
4
+ attr_reader :logical_name, :id
5
+ attr_accessor :client
6
+
7
+ def initialize(logical_name, id, client)
8
+ @logical_name = logical_name
9
+ @id = id
10
+ @client = client
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ module DynamicsCRM
2
+ module Model
3
+ class Opportunity < Entity
4
+ def initialize(id, client)
5
+ super("opportunity", id, client)
6
+ end
7
+
8
+ def set_as_won
9
+ self.send_status("WinOpportunity")
10
+ end
11
+
12
+ def set_as_lost
13
+ self.send_status("LoseOpportunity")
14
+ end
15
+
16
+ protected
17
+
18
+ def send_status(message_type, status=-1)
19
+ entity = DynamicsCRM::XML::Entity.new("opportunityclose")
20
+ entity.attributes = DynamicsCRM::XML::Attributes.new(
21
+ opportunityid: DynamicsCRM::XML::EntityReference.new(@logical_name, @id)
22
+ )
23
+
24
+ response = @client.execute(message_type, {
25
+ OpportunityClose: entity,
26
+ Status: {type: "OptionSetValue", value: -1}
27
+ })
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module DynamicsCRM
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -21,6 +21,8 @@ module DynamicsCRM
21
21
  type = "dateTime"
22
22
  when ::Hash, EntityReference
23
23
  type = "EntityReference"
24
+ when Entity
25
+ type = "Entity"
24
26
  when Query
25
27
  type = "QueryExpression"
26
28
  when FetchExpression
@@ -5,21 +5,28 @@ module DynamicsCRM
5
5
 
6
6
  attr_accessor :attributes, :entity_state, :formatted_values, :id, :logical_name, :related_entities
7
7
 
8
- def initialize(logical_name)
8
+ def initialize(logical_name, id=nil)
9
9
  @logical_name = logical_name
10
- @id = "00000000-0000-0000-0000-000000000000"
10
+ @id = id || "00000000-0000-0000-0000-000000000000"
11
11
  end
12
12
 
13
13
  # Using Entity vs entity causes the error: Value cannot be null.
14
14
  def to_xml(options={})
15
- %Q{
16
- <entity xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
15
+
16
+ inner_xml = %Q{
17
17
  #{@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>
21
21
  <a:LogicalName>#{@logical_name}</a:LogicalName>
22
22
  <a:RelatedEntities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
23
+ }
24
+
25
+ return inner_xml if options[:exclude_root]
26
+
27
+ %Q{
28
+ <entity xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
29
+ #{inner_xml}
23
30
  </entity>
24
31
  }
25
32
  end
@@ -14,8 +14,8 @@ module DynamicsCRM
14
14
  namespace = options[:namespace] ? "#{options[:namespace]}:" : ''
15
15
 
16
16
  xml = %Q{
17
- <#{namespace}LogicalName>#{@logical_name}</#{namespace}LogicalName>
18
17
  <#{namespace}Id>#{@id}</#{namespace}Id>
18
+ <#{namespace}LogicalName>#{@logical_name}</#{namespace}LogicalName>
19
19
  <#{namespace}Name #{@name ? '' : 'nil="true"'}>#{@name}</#{namespace}Name>
20
20
  }
21
21
 
data/lib/dynamics_crm.rb CHANGED
@@ -22,6 +22,9 @@ require "dynamics_crm/metadata/attribute_metadata"
22
22
  require "dynamics_crm/metadata/retrieve_all_entities_response"
23
23
  require "dynamics_crm/metadata/retrieve_entity_response"
24
24
  require "dynamics_crm/metadata/retrieve_attribute_response"
25
+ # Model
26
+ require "dynamics_crm/model/entity"
27
+ require "dynamics_crm/model/opportunity"
25
28
  # Client
26
29
  require "dynamics_crm/client"
27
30
 
@@ -0,0 +1,22 @@
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:52737665-aa13-4494-b531-66bcfeb6be0f</a:RelatesTo>
6
+ <ActivityId CorrelationId="ab687b22-53ca-4adb-bbe9-57a33b1ee830" 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-23T08:05:56.843Z</u:Created>
10
+ <u:Expires>2014-03-23T08:10:56.843Z</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="c:LoseOpportunityResponse" xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:c="http://schemas.microsoft.com/crm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
17
+ <b:ResponseName>LoseOpportunity</b:ResponseName>
18
+ <b:Results xmlns:d="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
19
+ </ExecuteResult>
20
+ </ExecuteResponse>
21
+ </s:Body>
22
+ </s:Envelope>
@@ -0,0 +1,22 @@
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:4e863a40-ee2f-43cc-8482-27d70a1d60f2</a:RelatesTo>
6
+ <ActivityId CorrelationId="4ecc6e14-b29c-4bcc-b403-9417e682bc8a" 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-23T08:04:55.888Z</u:Created>
10
+ <u:Expires>2014-03-23T08:09:55.888Z</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="c:WinOpportunityResponse" xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:c="http://schemas.microsoft.com/crm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
17
+ <b:ResponseName>WinOpportunity</b:ResponseName>
18
+ <b:Results xmlns:d="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
19
+ </ExecuteResult>
20
+ </ExecuteResponse>
21
+ </s:Body>
22
+ </s:Envelope>
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe DynamicsCRM::Model::Opportunity do
4
+
5
+ subject {
6
+ client = DynamicsCRM::Client.new(organization_name: "tinderboxdev")
7
+ DynamicsCRM::Model::Opportunity.new("2dc8d7bb-149f-e311-ba8d-6c3be5a8ad64", client)
8
+ }
9
+
10
+ describe '#initialize' do
11
+
12
+ context "default instance" do
13
+ it { subject.logical_name.should == "opportunity" }
14
+ it { subject.id.should == "2dc8d7bb-149f-e311-ba8d-6c3be5a8ad64" }
15
+ it { subject.client.should_not be_nil }
16
+ end
17
+
18
+ end
19
+
20
+ describe '#send_status' do
21
+
22
+ context "#set_as_won" do
23
+
24
+ it "sets as won" do
25
+ subject.client.stub(:post).and_return(fixture("win_opportunity_response"))
26
+ subject.set_as_won.should == {"ResponseName"=>"WinOpportunity"}
27
+ end
28
+ end
29
+
30
+ context "#set_as_lost" do
31
+
32
+ it "set as lost" do
33
+ subject.client.stub(:post).and_return(fixture("lose_opportunity_response"))
34
+ subject.set_as_lost.should == {"ResponseName"=>"LoseOpportunity"}
35
+ end
36
+ end
37
+ end
38
+
39
+ end
@@ -18,8 +18,8 @@ describe DynamicsCRM::XML::EntityReference do
18
18
  # Spacing here is intentional to match created string.
19
19
  expected_xml = %Q{
20
20
  <entityReference>
21
- <LogicalName>opportunity</LogicalName>
22
21
  <Id>9BF1325C-A592-E311-B7F3-6C3BE5A8A0C8</Id>
22
+ <LogicalName>opportunity</LogicalName>
23
23
  <Name #{@name ? '' : 'nil="true"'}>#{@name}</Name>
24
24
  </entityReference>
25
25
  }
@@ -47,7 +47,7 @@ describe DynamicsCRM::XML::Entity do
47
47
  subject {
48
48
  document = REXML::Document.new(fixture("retrieve_multiple_result"))
49
49
  entity_xml = document.get_elements("//b:Entity").first
50
- DynamicsCRM::XML::Entity.from_xml(entity_xml)
50
+ DynamicsCRM::XML::Entity.from_xml(entity_xml)
51
51
  }
52
52
 
53
53
  context "parses XML document into instance variables" do
@@ -58,6 +58,6 @@ describe DynamicsCRM::XML::Entity do
58
58
  it { subject.logical_name.should == "account" }
59
59
  it { subject.related_entities.should be_nil }
60
60
  end
61
- end
61
+ end
62
62
 
63
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamics_crm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Heth
@@ -129,6 +129,8 @@ files:
129
129
  - lib/dynamics_crm/metadata/retrieve_attribute_response.rb
130
130
  - lib/dynamics_crm/metadata/retrieve_entity_response.rb
131
131
  - lib/dynamics_crm/metadata/xml_document.rb
132
+ - lib/dynamics_crm/model/entity.rb
133
+ - lib/dynamics_crm/model/opportunity.rb
132
134
  - lib/dynamics_crm/response/create_result.rb
133
135
  - lib/dynamics_crm/response/execute_result.rb
134
136
  - lib/dynamics_crm/response/result.rb
@@ -152,6 +154,7 @@ files:
152
154
  - spec/fixtures/delete_response.xml
153
155
  - spec/fixtures/disassociate_response.xml
154
156
  - spec/fixtures/fetch_xml_response.xml
157
+ - spec/fixtures/lose_opportunity_response.xml
155
158
  - spec/fixtures/receiver_fault.xml
156
159
  - spec/fixtures/request_security_token_response.xml
157
160
  - spec/fixtures/retrieve_account_all_columns.xml
@@ -164,11 +167,13 @@ files:
164
167
  - spec/fixtures/sender_fault.xml
165
168
  - spec/fixtures/update_response.xml
166
169
  - spec/fixtures/who_am_i_result.xml
170
+ - spec/fixtures/win_opportunity_response.xml
167
171
  - spec/lib/client_spec.rb
168
172
  - spec/lib/metadata/entity_metadata_spec.rb
169
173
  - spec/lib/metadata/retrieve_all_entities_response_spec.rb
170
174
  - spec/lib/metadata/retrieve_attribute_response_spec.rb
171
175
  - spec/lib/metadata/retrieve_entity_response_spec.rb
176
+ - spec/lib/model/opportunity_spec.rb
172
177
  - spec/lib/response/execute_result_spec.rb
173
178
  - spec/lib/response/retrieve_multiple_spec.rb
174
179
  - spec/lib/response/retrieve_result_spec.rb
@@ -210,6 +215,7 @@ test_files:
210
215
  - spec/fixtures/delete_response.xml
211
216
  - spec/fixtures/disassociate_response.xml
212
217
  - spec/fixtures/fetch_xml_response.xml
218
+ - spec/fixtures/lose_opportunity_response.xml
213
219
  - spec/fixtures/receiver_fault.xml
214
220
  - spec/fixtures/request_security_token_response.xml
215
221
  - spec/fixtures/retrieve_account_all_columns.xml
@@ -222,11 +228,13 @@ test_files:
222
228
  - spec/fixtures/sender_fault.xml
223
229
  - spec/fixtures/update_response.xml
224
230
  - spec/fixtures/who_am_i_result.xml
231
+ - spec/fixtures/win_opportunity_response.xml
225
232
  - spec/lib/client_spec.rb
226
233
  - spec/lib/metadata/entity_metadata_spec.rb
227
234
  - spec/lib/metadata/retrieve_all_entities_response_spec.rb
228
235
  - spec/lib/metadata/retrieve_attribute_response_spec.rb
229
236
  - spec/lib/metadata/retrieve_entity_response_spec.rb
237
+ - spec/lib/model/opportunity_spec.rb
230
238
  - spec/lib/response/execute_result_spec.rb
231
239
  - spec/lib/response/retrieve_multiple_spec.rb
232
240
  - spec/lib/response/retrieve_result_spec.rb