azure-fix 0.7.0.pre3

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.
Files changed (311) hide show
  1. checksums.yaml +7 -0
  2. data/.env_sample +13 -0
  3. data/.gitignore +30 -0
  4. data/.travis.yml +13 -0
  5. data/ChangeLog.txt +56 -0
  6. data/Gemfile +16 -0
  7. data/LICENSE.txt +202 -0
  8. data/README.md +702 -0
  9. data/Rakefile +121 -0
  10. data/azure.gemspec +51 -0
  11. data/bin/pfxer +35 -0
  12. data/lib/azure.rb +147 -0
  13. data/lib/azure/base_management/affinity_group.rb +32 -0
  14. data/lib/azure/base_management/base_management_service.rb +220 -0
  15. data/lib/azure/base_management/location.rb +27 -0
  16. data/lib/azure/base_management/management_http_request.rb +172 -0
  17. data/lib/azure/base_management/serialization.rb +135 -0
  18. data/lib/azure/base_management/sql_management_http_request.rb +35 -0
  19. data/lib/azure/blob/auth/shared_access_signature.rb +147 -0
  20. data/lib/azure/blob/blob.rb +32 -0
  21. data/lib/azure/blob/blob_service.rb +1452 -0
  22. data/lib/azure/blob/block.rb +31 -0
  23. data/lib/azure/blob/container.rb +32 -0
  24. data/lib/azure/blob/serialization.rb +285 -0
  25. data/lib/azure/client.rb +31 -0
  26. data/lib/azure/client_services.rb +98 -0
  27. data/lib/azure/cloud_service_management/cloud_service.rb +38 -0
  28. data/lib/azure/cloud_service_management/cloud_service_management_service.rb +135 -0
  29. data/lib/azure/cloud_service_management/serialization.rb +118 -0
  30. data/lib/azure/configurable.rb +290 -0
  31. data/lib/azure/core/auth/authorizer.rb +36 -0
  32. data/lib/azure/core/auth/shared_key.rb +118 -0
  33. data/lib/azure/core/auth/shared_key_lite.rb +48 -0
  34. data/lib/azure/core/auth/signer.rb +51 -0
  35. data/lib/azure/core/error.rb +21 -0
  36. data/lib/azure/core/filtered_service.rb +45 -0
  37. data/lib/azure/core/http/debug_filter.rb +36 -0
  38. data/lib/azure/core/http/http_error.rb +86 -0
  39. data/lib/azure/core/http/http_filter.rb +53 -0
  40. data/lib/azure/core/http/http_request.rb +173 -0
  41. data/lib/azure/core/http/http_response.rb +96 -0
  42. data/lib/azure/core/http/retry_policy.rb +74 -0
  43. data/lib/azure/core/http/signer_filter.rb +33 -0
  44. data/lib/azure/core/service.rb +46 -0
  45. data/lib/azure/core/signed_service.rb +45 -0
  46. data/lib/azure/core/utility.rb +244 -0
  47. data/lib/azure/default.rb +126 -0
  48. data/lib/azure/http_client.rb +85 -0
  49. data/lib/azure/queue/message.rb +30 -0
  50. data/lib/azure/queue/queue.rb +28 -0
  51. data/lib/azure/queue/queue_service.rb +570 -0
  52. data/lib/azure/queue/serialization.rb +105 -0
  53. data/lib/azure/service/access_policy.rb +26 -0
  54. data/lib/azure/service/cors.rb +11 -0
  55. data/lib/azure/service/cors_rule.rb +15 -0
  56. data/lib/azure/service/enumeration_results.rb +21 -0
  57. data/lib/azure/service/logging.rb +32 -0
  58. data/lib/azure/service/metrics.rb +31 -0
  59. data/lib/azure/service/retention_policy.rb +25 -0
  60. data/lib/azure/service/serialization.rb +299 -0
  61. data/lib/azure/service/signed_identifier.rb +30 -0
  62. data/lib/azure/service/storage_service.rb +86 -0
  63. data/lib/azure/service/storage_service_properties.rb +37 -0
  64. data/lib/azure/service_bus/action.rb +21 -0
  65. data/lib/azure/service_bus/auth/shared_access_signer.rb +44 -0
  66. data/lib/azure/service_bus/auth/wrap_service.rb +90 -0
  67. data/lib/azure/service_bus/auth/wrap_signer.rb +77 -0
  68. data/lib/azure/service_bus/brokered_message.rb +124 -0
  69. data/lib/azure/service_bus/brokered_message_serializer.rb +159 -0
  70. data/lib/azure/service_bus/correlation_filter.rb +45 -0
  71. data/lib/azure/service_bus/empty_rule_action.rb +30 -0
  72. data/lib/azure/service_bus/false_filter.rb +38 -0
  73. data/lib/azure/service_bus/filter.rb +21 -0
  74. data/lib/azure/service_bus/interval.rb +104 -0
  75. data/lib/azure/service_bus/queue.rb +230 -0
  76. data/lib/azure/service_bus/relay.rb +88 -0
  77. data/lib/azure/service_bus/resource.rb +109 -0
  78. data/lib/azure/service_bus/rule.rb +98 -0
  79. data/lib/azure/service_bus/rule_aspect.rb +34 -0
  80. data/lib/azure/service_bus/serialization.rb +161 -0
  81. data/lib/azure/service_bus/service_bus_service.rb +899 -0
  82. data/lib/azure/service_bus/sql_filter.rb +50 -0
  83. data/lib/azure/service_bus/sql_rule_action.rb +50 -0
  84. data/lib/azure/service_bus/subscription.rb +184 -0
  85. data/lib/azure/service_bus/topic.rb +187 -0
  86. data/lib/azure/service_bus/true_filter.rb +38 -0
  87. data/lib/azure/sql_database_management/errors.rb +11 -0
  88. data/lib/azure/sql_database_management/firewall_rule.rb +30 -0
  89. data/lib/azure/sql_database_management/serialization.rb +99 -0
  90. data/lib/azure/sql_database_management/sql_database_management_service.rb +211 -0
  91. data/lib/azure/sql_database_management/sql_server.rb +32 -0
  92. data/lib/azure/storage_management/serialization.rb +204 -0
  93. data/lib/azure/storage_management/storage_account.rb +48 -0
  94. data/lib/azure/storage_management/storage_management_service.rb +207 -0
  95. data/lib/azure/table/auth/shared_key.rb +59 -0
  96. data/lib/azure/table/auth/shared_key_lite.rb +44 -0
  97. data/lib/azure/table/batch.rb +330 -0
  98. data/lib/azure/table/batch_response.rb +118 -0
  99. data/lib/azure/table/edmtype.rb +127 -0
  100. data/lib/azure/table/entity.rb +31 -0
  101. data/lib/azure/table/guid.rb +24 -0
  102. data/lib/azure/table/query.rb +112 -0
  103. data/lib/azure/table/serialization.rb +108 -0
  104. data/lib/azure/table/table_service.rb +563 -0
  105. data/lib/azure/version.rb +31 -0
  106. data/lib/azure/virtual_machine_image_management/serialization.rb +70 -0
  107. data/lib/azure/virtual_machine_image_management/virtual_machine_disk.rb +25 -0
  108. data/lib/azure/virtual_machine_image_management/virtual_machine_image.rb +25 -0
  109. data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +83 -0
  110. data/lib/azure/virtual_machine_management/serialization.rb +459 -0
  111. data/lib/azure/virtual_machine_management/virtual_machine.rb +44 -0
  112. data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +552 -0
  113. data/lib/azure/virtual_network_management/serialization.rb +193 -0
  114. data/lib/azure/virtual_network_management/virtual_network.rb +37 -0
  115. data/lib/azure/virtual_network_management/virtual_network_management_service.rb +108 -0
  116. data/test/fixtures/32px-fulls-black.jpg +0 -0
  117. data/test/fixtures/affinity_group.xml +33 -0
  118. data/test/fixtures/all_containers.xml +20 -0
  119. data/test/fixtures/all_tables.xml +22 -0
  120. data/test/fixtures/container_acl.xml +11 -0
  121. data/test/fixtures/create_sql_database_server.xml +2 -0
  122. data/test/fixtures/create_storage_desc_error.xml +5 -0
  123. data/test/fixtures/create_storage_extendedprop_error.xml +8 -0
  124. data/test/fixtures/create_storage_extendedpropname_error.xml +6 -0
  125. data/test/fixtures/create_storage_full_error.xml +6 -0
  126. data/test/fixtures/create_storage_label_error.xml +5 -0
  127. data/test/fixtures/create_storage_location_error.xml +5 -0
  128. data/test/fixtures/create_storage_name_error.xml +6 -0
  129. data/test/fixtures/create_table_response_entry.xml +15 -0
  130. data/test/fixtures/delete_storage_container_error.xml +5 -0
  131. data/test/fixtures/delete_storage_error.xml +5 -0
  132. data/test/fixtures/deployment_error.xml +5 -0
  133. data/test/fixtures/empty_xml_file +0 -0
  134. data/test/fixtures/get_storage_account_error.xml +5 -0
  135. data/test/fixtures/get_storage_account_properties.xml +34 -0
  136. data/test/fixtures/get_storage_account_properties_new.xml +32 -0
  137. data/test/fixtures/http_error.xml +5 -0
  138. data/test/fixtures/insert_entity_response_entry.xml +25 -0
  139. data/test/fixtures/list_affinity_groups.xml +22 -0
  140. data/test/fixtures/list_blobs.xml +121 -0
  141. data/test/fixtures/list_block_all_with_none_committed.xml +22 -0
  142. data/test/fixtures/list_blocks_all.xml +23 -0
  143. data/test/fixtures/list_blocks_committed.xml +13 -0
  144. data/test/fixtures/list_cloud_services.xml +39 -0
  145. data/test/fixtures/list_containers.xml +38 -0
  146. data/test/fixtures/list_firewall_management_endpoint.xml +27 -0
  147. data/test/fixtures/list_locations.xml +212 -0
  148. data/test/fixtures/list_os_images.xml +110 -0
  149. data/test/fixtures/list_page_ranges.xml +11 -0
  150. data/test/fixtures/list_sql_database.xml +24 -0
  151. data/test/fixtures/list_sql_server_firewall.xml +23 -0
  152. data/test/fixtures/list_storage_account_single.xml +25 -0
  153. data/test/fixtures/list_storage_accounts.xml +48 -0
  154. data/test/fixtures/list_virtual_networks.xml +92 -0
  155. data/test/fixtures/list_vm_images.xml +21 -0
  156. data/test/fixtures/logging.xml +11 -0
  157. data/test/fixtures/management_certificate.pfx +0 -0
  158. data/test/fixtures/messages.xml +12 -0
  159. data/test/fixtures/metrics.xml +10 -0
  160. data/test/fixtures/privatekey.key +28 -0
  161. data/test/fixtures/query_entities_empty_response.xml +7 -0
  162. data/test/fixtures/query_entities_response.xml +45 -0
  163. data/test/fixtures/queue_service_properties.xml +22 -0
  164. data/test/fixtures/queue_service_properties_original.xml +19 -0
  165. data/test/fixtures/queues.xml +16 -0
  166. data/test/fixtures/retention_policy.xml +5 -0
  167. data/test/fixtures/sb_default_create_queue_response.xml +23 -0
  168. data/test/fixtures/sb_default_create_relay_response.xml +15 -0
  169. data/test/fixtures/sb_default_create_topic_response.xml +18 -0
  170. data/test/fixtures/sb_get_access_token_response.txt +1 -0
  171. data/test/fixtures/sb_queues_runtime_peek_message_response_headers.txt +9 -0
  172. data/test/fixtures/storage_service_keys.xml +8 -0
  173. data/test/fixtures/storage_service_properties.xml +55 -0
  174. data/test/fixtures/update_storage_account.xml +16 -0
  175. data/test/fixtures/update_storage_error.xml +5 -0
  176. data/test/fixtures/updated_storage_accounts.xml +55 -0
  177. data/test/fixtures/virtual_machine.xml +116 -0
  178. data/test/fixtures/windows_virtual_machine.xml +106 -0
  179. data/test/integration/affinity_group/Affinity_test.rb +55 -0
  180. data/test/integration/affinity_group/Create_Affinity_test.rb +64 -0
  181. data/test/integration/affinity_group/Delete_Affinity_test.rb +56 -0
  182. data/test/integration/affinity_group/List_Affinity_test.rb +41 -0
  183. data/test/integration/affinity_group/Update_Affinity_test.rb +87 -0
  184. data/test/integration/blob/blob_gb18030_test.rb +199 -0
  185. data/test/integration/blob/blob_metadata_test.rb +75 -0
  186. data/test/integration/blob/blob_pages_test.rb +119 -0
  187. data/test/integration/blob/blob_properties_test.rb +77 -0
  188. data/test/integration/blob/block_blob_test.rb +254 -0
  189. data/test/integration/blob/container/container_acl_test.rb +69 -0
  190. data/test/integration/blob/container/container_metadata_test.rb +50 -0
  191. data/test/integration/blob/container/create_container_test.rb +60 -0
  192. data/test/integration/blob/container/delete_container_test.rb +39 -0
  193. data/test/integration/blob/container/get_container_properties_test.rb +48 -0
  194. data/test/integration/blob/container/list_containers_test.rb +79 -0
  195. data/test/integration/blob/container/root_container_test.rb +55 -0
  196. data/test/integration/blob/copy_blob_test.rb +113 -0
  197. data/test/integration/blob/create_blob_snapshot_test.rb +80 -0
  198. data/test/integration/blob/create_page_blob_test.rb +83 -0
  199. data/test/integration/blob/delete_blob_test.rb +159 -0
  200. data/test/integration/blob/get_blob_test.rb +65 -0
  201. data/test/integration/blob/informative_errors_test.rb +39 -0
  202. data/test/integration/blob/lease/acquire_lease_test.rb +36 -0
  203. data/test/integration/blob/lease/break_lease_test.rb +40 -0
  204. data/test/integration/blob/lease/release_lease_test.rb +40 -0
  205. data/test/integration/blob/lease/renew_lease_test.rb +42 -0
  206. data/test/integration/blob/list_blobs_test.rb +113 -0
  207. data/test/integration/cloud_service/Cloud_Create_test.rb +45 -0
  208. data/test/integration/cloud_service/Cloud_Delete_test.rb +45 -0
  209. data/test/integration/database/create_sql_server_firewall_test.rb +81 -0
  210. data/test/integration/database/create_sql_server_test.rb +53 -0
  211. data/test/integration/database/delete_sql_server_firewall_test.rb +64 -0
  212. data/test/integration/database/delete_sql_server_test.rb +45 -0
  213. data/test/integration/database/list_sql_server_firewall_test.rb +44 -0
  214. data/test/integration/database/list_sql_servers_test.rb +44 -0
  215. data/test/integration/database/reset_password_sql_server_test.rb +53 -0
  216. data/test/integration/location/Location_List_test.rb +39 -0
  217. data/test/integration/location/RoleSize_List_test.rb +35 -0
  218. data/test/integration/queue/clear_messages_test.rb +42 -0
  219. data/test/integration/queue/create_message_test.rb +75 -0
  220. data/test/integration/queue/create_queue_test.rb +50 -0
  221. data/test/integration/queue/delete_message_test.rb +67 -0
  222. data/test/integration/queue/delete_queue_test.rb +45 -0
  223. data/test/integration/queue/informative_errors_test.rb +42 -0
  224. data/test/integration/queue/list_messages_encoded_test.rb +79 -0
  225. data/test/integration/queue/list_messages_test.rb +79 -0
  226. data/test/integration/queue/list_queues_test.rb +43 -0
  227. data/test/integration/queue/peek_messages_test.rb +59 -0
  228. data/test/integration/queue/queue_gb18030_test.rb +131 -0
  229. data/test/integration/queue/queue_metadata_test.rb +40 -0
  230. data/test/integration/queue/update_message_test.rb +74 -0
  231. data/test/integration/service_bus/informative_errors_test.rb +37 -0
  232. data/test/integration/service_bus/queues_scenario_test.rb +200 -0
  233. data/test/integration/service_bus/queues_test.rb +266 -0
  234. data/test/integration/service_bus/relay_test.rb +132 -0
  235. data/test/integration/service_bus/rules_test.rb +145 -0
  236. data/test/integration/service_bus/sb_queue_gb18030_test.rb +182 -0
  237. data/test/integration/service_bus/scenario_test.rb +101 -0
  238. data/test/integration/service_bus/subscriptions_test.rb +211 -0
  239. data/test/integration/service_bus/topics_scenario_test.rb +406 -0
  240. data/test/integration/service_bus/topics_test.rb +129 -0
  241. data/test/integration/storage_management/storage_management_test.rb +185 -0
  242. data/test/integration/table/create_table_test.rb +36 -0
  243. data/test/integration/table/delete_entity_batch_test.rb +107 -0
  244. data/test/integration/table/delete_entity_test.rb +94 -0
  245. data/test/integration/table/delete_table_test.rb +40 -0
  246. data/test/integration/table/get_table_test.rb +37 -0
  247. data/test/integration/table/informative_errors_test.rb +39 -0
  248. data/test/integration/table/insert_entity_batch_test.rb +100 -0
  249. data/test/integration/table/insert_entity_test.rb +88 -0
  250. data/test/integration/table/insert_or_merge_entity_batch_test.rb +159 -0
  251. data/test/integration/table/insert_or_merge_entity_test.rb +143 -0
  252. data/test/integration/table/insert_or_replace_entity_batch_test.rb +152 -0
  253. data/test/integration/table/insert_or_replace_entity_test.rb +137 -0
  254. data/test/integration/table/merge_entity_batch_test.rb +128 -0
  255. data/test/integration/table/merge_entity_test.rb +113 -0
  256. data/test/integration/table/query_entities_test.rb +196 -0
  257. data/test/integration/table/query_tables_test.rb +43 -0
  258. data/test/integration/table/query_test.rb +251 -0
  259. data/test/integration/table/table_acl_test.rb +52 -0
  260. data/test/integration/table/table_gb18030_test.rb +355 -0
  261. data/test/integration/table/update_entity_batch_test.rb +149 -0
  262. data/test/integration/table/update_entity_test.rb +131 -0
  263. data/test/integration/test_helper.rb +40 -0
  264. data/test/integration/vm/VM_Create_test.rb +262 -0
  265. data/test/integration/vm/VM_Delete_test.rb +53 -0
  266. data/test/integration/vm/VM_Operations_test.rb +172 -0
  267. data/test/integration/vm_image/virtual_machine_disk_test.rb +37 -0
  268. data/test/integration/vm_image/virtual_machine_image_test.rb +37 -0
  269. data/test/integration/vnet/Virtual_Network_Create_test.rb +116 -0
  270. data/test/integration/vnet/Virtual_Network_list_test.rb +48 -0
  271. data/test/support/env.rb +19 -0
  272. data/test/support/fixtures.rb +36 -0
  273. data/test/support/name_generator.rb +168 -0
  274. data/test/support/stubs.rb +42 -0
  275. data/test/support/virtual_machine_name_generator.rb +102 -0
  276. data/test/support/virtual_network_helper.rb +73 -0
  277. data/test/test_helper.rb +47 -0
  278. data/test/unit/affinity_group/affinity_group_test.rb +189 -0
  279. data/test/unit/affinity_group/serialization_test.rb +87 -0
  280. data/test/unit/base_management/base_management_service_test.rb +19 -0
  281. data/test/unit/base_management/location_test.rb +56 -0
  282. data/test/unit/base_management/role_size_test.rb +50 -0
  283. data/test/unit/blob/auth/shared_access_signature_test.rb +71 -0
  284. data/test/unit/blob/blob_service_test.rb +1970 -0
  285. data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +94 -0
  286. data/test/unit/cloud_service_management/serialization_test.rb +169 -0
  287. data/test/unit/config/azure_test.rb +112 -0
  288. data/test/unit/config/client_test.rb +37 -0
  289. data/test/unit/core/auth/shared_key_lite_test.rb +51 -0
  290. data/test/unit/core/auth/shared_key_test.rb +58 -0
  291. data/test/unit/core/auth/signer_test.rb +30 -0
  292. data/test/unit/core/http/http_error_test.rb +61 -0
  293. data/test/unit/core/http/http_request_test.rb +138 -0
  294. data/test/unit/core/http/http_response_test.rb +20 -0
  295. data/test/unit/core/http/retry_policy_test.rb +23 -0
  296. data/test/unit/core/utility_test.rb +122 -0
  297. data/test/unit/database/serialization_test.rb +94 -0
  298. data/test/unit/database/sql_database_server_service_test.rb +341 -0
  299. data/test/unit/http_client_test.rb +74 -0
  300. data/test/unit/service/serialization_test.rb +533 -0
  301. data/test/unit/service/storage_service_test.rb +297 -0
  302. data/test/unit/storage_management/serialization_test.rb +244 -0
  303. data/test/unit/storage_management/storage_management_service_test.rb +247 -0
  304. data/test/unit/table/edmtype_test.rb +108 -0
  305. data/test/unit/virtual_machine_image_management/serialization_test.rb +50 -0
  306. data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +114 -0
  307. data/test/unit/virtual_machine_management/serialization_test.rb +316 -0
  308. data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +480 -0
  309. data/test/unit/vnet/serialization_test.rb +187 -0
  310. data/test/unit/vnet/virtual_network_management_service_test.rb +131 -0
  311. metadata +579 -0
@@ -0,0 +1,899 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+ require 'azure/core/signed_service'
16
+ require 'azure/service_bus/auth/wrap_signer'
17
+ require 'azure/service_bus/auth/shared_access_signer'
18
+ require 'azure/service_bus/serialization'
19
+
20
+ require 'azure/service_bus/brokered_message_serializer'
21
+ require 'azure/core/http/http_response'
22
+
23
+ module Azure
24
+ module ServiceBus
25
+ class ServiceBusService < Azure::Core::SignedService
26
+
27
+ DEFAULT_TIMEOUT = 60
28
+
29
+ def initialize(host=nil, options = {})
30
+ client_config = options[:client] || Azure
31
+ signer = options[:signer] || Auth::WrapSigner.new(client_config.acs_host, client: client_config)
32
+ super(signer, nil, options)
33
+ @host = host || @client.config.service_bus_host
34
+
35
+ with_filter do |req, res|
36
+ req.headers.delete 'x-ms-date'
37
+ req.headers.delete 'x-ms-version'
38
+ req.headers.delete 'DataServiceVersion'
39
+ req.headers.delete 'MaxDataServiceVersion'
40
+ req.headers['X-Process-At'] = 'servicebus'
41
+ res.call
42
+ end
43
+ end
44
+
45
+ # Creates a new relay endpoint. Once created, this relay endpoint resource manifest is immutable.
46
+ #
47
+ # ==== Attributes
48
+ #
49
+ # * +relay+ - Azure::ServiceBus::Relay instance to create on server, or a string of the relay endpoint name
50
+ # * +options+ - Hash. The relay endpoint properties.
51
+ #
52
+ # ==== Options
53
+ #
54
+ # Accepted key/value pairs in options parameter are:
55
+ # * +:relay_type+ - String. Determines the type of the relay endpoint.
56
+ # * +:requires_client_authorization+ - Boolean. Determines whether or not clients need to authenticate when making calls.
57
+ # * +:requires_transport_security+ - Boolean. Determines whether or not the endpoint uses transport security.
58
+ #
59
+ def create_relay(relay, options={})
60
+ relay = _new_or_existing(Azure::ServiceBus::Relay, relay, options ? options : {})
61
+ create_resource_entry(:relay, relay, relay.name)
62
+ end
63
+
64
+ # Deletes an existing relay endpoint.
65
+ #
66
+ # ==== Attributes
67
+ #
68
+ # * +relay+ - Azure::ServiceBus::Relay instance to delete or a string of the relay endpoint name
69
+ def delete_relay(relay)
70
+ delete_resource_entry(:relay, _name_for(relay))
71
+ end
72
+
73
+ # Retrieves the description for the specified relay endpoint.
74
+ #
75
+ # ==== Attributes
76
+ #
77
+ # * +relay+ - Azure::ServiceBus::Relay instance to retrieve or a string of the relay endpoint name
78
+ def get_relay(relay)
79
+ resource_entry(:relay, _name_for(relay))
80
+ end
81
+
82
+ # Enumerates the relay endpoints in the service namespace.
83
+ #
84
+ # ==== Attributes
85
+ #
86
+ # * +options+ - Hash. Optional parameters.
87
+ #
88
+ # ==== Options
89
+ #
90
+ # Accepted key/value pairs in options parameter are:
91
+ # * +:skip+ - Integer. Number of queues to skip.
92
+ # * +:top+ - Integer. Number of queues to list.
93
+ def list_relays(options={})
94
+ query = {}
95
+ query["$skip"] = options[:skip].to_i.to_s if options[:skip]
96
+ query["$top"] = options[:top].to_i.to_s if options[:top]
97
+
98
+ resource_list(:relay, query)
99
+ end
100
+
101
+ # Creates a new queue. Once created, this queue's resource manifest is immutable.
102
+ #
103
+ # ==== Attributes
104
+ #
105
+ # * +queue+ - Azure::ServiceBus::Queue instance to create on server, or a string of the queue name
106
+ # * +options+ - Hash. The queue properties.
107
+ #
108
+ # ==== Options
109
+ #
110
+ # Accepted key/value pairs in options parameter are:
111
+ # * +:default_message_time_to_live+ - XML datetime. Determines how long a message lives in the associated subscriptions.
112
+ # * +:duplicate_detection_history_time_window+ - XML datetime. Specifies the time span during which the Service Bus will detect message duplication.
113
+ # * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
114
+ # * +:dead_lettering_on_message_expiration:+ - Boolean. This field controls how the Service Bus handles a message whose TTL has expired.
115
+ # * +:lock_duration+ - XML datetime. Determines the amount of time in seconds in which a message should be locked for processing by a receiver.
116
+ # * +:max_delivery_count+ - Number. A message is automatically deadlettered after this number of deliveries.
117
+ # * +:max_size_in_megabytes+ - Number. Specifies the maximum topic size in megabytes
118
+ # * +:message_count+ - Number. Displays the number of messages currently in the queue.
119
+ # * +:requires_duplicate_detection+ - Boolean. If enabled, the topic will detect duplicate messages within the time span specified by the DuplicateDetectionHistoryTimeWindow property
120
+ # * +:requires_session+ - Boolean. If set to true, the queue will be session-aware and only SessionReceiver will be supported.
121
+ # * +:size_in_bytes+ - Number. Reflects the actual bytes toward the topic quota that messages in the topic currently occupy.
122
+ #
123
+ def create_queue(queue, options={})
124
+ queue = _new_or_existing(Azure::ServiceBus::Queue, queue, options ? options : {})
125
+ create_resource_entry(:queue, queue, queue.name)
126
+ end
127
+
128
+ # Deletes an existing queue. This operation will also remove all associated state
129
+ # including messages in the queue.
130
+ #
131
+ # ==== Attributes
132
+ #
133
+ # * +queue+ - Azure::ServiceBus::Queue instance to delete or a string of the queue name
134
+ def delete_queue(queue)
135
+ delete_resource_entry(:queue, _name_for(queue))
136
+ end
137
+
138
+ # Retrieves an existing queue.
139
+ #
140
+ # ==== Attributes
141
+ #
142
+ # * +queue+ - Azure::ServiceBus::Queue instance to retrieve or a string of the queue name
143
+ def get_queue(queue)
144
+ resource_entry(:queue, _name_for(queue))
145
+ end
146
+
147
+ # Enumerates the queues in the service namespace.
148
+ #
149
+ # ==== Attributes
150
+ #
151
+ # * +options+ - Hash. Optional parameters.
152
+ #
153
+ # ==== Options
154
+ #
155
+ # Accepted key/value pairs in options parameter are:
156
+ # * +:skip+ - Integer. Number of queues to skip.
157
+ # * +:top+ - Integer. Number of queues to list.
158
+ def list_queues(options={})
159
+ query = {}
160
+ query["$skip"] = options[:skip].to_i.to_s if options[:skip]
161
+ query["$top"] = options[:top].to_i.to_s if options[:top]
162
+
163
+ resource_list(:queue, query)
164
+ end
165
+
166
+ # Creates a new topic. Once created, this topic resource manifest is immutable.
167
+ #
168
+ # ==== Attributes
169
+ #
170
+ # * +topic+ - Azure::ServiceBus::Topic instance to create on server, or a string of the topic name
171
+ # * +options+ - Hash. The topic properties.
172
+ #
173
+ # ==== Options
174
+ #
175
+ # Accepted key/value pairs in options parameter are:
176
+ # * +:default_message_time_to_tive+ - XML datetime. Determines how long a message lives in the associated subscriptions.
177
+ # * +:maximum_number_of_subscriptions+ - Number. Specifies the maximum number of subscriptions that can be associated with the topic.
178
+ # * +:max_size_in_megabytes+ - Number. Specifies the maximum topic size in megabytes
179
+ # * +:requires_duplicate_detection+ - Boolean. If enabled, the topic will detect duplicate messages within the time span specified by the DuplicateDetectionHistoryTimeWindow property
180
+ # * +:dead_lettering_on_filter_evaluation_exceptions+ - Boolean. Determines how the Service Bus handles a message that causes an exception during a subscription's filter evaluation.
181
+ # * +:duplicate_detection_history_time_window+ - XML datetime. Specifies the time span during which the Service Bus will detect message duplication.
182
+ # * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
183
+ #
184
+ def create_topic(topic, options={})
185
+ topic = _new_or_existing(Azure::ServiceBus::Topic, topic, options ? options : {})
186
+ create_resource_entry(:topic, topic, topic.name)
187
+ end
188
+
189
+ # Deletes an existing topic. This operation will also remove all associated state
190
+ # including associated subscriptions.
191
+ #
192
+ # ==== Attributes
193
+ #
194
+ # * +topic+ - Azure::ServiceBus::Topic instance to delete or a string of the topic name
195
+ def delete_topic(topic)
196
+ delete_resource_entry(:topic, _name_for(topic))
197
+ end
198
+
199
+ # Retrieves the description for the specified topic.
200
+ #
201
+ # ==== Attributes
202
+ #
203
+ # * +topic+ - Azure::ServiceBus::Topic instance to retrieve or a string of the topic name
204
+ def get_topic(topic)
205
+ resource_entry(:topic, _name_for(topic))
206
+ end
207
+
208
+ # Retrieves the topics in the service namespace.
209
+ #
210
+ # ==== Attributes
211
+ #
212
+ # * +options+ - Hash. Optional parameters.
213
+ #
214
+ # ==== Options
215
+ #
216
+ # Accepted key/value pairs in options parameter are:
217
+ # * +:skip+ - Integer. Number of topics to skip.
218
+ # * +:top+ - Integer. Number of topics to list.
219
+ def list_topics(options={})
220
+ query = {}
221
+ query["$skip"] = options[:skip].to_i.to_s if options[:skip]
222
+ query["$top"] = options[:top].to_i.to_s if options[:top]
223
+
224
+ resource_list(:topic, query)
225
+ end
226
+
227
+ # Creates a new rule. Once created, this rule's resource manifest is immutable.
228
+ #
229
+ # ==== Attributes
230
+ #
231
+ # Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a rule object.
232
+ # When using (topic_name, subscription_name, rule_name, options) overload, you may also pass the properties for the rule.
233
+ #
234
+ # ==== Options
235
+ #
236
+ # Accepted key/value pairs in options parameter are:
237
+ # * +:filter+ - String. The rule filter.
238
+ # * +:action+ - String. The rule action.
239
+ #
240
+ def create_rule(*p)
241
+ rule = _rule_from(*p)
242
+ result = create_resource_entry(:rule, rule, rule.topic, rule.subscription, rule.name)
243
+ result.topic = rule.topic
244
+ result.subscription = rule.subscription
245
+ result
246
+ end
247
+
248
+ # Deletes an existing rule.
249
+ #
250
+ # ==== Attributes
251
+ #
252
+ # Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and
253
+ # .subscription methods such as Azure::ServiceBus::Rule instance.
254
+ #
255
+ # Note: The default rule name is '$Default'. Use this name to delete the default rule for the subscription.
256
+ def delete_rule(*p)
257
+ topic_name, subscription_name, rule_name = _rule_args(*p)
258
+
259
+ delete_resource_entry(:rule, topic_name, subscription_name, rule_name)
260
+ end
261
+
262
+ # Retrieves the description for the specified rule.
263
+ #
264
+ # ==== Attributes
265
+ #
266
+ # Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and
267
+ # .subscription methods such as Azure::ServiceBus::Rule instance.
268
+ #
269
+ # Note: The default rule name is '$Default'. Use this name to retrieve the default rule for the subscription.
270
+ def get_rule(*p)
271
+ topic_name, subscription_name, rule_name = _rule_args(*p)
272
+
273
+ result = resource_entry(:rule, topic_name, subscription_name, rule_name)
274
+ result.topic = topic_name
275
+ result.subscription = subscription_name
276
+ result
277
+ end
278
+
279
+ # Retrieves the rules that exist under the specified subscription.
280
+ #
281
+ # ==== Attributes
282
+ #
283
+ # Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
284
+ # such as Azure::ServiceBus::Subscription instance.
285
+ #
286
+ # * +options+ - Hash. Optional parameters.
287
+ #
288
+ # ==== Options
289
+ #
290
+ # Accepted key/value pairs in options parameter are:
291
+ # * +:skip+ - Integer. Number of topics to skip.
292
+ # * +:top+ - Integer. Number of topics to list.
293
+ def list_rules(*p)
294
+ topic_name, subscription_name, options = _subscription_args(*p)
295
+
296
+ query = {}
297
+ query["$skip"] = options[:skip].to_i.to_s if options[:skip]
298
+ query["$top"] = options[:top].to_i.to_s if options[:top]
299
+
300
+ results = resource_list(:rule, topic_name, subscription_name, query)
301
+ results.each { |r| r.topic = topic_name; r.subscription=subscription_name }
302
+
303
+ return results
304
+ end
305
+
306
+ # Creates a new subscription. Once created, this subscription resource manifest is
307
+ # immutable.
308
+ #
309
+ # ==== Attributes
310
+ #
311
+ # Pass either (topic_name, subscription_name) as strings, or (subscription) a object.
312
+ # When using (topic_name, subscription_name) overload, you may also pass optional properties for the subscription.
313
+ #
314
+ # ==== Options
315
+ #
316
+ # Accepted key/value pairs in options parameter are:
317
+ # * +:lock_duration+ - XML datetime. Determines the amount of time in seconds in which a message should be locked for processing by a receiver.
318
+ # * +:requires_session+ - Boolean. If set to true, the queue will be session-aware and only SessionReceiver will be supported.
319
+ # * +:default_message_time_to_live+ - XML datetime. Determines how long a message lives in the associated subscriptions.
320
+ # * +:dead_lettering_on_message_expiration:+ - Boolean. This field controls how the Service Bus handles a message whose TTL has expired.
321
+ # * +:dead_lettering_on_filter_evaluation_exceptions+ - Boolean. Determines how the Service Bus handles a message that causes an exception during a subscription's filter evaluation.
322
+ # * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
323
+ # * +:max_delivery_count+ - Number. A message is automatically deadlettered after this number of deliveries.
324
+ # * +:message_count+ - Number. Displays the number of messages currently in the queue.
325
+ #
326
+ def create_subscription(*p)
327
+ subscription = _subscription_from(*p)
328
+
329
+ result = create_resource_entry(:subscription, subscription, subscription.topic, subscription.name)
330
+ result.topic = subscription.topic
331
+ result
332
+ end
333
+
334
+ #
335
+ # Deletes an existing subscription.
336
+ #
337
+ # ==== Attributes
338
+ #
339
+ # Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
340
+ # such as Azure::ServiceBus::Subscription instance.
341
+ def delete_subscription(*p)
342
+ topic_name, subscription_name = _subscription_args(*p)
343
+
344
+ delete_resource_entry(:subscription, topic_name, subscription_name)
345
+ end
346
+
347
+ # Gets an existing subscription.
348
+ #
349
+ # ==== Attributes
350
+ #
351
+ # Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
352
+ # such as Azure::ServiceBus::Subscription instance.
353
+ def get_subscription(*p)
354
+ topic_name, subscription_name = _subscription_args(*p)
355
+
356
+ result = resource_entry(:subscription, topic_name, subscription_name)
357
+ result.topic = topic_name
358
+ result
359
+ end
360
+
361
+ # Retrieves the subscriptions in the specified topic.
362
+ #
363
+ # ==== Attributes
364
+ #
365
+ # * +topic+ - Either a Azure::ServiceBus::Topic instance or a string of the topic name
366
+ # * +options+ - Hash. Optional parameters.
367
+ #
368
+ # ==== Options
369
+ #
370
+ # Accepted key/value pairs in options parameter are:
371
+ # * +:skip+ - Integer. Number of subscriptions to skip.
372
+ # * +:top+ - Integer. Number of subscriptions to list.
373
+ def list_subscriptions(topic, options={})
374
+ topic = _name_for(topic)
375
+ query = {}
376
+ query["$skip"] = options[:skip].to_i.to_s if options[:skip]
377
+ query["$top"] = options[:top].to_i.to_s if options[:top]
378
+
379
+ results = resource_list(:subscription, topic, query)
380
+ results.each { |s| s.topic = topic }
381
+
382
+ return results
383
+ end
384
+
385
+ # Enqueues a message into the specified topic. The limit to the number of messages
386
+ # which may be present in the topic is governed by the message size in MaxTopicSizeInBytes.
387
+ # If this message causes the topic to exceed its quota, a quota exceeded error is
388
+ # returned and the message will be rejected.
389
+ #
390
+ # ==== Attributes
391
+ #
392
+ # * +topic+ - Either a Azure::ServiceBus::Topic instance or a string of the topic name
393
+ # * +message+ - An Azure::ServiceBus::BrokeredMessage object containing message body and properties,
394
+ # or a string of the message body (a default BrokeredMessage will be created from the string).
395
+ def send_topic_message(topic, message)
396
+ _send_message(_name_for(topic), message)
397
+ end
398
+
399
+ # This operation is used to atomically retrieve and lock a message for processing.
400
+ # The message is guaranteed not to be delivered to other receivers during the lock
401
+ # duration period specified in buffer description. Once the lock expires, the
402
+ # message will be available to other receivers (on the same subscription only)
403
+ # during the lock duration period specified in the topic description. Once the lock
404
+ # expires, the message will be available to other receivers. In order to complete
405
+ # processing of the message, the receiver should issue a delete command with the
406
+ # lock ID received from this operation. To abandon processing of the message and
407
+ # unlock it for other receivers, an Unlock Message command should be issued, or
408
+ # the lock duration period can expire.
409
+ #
410
+ # ==== Attributes
411
+ #
412
+ # * +topic+ - String. The name of the topic or a Topic instance
413
+ # * +subscription+ - String. The name of the subscription or a Subscription instance
414
+ # * +options+ - Hash. Optional parameters.
415
+ #
416
+ # ==== Options
417
+ #
418
+ # Accepted key/value pairs in options parameter are:
419
+ # * +:timeout+ - Integer. Timeout for the REST call.
420
+ def peek_lock_subscription_message(topic, subscription, options={})
421
+ topic = _name_for(topic)
422
+ subscription = _name_for(subscription)
423
+
424
+ _peek_lock_message(subscriptions_path(topic, subscription), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
425
+ end
426
+
427
+ #
428
+ # Unlock a message for processing by other receivers on a given subscription.
429
+ # This operation deletes the lock object, causing the message to be unlocked.
430
+ # A message must have first been locked by a receiver before this operation
431
+ # is called.
432
+ #
433
+ # ==== Attributes
434
+ #
435
+ # * +message+ - String. Either the message location URL or a message object.
436
+ #
437
+ def unlock_subscription_message(message)
438
+ _unlock_message(message)
439
+ end
440
+
441
+ # Read and delete a message from a subscription as an atomic operation. This
442
+ # operation should be used when a best-effort guarantee is sufficient for an
443
+ # application; that is, using this operation it is possible for messages to
444
+ # be lost if processing fails.
445
+ #
446
+ # ==== Attributes
447
+ #
448
+ # * +topic+ - The name of the topic or a Topic instance
449
+ # * +subscription+ - The name of the subscription or a Subscription instance
450
+ # * +options+ - Hash. Optional parameters.
451
+ #
452
+ # ==== Options
453
+ #
454
+ # Accepted key/value pairs in options parameter are:
455
+ # * +:timeout+ - Integer. Timeout for the REST call.
456
+ #
457
+ def read_delete_subscription_message(topic, subscription, options={})
458
+ topic = _name_for(topic)
459
+ subscription = _name_for(subscription)
460
+
461
+ _read_delete_message(subscriptions_path(topic, subscription), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
462
+ end
463
+
464
+ # Completes processing on a locked message and delete it from the subscription.
465
+ # This operation should only be called after processing a previously locked
466
+ # message is successful to maintain At-Least-Once delivery assurances.
467
+ #
468
+ # ==== Attributes
469
+ #
470
+ # * +message+ - String. Either the message location URL or a message object.
471
+ #
472
+ def delete_subscription_message(message)
473
+ _delete_message(message)
474
+ end
475
+
476
+ # Sends a message into the specified queue. The limit to the number of messages
477
+ # which may be present in the topic is governed by the message size the
478
+ # MaxTopicSizeInMegaBytes. If this message will cause the queue to exceed its
479
+ # quota, a quota exceeded error is returned and the message will be rejected.
480
+ #
481
+ # ==== Attributes
482
+ #
483
+ # * +queue+ - Either a Azure::ServiceBus::Queue instance or a string of the queue name
484
+ # * +message+ - An Azure::ServiceBus::BrokeredMessage object containing message body and properties,
485
+ # or a string of the message body (a default BrokeredMessage will be created from the string).
486
+ def send_queue_message(queue, message)
487
+ _send_message(_name_for(queue), message)
488
+ end
489
+
490
+ #
491
+ # Automatically retrieves and locks a message from a queue for processing. The
492
+ # message is guaranteed not to be delivered to other receivers (on the same
493
+ # subscription only) during the lock duration period specified in the queue
494
+ # description. Once the lock expires, the message will be available to other
495
+ # receivers. In order to complete processing of the message, the receiver
496
+ # should issue a delete command with the lock ID received from this operation.
497
+ # To abandon processing of the message and unlock it for other receivers,
498
+ # an Unlock Message command should be issued, or the lock duration period
499
+ # can expire.
500
+ #
501
+ # ==== Attributes
502
+ #
503
+ # * +queue+ - String. Either a Azure::ServiceBus::Queue instance or a string of the queue name
504
+ # * +options+ - Hash. Optional parameters.
505
+ #
506
+ # ==== Options
507
+ #
508
+ # Accepted key/value pairs in options parameter are:
509
+ # * +:timeout+ - Integer. Timeout for the REST call.
510
+ #
511
+ def peek_lock_queue_message(queue, options={})
512
+ _peek_lock_message(_name_for(queue), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
513
+ end
514
+
515
+ # Unlocks a message for processing by other receivers on a given subscription.
516
+ # This operation deletes the lock object, causing the message to be unlocked.
517
+ # A message must have first been locked by a receiver before this operation is
518
+ # called.
519
+ #
520
+ # ==== Attributes
521
+ #
522
+ # * +message+ - String. Either the message location URL or a message object.
523
+ #
524
+ def unlock_queue_message(message)
525
+ _unlock_message(message)
526
+ end
527
+
528
+ # Reads and deletes a message from a queue as an atomic operation. This operation
529
+ # should be used when a best-effort guarantee is sufficient for an application;
530
+ # that is, using this operation it is possible for messages to be lost if
531
+ # processing fails.
532
+ #
533
+ # ==== Attributes
534
+ #
535
+ # * +queue+ - Either a Azure::ServiceBus::Queue instance or a string of the queue name
536
+ # * +options+ - Hash. Optional parameters.
537
+ #
538
+ # ==== Options
539
+ #
540
+ # Accepted key/value pairs in options parameter are:
541
+ # * +:timeout+ - Integer. Timeout for the REST call.
542
+ #
543
+ def read_delete_queue_message(queue, options={})
544
+ _read_delete_message(_name_for(queue), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
545
+ end
546
+
547
+ # Completes processing on a locked message and delete it from the queue. This
548
+ # operation should only be called after processing a previously locked message
549
+ # is successful to maintain At-Least-Once delivery assurances.
550
+ #
551
+ # ==== Attributes
552
+ #
553
+ # * +message+ - String. Either the message location URL or a message object.
554
+ #
555
+ def delete_queue_message(message)
556
+ _delete_message(message)
557
+ end
558
+
559
+ # Public: Receives a queue message.
560
+ #
561
+ # ==== Attributes
562
+ #
563
+ # * +queue+ - String. The queue name.
564
+ # * +options+ - Hash. Optional parameters.
565
+ #
566
+ # ==== Options
567
+ #
568
+ # Accepted key/value pairs in options parameter are:
569
+ # * +:peek_lock+ - Boolean. Lock when peeking.
570
+ # * +:timeout+ - Integer. Timeout for the REST call.
571
+ #
572
+ def receive_queue_message(queue, options={})
573
+ peek_lock = options.fetch(:peek_lock, true)
574
+
575
+ options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
576
+ if peek_lock
577
+ peek_lock_queue_message(queue, options)
578
+ else
579
+ read_delete_queue_message(queue, options)
580
+ end
581
+ end
582
+
583
+ # Public: Receives a subscription message.
584
+ #
585
+ # ==== Attributes
586
+ #
587
+ # * +topic+ - String. The topic name.
588
+ # * +options+ - Hash. Optional parameters.
589
+ #
590
+ # ==== Options
591
+ #
592
+ # Accepted key/value pairs in options parameter are:
593
+ # * +:peek_lock+ - Boolean. Lock when peeking.
594
+ # * +:timeout+ - Integer. Timeout for the REST call.
595
+ #
596
+ def receive_subscription_message(topic, subscription, options={})
597
+ peek_lock = options.fetch(:peek_lock, true)
598
+
599
+ options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
600
+ if peek_lock
601
+ peek_lock_subscription_message(topic, subscription, options)
602
+ else
603
+ read_delete_subscription_message(topic, subscription, options)
604
+ end
605
+ end
606
+
607
+ private
608
+
609
+ def _unlock_message(message)
610
+ _modify_message(:put, message)
611
+ end
612
+
613
+ def _delete_message(message)
614
+ _modify_message(:delete, message)
615
+ end
616
+
617
+ def _modify_message(method, message)
618
+ uri = if (message.respond_to? :location)
619
+ message.location
620
+ else
621
+ message
622
+ end
623
+
624
+ call(method, uri)
625
+ nil
626
+ end
627
+
628
+ def _send_message(path, message)
629
+ message = Azure::ServiceBus::BrokeredMessage.new(message.to_s) unless message.kind_of?(Azure::ServiceBus::BrokeredMessage)
630
+
631
+ serializer = BrokeredMessageSerializer.new(message)
632
+ broker_properties = serializer.to_json
633
+ message_properties = serializer.get_property_headers
634
+
635
+ content_type = message.content_type || 'text/plain'
636
+
637
+ headers = {
638
+ 'BrokerProperties' => broker_properties
639
+ }
640
+
641
+ message_properties.each do |k, v|
642
+ headers[k.to_s.encode("UTF-8")] = v.encode("UTF-8")
643
+ end
644
+
645
+ headers["Content-Type"] = content_type
646
+
647
+ call(:post, messages_uri(path), message.body, headers)
648
+ nil
649
+ end
650
+
651
+ def _read_delete_message(path, timeout=DEFAULT_TIMEOUT)
652
+ _retrieve_message(:delete, path, timeout)
653
+ end
654
+
655
+ def _peek_lock_message(path, timeout=DEFAULT_TIMEOUT)
656
+ _retrieve_message(:post, path, timeout)
657
+ end
658
+
659
+ def _retrieve_message(method, path, timeout=DEFAULT_TIMEOUT)
660
+ uri = messages_head_uri(path, {"timeout" => timeout.to_s})
661
+
662
+ response = call(method, uri)
663
+ (response.status_code == 204) ? nil : BrokeredMessageSerializer.get_from_http_response(response)
664
+ end
665
+
666
+ def _rule_from(*p)
667
+ rule = nil
668
+
669
+ if p.length == 3 or p.length == 4
670
+ rule = Azure::ServiceBus::Rule.new(p[2]) do |r|
671
+ r.topic = p[0]
672
+ r.subscription = p[1]
673
+ r.description = p[3] if p.length == 4
674
+ end
675
+ elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic and p[0].respond_to? :subscription and p[0].respond_to? :description
676
+ rule = p[0]
677
+ else
678
+ raise ArgumentError, "Must provide either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods such as Azure::ServiceBus::Subscription instance."
679
+ end
680
+
681
+ rule
682
+ end
683
+
684
+ def _rule_args(*p)
685
+ if p.length == 3
686
+ topic_name = p[0]
687
+ subscription_name = p[1]
688
+ rule_name = p[2]
689
+ elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic
690
+ topic_name = p[0].topic
691
+ subscription_name = p[0].subscription
692
+ rule_name = p[0].name
693
+ else
694
+ raise ArgumentError, "Must provide either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and .subscription methods such as Azure::ServiceBus::Rule instance."
695
+ end
696
+
697
+ return topic_name, subscription_name, rule_name
698
+ end
699
+
700
+ def _subscription_from(*p)
701
+ subscription = nil
702
+
703
+ if p.length == 3
704
+ subscription = Azure::ServiceBus::Subscription.new(p[1], p[2]) do |sub|
705
+ sub.topic = p[0]
706
+ end
707
+ elsif p.length == 2
708
+ subscription = Azure::ServiceBus::Subscription.new(p[1]) do |sub|
709
+ sub.topic = p[0]
710
+ end
711
+ elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic and p[0].respond_to? :description
712
+ subscription = p[0]
713
+ else
714
+ raise ArgumentError, "Must provide either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods such as Azure::ServiceBus::Subscription instance."
715
+ end
716
+
717
+ subscription
718
+ end
719
+
720
+ def _subscription_args(*p)
721
+
722
+ raise ArgumentError, "Not enough args" if p.length < 1
723
+ topic_name = nil
724
+ subscription_name = nil
725
+ options = {}
726
+
727
+ if p.length == 3
728
+ # topic/sub/options
729
+ topic_name = _name_for(p[0])
730
+ subscription_name = _name_for(p[1])
731
+ options =p[2]
732
+ elsif p.length == 2
733
+ # either subscription/options or topic/sub
734
+ if p[0].respond_to? :name and p[0].respond_to? :topic
735
+ topic_name = p[0].topic
736
+ subscription_name = p[0].name
737
+ options =p[1]
738
+ else
739
+ topic_name = _name_for(p[0])
740
+ subscription_name = _name_for(p[1])
741
+ end
742
+ elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic
743
+ topic_name = p[0].topic
744
+ subscription_name = p[0].name
745
+ else
746
+ raise ArgumentError, "Must provide either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods such as Azure::ServiceBus::Subscription instance."
747
+ end
748
+
749
+ return topic_name, subscription_name, options
750
+ end
751
+
752
+ def _name_for(val)
753
+ val.respond_to?(:name) ? val.name : val
754
+ end
755
+
756
+ def _new_or_existing(type, *p)
757
+ p[0].kind_of?(type) ? p[0] : type.new(*p)
758
+ end
759
+
760
+
761
+ def create_resource_entry(resource, entry, *p)
762
+ body = Serialization.resource_to_xml resource, entry
763
+ response = call(:put, self.send("#{resource.to_s}_uri", *p), body)
764
+ results = Serialization.resources_from_xml(resource, response.body)
765
+ results ? results.first : results
766
+ end
767
+
768
+ def delete_resource_entry(resource, *p)
769
+ call(:delete, self.send("#{resource.to_s}_uri", *p))
770
+ nil
771
+ end
772
+
773
+ def resource_entry(resource, *p)
774
+ uri = self.send("#{resource.to_s}_uri", *p)
775
+ response = call(:get, uri)
776
+ results = Serialization.resources_from_xml(resource, response.body)
777
+ result = results ? results.first : results
778
+ raise Azure::Core::Http::HTTPError.new(Azure::Core::Http::HttpResponse.new(Azure::Core::Http::HttpResponse::MockResponse.new(404, '<?xml version="1.0"?><error><code>ResourceNotFound</code><message xml:lang="en-US">The specified resource does not exist.</message></error>', {}), uri)) unless result
779
+ result
780
+ end
781
+
782
+ def resource_list(resource, *p)
783
+ response = call(:get, self.send("#{resource.to_s}_list_uri", *p))
784
+ Serialization.resources_from_xml_with_next_link(resource, response.body)
785
+ end
786
+
787
+ # paths
788
+
789
+ protected
790
+ def message_path(path, sequence_number, lock_token)
791
+ "#{messages_path(path)}/#{sequence_number}/#{lock_token}"
792
+ end
793
+
794
+ protected
795
+ def messages_head_path(path)
796
+ "#{messages_path(path)}/head"
797
+ end
798
+
799
+ protected
800
+ def messages_path(path)
801
+ "#{path}/messages"
802
+ end
803
+
804
+ protected
805
+ def rule_path(topic, subscription, rule)
806
+ "#{subscriptions_path(topic, subscription)}/rules/#{rule}"
807
+ end
808
+
809
+ protected
810
+ def subscriptions_path(topic, subscription)
811
+ "#{topic}/subscriptions/#{subscription}"
812
+ end
813
+
814
+ # messages uris
815
+
816
+ protected
817
+ def message_uri(path, sequence_number, lock_token, query={})
818
+ generate_uri(message_path(path, sequence_number, lock_token), query)
819
+ end
820
+
821
+ protected
822
+ def messages_head_uri(path, query={})
823
+ generate_uri(messages_head_path(path), query)
824
+ end
825
+
826
+ protected
827
+ def messages_uri(path, query={})
828
+ generate_uri(messages_path(path), query)
829
+ end
830
+
831
+ # entry uris
832
+ protected
833
+ def rule_uri(topic, subscription, rule, query={})
834
+ generate_uri(rule_path(topic, subscription, rule), query)
835
+ end
836
+
837
+ protected
838
+ def subscription_uri(topic, subscription, query={})
839
+ generate_uri(subscriptions_path(topic, subscription), query)
840
+ end
841
+
842
+ protected
843
+ def relay_uri(relay, query={})
844
+ query["api-version"] = "2013-10"
845
+ generate_uri(relay, query)
846
+ end
847
+
848
+ protected
849
+ def queue_uri(topic, query={})
850
+ generate_uri(topic, query)
851
+ end
852
+
853
+ protected
854
+ def topic_uri(topic, query={})
855
+ generate_uri(topic, query)
856
+ end
857
+
858
+ # list uris
859
+
860
+ protected
861
+ def rule_list_uri(topic, subscription, query={})
862
+ resource_list_uri(:rule, query, subscriptions_path(topic, subscription))
863
+ end
864
+
865
+ protected
866
+ def subscription_list_uri(topic, query={})
867
+ resource_list_uri(:subscription, query, topic)
868
+ end
869
+
870
+ protected
871
+ def relay_list_uri(query={})
872
+ resource_list_uri(:relay, query)
873
+ end
874
+
875
+ protected
876
+ def queue_list_uri(query={})
877
+ resource_list_uri(:queue, query)
878
+ end
879
+
880
+ protected
881
+ def topic_list_uri(query={})
882
+ resource_list_uri(:topic, query)
883
+ end
884
+
885
+ protected
886
+ def resource_list_uri(resource, query={}, subpath='$Resources')
887
+ skip = query.delete ["$skip"]
888
+ top = query.delete ["$top"]
889
+
890
+ uri = generate_uri("#{subpath}/#{resource.to_s.capitalize}s", query)
891
+ uri.query = [uri.query, "$skip=" + skip].join('&') if skip
892
+ uri.query = [uri.query, "$top=" + top].join('&') if top
893
+ uri
894
+ end
895
+ end
896
+ end
897
+ end
898
+
899
+ Azure::ServiceBusService = Azure::ServiceBus::ServiceBusService