stuartpreston-azure-sdk-for-ruby 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (292) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.travis.yml +10 -0
  4. data/ChangeLog.txt +40 -0
  5. data/Gemfile +16 -0
  6. data/README.md +616 -0
  7. data/Rakefile +133 -0
  8. data/azure.gemspec +44 -0
  9. data/lib/azure.rb +52 -0
  10. data/lib/azure/base_management/affinity_group.rb +32 -0
  11. data/lib/azure/base_management/base_management_service.rb +234 -0
  12. data/lib/azure/base_management/location.rb +27 -0
  13. data/lib/azure/base_management/management_http_request.rb +172 -0
  14. data/lib/azure/base_management/serialization.rb +129 -0
  15. data/lib/azure/base_management/sql_management_http_request.rb +45 -0
  16. data/lib/azure/blob/blob.rb +32 -0
  17. data/lib/azure/blob/blob_service.rb +1423 -0
  18. data/lib/azure/blob/block.rb +31 -0
  19. data/lib/azure/blob/container.rb +32 -0
  20. data/lib/azure/blob/serialization.rb +285 -0
  21. data/lib/azure/cloud_service_management/cloud_service.rb +38 -0
  22. data/lib/azure/cloud_service_management/cloud_service_management_service.rb +140 -0
  23. data/lib/azure/cloud_service_management/serialization.rb +117 -0
  24. data/lib/azure/core.rb +39 -0
  25. data/lib/azure/core/auth/authorizer.rb +36 -0
  26. data/lib/azure/core/auth/shared_key.rb +110 -0
  27. data/lib/azure/core/auth/shared_key_lite.rb +48 -0
  28. data/lib/azure/core/auth/signer.rb +48 -0
  29. data/lib/azure/core/configuration.rb +211 -0
  30. data/lib/azure/core/error.rb +22 -0
  31. data/lib/azure/core/filtered_service.rb +44 -0
  32. data/lib/azure/core/http/debug_filter.rb +36 -0
  33. data/lib/azure/core/http/http_error.rb +88 -0
  34. data/lib/azure/core/http/http_filter.rb +53 -0
  35. data/lib/azure/core/http/http_request.rb +157 -0
  36. data/lib/azure/core/http/http_response.rb +140 -0
  37. data/lib/azure/core/http/retry_policy.rb +74 -0
  38. data/lib/azure/core/http/signer_filter.rb +34 -0
  39. data/lib/azure/core/service.rb +63 -0
  40. data/lib/azure/core/signed_service.rb +43 -0
  41. data/lib/azure/core/utility.rb +190 -0
  42. data/lib/azure/queue/message.rb +30 -0
  43. data/lib/azure/queue/queue.rb +29 -0
  44. data/lib/azure/queue/queue_service.rb +568 -0
  45. data/lib/azure/queue/serialization.rb +106 -0
  46. data/lib/azure/service/access_policy.rb +26 -0
  47. data/lib/azure/service/cors.rb +11 -0
  48. data/lib/azure/service/cors_rule.rb +15 -0
  49. data/lib/azure/service/enumeration_results.rb +21 -0
  50. data/lib/azure/service/logging.rb +32 -0
  51. data/lib/azure/service/metrics.rb +31 -0
  52. data/lib/azure/service/retention_policy.rb +25 -0
  53. data/lib/azure/service/serialization.rb +298 -0
  54. data/lib/azure/service/signed_identifier.rb +30 -0
  55. data/lib/azure/service/storage_service.rb +83 -0
  56. data/lib/azure/service/storage_service_properties.rb +37 -0
  57. data/lib/azure/service_bus/action.rb +21 -0
  58. data/lib/azure/service_bus/auth/wrap_service.rb +89 -0
  59. data/lib/azure/service_bus/auth/wrap_signer.rb +69 -0
  60. data/lib/azure/service_bus/brokered_message.rb +124 -0
  61. data/lib/azure/service_bus/brokered_message_serializer.rb +159 -0
  62. data/lib/azure/service_bus/correlation_filter.rb +45 -0
  63. data/lib/azure/service_bus/empty_rule_action.rb +30 -0
  64. data/lib/azure/service_bus/false_filter.rb +38 -0
  65. data/lib/azure/service_bus/filter.rb +21 -0
  66. data/lib/azure/service_bus/interval.rb +104 -0
  67. data/lib/azure/service_bus/queue.rb +230 -0
  68. data/lib/azure/service_bus/relay.rb +88 -0
  69. data/lib/azure/service_bus/resource.rb +109 -0
  70. data/lib/azure/service_bus/rule.rb +98 -0
  71. data/lib/azure/service_bus/rule_aspect.rb +34 -0
  72. data/lib/azure/service_bus/serialization.rb +161 -0
  73. data/lib/azure/service_bus/service_bus_service.rb +897 -0
  74. data/lib/azure/service_bus/sql_filter.rb +50 -0
  75. data/lib/azure/service_bus/sql_rule_action.rb +50 -0
  76. data/lib/azure/service_bus/subscription.rb +184 -0
  77. data/lib/azure/service_bus/topic.rb +187 -0
  78. data/lib/azure/service_bus/true_filter.rb +38 -0
  79. data/lib/azure/sql_database_management/serialization.rb +111 -0
  80. data/lib/azure/sql_database_management/sql_database.rb +31 -0
  81. data/lib/azure/sql_database_management/sql_database_management_service.rb +200 -0
  82. data/lib/azure/storage_management/serialization.rb +184 -0
  83. data/lib/azure/storage_management/storage_account.rb +40 -0
  84. data/lib/azure/storage_management/storage_management_service.rb +166 -0
  85. data/lib/azure/table/auth/shared_key.rb +92 -0
  86. data/lib/azure/table/auth/shared_key_lite.rb +44 -0
  87. data/lib/azure/table/batch.rb +330 -0
  88. data/lib/azure/table/batch_response.rb +118 -0
  89. data/lib/azure/table/edmtype.rb +127 -0
  90. data/lib/azure/table/entity.rb +31 -0
  91. data/lib/azure/table/guid.rb +24 -0
  92. data/lib/azure/table/query.rb +112 -0
  93. data/lib/azure/table/serialization.rb +108 -0
  94. data/lib/azure/table/table_service.rb +560 -0
  95. data/lib/azure/version.rb +31 -0
  96. data/lib/azure/virtual_machine_image_management/serialization.rb +66 -0
  97. data/lib/azure/virtual_machine_image_management/virtual_machine_disk.rb +25 -0
  98. data/lib/azure/virtual_machine_image_management/virtual_machine_image.rb +25 -0
  99. data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +94 -0
  100. data/lib/azure/virtual_machine_management/serialization.rb +463 -0
  101. data/lib/azure/virtual_machine_management/virtual_machine.rb +45 -0
  102. data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +589 -0
  103. data/lib/azure/virtual_network_management/serialization.rb +186 -0
  104. data/lib/azure/virtual_network_management/virtual_network.rb +36 -0
  105. data/lib/azure/virtual_network_management/virtual_network_management_service.rb +109 -0
  106. data/test/fixtures/32px-fulls-black.jpg +0 -0
  107. data/test/fixtures/affinity_group.xml +33 -0
  108. data/test/fixtures/all_containers.xml +20 -0
  109. data/test/fixtures/all_tables.xml +22 -0
  110. data/test/fixtures/certificate.pem +21 -0
  111. data/test/fixtures/container_acl.xml +11 -0
  112. data/test/fixtures/create_sql_database_server.xml +2 -0
  113. data/test/fixtures/create_storage_desc_error.xml +5 -0
  114. data/test/fixtures/create_storage_extendedprop_error.xml +8 -0
  115. data/test/fixtures/create_storage_extendedpropname_error.xml +6 -0
  116. data/test/fixtures/create_storage_full_error.xml +6 -0
  117. data/test/fixtures/create_storage_label_error.xml +5 -0
  118. data/test/fixtures/create_storage_location_error.xml +5 -0
  119. data/test/fixtures/create_storage_name_error.xml +6 -0
  120. data/test/fixtures/create_table_response_entry.xml +15 -0
  121. data/test/fixtures/delete_storage_container_error.xml +5 -0
  122. data/test/fixtures/delete_storage_error.xml +5 -0
  123. data/test/fixtures/deployment_error.xml +5 -0
  124. data/test/fixtures/empty_xml_file +0 -0
  125. data/test/fixtures/get_storage_account_error.xml +5 -0
  126. data/test/fixtures/get_storage_account_properties.xml +32 -0
  127. data/test/fixtures/get_storage_account_properties_new.xml +32 -0
  128. data/test/fixtures/http_error.xml +5 -0
  129. data/test/fixtures/insert_entity_response_entry.xml +25 -0
  130. data/test/fixtures/list_affinity_groups.xml +22 -0
  131. data/test/fixtures/list_blobs.xml +121 -0
  132. data/test/fixtures/list_block_all_with_none_committed.xml +22 -0
  133. data/test/fixtures/list_blocks_all.xml +23 -0
  134. data/test/fixtures/list_blocks_committed.xml +13 -0
  135. data/test/fixtures/list_cloud_services.xml +39 -0
  136. data/test/fixtures/list_containers.xml +38 -0
  137. data/test/fixtures/list_firewall_management_endpoint.xml +27 -0
  138. data/test/fixtures/list_images.xml +110 -0
  139. data/test/fixtures/list_locations.xml +62 -0
  140. data/test/fixtures/list_page_ranges.xml +11 -0
  141. data/test/fixtures/list_sql_database.xml +36 -0
  142. data/test/fixtures/list_sql_server_firewall.xml +23 -0
  143. data/test/fixtures/list_storage_account_single.xml +25 -0
  144. data/test/fixtures/list_storage_accounts.xml +46 -0
  145. data/test/fixtures/list_virtual_networks.xml +92 -0
  146. data/test/fixtures/logging.xml +11 -0
  147. data/test/fixtures/management_certificate.pem +55 -0
  148. data/test/fixtures/messages.xml +12 -0
  149. data/test/fixtures/metrics.xml +10 -0
  150. data/test/fixtures/privatekey.key +28 -0
  151. data/test/fixtures/query_entities_empty_response.xml +7 -0
  152. data/test/fixtures/query_entities_response.xml +45 -0
  153. data/test/fixtures/queue_service_properties.xml +22 -0
  154. data/test/fixtures/queue_service_properties_original.xml +19 -0
  155. data/test/fixtures/queues.xml +16 -0
  156. data/test/fixtures/retention_policy.xml +5 -0
  157. data/test/fixtures/sb_default_create_queue_response.xml +23 -0
  158. data/test/fixtures/sb_default_create_relay_response.xml +15 -0
  159. data/test/fixtures/sb_default_create_topic_response.xml +18 -0
  160. data/test/fixtures/sb_get_access_token_response.txt +1 -0
  161. data/test/fixtures/sb_queues_runtime_peek_message_response_headers.txt +9 -0
  162. data/test/fixtures/storage_service_properties.xml +54 -0
  163. data/test/fixtures/update_storage_account.xml +16 -0
  164. data/test/fixtures/update_storage_error.xml +5 -0
  165. data/test/fixtures/updated_storage_accounts.xml +53 -0
  166. data/test/fixtures/virtual_machine.xml +113 -0
  167. data/test/fixtures/windows_virtual_machine.xml +106 -0
  168. data/test/integration/affinity_group/Affinity_test.rb +55 -0
  169. data/test/integration/affinity_group/Create_Affinity_test.rb +63 -0
  170. data/test/integration/affinity_group/Delete_Affinity_test.rb +56 -0
  171. data/test/integration/affinity_group/List_Affinity_test.rb +41 -0
  172. data/test/integration/affinity_group/Update_Affinity_test.rb +82 -0
  173. data/test/integration/blob/blob_gb18030_test.rb +199 -0
  174. data/test/integration/blob/blob_metadata_test.rb +75 -0
  175. data/test/integration/blob/blob_pages_test.rb +119 -0
  176. data/test/integration/blob/blob_properties_test.rb +77 -0
  177. data/test/integration/blob/block_blob_test.rb +254 -0
  178. data/test/integration/blob/container/container_acl_test.rb +69 -0
  179. data/test/integration/blob/container/container_metadata_test.rb +50 -0
  180. data/test/integration/blob/container/create_container_test.rb +60 -0
  181. data/test/integration/blob/container/delete_container_test.rb +39 -0
  182. data/test/integration/blob/container/get_container_properties_test.rb +48 -0
  183. data/test/integration/blob/container/list_containers_test.rb +79 -0
  184. data/test/integration/blob/container/root_container_test.rb +54 -0
  185. data/test/integration/blob/copy_blob_test.rb +113 -0
  186. data/test/integration/blob/create_blob_snapshot_test.rb +80 -0
  187. data/test/integration/blob/create_page_blob_test.rb +83 -0
  188. data/test/integration/blob/delete_blob_test.rb +159 -0
  189. data/test/integration/blob/get_blob_test.rb +65 -0
  190. data/test/integration/blob/informative_errors_test.rb +39 -0
  191. data/test/integration/blob/lease/acquire_lease_test.rb +36 -0
  192. data/test/integration/blob/lease/break_lease_test.rb +40 -0
  193. data/test/integration/blob/lease/release_lease_test.rb +40 -0
  194. data/test/integration/blob/lease/renew_lease_test.rb +42 -0
  195. data/test/integration/blob/list_blobs_test.rb +113 -0
  196. data/test/integration/cloud_service/Cloud_Create_test.rb +44 -0
  197. data/test/integration/cloud_service/Cloud_Delete_test.rb +44 -0
  198. data/test/integration/database/create_sql_server_firewall_test.rb +86 -0
  199. data/test/integration/database/create_sql_server_test.rb +53 -0
  200. data/test/integration/database/delete_sql_server_firewall_test.rb +70 -0
  201. data/test/integration/database/delete_sql_server_test.rb +58 -0
  202. data/test/integration/database/list_sql_server_firewall_test.rb +45 -0
  203. data/test/integration/database/list_sql_servers_test.rb +44 -0
  204. data/test/integration/database/reset_password_sql_server_test.rb +55 -0
  205. data/test/integration/location/Location_List_test.rb +39 -0
  206. data/test/integration/queue/clear_messages_test.rb +42 -0
  207. data/test/integration/queue/create_message_test.rb +75 -0
  208. data/test/integration/queue/create_queue_test.rb +50 -0
  209. data/test/integration/queue/delete_message_test.rb +67 -0
  210. data/test/integration/queue/delete_queue_test.rb +45 -0
  211. data/test/integration/queue/informative_errors_test.rb +42 -0
  212. data/test/integration/queue/list_messages_encoded_test.rb +79 -0
  213. data/test/integration/queue/list_messages_test.rb +79 -0
  214. data/test/integration/queue/list_queues_test.rb +44 -0
  215. data/test/integration/queue/peek_messages_test.rb +59 -0
  216. data/test/integration/queue/queue_gb18030_test.rb +131 -0
  217. data/test/integration/queue/queue_metadata_test.rb +40 -0
  218. data/test/integration/queue/update_message_test.rb +74 -0
  219. data/test/integration/service_bus/informative_errors_test.rb +37 -0
  220. data/test/integration/service_bus/queues_scenario_test.rb +200 -0
  221. data/test/integration/service_bus/queues_test.rb +266 -0
  222. data/test/integration/service_bus/relay_test.rb +132 -0
  223. data/test/integration/service_bus/rules_test.rb +145 -0
  224. data/test/integration/service_bus/sb_queue_gb18030_test.rb +182 -0
  225. data/test/integration/service_bus/scenario_test.rb +101 -0
  226. data/test/integration/service_bus/subscriptions_test.rb +211 -0
  227. data/test/integration/service_bus/topics_scenario_test.rb +406 -0
  228. data/test/integration/service_bus/topics_test.rb +129 -0
  229. data/test/integration/storage_management/storage_management_test.rb +160 -0
  230. data/test/integration/table/create_table_test.rb +36 -0
  231. data/test/integration/table/delete_entity_batch_test.rb +107 -0
  232. data/test/integration/table/delete_entity_test.rb +94 -0
  233. data/test/integration/table/delete_table_test.rb +40 -0
  234. data/test/integration/table/get_table_test.rb +37 -0
  235. data/test/integration/table/informative_errors_test.rb +39 -0
  236. data/test/integration/table/insert_entity_batch_test.rb +100 -0
  237. data/test/integration/table/insert_entity_test.rb +88 -0
  238. data/test/integration/table/insert_or_merge_entity_batch_test.rb +159 -0
  239. data/test/integration/table/insert_or_merge_entity_test.rb +143 -0
  240. data/test/integration/table/insert_or_replace_entity_batch_test.rb +152 -0
  241. data/test/integration/table/insert_or_replace_entity_test.rb +137 -0
  242. data/test/integration/table/merge_entity_batch_test.rb +128 -0
  243. data/test/integration/table/merge_entity_test.rb +113 -0
  244. data/test/integration/table/query_entities_test.rb +195 -0
  245. data/test/integration/table/query_tables_test.rb +43 -0
  246. data/test/integration/table/query_test.rb +251 -0
  247. data/test/integration/table/table_acl_test.rb +52 -0
  248. data/test/integration/table/table_gb18030_test.rb +355 -0
  249. data/test/integration/table/update_entity_batch_test.rb +149 -0
  250. data/test/integration/table/update_entity_test.rb +131 -0
  251. data/test/integration/test_helper.rb +42 -0
  252. data/test/integration/vm/VM_Create_test.rb +260 -0
  253. data/test/integration/vm/VM_Delete_test.rb +55 -0
  254. data/test/integration/vm/VM_Operations_test.rb +173 -0
  255. data/test/integration/vm_image/virtual_machine_disk_test.rb +37 -0
  256. data/test/integration/vm_image/virtual_machine_image_test.rb +37 -0
  257. data/test/integration/vnet/Virtual_Network_Create_test.rb +122 -0
  258. data/test/integration/vnet/Virtual_Network_list_test.rb +53 -0
  259. data/test/support/env.rb +19 -0
  260. data/test/support/fixtures.rb +36 -0
  261. data/test/support/name_generator.rb +168 -0
  262. data/test/support/stubs.rb +42 -0
  263. data/test/support/virtual_machine_name_generator.rb +102 -0
  264. data/test/support/virtual_network_helper.rb +73 -0
  265. data/test/test_helper.rb +54 -0
  266. data/test/unit/affinity_group/affinity_group_test.rb +192 -0
  267. data/test/unit/affinity_group/serialization_test.rb +88 -0
  268. data/test/unit/base_management/location_test.rb +57 -0
  269. data/test/unit/blob/blob_service_test.rb +1947 -0
  270. data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +94 -0
  271. data/test/unit/cloud_service_management/serialization_test.rb +169 -0
  272. data/test/unit/core/auth/shared_key_lite_test.rb +51 -0
  273. data/test/unit/core/auth/shared_key_test.rb +58 -0
  274. data/test/unit/core/auth/signer_test.rb +30 -0
  275. data/test/unit/core/http/http_error_test.rb +57 -0
  276. data/test/unit/core/http/http_request_test.rb +66 -0
  277. data/test/unit/core/http/http_response_test.rb +45 -0
  278. data/test/unit/core/http/retry_policy_test.rb +23 -0
  279. data/test/unit/database/serialization_test.rb +97 -0
  280. data/test/unit/database/sql_database_server_service_test.rb +288 -0
  281. data/test/unit/service/serialization_test.rb +533 -0
  282. data/test/unit/service/storage_service_test.rb +293 -0
  283. data/test/unit/storage_management/serialization_test.rb +232 -0
  284. data/test/unit/storage_management/storage_management_service_test.rb +261 -0
  285. data/test/unit/table/edmtype_test.rb +108 -0
  286. data/test/unit/virtual_machine_image_management/serialization_test.rb +35 -0
  287. data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +65 -0
  288. data/test/unit/virtual_machine_management/serialization_test.rb +258 -0
  289. data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +440 -0
  290. data/test/unit/vnet/serialization_test.rb +187 -0
  291. data/test/unit/vnet/virtual_network_management_service_test.rb +131 -0
  292. metadata +476 -0
@@ -0,0 +1,897 @@
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/serialization'
18
+
19
+ require 'azure/service_bus/brokered_message_serializer'
20
+ require 'azure/core/http/http_response'
21
+
22
+ module Azure
23
+ module ServiceBus
24
+ class ServiceBusService < Azure::Core::SignedService
25
+
26
+ DEFAULT_TIMEOUT = 60
27
+
28
+ def initialize(host=Azure.config.service_bus_host)
29
+ super(Azure::ServiceBus::Auth::WrapSigner.new)
30
+ @host = host
31
+
32
+ with_filter do |req, res|
33
+ req.headers.delete "x-ms-date"
34
+ req.headers.delete "x-ms-version"
35
+ req.headers.delete "DataServiceVersion"
36
+ req.headers.delete "MaxDataServiceVersion"
37
+ req.headers["X-Process-At"] = "servicebus"
38
+ res.call
39
+ end
40
+ end
41
+
42
+ # Creates a new relay endpoint. Once created, this relay endpoint resource manifest is immutable.
43
+ #
44
+ # ==== Attributes
45
+ #
46
+ # * +relay+ - Azure::ServiceBus::Relay instance to create on server, or a string of the relay endpoint name
47
+ # * +options+ - Hash. The relay endpoint properties.
48
+ #
49
+ # ==== Options
50
+ #
51
+ # Accepted key/value pairs in options parameter are:
52
+ # * +:relay_type+ - String. Determines the type of the relay endpoint.
53
+ # * +:requires_client_authorization+ - Boolean. Determines whether or not clients need to authenticate when making calls.
54
+ # * +:requires_transport_security+ - Boolean. Determines whether or not the endpoint uses transport security.
55
+ #
56
+ def create_relay(relay, options={})
57
+ relay = _new_or_existing(Azure::ServiceBus::Relay, relay, options ? options : {})
58
+ create_resource_entry(:relay, relay, relay.name)
59
+ end
60
+
61
+ # Deletes an existing relay endpoint.
62
+ #
63
+ # ==== Attributes
64
+ #
65
+ # * +relay+ - Azure::ServiceBus::Relay instance to delete or a string of the relay endpoint name
66
+ def delete_relay(relay)
67
+ delete_resource_entry(:relay, _name_for(relay))
68
+ end
69
+
70
+ # Retrieves the description for the specified relay endpoint.
71
+ #
72
+ # ==== Attributes
73
+ #
74
+ # * +relay+ - Azure::ServiceBus::Relay instance to retrieve or a string of the relay endpoint name
75
+ def get_relay(relay)
76
+ resource_entry(:relay, _name_for(relay))
77
+ end
78
+
79
+ # Enumerates the relay endpoints in the service namespace.
80
+ #
81
+ # ==== Attributes
82
+ #
83
+ # * +options+ - Hash. Optional parameters.
84
+ #
85
+ # ==== Options
86
+ #
87
+ # Accepted key/value pairs in options parameter are:
88
+ # * +:skip+ - Integer. Number of queues to skip.
89
+ # * +:top+ - Integer. Number of queues to list.
90
+ def list_relays(options={})
91
+ query = {}
92
+ query["$skip"] = options[:skip].to_i.to_s if options[:skip]
93
+ query["$top"] = options[:top].to_i.to_s if options[:top]
94
+
95
+ resource_list(:relay, query)
96
+ end
97
+
98
+ # Creates a new queue. Once created, this queue's resource manifest is immutable.
99
+ #
100
+ # ==== Attributes
101
+ #
102
+ # * +queue+ - Azure::ServiceBus::Queue instance to create on server, or a string of the queue name
103
+ # * +options+ - Hash. The queue properties.
104
+ #
105
+ # ==== Options
106
+ #
107
+ # Accepted key/value pairs in options parameter are:
108
+ # * +:default_message_time_to_live+ - XML datetime. Determines how long a message lives in the associated subscriptions.
109
+ # * +:duplicate_detection_history_time_window+ - XML datetime. Specifies the time span during which the Service Bus will detect message duplication.
110
+ # * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
111
+ # * +:dead_lettering_on_message_expiration:+ - Boolean. This field controls how the Service Bus handles a message whose TTL has expired.
112
+ # * +:lock_duration+ - XML datetime. Determines the amount of time in seconds in which a message should be locked for processing by a receiver.
113
+ # * +:max_delivery_count+ - Number. A message is automatically deadlettered after this number of deliveries.
114
+ # * +:max_size_in_megabytes+ - Number. Specifies the maximum topic size in megabytes
115
+ # * +:message_count+ - Number. Displays the number of messages currently in the queue.
116
+ # * +:requires_duplicate_detection+ - Boolean. If enabled, the topic will detect duplicate messages within the time span specified by the DuplicateDetectionHistoryTimeWindow property
117
+ # * +:requires_session+ - Boolean. If set to true, the queue will be session-aware and only SessionReceiver will be supported.
118
+ # * +:size_in_bytes+ - Number. Reflects the actual bytes toward the topic quota that messages in the topic currently occupy.
119
+ #
120
+ def create_queue(queue, options={})
121
+ queue = _new_or_existing(Azure::ServiceBus::Queue, queue, options ? options : {})
122
+ create_resource_entry(:queue, queue, queue.name)
123
+ end
124
+
125
+ # Deletes an existing queue. This operation will also remove all associated state
126
+ # including messages in the queue.
127
+ #
128
+ # ==== Attributes
129
+ #
130
+ # * +queue+ - Azure::ServiceBus::Queue instance to delete or a string of the queue name
131
+ def delete_queue(queue)
132
+ delete_resource_entry(:queue, _name_for(queue))
133
+ end
134
+
135
+ # Retrieves an existing queue.
136
+ #
137
+ # ==== Attributes
138
+ #
139
+ # * +queue+ - Azure::ServiceBus::Queue instance to retrieve or a string of the queue name
140
+ def get_queue(queue)
141
+ resource_entry(:queue, _name_for(queue))
142
+ end
143
+
144
+ # Enumerates the queues in the service namespace.
145
+ #
146
+ # ==== Attributes
147
+ #
148
+ # * +options+ - Hash. Optional parameters.
149
+ #
150
+ # ==== Options
151
+ #
152
+ # Accepted key/value pairs in options parameter are:
153
+ # * +:skip+ - Integer. Number of queues to skip.
154
+ # * +:top+ - Integer. Number of queues to list.
155
+ def list_queues(options={})
156
+ query = {}
157
+ query["$skip"] = options[:skip].to_i.to_s if options[:skip]
158
+ query["$top"] = options[:top].to_i.to_s if options[:top]
159
+
160
+ resource_list(:queue, query)
161
+ end
162
+
163
+ # Creates a new topic. Once created, this topic resource manifest is immutable.
164
+ #
165
+ # ==== Attributes
166
+ #
167
+ # * +topic+ - Azure::ServiceBus::Topic instance to create on server, or a string of the topic name
168
+ # * +options+ - Hash. The topic properties.
169
+ #
170
+ # ==== Options
171
+ #
172
+ # Accepted key/value pairs in options parameter are:
173
+ # * +:default_message_time_to_tive+ - XML datetime. Determines how long a message lives in the associated subscriptions.
174
+ # * +:maximum_number_of_subscriptions+ - Number. Specifies the maximum number of subscriptions that can be associated with the topic.
175
+ # * +:max_size_in_megabytes+ - Number. Specifies the maximum topic size in megabytes
176
+ # * +:requires_duplicate_detection+ - Boolean. If enabled, the topic will detect duplicate messages within the time span specified by the DuplicateDetectionHistoryTimeWindow property
177
+ # * +: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.
178
+ # * +:duplicate_detection_history_time_window+ - XML datetime. Specifies the time span during which the Service Bus will detect message duplication.
179
+ # * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
180
+ #
181
+ def create_topic(topic, options={})
182
+ topic = _new_or_existing(Azure::ServiceBus::Topic, topic, options ? options : {})
183
+ create_resource_entry(:topic, topic, topic.name)
184
+ end
185
+
186
+ # Deletes an existing topic. This operation will also remove all associated state
187
+ # including associated subscriptions.
188
+ #
189
+ # ==== Attributes
190
+ #
191
+ # * +topic+ - Azure::ServiceBus::Topic instance to delete or a string of the topic name
192
+ def delete_topic(topic)
193
+ delete_resource_entry(:topic, _name_for(topic))
194
+ end
195
+
196
+ # Retrieves the description for the specified topic.
197
+ #
198
+ # ==== Attributes
199
+ #
200
+ # * +topic+ - Azure::ServiceBus::Topic instance to retrieve or a string of the topic name
201
+ def get_topic(topic)
202
+ resource_entry(:topic, _name_for(topic))
203
+ end
204
+
205
+ # Retrieves the topics in the service namespace.
206
+ #
207
+ # ==== Attributes
208
+ #
209
+ # * +options+ - Hash. Optional parameters.
210
+ #
211
+ # ==== Options
212
+ #
213
+ # Accepted key/value pairs in options parameter are:
214
+ # * +:skip+ - Integer. Number of topics to skip.
215
+ # * +:top+ - Integer. Number of topics to list.
216
+ def list_topics(options={})
217
+ query = {}
218
+ query["$skip"] = options[:skip].to_i.to_s if options[:skip]
219
+ query["$top"] = options[:top].to_i.to_s if options[:top]
220
+
221
+ resource_list(:topic, query)
222
+ end
223
+
224
+ # Creates a new rule. Once created, this rule's resource manifest is immutable.
225
+ #
226
+ # ==== Attributes
227
+ #
228
+ # Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a rule object.
229
+ # When using (topic_name, subscription_name, rule_name, options) overload, you may also pass the properties for the rule.
230
+ #
231
+ # ==== Options
232
+ #
233
+ # Accepted key/value pairs in options parameter are:
234
+ # * +:filter+ - String. The rule filter.
235
+ # * +:action+ - String. The rule action.
236
+ #
237
+ def create_rule(*p)
238
+ rule = _rule_from(*p)
239
+ result = create_resource_entry(:rule, rule, rule.topic, rule.subscription, rule.name)
240
+ result.topic = rule.topic
241
+ result.subscription = rule.subscription
242
+ result
243
+ end
244
+
245
+ # Deletes an existing rule.
246
+ #
247
+ # ==== Attributes
248
+ #
249
+ # Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and
250
+ # .subscription methods such as Azure::ServiceBus::Rule instance.
251
+ #
252
+ # Note: The default rule name is '$Default'. Use this name to delete the default rule for the subscription.
253
+ def delete_rule(*p)
254
+ topic_name, subscription_name, rule_name = _rule_args(*p)
255
+
256
+ delete_resource_entry(:rule, topic_name, subscription_name, rule_name)
257
+ end
258
+
259
+ # Retrieves the description for the specified rule.
260
+ #
261
+ # ==== Attributes
262
+ #
263
+ # Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and
264
+ # .subscription methods such as Azure::ServiceBus::Rule instance.
265
+ #
266
+ # Note: The default rule name is '$Default'. Use this name to retrieve the default rule for the subscription.
267
+ def get_rule(*p)
268
+ topic_name, subscription_name, rule_name = _rule_args(*p)
269
+
270
+ result = resource_entry(:rule, topic_name, subscription_name, rule_name)
271
+ result.topic = topic_name
272
+ result.subscription = subscription_name
273
+ result
274
+ end
275
+
276
+ # Retrieves the rules that exist under the specified subscription.
277
+ #
278
+ # ==== Attributes
279
+ #
280
+ # Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
281
+ # such as Azure::ServiceBus::Subscription instance.
282
+ #
283
+ # * +options+ - Hash. Optional parameters.
284
+ #
285
+ # ==== Options
286
+ #
287
+ # Accepted key/value pairs in options parameter are:
288
+ # * +:skip+ - Integer. Number of topics to skip.
289
+ # * +:top+ - Integer. Number of topics to list.
290
+ def list_rules(*p)
291
+ topic_name, subscription_name, options = _subscription_args(*p)
292
+
293
+ query = {}
294
+ query["$skip"] = options[:skip].to_i.to_s if options[:skip]
295
+ query["$top"] = options[:top].to_i.to_s if options[:top]
296
+
297
+ results = resource_list(:rule, topic_name, subscription_name, query)
298
+ results.each{|r| r.topic = topic_name; r.subscription=subscription_name}
299
+
300
+ return results
301
+ end
302
+
303
+ # Creates a new subscription. Once created, this subscription resource manifest is
304
+ # immutable.
305
+ #
306
+ # ==== Attributes
307
+ #
308
+ # Pass either (topic_name, subscription_name) as strings, or (subscription) a object.
309
+ # When using (topic_name, subscription_name) overload, you may also pass optional properties for the subscription.
310
+ #
311
+ # ==== Options
312
+ #
313
+ # Accepted key/value pairs in options parameter are:
314
+ # * +:lock_duration+ - XML datetime. Determines the amount of time in seconds in which a message should be locked for processing by a receiver.
315
+ # * +:requires_session+ - Boolean. If set to true, the queue will be session-aware and only SessionReceiver will be supported.
316
+ # * +:default_message_time_to_live+ - XML datetime. Determines how long a message lives in the associated subscriptions.
317
+ # * +:dead_lettering_on_message_expiration:+ - Boolean. This field controls how the Service Bus handles a message whose TTL has expired.
318
+ # * +: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.
319
+ # * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
320
+ # * +:max_delivery_count+ - Number. A message is automatically deadlettered after this number of deliveries.
321
+ # * +:message_count+ - Number. Displays the number of messages currently in the queue.
322
+ #
323
+ def create_subscription(*p)
324
+ subscription = _subscription_from(*p)
325
+
326
+ result = create_resource_entry(:subscription, subscription, subscription.topic, subscription.name)
327
+ result.topic = subscription.topic
328
+ result
329
+ end
330
+
331
+ #
332
+ # Deletes an existing subscription.
333
+ #
334
+ # ==== Attributes
335
+ #
336
+ # Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
337
+ # such as Azure::ServiceBus::Subscription instance.
338
+ def delete_subscription(*p)
339
+ topic_name, subscription_name = _subscription_args(*p)
340
+
341
+ delete_resource_entry(:subscription, topic_name, subscription_name)
342
+ end
343
+
344
+ # Gets an existing subscription.
345
+ #
346
+ # ==== Attributes
347
+ #
348
+ # Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
349
+ # such as Azure::ServiceBus::Subscription instance.
350
+ def get_subscription(*p)
351
+ topic_name, subscription_name = _subscription_args(*p)
352
+
353
+ result = resource_entry(:subscription, topic_name, subscription_name)
354
+ result.topic = topic_name
355
+ result
356
+ end
357
+
358
+ # Retrieves the subscriptions in the specified topic.
359
+ #
360
+ # ==== Attributes
361
+ #
362
+ # * +topic+ - Either a Azure::ServiceBus::Topic instance or a string of the topic name
363
+ # * +options+ - Hash. Optional parameters.
364
+ #
365
+ # ==== Options
366
+ #
367
+ # Accepted key/value pairs in options parameter are:
368
+ # * +:skip+ - Integer. Number of subscriptions to skip.
369
+ # * +:top+ - Integer. Number of subscriptions to list.
370
+ def list_subscriptions(topic, options={})
371
+ topic = _name_for(topic)
372
+ query = {}
373
+ query["$skip"] = options[:skip].to_i.to_s if options[:skip]
374
+ query["$top"] = options[:top].to_i.to_s if options[:top]
375
+
376
+ results = resource_list(:subscription, topic, query)
377
+ results.each { |s| s.topic = topic }
378
+
379
+ return results
380
+ end
381
+
382
+ # Enqueues a message into the specified topic. The limit to the number of messages
383
+ # which may be present in the topic is governed by the message size in MaxTopicSizeInBytes.
384
+ # If this message causes the topic to exceed its quota, a quota exceeded error is
385
+ # returned and the message will be rejected.
386
+ #
387
+ # ==== Attributes
388
+ #
389
+ # * +topic+ - Either a Azure::ServiceBus::Topic instance or a string of the topic name
390
+ # * +message+ - An Azure::ServiceBus::BrokeredMessage object containing message body and properties,
391
+ # or a string of the message body (a default BrokeredMessage will be created from the string).
392
+ def send_topic_message(topic, message)
393
+ _send_message(_name_for(topic), message)
394
+ end
395
+
396
+ # This operation is used to atomically retrieve and lock a message for processing.
397
+ # The message is guaranteed not to be delivered to other receivers during the lock
398
+ # duration period specified in buffer description. Once the lock expires, the
399
+ # message will be available to other receivers (on the same subscription only)
400
+ # during the lock duration period specified in the topic description. Once the lock
401
+ # expires, the message will be available to other receivers. In order to complete
402
+ # processing of the message, the receiver should issue a delete command with the
403
+ # lock ID received from this operation. To abandon processing of the message and
404
+ # unlock it for other receivers, an Unlock Message command should be issued, or
405
+ # the lock duration period can expire.
406
+ #
407
+ # ==== Attributes
408
+ #
409
+ # * +topic+ - String. The name of the topic or a Topic instance
410
+ # * +subscription+ - String. The name of the subscription or a Subscription instance
411
+ # * +options+ - Hash. Optional parameters.
412
+ #
413
+ # ==== Options
414
+ #
415
+ # Accepted key/value pairs in options parameter are:
416
+ # * +:timeout+ - Integer. Timeout for the REST call.
417
+ def peek_lock_subscription_message(topic, subscription, options={})
418
+ topic = _name_for(topic)
419
+ subscription = _name_for(subscription)
420
+
421
+ _peek_lock_message(subscriptions_path(topic, subscription), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
422
+ end
423
+
424
+ #
425
+ # Unlock a message for processing by other receivers on a given subscription.
426
+ # This operation deletes the lock object, causing the message to be unlocked.
427
+ # A message must have first been locked by a receiver before this operation
428
+ # is called.
429
+ #
430
+ # ==== Attributes
431
+ #
432
+ # * +message+ - String. Either the message location URL or a message object.
433
+ #
434
+ def unlock_subscription_message(message)
435
+ _unlock_message(message)
436
+ end
437
+
438
+ # Read and delete a message from a subscription as an atomic operation. This
439
+ # operation should be used when a best-effort guarantee is sufficient for an
440
+ # application; that is, using this operation it is possible for messages to
441
+ # be lost if processing fails.
442
+ #
443
+ # ==== Attributes
444
+ #
445
+ # * +topic+ - The name of the topic or a Topic instance
446
+ # * +subscription+ - The name of the subscription or a Subscription instance
447
+ # * +options+ - Hash. Optional parameters.
448
+ #
449
+ # ==== Options
450
+ #
451
+ # Accepted key/value pairs in options parameter are:
452
+ # * +:timeout+ - Integer. Timeout for the REST call.
453
+ #
454
+ def read_delete_subscription_message(topic, subscription, options={})
455
+ topic = _name_for(topic)
456
+ subscription = _name_for(subscription)
457
+
458
+ _read_delete_message(subscriptions_path(topic, subscription), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
459
+ end
460
+
461
+ # Completes processing on a locked message and delete it from the subscription.
462
+ # This operation should only be called after processing a previously locked
463
+ # message is successful to maintain At-Least-Once delivery assurances.
464
+ #
465
+ # ==== Attributes
466
+ #
467
+ # * +message+ - String. Either the message location URL or a message object.
468
+ #
469
+ def delete_subscription_message(message)
470
+ _delete_message(message)
471
+ end
472
+
473
+ # Sends a message into the specified queue. The limit to the number of messages
474
+ # which may be present in the topic is governed by the message size the
475
+ # MaxTopicSizeInMegaBytes. If this message will cause the queue to exceed its
476
+ # quota, a quota exceeded error is returned and the message will be rejected.
477
+ #
478
+ # ==== Attributes
479
+ #
480
+ # * +queue+ - Either a Azure::ServiceBus::Queue instance or a string of the queue name
481
+ # * +message+ - An Azure::ServiceBus::BrokeredMessage object containing message body and properties,
482
+ # or a string of the message body (a default BrokeredMessage will be created from the string).
483
+ def send_queue_message(queue, message)
484
+ _send_message(_name_for(queue), message)
485
+ end
486
+
487
+ #
488
+ # Automatically retrieves and locks a message from a queue for processing. The
489
+ # message is guaranteed not to be delivered to other receivers (on the same
490
+ # subscription only) during the lock duration period specified in the queue
491
+ # description. Once the lock expires, the message will be available to other
492
+ # receivers. In order to complete processing of the message, the receiver
493
+ # should issue a delete command with the lock ID received from this operation.
494
+ # To abandon processing of the message and unlock it for other receivers,
495
+ # an Unlock Message command should be issued, or the lock duration period
496
+ # can expire.
497
+ #
498
+ # ==== Attributes
499
+ #
500
+ # * +queue+ - String. Either a Azure::ServiceBus::Queue instance or a string of the queue name
501
+ # * +options+ - Hash. Optional parameters.
502
+ #
503
+ # ==== Options
504
+ #
505
+ # Accepted key/value pairs in options parameter are:
506
+ # * +:timeout+ - Integer. Timeout for the REST call.
507
+ #
508
+ def peek_lock_queue_message(queue, options={})
509
+ _peek_lock_message(_name_for(queue), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
510
+ end
511
+
512
+ # Unlocks a message for processing by other receivers on a given subscription.
513
+ # This operation deletes the lock object, causing the message to be unlocked.
514
+ # A message must have first been locked by a receiver before this operation is
515
+ # called.
516
+ #
517
+ # ==== Attributes
518
+ #
519
+ # * +message+ - String. Either the message location URL or a message object.
520
+ #
521
+ def unlock_queue_message(message)
522
+ _unlock_message(message)
523
+ end
524
+
525
+ # Reads and deletes a message from a queue as an atomic operation. This operation
526
+ # should be used when a best-effort guarantee is sufficient for an application;
527
+ # that is, using this operation it is possible for messages to be lost if
528
+ # processing fails.
529
+ #
530
+ # ==== Attributes
531
+ #
532
+ # * +queue+ - Either a Azure::ServiceBus::Queue instance or a string of the queue name
533
+ # * +options+ - Hash. Optional parameters.
534
+ #
535
+ # ==== Options
536
+ #
537
+ # Accepted key/value pairs in options parameter are:
538
+ # * +:timeout+ - Integer. Timeout for the REST call.
539
+ #
540
+ def read_delete_queue_message(queue, options={})
541
+ _read_delete_message(_name_for(queue), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
542
+ end
543
+
544
+ # Completes processing on a locked message and delete it from the queue. This
545
+ # operation should only be called after processing a previously locked message
546
+ # is successful to maintain At-Least-Once delivery assurances.
547
+ #
548
+ # ==== Attributes
549
+ #
550
+ # * +message+ - String. Either the message location URL or a message object.
551
+ #
552
+ def delete_queue_message(message)
553
+ _delete_message(message)
554
+ end
555
+
556
+ # Public: Receives a queue message.
557
+ #
558
+ # ==== Attributes
559
+ #
560
+ # * +queue+ - String. The queue name.
561
+ # * +options+ - Hash. Optional parameters.
562
+ #
563
+ # ==== Options
564
+ #
565
+ # Accepted key/value pairs in options parameter are:
566
+ # * +:peek_lock+ - Boolean. Lock when peeking.
567
+ # * +:timeout+ - Integer. Timeout for the REST call.
568
+ #
569
+ def receive_queue_message(queue, options={})
570
+ peek_lock = true
571
+ peek_lock = options[:peek_lock] if options[:peek_lock]
572
+
573
+ options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
574
+ if peek_lock
575
+ peek_lock_queue_message(queue, options)
576
+ else
577
+ read_delete_queue_message(queue, options)
578
+ end
579
+ end
580
+
581
+ # Public: Receives a subscription message.
582
+ #
583
+ # ==== Attributes
584
+ #
585
+ # * +topic+ - String. The topic name.
586
+ # * +options+ - Hash. Optional parameters.
587
+ #
588
+ # ==== Options
589
+ #
590
+ # Accepted key/value pairs in options parameter are:
591
+ # * +:peek_lock+ - Boolean. Lock when peeking.
592
+ # * +:timeout+ - Integer. Timeout for the REST call.
593
+ #
594
+ def receive_subscription_message(topic, subscription, options={})
595
+ peek_lock = true
596
+ peek_lock = options[:peek_lock] if options[:peek_lock]
597
+
598
+ options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
599
+ if peek_lock
600
+ peek_lock_subscription_message(topic, subscription, options)
601
+ else
602
+ read_delete_subscription_message(topic, subscription, options)
603
+ end
604
+ end
605
+
606
+ private
607
+
608
+ def _unlock_message(message)
609
+ _modify_message(:put, message)
610
+ end
611
+
612
+ def _delete_message(message)
613
+ _modify_message(:delete, message)
614
+ end
615
+
616
+ def _modify_message(method, message)
617
+ uri = nil
618
+ if (message.respond_to? :location)
619
+ uri = message.location
620
+ else
621
+ uri = 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