sekken 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.travis.yml +11 -0
  4. data/.yardopts +6 -0
  5. data/CONTRIBUTING.md +46 -0
  6. data/Gemfile +27 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +28 -0
  9. data/Rakefile +21 -0
  10. data/donate.png +0 -0
  11. data/lib/sekken.rb +75 -0
  12. data/lib/sekken/envelope.rb +92 -0
  13. data/lib/sekken/errors.rb +9 -0
  14. data/lib/sekken/example_message.rb +41 -0
  15. data/lib/sekken/httpclient.rb +35 -0
  16. data/lib/sekken/importer.rb +77 -0
  17. data/lib/sekken/message.rb +135 -0
  18. data/lib/sekken/operation.rb +100 -0
  19. data/lib/sekken/resolver.rb +20 -0
  20. data/lib/sekken/response.rb +50 -0
  21. data/lib/sekken/version.rb +5 -0
  22. data/lib/sekken/wsdl.rb +86 -0
  23. data/lib/sekken/wsdl/binding.rb +64 -0
  24. data/lib/sekken/wsdl/binding_operation.rb +85 -0
  25. data/lib/sekken/wsdl/document.rb +83 -0
  26. data/lib/sekken/wsdl/document_collection.rb +61 -0
  27. data/lib/sekken/wsdl/input_output.rb +84 -0
  28. data/lib/sekken/wsdl/message.rb +38 -0
  29. data/lib/sekken/wsdl/operation.rb +47 -0
  30. data/lib/sekken/wsdl/port.rb +29 -0
  31. data/lib/sekken/wsdl/port_type.rb +38 -0
  32. data/lib/sekken/wsdl/port_type_operation.rb +42 -0
  33. data/lib/sekken/wsdl/service.rb +55 -0
  34. data/lib/sekken/xml/attribute.rb +13 -0
  35. data/lib/sekken/xml/element.rb +82 -0
  36. data/lib/sekken/xml/element_builder.rb +220 -0
  37. data/lib/sekken/xs/schema.rb +57 -0
  38. data/lib/sekken/xs/schema_collection.rb +49 -0
  39. data/lib/sekken/xs/types.rb +272 -0
  40. data/sekken.gemspec +42 -0
  41. data/spec/fixtures/response/another_soap_fault.xml +14 -0
  42. data/spec/fixtures/response/authentication.xml +14 -0
  43. data/spec/fixtures/response/header.xml +13 -0
  44. data/spec/fixtures/response/list.xml +18 -0
  45. data/spec/fixtures/response/multi_ref.xml +39 -0
  46. data/spec/fixtures/response/soap_fault.xml +8 -0
  47. data/spec/fixtures/response/soap_fault12.xml +18 -0
  48. data/spec/fixtures/response/taxcloud.xml +1 -0
  49. data/spec/fixtures/wsdl/amazon.wsdl +1920 -0
  50. data/spec/fixtures/wsdl/arrays_with_attributes.wsdl +117 -0
  51. data/spec/fixtures/wsdl/authentication.wsdl +63 -0
  52. data/spec/fixtures/wsdl/awse.wsdl +1510 -0
  53. data/spec/fixtures/wsdl/betfair.wsdl +2981 -0
  54. data/spec/fixtures/wsdl/blz_service.wsdl +88 -0
  55. data/spec/fixtures/wsdl/bookt/bookt.wsdl +11 -0
  56. data/spec/fixtures/wsdl/bookt/bookt0.xsd +433 -0
  57. data/spec/fixtures/wsdl/bookt/bookt1.xsd +42 -0
  58. data/spec/fixtures/wsdl/bookt/bookt10.xsd +38 -0
  59. data/spec/fixtures/wsdl/bookt/bookt11.xsd +17 -0
  60. data/spec/fixtures/wsdl/bookt/bookt12.xsd +18 -0
  61. data/spec/fixtures/wsdl/bookt/bookt13.xsd +22 -0
  62. data/spec/fixtures/wsdl/bookt/bookt14.xsd +27 -0
  63. data/spec/fixtures/wsdl/bookt/bookt15.xsd +28 -0
  64. data/spec/fixtures/wsdl/bookt/bookt2.wsdl +243 -0
  65. data/spec/fixtures/wsdl/bookt/bookt2.xsd +81 -0
  66. data/spec/fixtures/wsdl/bookt/bookt3.wsdl +286 -0
  67. data/spec/fixtures/wsdl/bookt/bookt3.xsd +61 -0
  68. data/spec/fixtures/wsdl/bookt/bookt4.xsd +35 -0
  69. data/spec/fixtures/wsdl/bookt/bookt5.xsd +22 -0
  70. data/spec/fixtures/wsdl/bookt/bookt6.xsd +26 -0
  71. data/spec/fixtures/wsdl/bookt/bookt7.xsd +18 -0
  72. data/spec/fixtures/wsdl/bookt/bookt8.xsd +22 -0
  73. data/spec/fixtures/wsdl/bookt/bookt9.xsd +29 -0
  74. data/spec/fixtures/wsdl/bronto.wsdl +3285 -0
  75. data/spec/fixtures/wsdl/bydexchange/bydexchange.wsdl +104 -0
  76. data/spec/fixtures/wsdl/bydexchange/bydexchange0.xsd +1 -0
  77. data/spec/fixtures/wsdl/bydexchange/bydexchange1.xsd +1 -0
  78. data/spec/fixtures/wsdl/bydexchange/bydexchange2.wsdl +119 -0
  79. data/spec/fixtures/wsdl/bydexchange/bydexchange2.xsd +1 -0
  80. data/spec/fixtures/wsdl/bydexchange/bydexchange3.xsd +1 -0
  81. data/spec/fixtures/wsdl/bydexchange/bydexchange4.xsd +1 -0
  82. data/spec/fixtures/wsdl/bydexchange/bydexchange5.xsd +1 -0
  83. data/spec/fixtures/wsdl/bydexchange/bydexchange6.xsd +1 -0
  84. data/spec/fixtures/wsdl/bydexchange/bydexchange7.xsd +1 -0
  85. data/spec/fixtures/wsdl/bydexchange/bydexchange8.xsd +1 -0
  86. data/spec/fixtures/wsdl/crowd.wsdl +2437 -0
  87. data/spec/fixtures/wsdl/data_exchange.wsdl +98 -0
  88. data/spec/fixtures/wsdl/document_literal_wrapped.wsdl +153 -0
  89. data/spec/fixtures/wsdl/economic.wsdl +65660 -0
  90. data/spec/fixtures/wsdl/edialog.wsdl +13148 -0
  91. data/spec/fixtures/wsdl/email_verification.wsdl +394 -0
  92. data/spec/fixtures/wsdl/equifax.wsdl +794 -0
  93. data/spec/fixtures/wsdl/geotrust.wsdl +156 -0
  94. data/spec/fixtures/wsdl/interhome.wsdl +2137 -0
  95. data/spec/fixtures/wsdl/iws.wsdl +695 -0
  96. data/spec/fixtures/wsdl/jetairways.wsdl +156 -0
  97. data/spec/fixtures/wsdl/jira.wsdl +3890 -0
  98. data/spec/fixtures/wsdl/juniper.wsdl +215 -0
  99. data/spec/fixtures/wsdl/namespaced_actions.wsdl +307 -0
  100. data/spec/fixtures/wsdl/oracle.wsdl +3629 -0
  101. data/spec/fixtures/wsdl/ratp.wsdl +955 -0
  102. data/spec/fixtures/wsdl/rio2/rio2.wsdl +74 -0
  103. data/spec/fixtures/wsdl/rio2/rio2_0.wsdl +55 -0
  104. data/spec/fixtures/wsdl/rio2/rio2_0.xsd +58 -0
  105. data/spec/fixtures/wsdl/rio2/rio2_1.xsd +41 -0
  106. data/spec/fixtures/wsdl/rio2/rio2_2.xsd +222 -0
  107. data/spec/fixtures/wsdl/rio2/rio2_3.xsd +10 -0
  108. data/spec/fixtures/wsdl/rpc_literal.wsdl +105 -0
  109. data/spec/fixtures/wsdl/spyne.wsdl +70 -0
  110. data/spec/fixtures/wsdl/stockquote.wsdl +124 -0
  111. data/spec/fixtures/wsdl/taxcloud.wsdl +934 -0
  112. data/spec/fixtures/wsdl/team_software/team_software.wsdl +542 -0
  113. data/spec/fixtures/wsdl/team_software/team_software0.xsd +448 -0
  114. data/spec/fixtures/wsdl/team_software/team_software1.xsd +41 -0
  115. data/spec/fixtures/wsdl/team_software/team_software2.xsd +258 -0
  116. data/spec/fixtures/wsdl/team_software/team_software3.xsd +14 -0
  117. data/spec/fixtures/wsdl/telefonkatalogen.wsdl +45 -0
  118. data/spec/fixtures/wsdl/temperature.wsdl +136 -0
  119. data/spec/fixtures/wsdl/wasmuth/wasmuth.wsdl +157 -0
  120. data/spec/fixtures/wsdl/wasmuth/wasmuth1.xsd +210 -0
  121. data/spec/fixtures/wsdl/wasmuth/wasmuth2.xsd +549 -0
  122. data/spec/fixtures/wsdl/xignite.wsdl +3470 -0
  123. data/spec/fixtures/wsdl/yahoo.wsdl +2425 -0
  124. data/spec/fixtures/wsdl/zanox_export_service.xml +520 -0
  125. data/spec/integration/amazon_spec.rb +51 -0
  126. data/spec/integration/authentication_spec.rb +38 -0
  127. data/spec/integration/awse_spec.rb +95 -0
  128. data/spec/integration/betfair_spec.rb +179 -0
  129. data/spec/integration/blz_service_spec.rb +46 -0
  130. data/spec/integration/bookt_spec.rb +59 -0
  131. data/spec/integration/bronto_spec.rb +178 -0
  132. data/spec/integration/bydexchange_spec.rb +40 -0
  133. data/spec/integration/crowd_spec.rb +44 -0
  134. data/spec/integration/data_exchange_spec.rb +27 -0
  135. data/spec/integration/document_literal_spec.rb +104 -0
  136. data/spec/integration/economic_spec.rb +64 -0
  137. data/spec/integration/email_verification_spec.rb +82 -0
  138. data/spec/integration/equifax_spec.rb +216 -0
  139. data/spec/integration/geotrust_spec.rb +17 -0
  140. data/spec/integration/interhome_spec.rb +156 -0
  141. data/spec/integration/iws_spec.rb +27 -0
  142. data/spec/integration/jetairways_spec.rb +142 -0
  143. data/spec/integration/jira_spec.rb +27 -0
  144. data/spec/integration/juniper_spec.rb +20 -0
  145. data/spec/integration/namespaced_actions_spec.rb +37 -0
  146. data/spec/integration/oracle_spec.rb +61 -0
  147. data/spec/integration/ratp_spec.rb +178 -0
  148. data/spec/integration/rio2_spec.rb +56 -0
  149. data/spec/integration/rpc_literal_spec.rb +101 -0
  150. data/spec/integration/spyne_spec.rb +60 -0
  151. data/spec/integration/stockquote_spec.rb +46 -0
  152. data/spec/integration/taxcloud_spec.rb +45 -0
  153. data/spec/integration/team_software_spec.rb +51 -0
  154. data/spec/integration/telefonkatalogen_spec.rb +42 -0
  155. data/spec/integration/temperature_spec.rb +71 -0
  156. data/spec/integration/wasmuth_spec.rb +47 -0
  157. data/spec/integration/xignite_spec.rb +112 -0
  158. data/spec/integration/yahoo_spec.rb +116 -0
  159. data/spec/sekken/httpclient_spec.rb +41 -0
  160. data/spec/sekken/operation/build_spec.rb +308 -0
  161. data/spec/sekken/operation/document_literal_spec.rb +53 -0
  162. data/spec/sekken/operation/example_body_spec.rb +95 -0
  163. data/spec/sekken/operation/rpc_literal_spec.rb +50 -0
  164. data/spec/sekken/operation_spec.rb +169 -0
  165. data/spec/sekken/resolver_spec.rb +38 -0
  166. data/spec/sekken/response_spec.rb +17 -0
  167. data/spec/sekken/wsdl/document_spec.rb +191 -0
  168. data/spec/sekken/wsdl_spec.rb +46 -0
  169. data/spec/sekken/xs/complex_type_spec.rb +197 -0
  170. data/spec/sekken/xs/element_spec.rb +82 -0
  171. data/spec/sekken/xs/simple_type_spec.rb +39 -0
  172. data/spec/sekken_spec.rb +128 -0
  173. data/spec/spec_helper.rb +37 -0
  174. data/spec/support/fixture.rb +19 -0
  175. data/spec/support/http_mock.rb +43 -0
  176. metadata +344 -0
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Integration with Wasmuth' do
4
+
5
+ subject(:client) { Sekken.new(wsdl_url, http_mock) }
6
+
7
+ let(:wsdl_url) { 'http://www3.mediaservice-wasmuth.de/online-ws-2.0/OnlineSync?wsdl' }
8
+
9
+ before do
10
+ http_mock.fake_request(wsdl_url, 'wsdl/wasmuth/wasmuth.wsdl')
11
+
12
+ # 2 schemas to import.
13
+ schema_import_base = 'http://www3.mediaservice-wasmuth.de:80/online-ws-2.0/OnlineSync?xsd=%d'
14
+ http_mock.fake_request(schema_import_base % 1, "wsdl/wasmuth/wasmuth1.xsd")
15
+ http_mock.fake_request(schema_import_base % 2, "wsdl/wasmuth/wasmuth2.xsd")
16
+ end
17
+
18
+ it 'returns a map of services and ports' do
19
+ expect(client.services).to eq(
20
+ 'OnlineSyncService' => {
21
+ :ports => {
22
+ 'OnlineSyncPort' => {
23
+ :type => 'http://schemas.xmlsoap.org/wsdl/soap/',
24
+ :location => 'http://www3.mediaservice-wasmuth.de:80/online-ws-2.0/OnlineSync'
25
+ }
26
+ }
27
+ }
28
+ )
29
+ end
30
+
31
+ it 'knows the operations' do
32
+ operation = client.operation('OnlineSyncService', 'OnlineSyncPort', 'getStTables')
33
+
34
+ expect(operation.soap_action).to eq('')
35
+ expect(operation.endpoint).to eq('http://www3.mediaservice-wasmuth.de:80/online-ws-2.0/OnlineSync')
36
+
37
+ namespace = 'http://ws.online.msw/'
38
+
39
+ expect(operation.body_parts).to eq([
40
+ [['getStTables'], { namespace: namespace, form: 'qualified', singular: true }],
41
+ [['getStTables', 'username'], { namespace: namespace, form: 'unqualified', singular: true, type: 'xs:string' }],
42
+ [['getStTables', 'password'], { namespace: namespace, form: 'unqualified', singular: true, type: 'xs:string' }],
43
+ [['getStTables', 'version'], { namespace: namespace, form: 'unqualified', singular: true, type: 'xs:string' }]
44
+ ])
45
+ end
46
+
47
+ end
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Integration with Xignite' do
4
+
5
+ # reference: http://www.xignite.com/product/global-security-master-data/api/GetSecurities/
6
+ subject(:client) { Sekken.new fixture('wsdl/xignite') }
7
+
8
+ let(:service_name) { :XigniteGlobalMaster }
9
+ let(:port_name) { :XigniteGlobalMasterSoap12 }
10
+
11
+ it 'returns a map of services and ports' do
12
+ expect(client.services).to eq(
13
+ 'XigniteGlobalMaster' => {
14
+ ports: {
15
+ 'XigniteGlobalMasterSoap' => {
16
+ type: 'http://schemas.xmlsoap.org/wsdl/soap/',
17
+ location: 'http://globalmaster.xignite.com/xglobalmaster.asmx'
18
+ },
19
+ 'XigniteGlobalMasterSoap12' => {
20
+ type: 'http://schemas.xmlsoap.org/wsdl/soap12/',
21
+ location: 'http://globalmaster.xignite.com/xglobalmaster.asmx'
22
+ }
23
+ }
24
+ }
25
+ )
26
+ end
27
+
28
+ it 'knows the operations' do
29
+ operation = client.operation(service_name, port_name, :GetSecurities)
30
+
31
+ expect(operation.soap_action).to eq('http://www.xignite.com/services/GetSecurities')
32
+ expect(operation.endpoint).to eq('http://globalmaster.xignite.com/xglobalmaster.asmx')
33
+
34
+ namespace = 'http://www.xignite.com/services/'
35
+
36
+ expect(operation.body_parts).to eq([
37
+ [['GetSecurities'], { namespace: namespace, form: 'qualified', singular: true }],
38
+ [['GetSecurities', 'Identifiers'], { namespace: namespace, form: 'qualified', singular: true, type: 's:string' }],
39
+ [['GetSecurities', 'IdentifierType'], { namespace: namespace, form: 'qualified', singular: true, type: 's:string' }],
40
+ [['GetSecurities', 'AsOfDate'], { namespace: namespace, form: 'qualified', singular: true, type: 's:string' }]
41
+ ])
42
+ end
43
+
44
+ it 'creates an example header' do
45
+ operation = client.operation(service_name, port_name, :GetSecurities)
46
+
47
+ expect(operation.example_header).to eq(
48
+ Header: {
49
+ Username: 'string',
50
+ Password: 'string',
51
+ Tracer: 'string'
52
+ }
53
+ )
54
+ end
55
+
56
+ it 'creates an example body' do
57
+ operation = client.operation(service_name, port_name, :GetSecurities)
58
+
59
+ expect(operation.example_body).to eq(
60
+ GetSecurities: {
61
+ Identifiers: 'string',
62
+ IdentifierType: 'string',
63
+ AsOfDate: 'string'
64
+ }
65
+ )
66
+ end
67
+
68
+ it 'creates a request with a header' do
69
+ operation = client.operation(service_name, port_name, :GetSecurities)
70
+
71
+ operation.header = {
72
+ Header: {
73
+ Username: 'test',
74
+ Password: 'secret',
75
+ Tracer: 'i-dont-know'
76
+ }
77
+ }
78
+
79
+ operation.body = {
80
+ GetSecurities: {
81
+ Identifiers: 'NESN.XVTX,BMW.XETR',
82
+ IdentifierType: 'Symbol',
83
+ AsOfDate: '6/4/2013'
84
+ }
85
+ }
86
+
87
+ expected = Nokogiri.XML('
88
+ <env:Envelope
89
+ xmlns:lol0="http://www.xignite.com/services/"
90
+ xmlns:env="http://www.w3.org/2003/05/soap-envelope">
91
+ <env:Header>
92
+ <lol0:Header>
93
+ <lol0:Username>test</lol0:Username>
94
+ <lol0:Password>secret</lol0:Password>
95
+ <lol0:Tracer>i-dont-know</lol0:Tracer>
96
+ </lol0:Header>
97
+ </env:Header>
98
+ <env:Body>
99
+ <lol0:GetSecurities>
100
+ <lol0:Identifiers>NESN.XVTX,BMW.XETR</lol0:Identifiers>
101
+ <lol0:IdentifierType>Symbol</lol0:IdentifierType>
102
+ <lol0:AsOfDate>6/4/2013</lol0:AsOfDate>
103
+ </lol0:GetSecurities>
104
+ </env:Body>
105
+ </env:Envelope>
106
+ ')
107
+
108
+ expect(Nokogiri.XML operation.build).
109
+ to be_equivalent_to(expected).respecting_element_order
110
+ end
111
+
112
+ end
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Integration with Yahoo\'s AccountService' do
4
+
5
+ subject(:client) { Sekken.new fixture('wsdl/yahoo') }
6
+
7
+ let(:service_name) { :AccountServiceService }
8
+ let(:port_name) { :AccountService }
9
+
10
+ it 'returns a map of services and ports' do
11
+ expect(client.services).to eq(
12
+ 'AccountServiceService' => {
13
+ ports: {
14
+ 'AccountService' => {
15
+ type: 'http://schemas.xmlsoap.org/wsdl/soap/',
16
+
17
+ # symbolic endpoint
18
+ location: 'https://USE_ADDRESS_RETURNED_BY_LOCATION_SERVICE/services/V10/AccountService'
19
+ }
20
+ }
21
+ }
22
+ )
23
+ end
24
+
25
+ it 'knows the operations' do
26
+ operation = client.operation(service_name, port_name, :updateStatusForManagedPublisher)
27
+
28
+ expect(operation.soap_action).to eq('')
29
+ expect(operation.endpoint).to eq('https://USE_ADDRESS_RETURNED_BY_LOCATION_SERVICE/services/V10/AccountService')
30
+
31
+ namespace = 'http://apt.yahooapis.com/V10'
32
+
33
+ expect(operation.body_parts).to eq([
34
+ [['updateStatusForManagedPublisher'], { namespace: namespace, form: 'qualified', singular: true }],
35
+ [['updateStatusForManagedPublisher', 'accountID'], { namespace: namespace, form: 'qualified', singular: true, type: 'xsd:string' }],
36
+ [['updateStatusForManagedPublisher', 'accountStatus'], { namespace: namespace, form: 'qualified', singular: true, type: 'xsd:string' }]
37
+ ])
38
+ end
39
+
40
+ # multiple implicit headers. reference: http://www.ibm.com/developerworks/library/ws-tip-headers/index.html
41
+ it 'creates an example header' do
42
+ operation = client.operation(service_name, port_name, :updateStatusForManagedPublisher)
43
+
44
+ expect(operation.example_header).to eq(
45
+ Security: {
46
+ UsernameToken: {
47
+ Username: 'string',
48
+ Password: 'string'
49
+ }
50
+ },
51
+ license: 'string',
52
+ accountID: 'string'
53
+ )
54
+ end
55
+
56
+ it 'creates an example body' do
57
+ operation = client.operation(service_name, port_name, :updateStatusForManagedPublisher)
58
+
59
+ expect(operation.example_body).to eq(
60
+ updateStatusForManagedPublisher: {
61
+ accountID: 'string',
62
+ accountStatus: 'string'
63
+ }
64
+ )
65
+ end
66
+
67
+ it 'creates a request with multiple headers' do
68
+ operation = client.operation(service_name, port_name, :updateStatusForManagedPublisher)
69
+
70
+ operation.header = {
71
+ Security: {
72
+ UsernameToken: {
73
+ Username: 'admin',
74
+ Password: 'secret'
75
+ }
76
+ },
77
+ license: 'abc-license',
78
+ accountID: '23'
79
+ }
80
+
81
+ operation.body = {
82
+ updateStatusForManagedPublisher: {
83
+ accountID: '23',
84
+ accountStatus: 'closed'
85
+ }
86
+ }
87
+
88
+ expected = Nokogiri.XML('
89
+ <env:Envelope
90
+ xmlns:lol0="http://schemas.xmlsoap.org/ws/2002/07/secext"
91
+ xmlns:lol1="http://apt.yahooapis.com/V10"
92
+ xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
93
+ <env:Header>
94
+ <lol0:Security>
95
+ <UsernameToken>
96
+ <Username>admin</Username>
97
+ <Password>secret</Password>
98
+ </UsernameToken>
99
+ </lol0:Security>
100
+ <lol1:license>abc-license</lol1:license>
101
+ <lol1:accountID>23</lol1:accountID>
102
+ </env:Header>
103
+ <env:Body>
104
+ <lol1:updateStatusForManagedPublisher>
105
+ <lol1:accountID>23</lol1:accountID>
106
+ <lol1:accountStatus>closed</lol1:accountStatus>
107
+ </lol1:updateStatusForManagedPublisher>
108
+ </env:Body>
109
+ </env:Envelope>
110
+ ')
111
+
112
+ expect(Nokogiri.XML operation.build).
113
+ to be_equivalent_to(expected).respecting_element_order
114
+ end
115
+
116
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sekken::HTTPClient do
4
+
5
+ subject(:http) { Sekken::HTTPClient.new }
6
+
7
+ describe '#client' do
8
+ it 'returns the HTTPClient instance to configure' do
9
+ expect(http.client).to be_an_instance_of(HTTPClient)
10
+ end
11
+ end
12
+
13
+ describe '#get' do
14
+ it 'executes an HTTP GET request and returns the raw response' do
15
+ url = 'http://example.com'
16
+
17
+ response = mock(content: 'raw get!')
18
+ http.client.expects(:request).with(:get, url, nil, nil, {}).returns(response)
19
+
20
+ raw_response = http.get(url)
21
+
22
+ expect(raw_response).to eq('raw get!')
23
+ end
24
+ end
25
+
26
+ describe '#post' do
27
+ it 'executes an HTTP POST request and returns the raw response' do
28
+ url = 'http://example.com'
29
+ body = 'post request!'
30
+ headers = { 'Content-Length' => 5 }
31
+
32
+ response = mock(content: 'raw post!')
33
+ http.client.expects(:request).with(:post, url, nil, body, headers).returns(response)
34
+
35
+ raw_response = http.post(url, headers, body)
36
+
37
+ expect(raw_response).to eq('raw post!')
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,308 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sekken::Operation do
4
+
5
+ let(:add_logins) {
6
+ client = Sekken.new fixture('wsdl/bronto')
7
+
8
+ service_name = :BrontoSoapApiImplService
9
+ port_name = :BrontoSoapApiImplPort
10
+
11
+ client.operation(service_name, port_name, :addLogins)
12
+ }
13
+
14
+ let(:get_mu_bets_lite) {
15
+ client = Sekken.new fixture('wsdl/betfair')
16
+
17
+ service_name = port_name = :BFExchangeService
18
+ client.operation(service_name, port_name, :getMUBetsLite)
19
+ }
20
+
21
+ let(:vatAccount_update_from_data_array) {
22
+ client = Sekken.new fixture('wsdl/arrays_with_attributes')
23
+
24
+ service, port = "EconomicWebService", "EconomicWebServiceSoap"
25
+
26
+ client.operation(service, port, 'VatAccount_UpdateFromDataArray')
27
+ }
28
+
29
+ let(:zanox_export_service){
30
+ client = Sekken.new fixture('wsdl/zanox_export_service')
31
+
32
+ service, port = "ExportService", "ExportServiceSoap"
33
+
34
+ client.operation(service, port, 'GetPps')
35
+ }
36
+
37
+ describe '#build' do
38
+ it 'expects Arrays of complex types as Arrays of Hashes' do
39
+ add_logins.body = {
40
+ addLogins: {
41
+
42
+ # accounts in an array of complex types
43
+ # which can be represented by hashes.
44
+ accounts: [
45
+ {
46
+ username: 'first',
47
+ password: 'secret',
48
+ contactInformation: {
49
+ email: 'first@example.com',
50
+ }
51
+ },
52
+ {
53
+ username: 'second',
54
+ password: 'ubersecret',
55
+ contactInformation: {
56
+ email: 'second@example.com',
57
+ }
58
+ }
59
+ ]
60
+ }
61
+ }
62
+
63
+ expected = Nokogiri.XML('
64
+ <env:Envelope
65
+ xmlns:lol0="http://api.bronto.com/v4"
66
+ xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
67
+ <env:Header>
68
+ </env:Header>
69
+ <env:Body>
70
+ <lol0:addLogins>
71
+ <accounts>
72
+ <username>first</username>
73
+ <password>secret</password>
74
+ <contactInformation>
75
+ <email>first@example.com</email>
76
+ </contactInformation>
77
+ </accounts>
78
+ <accounts>
79
+ <username>second</username>
80
+ <password>ubersecret</password>
81
+ <contactInformation>
82
+ <email>second@example.com</email>
83
+ </contactInformation>
84
+ </accounts>
85
+ </lol0:addLogins>
86
+ </env:Body>
87
+ </env:Envelope>
88
+ ')
89
+
90
+ expect(Nokogiri.XML add_logins.build).
91
+ to be_equivalent_to(expected).respecting_element_order
92
+ end
93
+
94
+ it 'raises if it did not receive a Hash for a singular complex type' do
95
+ add_logins.body = {
96
+ addLogins: [
97
+ {
98
+ accounts: {
99
+ username: 'test'
100
+ }
101
+ }
102
+ ]
103
+ }
104
+
105
+ expect { add_logins.build }.
106
+ to raise_error(ArgumentError, "Expected a Hash for the :addLogins complex type")
107
+ end
108
+
109
+ it 'raises if it did not receive an Array for an Array of complex types' do
110
+ add_logins.body = {
111
+ addLogins: {
112
+
113
+ # accounts is an array and we expect the value
114
+ # to be an array of hashes to reflect this.
115
+ accounts: {
116
+ username: 'test'
117
+ }
118
+ }
119
+ }
120
+
121
+ expect { add_logins.build }.
122
+ to raise_error(ArgumentError, "Expected an Array of Hashes for the :accounts complex type")
123
+ end
124
+
125
+ it 'raises if it received an Array for a singular simple type' do
126
+ add_logins.body = {
127
+ addLogins: {
128
+ accounts: [
129
+ {
130
+ username: ['multiple', 'tests']
131
+ }
132
+ ]
133
+ }
134
+ }
135
+
136
+ expect { add_logins.build }.
137
+ to raise_error(ArgumentError, "Unexpected Array for the :username simple type")
138
+ end
139
+
140
+ it 'expectes Arrays of simple types to be represented as Arrays of values' do
141
+ get_mu_bets_lite.body = {
142
+ getMUBetsLite: {
143
+ request: {
144
+ betIds: {
145
+ betId: [1, 2, 3]
146
+ }
147
+ }
148
+ }
149
+ }
150
+
151
+ expected = Nokogiri.XML(%{
152
+ <env:Envelope
153
+ xmlns:lol0="http://www.betfair.com/publicapi/v5/BFExchangeService/"
154
+ xmlns:lol1="http://www.betfair.com/publicapi/types/exchange/v5/"
155
+ xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
156
+ <env:Header/>
157
+ <env:Body>
158
+ <lol0:getMUBetsLite>
159
+ <lol0:request>
160
+ <betIds>
161
+ <lol1:betId>1</lol1:betId>
162
+ <lol1:betId>2</lol1:betId>
163
+ <lol1:betId>3</lol1:betId>
164
+ </betIds>
165
+ </lol0:request>
166
+ </lol0:getMUBetsLite>
167
+ </env:Body>
168
+ </env:Envelope>
169
+ })
170
+
171
+ expect(Nokogiri.XML get_mu_bets_lite.build).
172
+ to be_equivalent_to(expected).respecting_element_order
173
+ end
174
+
175
+ it 'raises if it did not receive an Array for an Array of simple types' do
176
+ get_mu_bets_lite.body = {
177
+ getMUBetsLite: {
178
+ request: {
179
+ betIds: {
180
+ betId: 1
181
+ }
182
+ }
183
+ }
184
+ }
185
+
186
+ expect { get_mu_bets_lite.build }.
187
+ to raise_error(ArgumentError, "Expected an Array of values for the :betId simple type")
188
+ end
189
+
190
+ it 'test' do
191
+ zanox_export_service.header = {
192
+ zanox: {
193
+ ticket: 'EFB745D691DBFF2DFA9F8B10A4D7A7B1AEA850CD'
194
+ }
195
+ }
196
+ zanox_export_service.body = {
197
+ :GetPps => {
198
+ programid: 5574,
199
+ ppsfilter: {
200
+ period: {
201
+ :_from => '2013-10-01T00:00:00+02:00',
202
+ :_to => '2013-11-12T00:00:00+02:00'
203
+ },
204
+ :reviewstate => {reviewstate: 0, :_negate => 1},
205
+ :categoryid => {}
206
+ }
207
+ }
208
+ }
209
+
210
+ expected = Nokogiri.XML(%{
211
+ <env:Envelope xmlns:lol0="http://services.zanox.com/erp" xmlns:lol1="http://services.zanox.com/erp/Export" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
212
+ <env:Header>
213
+ <lol0:zanox>
214
+ <lol0:ticket>EFB745D691DBFF2DFA9F8B10A4D7A7B1AEA850CD</lol0:ticket>
215
+ </lol0:zanox>
216
+ </env:Header>
217
+ <env:Body>
218
+ <lol0:GetPps>
219
+ <lol0:programid>5574</lol0:programid>
220
+ <lol1:ppsfilter>
221
+ <lol1:period from="2013-10-01T00:00:00+02:00" to="2013-11-12T00:00:00+02:00"/>
222
+ <lol1:reviewstate negate='1'>0</lol1:reviewstate>
223
+ <lol1:categoryid/>
224
+ </lol1:ppsfilter>
225
+ </lol0:GetPps>
226
+ </env:Body>
227
+ </env:Envelope>})
228
+
229
+ expect(Nokogiri.XML zanox_export_service.build).
230
+ to be_equivalent_to(expected).respecting_element_order
231
+ end
232
+
233
+ it 'expects Array of Hashes with attributes to return Array of complex types with attributes' do
234
+ vatAccount_update_from_data_array.body = {
235
+ :VatAccount_UpdateFromDataArray => {
236
+ :dataArray => {
237
+ :VatAccountData => [
238
+ {
239
+ :Handle => {:VatCode => "VAT123"},
240
+ :VatCode => {:_attribute => 'test', :_foo => 11, :VatCode => "VAT123"},
241
+ :Name => "ITS",
242
+ :Type => "Ltd",
243
+ :RateAsPercent => 17.5,
244
+ :AccountHandle => {:Number => 123}, :ContraAccountHandle => {:Number => 456},
245
+ :_Thaco => "Testing 1234"
246
+ },
247
+ {
248
+ :Handle => {:VatCode => "VAT987"},
249
+ :VatCode => "VAT987",
250
+ :Name => "Banana",
251
+ :Type => "PLC",
252
+ :RateAsPercent => 21.12,
253
+ :AccountHandle => {:Number => 876}, :ContraAccountHandle => {:Number => 8756},
254
+ :_Thaco => "Testing 5678"
255
+ }
256
+ ]
257
+ }
258
+ }
259
+ }
260
+
261
+ expected = Nokogiri.XML(%{
262
+ <env:Envelope xmlns:lol0="http://e-conomic.com" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
263
+ <env:Header>
264
+ </env:Header>
265
+ <env:Body>
266
+ <lol0:VatAccount_UpdateFromDataArray>
267
+ <lol0:dataArray>
268
+ <lol0:VatAccountData Thaco="Testing 1234">
269
+ <lol0:Handle>
270
+ <lol0:VatCode>VAT123</lol0:VatCode>
271
+ </lol0:Handle>
272
+ <lol0:VatCode attribute='test' foo='11'>VAT123</lol0:VatCode>
273
+ <lol0:Name>ITS</lol0:Name>
274
+ <lol0:Type>Ltd</lol0:Type>
275
+ <lol0:RateAsPercent>17.5</lol0:RateAsPercent>
276
+ <lol0:AccountHandle>
277
+ <lol0:Number>123</lol0:Number>
278
+ </lol0:AccountHandle>
279
+ <lol0:ContraAccountHandle>
280
+ <lol0:Number>456</lol0:Number>
281
+ </lol0:ContraAccountHandle>
282
+ </lol0:VatAccountData>
283
+ <lol0:VatAccountData Thaco="Testing 5678">
284
+ <lol0:Handle>
285
+ <lol0:VatCode>VAT987</lol0:VatCode>
286
+ </lol0:Handle>
287
+ <lol0:VatCode>VAT987</lol0:VatCode>
288
+ <lol0:Name>Banana</lol0:Name>
289
+ <lol0:Type>PLC</lol0:Type>
290
+ <lol0:RateAsPercent>21.12</lol0:RateAsPercent>
291
+ <lol0:AccountHandle>
292
+ <lol0:Number>876</lol0:Number>
293
+ </lol0:AccountHandle>
294
+ <lol0:ContraAccountHandle>
295
+ <lol0:Number>8756</lol0:Number>
296
+ </lol0:ContraAccountHandle>
297
+ </lol0:VatAccountData>
298
+ </lol0:dataArray>
299
+ </lol0:VatAccount_UpdateFromDataArray>
300
+ </env:Body>
301
+ </env:Envelope>})
302
+
303
+ expect(Nokogiri.XML vatAccount_update_from_data_array.build).
304
+ to be_equivalent_to(expected).respecting_element_order
305
+ end
306
+ end
307
+
308
+ end