juliusl-azure-sdk-for-ruby 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (300) hide show
  1. checksums.yaml +7 -0
  2. data/.env_sample +11 -0
  3. data/.gitignore +15 -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 +630 -0
  9. data/Rakefile +121 -0
  10. data/azure.gemspec +47 -0
  11. data/bin/pfxer +35 -0
  12. data/lib/azure.rb +60 -0
  13. data/lib/azure/base_management/affinity_group.rb +32 -0
  14. data/lib/azure/base_management/base_management_service.rb +245 -0
  15. data/lib/azure/base_management/location.rb +27 -0
  16. data/lib/azure/base_management/management_http_request.rb +175 -0
  17. data/lib/azure/base_management/serialization.rb +135 -0
  18. data/lib/azure/base_management/sql_management_http_request.rb +45 -0
  19. data/lib/azure/blob/auth/shared_access_signature.rb +141 -0
  20. data/lib/azure/blob/blob.rb +32 -0
  21. data/lib/azure/blob/blob_service.rb +1427 -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/cloud_service_management/cloud_service.rb +38 -0
  26. data/lib/azure/cloud_service_management/cloud_service_management_service.rb +137 -0
  27. data/lib/azure/cloud_service_management/serialization.rb +118 -0
  28. data/lib/azure/core.rb +41 -0
  29. data/lib/azure/core/auth/authorizer.rb +36 -0
  30. data/lib/azure/core/auth/shared_key.rb +110 -0
  31. data/lib/azure/core/auth/shared_key_lite.rb +48 -0
  32. data/lib/azure/core/auth/signer.rb +52 -0
  33. data/lib/azure/core/configuration.rb +218 -0
  34. data/lib/azure/core/error.rb +22 -0
  35. data/lib/azure/core/filtered_service.rb +44 -0
  36. data/lib/azure/core/http/debug_filter.rb +36 -0
  37. data/lib/azure/core/http/http_error.rb +88 -0
  38. data/lib/azure/core/http/http_filter.rb +53 -0
  39. data/lib/azure/core/http/http_request.rb +160 -0
  40. data/lib/azure/core/http/http_response.rb +140 -0
  41. data/lib/azure/core/http/retry_policy.rb +74 -0
  42. data/lib/azure/core/http/signer_filter.rb +34 -0
  43. data/lib/azure/core/service.rb +63 -0
  44. data/lib/azure/core/signed_service.rb +43 -0
  45. data/lib/azure/core/utility.rb +242 -0
  46. data/lib/azure/queue/message.rb +30 -0
  47. data/lib/azure/queue/queue.rb +29 -0
  48. data/lib/azure/queue/queue_service.rb +568 -0
  49. data/lib/azure/queue/serialization.rb +106 -0
  50. data/lib/azure/service/access_policy.rb +26 -0
  51. data/lib/azure/service/cors.rb +11 -0
  52. data/lib/azure/service/cors_rule.rb +15 -0
  53. data/lib/azure/service/enumeration_results.rb +21 -0
  54. data/lib/azure/service/logging.rb +32 -0
  55. data/lib/azure/service/metrics.rb +31 -0
  56. data/lib/azure/service/retention_policy.rb +25 -0
  57. data/lib/azure/service/serialization.rb +299 -0
  58. data/lib/azure/service/signed_identifier.rb +30 -0
  59. data/lib/azure/service/storage_service.rb +83 -0
  60. data/lib/azure/service/storage_service_properties.rb +37 -0
  61. data/lib/azure/service_bus/action.rb +21 -0
  62. data/lib/azure/service_bus/auth/wrap_service.rb +89 -0
  63. data/lib/azure/service_bus/auth/wrap_signer.rb +69 -0
  64. data/lib/azure/service_bus/brokered_message.rb +124 -0
  65. data/lib/azure/service_bus/brokered_message_serializer.rb +159 -0
  66. data/lib/azure/service_bus/correlation_filter.rb +45 -0
  67. data/lib/azure/service_bus/empty_rule_action.rb +30 -0
  68. data/lib/azure/service_bus/false_filter.rb +38 -0
  69. data/lib/azure/service_bus/filter.rb +21 -0
  70. data/lib/azure/service_bus/interval.rb +104 -0
  71. data/lib/azure/service_bus/queue.rb +230 -0
  72. data/lib/azure/service_bus/relay.rb +88 -0
  73. data/lib/azure/service_bus/resource.rb +109 -0
  74. data/lib/azure/service_bus/rule.rb +98 -0
  75. data/lib/azure/service_bus/rule_aspect.rb +34 -0
  76. data/lib/azure/service_bus/serialization.rb +161 -0
  77. data/lib/azure/service_bus/service_bus_service.rb +895 -0
  78. data/lib/azure/service_bus/sql_filter.rb +50 -0
  79. data/lib/azure/service_bus/sql_rule_action.rb +50 -0
  80. data/lib/azure/service_bus/subscription.rb +184 -0
  81. data/lib/azure/service_bus/topic.rb +187 -0
  82. data/lib/azure/service_bus/true_filter.rb +38 -0
  83. data/lib/azure/sql_database_management/serialization.rb +112 -0
  84. data/lib/azure/sql_database_management/sql_database.rb +31 -0
  85. data/lib/azure/sql_database_management/sql_database_management_service.rb +200 -0
  86. data/lib/azure/storage_management/serialization.rb +204 -0
  87. data/lib/azure/storage_management/storage_account.rb +48 -0
  88. data/lib/azure/storage_management/storage_management_service.rb +208 -0
  89. data/lib/azure/table/auth/shared_key.rb +92 -0
  90. data/lib/azure/table/auth/shared_key_lite.rb +44 -0
  91. data/lib/azure/table/batch.rb +330 -0
  92. data/lib/azure/table/batch_response.rb +118 -0
  93. data/lib/azure/table/edmtype.rb +127 -0
  94. data/lib/azure/table/entity.rb +31 -0
  95. data/lib/azure/table/guid.rb +24 -0
  96. data/lib/azure/table/query.rb +112 -0
  97. data/lib/azure/table/serialization.rb +108 -0
  98. data/lib/azure/table/table_service.rb +560 -0
  99. data/lib/azure/version.rb +31 -0
  100. data/lib/azure/virtual_machine_image_management/serialization.rb +70 -0
  101. data/lib/azure/virtual_machine_image_management/virtual_machine_disk.rb +25 -0
  102. data/lib/azure/virtual_machine_image_management/virtual_machine_image.rb +25 -0
  103. data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +89 -0
  104. data/lib/azure/virtual_machine_management/serialization.rb +459 -0
  105. data/lib/azure/virtual_machine_management/virtual_machine.rb +44 -0
  106. data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +554 -0
  107. data/lib/azure/virtual_network_management/serialization.rb +193 -0
  108. data/lib/azure/virtual_network_management/virtual_network.rb +37 -0
  109. data/lib/azure/virtual_network_management/virtual_network_management_service.rb +109 -0
  110. data/test/fixtures/32px-fulls-black.jpg +0 -0
  111. data/test/fixtures/affinity_group.xml +33 -0
  112. data/test/fixtures/all_containers.xml +20 -0
  113. data/test/fixtures/all_tables.xml +22 -0
  114. data/test/fixtures/container_acl.xml +11 -0
  115. data/test/fixtures/create_sql_database_server.xml +2 -0
  116. data/test/fixtures/create_storage_desc_error.xml +5 -0
  117. data/test/fixtures/create_storage_extendedprop_error.xml +8 -0
  118. data/test/fixtures/create_storage_extendedpropname_error.xml +6 -0
  119. data/test/fixtures/create_storage_full_error.xml +6 -0
  120. data/test/fixtures/create_storage_label_error.xml +5 -0
  121. data/test/fixtures/create_storage_location_error.xml +5 -0
  122. data/test/fixtures/create_storage_name_error.xml +6 -0
  123. data/test/fixtures/create_table_response_entry.xml +15 -0
  124. data/test/fixtures/delete_storage_container_error.xml +5 -0
  125. data/test/fixtures/delete_storage_error.xml +5 -0
  126. data/test/fixtures/deployment_error.xml +5 -0
  127. data/test/fixtures/empty_xml_file +0 -0
  128. data/test/fixtures/get_storage_account_error.xml +5 -0
  129. data/test/fixtures/get_storage_account_properties.xml +34 -0
  130. data/test/fixtures/get_storage_account_properties_new.xml +32 -0
  131. data/test/fixtures/http_error.xml +5 -0
  132. data/test/fixtures/insert_entity_response_entry.xml +25 -0
  133. data/test/fixtures/list_affinity_groups.xml +22 -0
  134. data/test/fixtures/list_blobs.xml +121 -0
  135. data/test/fixtures/list_block_all_with_none_committed.xml +22 -0
  136. data/test/fixtures/list_blocks_all.xml +23 -0
  137. data/test/fixtures/list_blocks_committed.xml +13 -0
  138. data/test/fixtures/list_cloud_services.xml +39 -0
  139. data/test/fixtures/list_containers.xml +38 -0
  140. data/test/fixtures/list_firewall_management_endpoint.xml +27 -0
  141. data/test/fixtures/list_locations.xml +212 -0
  142. data/test/fixtures/list_os_images.xml +110 -0
  143. data/test/fixtures/list_page_ranges.xml +11 -0
  144. data/test/fixtures/list_sql_database.xml +36 -0
  145. data/test/fixtures/list_sql_server_firewall.xml +23 -0
  146. data/test/fixtures/list_storage_account_single.xml +25 -0
  147. data/test/fixtures/list_storage_accounts.xml +48 -0
  148. data/test/fixtures/list_virtual_networks.xml +92 -0
  149. data/test/fixtures/list_vm_images.xml +21 -0
  150. data/test/fixtures/logging.xml +11 -0
  151. data/test/fixtures/messages.xml +12 -0
  152. data/test/fixtures/metrics.xml +10 -0
  153. data/test/fixtures/privatekey.key +28 -0
  154. data/test/fixtures/query_entities_empty_response.xml +7 -0
  155. data/test/fixtures/query_entities_response.xml +45 -0
  156. data/test/fixtures/queue_service_properties.xml +22 -0
  157. data/test/fixtures/queue_service_properties_original.xml +19 -0
  158. data/test/fixtures/queues.xml +16 -0
  159. data/test/fixtures/retention_policy.xml +5 -0
  160. data/test/fixtures/sb_default_create_queue_response.xml +23 -0
  161. data/test/fixtures/sb_default_create_relay_response.xml +15 -0
  162. data/test/fixtures/sb_default_create_topic_response.xml +18 -0
  163. data/test/fixtures/sb_get_access_token_response.txt +1 -0
  164. data/test/fixtures/sb_queues_runtime_peek_message_response_headers.txt +9 -0
  165. data/test/fixtures/storage_service_keys.xml +8 -0
  166. data/test/fixtures/storage_service_properties.xml +55 -0
  167. data/test/fixtures/update_storage_account.xml +16 -0
  168. data/test/fixtures/update_storage_error.xml +5 -0
  169. data/test/fixtures/updated_storage_accounts.xml +55 -0
  170. data/test/fixtures/virtual_machine.xml +116 -0
  171. data/test/fixtures/windows_virtual_machine.xml +106 -0
  172. data/test/integration/affinity_group/Affinity_test.rb +55 -0
  173. data/test/integration/affinity_group/Create_Affinity_test.rb +64 -0
  174. data/test/integration/affinity_group/Delete_Affinity_test.rb +56 -0
  175. data/test/integration/affinity_group/List_Affinity_test.rb +41 -0
  176. data/test/integration/affinity_group/Update_Affinity_test.rb +83 -0
  177. data/test/integration/blob/blob_gb18030_test.rb +199 -0
  178. data/test/integration/blob/blob_metadata_test.rb +75 -0
  179. data/test/integration/blob/blob_pages_test.rb +119 -0
  180. data/test/integration/blob/blob_properties_test.rb +77 -0
  181. data/test/integration/blob/block_blob_test.rb +254 -0
  182. data/test/integration/blob/container/container_acl_test.rb +69 -0
  183. data/test/integration/blob/container/container_metadata_test.rb +50 -0
  184. data/test/integration/blob/container/create_container_test.rb +60 -0
  185. data/test/integration/blob/container/delete_container_test.rb +39 -0
  186. data/test/integration/blob/container/get_container_properties_test.rb +48 -0
  187. data/test/integration/blob/container/list_containers_test.rb +79 -0
  188. data/test/integration/blob/container/root_container_test.rb +54 -0
  189. data/test/integration/blob/copy_blob_test.rb +113 -0
  190. data/test/integration/blob/create_blob_snapshot_test.rb +80 -0
  191. data/test/integration/blob/create_page_blob_test.rb +83 -0
  192. data/test/integration/blob/delete_blob_test.rb +159 -0
  193. data/test/integration/blob/get_blob_test.rb +65 -0
  194. data/test/integration/blob/informative_errors_test.rb +39 -0
  195. data/test/integration/blob/lease/acquire_lease_test.rb +36 -0
  196. data/test/integration/blob/lease/break_lease_test.rb +40 -0
  197. data/test/integration/blob/lease/release_lease_test.rb +40 -0
  198. data/test/integration/blob/lease/renew_lease_test.rb +42 -0
  199. data/test/integration/blob/list_blobs_test.rb +113 -0
  200. data/test/integration/cloud_service/Cloud_Create_test.rb +45 -0
  201. data/test/integration/cloud_service/Cloud_Delete_test.rb +45 -0
  202. data/test/integration/database/create_sql_server_firewall_test.rb +86 -0
  203. data/test/integration/database/create_sql_server_test.rb +53 -0
  204. data/test/integration/database/delete_sql_server_firewall_test.rb +70 -0
  205. data/test/integration/database/delete_sql_server_test.rb +58 -0
  206. data/test/integration/database/list_sql_server_firewall_test.rb +45 -0
  207. data/test/integration/database/list_sql_servers_test.rb +44 -0
  208. data/test/integration/database/reset_password_sql_server_test.rb +55 -0
  209. data/test/integration/location/Location_List_test.rb +39 -0
  210. data/test/integration/location/RoleSize_List_test.rb +35 -0
  211. data/test/integration/queue/clear_messages_test.rb +42 -0
  212. data/test/integration/queue/create_message_test.rb +75 -0
  213. data/test/integration/queue/create_queue_test.rb +50 -0
  214. data/test/integration/queue/delete_message_test.rb +67 -0
  215. data/test/integration/queue/delete_queue_test.rb +45 -0
  216. data/test/integration/queue/informative_errors_test.rb +42 -0
  217. data/test/integration/queue/list_messages_encoded_test.rb +79 -0
  218. data/test/integration/queue/list_messages_test.rb +79 -0
  219. data/test/integration/queue/list_queues_test.rb +44 -0
  220. data/test/integration/queue/peek_messages_test.rb +59 -0
  221. data/test/integration/queue/queue_gb18030_test.rb +131 -0
  222. data/test/integration/queue/queue_metadata_test.rb +40 -0
  223. data/test/integration/queue/update_message_test.rb +74 -0
  224. data/test/integration/service_bus/informative_errors_test.rb +37 -0
  225. data/test/integration/service_bus/queues_scenario_test.rb +200 -0
  226. data/test/integration/service_bus/queues_test.rb +266 -0
  227. data/test/integration/service_bus/relay_test.rb +132 -0
  228. data/test/integration/service_bus/rules_test.rb +145 -0
  229. data/test/integration/service_bus/sb_queue_gb18030_test.rb +182 -0
  230. data/test/integration/service_bus/scenario_test.rb +101 -0
  231. data/test/integration/service_bus/subscriptions_test.rb +211 -0
  232. data/test/integration/service_bus/topics_scenario_test.rb +406 -0
  233. data/test/integration/service_bus/topics_test.rb +129 -0
  234. data/test/integration/storage_management/storage_management_test.rb +185 -0
  235. data/test/integration/table/create_table_test.rb +36 -0
  236. data/test/integration/table/delete_entity_batch_test.rb +107 -0
  237. data/test/integration/table/delete_entity_test.rb +94 -0
  238. data/test/integration/table/delete_table_test.rb +40 -0
  239. data/test/integration/table/get_table_test.rb +37 -0
  240. data/test/integration/table/informative_errors_test.rb +39 -0
  241. data/test/integration/table/insert_entity_batch_test.rb +100 -0
  242. data/test/integration/table/insert_entity_test.rb +88 -0
  243. data/test/integration/table/insert_or_merge_entity_batch_test.rb +159 -0
  244. data/test/integration/table/insert_or_merge_entity_test.rb +143 -0
  245. data/test/integration/table/insert_or_replace_entity_batch_test.rb +152 -0
  246. data/test/integration/table/insert_or_replace_entity_test.rb +137 -0
  247. data/test/integration/table/merge_entity_batch_test.rb +128 -0
  248. data/test/integration/table/merge_entity_test.rb +113 -0
  249. data/test/integration/table/query_entities_test.rb +195 -0
  250. data/test/integration/table/query_tables_test.rb +43 -0
  251. data/test/integration/table/query_test.rb +251 -0
  252. data/test/integration/table/table_acl_test.rb +52 -0
  253. data/test/integration/table/table_gb18030_test.rb +355 -0
  254. data/test/integration/table/update_entity_batch_test.rb +149 -0
  255. data/test/integration/table/update_entity_test.rb +131 -0
  256. data/test/integration/test_helper.rb +38 -0
  257. data/test/integration/vm/VM_Create_test.rb +262 -0
  258. data/test/integration/vm/VM_Delete_test.rb +53 -0
  259. data/test/integration/vm/VM_Operations_test.rb +172 -0
  260. data/test/integration/vm_image/virtual_machine_disk_test.rb +37 -0
  261. data/test/integration/vm_image/virtual_machine_image_test.rb +37 -0
  262. data/test/integration/vnet/Virtual_Network_Create_test.rb +116 -0
  263. data/test/integration/vnet/Virtual_Network_list_test.rb +48 -0
  264. data/test/support/env.rb +19 -0
  265. data/test/support/fixtures.rb +36 -0
  266. data/test/support/name_generator.rb +168 -0
  267. data/test/support/stubs.rb +42 -0
  268. data/test/support/virtual_machine_name_generator.rb +102 -0
  269. data/test/support/virtual_network_helper.rb +73 -0
  270. data/test/test_helper.rb +44 -0
  271. data/test/unit/affinity_group/affinity_group_test.rb +189 -0
  272. data/test/unit/affinity_group/serialization_test.rb +87 -0
  273. data/test/unit/base_management/location_test.rb +56 -0
  274. data/test/unit/base_management/role_size_test.rb +50 -0
  275. data/test/unit/blob/auth/shared_access_signature_test.rb +71 -0
  276. data/test/unit/blob/blob_service_test.rb +1969 -0
  277. data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +94 -0
  278. data/test/unit/cloud_service_management/serialization_test.rb +169 -0
  279. data/test/unit/core/auth/shared_key_lite_test.rb +51 -0
  280. data/test/unit/core/auth/shared_key_test.rb +58 -0
  281. data/test/unit/core/auth/signer_test.rb +30 -0
  282. data/test/unit/core/http/http_error_test.rb +62 -0
  283. data/test/unit/core/http/http_request_test.rb +113 -0
  284. data/test/unit/core/http/http_response_test.rb +45 -0
  285. data/test/unit/core/http/retry_policy_test.rb +23 -0
  286. data/test/unit/core/utility_test.rb +122 -0
  287. data/test/unit/database/serialization_test.rb +97 -0
  288. data/test/unit/database/sql_database_server_service_test.rb +284 -0
  289. data/test/unit/service/serialization_test.rb +533 -0
  290. data/test/unit/service/storage_service_test.rb +293 -0
  291. data/test/unit/storage_management/serialization_test.rb +244 -0
  292. data/test/unit/storage_management/storage_management_service_test.rb +247 -0
  293. data/test/unit/table/edmtype_test.rb +108 -0
  294. data/test/unit/virtual_machine_image_management/serialization_test.rb +50 -0
  295. data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +114 -0
  296. data/test/unit/virtual_machine_management/serialization_test.rb +316 -0
  297. data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +478 -0
  298. data/test/unit/vnet/serialization_test.rb +187 -0
  299. data/test/unit/vnet/virtual_network_management_service_test.rb +131 -0
  300. metadata +512 -0
@@ -0,0 +1,895 @@
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 = options.fetch(:peek_lock, true)
571
+
572
+ options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
573
+ if peek_lock
574
+ peek_lock_queue_message(queue, options)
575
+ else
576
+ read_delete_queue_message(queue, options)
577
+ end
578
+ end
579
+
580
+ # Public: Receives a subscription message.
581
+ #
582
+ # ==== Attributes
583
+ #
584
+ # * +topic+ - String. The topic name.
585
+ # * +options+ - Hash. Optional parameters.
586
+ #
587
+ # ==== Options
588
+ #
589
+ # Accepted key/value pairs in options parameter are:
590
+ # * +:peek_lock+ - Boolean. Lock when peeking.
591
+ # * +:timeout+ - Integer. Timeout for the REST call.
592
+ #
593
+ def receive_subscription_message(topic, subscription, options={})
594
+ peek_lock = options.fetch(:peek_lock, true)
595
+
596
+ options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
597
+ if peek_lock
598
+ peek_lock_subscription_message(topic, subscription, options)
599
+ else
600
+ read_delete_subscription_message(topic, subscription, options)
601
+ end
602
+ end
603
+
604
+ private
605
+
606
+ def _unlock_message(message)
607
+ _modify_message(:put, message)
608
+ end
609
+
610
+ def _delete_message(message)
611
+ _modify_message(:delete, message)
612
+ end
613
+
614
+ def _modify_message(method, message)
615
+ uri = nil
616
+ if (message.respond_to? :location)
617
+ uri = message.location
618
+ else
619
+ uri = message
620
+ end
621
+
622
+ call(method, uri)
623
+ nil
624
+ end
625
+
626
+ def _send_message(path, message)
627
+ message = Azure::ServiceBus::BrokeredMessage.new(message.to_s) unless message.kind_of?(Azure::ServiceBus::BrokeredMessage)
628
+
629
+ serializer = BrokeredMessageSerializer.new(message)
630
+ broker_properties = serializer.to_json
631
+ message_properties = serializer.get_property_headers
632
+
633
+ content_type = message.content_type || 'text/plain'
634
+
635
+ headers = {
636
+ 'BrokerProperties'=> broker_properties
637
+ }
638
+
639
+ message_properties.each do |k,v|
640
+ headers[k.to_s.encode("UTF-8")] = v.encode("UTF-8")
641
+ end
642
+
643
+ headers["Content-Type"] = content_type
644
+
645
+ call(:post, messages_uri(path), message.body, headers)
646
+ nil
647
+ end
648
+
649
+ def _read_delete_message(path, timeout=DEFAULT_TIMEOUT)
650
+ _retrieve_message(:delete, path, timeout)
651
+ end
652
+
653
+ def _peek_lock_message(path, timeout=DEFAULT_TIMEOUT)
654
+ _retrieve_message(:post, path, timeout)
655
+ end
656
+
657
+ def _retrieve_message(method, path, timeout=DEFAULT_TIMEOUT)
658
+ uri = messages_head_uri(path, { "timeout"=> timeout.to_s })
659
+
660
+ response = call(method, uri)
661
+ (response.status_code == 204) ? nil : BrokeredMessageSerializer.get_from_http_response(response)
662
+ end
663
+
664
+ def _rule_from(*p)
665
+ rule = nil
666
+
667
+ if p.length == 3 or p.length == 4
668
+ rule = Azure::ServiceBus::Rule.new(p[2]) do |r|
669
+ r.topic = p[0]
670
+ r.subscription = p[1]
671
+ r.description = p[3] if p.length == 4
672
+ end
673
+ 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
674
+ rule = p[0]
675
+ else
676
+ 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."
677
+ end
678
+
679
+ rule
680
+ end
681
+
682
+ def _rule_args(*p)
683
+ if p.length == 3
684
+ topic_name = p[0]
685
+ subscription_name = p[1]
686
+ rule_name = p[2]
687
+ elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic
688
+ topic_name = p[0].topic
689
+ subscription_name = p[0].subscription
690
+ rule_name = p[0].name
691
+ else
692
+ 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."
693
+ end
694
+
695
+ return topic_name, subscription_name, rule_name
696
+ end
697
+
698
+ def _subscription_from(*p)
699
+ subscription = nil
700
+
701
+ if p.length == 3
702
+ subscription = Azure::ServiceBus::Subscription.new(p[1], p[2]) do |sub|
703
+ sub.topic = p[0]
704
+ end
705
+ elsif p.length == 2
706
+ subscription = Azure::ServiceBus::Subscription.new(p[1]) do |sub|
707
+ sub.topic = p[0]
708
+ end
709
+ elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic and p[0].respond_to? :description
710
+ subscription = p[0]
711
+ else
712
+ 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."
713
+ end
714
+
715
+ subscription
716
+ end
717
+
718
+ def _subscription_args(*p)
719
+
720
+ raise ArgumentError, "Not enough args" if p.length < 1
721
+ topic_name = nil
722
+ subscription_name = nil
723
+ options = {}
724
+
725
+ if p.length == 3
726
+ # topic/sub/options
727
+ topic_name = _name_for(p[0])
728
+ subscription_name = _name_for(p[1])
729
+ options =p[2]
730
+ elsif p.length == 2
731
+ # either subscription/options or topic/sub
732
+ if p[0].respond_to? :name and p[0].respond_to? :topic
733
+ topic_name = p[0].topic
734
+ subscription_name = p[0].name
735
+ options =p[1]
736
+ else
737
+ topic_name = _name_for(p[0])
738
+ subscription_name = _name_for(p[1])
739
+ end
740
+ elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic
741
+ topic_name = p[0].topic
742
+ subscription_name = p[0].name
743
+ else
744
+ 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."
745
+ end
746
+
747
+ return topic_name, subscription_name, options
748
+ end
749
+
750
+ def _name_for(val)
751
+ val.respond_to?(:name) ? val.name : val
752
+ end
753
+
754
+ def _new_or_existing(type, *p)
755
+ p[0].kind_of?(type) ? p[0] : type.new(*p)
756
+ end
757
+
758
+
759
+ def create_resource_entry(resource, entry, *p)
760
+ body = Serialization.resource_to_xml resource, entry
761
+ response = call(:put, self.send("#{resource.to_s}_uri", *p), body)
762
+ results = Serialization.resources_from_xml(resource, response.body)
763
+ results ? results.first : results
764
+ end
765
+
766
+ def delete_resource_entry(resource, *p)
767
+ call(:delete, self.send("#{resource.to_s}_uri", *p))
768
+ nil
769
+ end
770
+
771
+ def resource_entry(resource, *p)
772
+ uri = self.send("#{resource.to_s}_uri", *p)
773
+ response = call(:get, uri)
774
+ results = Serialization.resources_from_xml(resource, response.body)
775
+ result = results ? results.first : results
776
+ 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
777
+ result
778
+ end
779
+
780
+ def resource_list(resource, *p)
781
+ response = call(:get, self.send("#{resource.to_s}_list_uri", *p))
782
+ Serialization.resources_from_xml_with_next_link(resource, response.body)
783
+ end
784
+
785
+ # paths
786
+
787
+ protected
788
+ def message_path(path, sequence_number, lock_token)
789
+ "#{messages_path(path)}/#{sequence_number}/#{lock_token}"
790
+ end
791
+
792
+ protected
793
+ def messages_head_path(path)
794
+ "#{messages_path(path)}/head"
795
+ end
796
+
797
+ protected
798
+ def messages_path(path)
799
+ "#{path}/messages"
800
+ end
801
+
802
+ protected
803
+ def rule_path(topic, subscription, rule)
804
+ "#{subscriptions_path(topic, subscription)}/rules/#{rule}"
805
+ end
806
+
807
+ protected
808
+ def subscriptions_path(topic, subscription)
809
+ "#{topic}/subscriptions/#{subscription}"
810
+ end
811
+
812
+ # messages uris
813
+
814
+ protected
815
+ def message_uri(path, sequence_number, lock_token, query={})
816
+ generate_uri(message_path(path, sequence_number, lock_token), query)
817
+ end
818
+
819
+ protected
820
+ def messages_head_uri(path, query={})
821
+ generate_uri(messages_head_path(path), query)
822
+ end
823
+
824
+ protected
825
+ def messages_uri(path, query={})
826
+ generate_uri(messages_path(path), query)
827
+ end
828
+
829
+ # entry uris
830
+ protected
831
+ def rule_uri(topic, subscription, rule, query={})
832
+ generate_uri(rule_path(topic, subscription, rule), query)
833
+ end
834
+
835
+ protected
836
+ def subscription_uri(topic, subscription, query={})
837
+ generate_uri(subscriptions_path(topic, subscription), query)
838
+ end
839
+
840
+ protected
841
+ def relay_uri(relay, query={})
842
+ query["api-version"] = "2013-10"
843
+ generate_uri(relay, query)
844
+ end
845
+
846
+ protected
847
+ def queue_uri(topic, query={})
848
+ generate_uri(topic, query)
849
+ end
850
+
851
+ protected
852
+ def topic_uri(topic, query={})
853
+ generate_uri(topic, query)
854
+ end
855
+
856
+ # list uris
857
+
858
+ protected
859
+ def rule_list_uri(topic, subscription, query={})
860
+ resource_list_uri(:rule, query, subscriptions_path(topic, subscription))
861
+ end
862
+
863
+ protected
864
+ def subscription_list_uri(topic, query={})
865
+ resource_list_uri(:subscription, query, topic)
866
+ end
867
+
868
+ protected
869
+ def relay_list_uri(query={})
870
+ resource_list_uri(:relay, query)
871
+ end
872
+
873
+ protected
874
+ def queue_list_uri(query={})
875
+ resource_list_uri(:queue, query)
876
+ end
877
+
878
+ protected
879
+ def topic_list_uri(query={})
880
+ resource_list_uri(:topic, query)
881
+ end
882
+
883
+ protected
884
+ def resource_list_uri(resource, query={}, subpath='$Resources')
885
+ skip = query.delete ["$skip"]
886
+ top = query.delete ["$top"]
887
+
888
+ uri = generate_uri("#{subpath}/#{resource.to_s.capitalize}s", query)
889
+ uri.query = [uri.query, "$skip=" + skip].join('&') if skip
890
+ uri.query = [uri.query, "$top=" + top].join('&') if top
891
+ uri
892
+ end
893
+ end
894
+ end
895
+ end