kinetic_sdk 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. checksums.yaml +7 -0
  2. data/GettingStarted.md +64 -0
  3. data/README.md +383 -0
  4. data/bin/console +12 -0
  5. data/bin/setup +8 -0
  6. data/gems/kontena-websocket-client-0.1.1/Gemfile +4 -0
  7. data/gems/kontena-websocket-client-0.1.1/LICENSE +190 -0
  8. data/gems/kontena-websocket-client-0.1.1/README.md +138 -0
  9. data/gems/kontena-websocket-client-0.1.1/Rakefile +6 -0
  10. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark-client.rb +45 -0
  11. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark-em.rb +66 -0
  12. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark.rb +161 -0
  13. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark.sh +17 -0
  14. data/gems/kontena-websocket-client-0.1.1/benchmark/websocket-echo-server.go +207 -0
  15. data/gems/kontena-websocket-client-0.1.1/examples/websocket-echo-client.rb +80 -0
  16. data/gems/kontena-websocket-client-0.1.1/kontena-websocket-client.gemspec +24 -0
  17. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/client/connection.rb +119 -0
  18. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/client/version.rb +13 -0
  19. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/client.rb +848 -0
  20. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/error.rb +81 -0
  21. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/logging.rb +55 -0
  22. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/openssl_patch.rb +10 -0
  23. data/gems/kontena-websocket-client-0.1.1/lib/kontena-websocket-client.rb +15 -0
  24. data/gems/mime-types-3.1/Code-of-Conduct.rdoc +74 -0
  25. data/gems/mime-types-3.1/Contributing.rdoc +130 -0
  26. data/gems/mime-types-3.1/History.rdoc +658 -0
  27. data/gems/mime-types-3.1/Licence.rdoc +25 -0
  28. data/gems/mime-types-3.1/Manifest.txt +31 -0
  29. data/gems/mime-types-3.1/README.rdoc +202 -0
  30. data/gems/mime-types-3.1/Rakefile +254 -0
  31. data/gems/mime-types-3.1/lib/mime/type/columnar.rb +55 -0
  32. data/gems/mime-types-3.1/lib/mime/type.rb +573 -0
  33. data/gems/mime-types-3.1/lib/mime/types/_columnar.rb +135 -0
  34. data/gems/mime-types-3.1/lib/mime/types/cache.rb +56 -0
  35. data/gems/mime-types-3.1/lib/mime/types/columnar.rb +1 -0
  36. data/gems/mime-types-3.1/lib/mime/types/container.rb +30 -0
  37. data/gems/mime-types-3.1/lib/mime/types/deprecations.rb +32 -0
  38. data/gems/mime-types-3.1/lib/mime/types/full.rb +17 -0
  39. data/gems/mime-types-3.1/lib/mime/types/loader.rb +148 -0
  40. data/gems/mime-types-3.1/lib/mime/types/logger.rb +37 -0
  41. data/gems/mime-types-3.1/lib/mime/types/registry.rb +81 -0
  42. data/gems/mime-types-3.1/lib/mime/types.rb +228 -0
  43. data/gems/mime-types-3.1/lib/mime-types.rb +1 -0
  44. data/gems/mime-types-3.1/test/bad-fixtures/malformed +9 -0
  45. data/gems/mime-types-3.1/test/fixture/json.json +1 -0
  46. data/gems/mime-types-3.1/test/fixture/old-data +9 -0
  47. data/gems/mime-types-3.1/test/fixture/yaml.yaml +55 -0
  48. data/gems/mime-types-3.1/test/minitest_helper.rb +13 -0
  49. data/gems/mime-types-3.1/test/test_mime_type.rb +603 -0
  50. data/gems/mime-types-3.1/test/test_mime_types.rb +161 -0
  51. data/gems/mime-types-3.1/test/test_mime_types_cache.rb +109 -0
  52. data/gems/mime-types-3.1/test/test_mime_types_class.rb +155 -0
  53. data/gems/mime-types-3.1/test/test_mime_types_lazy.rb +43 -0
  54. data/gems/mime-types-3.1/test/test_mime_types_loader.rb +32 -0
  55. data/gems/mime-types-data-3.2016.0521/Code-of-Conduct.md +75 -0
  56. data/gems/mime-types-data-3.2016.0521/Contributing.md +157 -0
  57. data/gems/mime-types-data-3.2016.0521/History.md +351 -0
  58. data/gems/mime-types-data-3.2016.0521/Licence.md +25 -0
  59. data/gems/mime-types-data-3.2016.0521/Manifest.txt +18 -0
  60. data/gems/mime-types-data-3.2016.0521/README.md +61 -0
  61. data/gems/mime-types-data-3.2016.0521/Rakefile +80 -0
  62. data/gems/mime-types-data-3.2016.0521/data/mime-types.json +1 -0
  63. data/gems/mime-types-data-3.2016.0521/data/mime.content_type.column +1964 -0
  64. data/gems/mime-types-data-3.2016.0521/data/mime.docs.column +1964 -0
  65. data/gems/mime-types-data-3.2016.0521/data/mime.encoding.column +1964 -0
  66. data/gems/mime-types-data-3.2016.0521/data/mime.flags.column +1964 -0
  67. data/gems/mime-types-data-3.2016.0521/data/mime.friendly.column +1964 -0
  68. data/gems/mime-types-data-3.2016.0521/data/mime.pext.column +1964 -0
  69. data/gems/mime-types-data-3.2016.0521/data/mime.use_instead.column +1964 -0
  70. data/gems/mime-types-data-3.2016.0521/data/mime.xrefs.column +1964 -0
  71. data/gems/mime-types-data-3.2016.0521/lib/mime/types/data.rb +21 -0
  72. data/gems/mime-types-data-3.2016.0521/lib/mime-types-data.rb +3 -0
  73. data/gems/multipart-post-2.0.0/Gemfile +14 -0
  74. data/gems/multipart-post-2.0.0/History.txt +60 -0
  75. data/gems/multipart-post-2.0.0/Manifest.txt +9 -0
  76. data/gems/multipart-post-2.0.0/README.md +77 -0
  77. data/gems/multipart-post-2.0.0/Rakefile +9 -0
  78. data/gems/multipart-post-2.0.0/lib/composite_io.rb +108 -0
  79. data/gems/multipart-post-2.0.0/lib/multipart_post.rb +9 -0
  80. data/gems/multipart-post-2.0.0/lib/multipartable.rb +29 -0
  81. data/gems/multipart-post-2.0.0/lib/net/http/post/multipart.rb +27 -0
  82. data/gems/multipart-post-2.0.0/lib/parts.rb +96 -0
  83. data/gems/multipart-post-2.0.0/multipart-post.gemspec +22 -0
  84. data/gems/multipart-post-2.0.0/test/multibyte.txt +1 -0
  85. data/gems/multipart-post-2.0.0/test/net/http/post/test_multipart.rb +110 -0
  86. data/gems/multipart-post-2.0.0/test/test_composite_io.rb +115 -0
  87. data/gems/multipart-post-2.0.0/test/test_parts.rb +86 -0
  88. data/gems/parallel-1.12.1/MIT-LICENSE.txt +20 -0
  89. data/gems/parallel-1.12.1/lib/parallel/processor_count.rb +93 -0
  90. data/gems/parallel-1.12.1/lib/parallel/version.rb +3 -0
  91. data/gems/parallel-1.12.1/lib/parallel.rb +500 -0
  92. data/gems/ruby-progressbar-1.9.0/LICENSE.txt +19 -0
  93. data/gems/ruby-progressbar-1.9.0/README.md +38 -0
  94. data/gems/ruby-progressbar-1.9.0/Rakefile +2 -0
  95. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/base.rb +183 -0
  96. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/calculators/length.rb +99 -0
  97. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/calculators/running_average.rb +9 -0
  98. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/bar.rb +96 -0
  99. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/percentage.rb +29 -0
  100. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/rate.rb +43 -0
  101. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/time.rb +107 -0
  102. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/title.rb +13 -0
  103. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components.rb +5 -0
  104. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/errors/invalid_progress_error.rb +4 -0
  105. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format/formatter.rb +27 -0
  106. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format/molecule.rb +59 -0
  107. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format/string.rb +36 -0
  108. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format.rb +3 -0
  109. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/output.rb +68 -0
  110. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/outputs/non_tty.rb +47 -0
  111. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/outputs/null.rb +33 -0
  112. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/outputs/tty.rb +32 -0
  113. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/progress.rb +118 -0
  114. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/refinements/enumerator.rb +25 -0
  115. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/refinements.rb +1 -0
  116. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/throttle.rb +25 -0
  117. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/time.rb +30 -0
  118. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/timer.rb +72 -0
  119. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/version.rb +3 -0
  120. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar.rb +18 -0
  121. data/gems/slugify-1.0.7/README +18 -0
  122. data/gems/slugify-1.0.7/lib/slugify.rb +1012 -0
  123. data/gems/slugify-1.0.7/lib/slugify_string.rb +11 -0
  124. data/gems/slugify-1.0.7/tests/slugify_test.rb +116 -0
  125. data/gems/slugify-1.0.7/tests/string_slugify_test.rb +23 -0
  126. data/gems/websocket-driver-0.6.5/CHANGELOG.md +123 -0
  127. data/gems/websocket-driver-0.6.5/LICENSE.md +22 -0
  128. data/gems/websocket-driver-0.6.5/README.md +369 -0
  129. data/gems/websocket-driver-0.6.5/examples/tcp_server.rb +28 -0
  130. data/gems/websocket-driver-0.6.5/ext/websocket-driver/Makefile +264 -0
  131. data/gems/websocket-driver-0.6.5/ext/websocket-driver/WebsocketMaskService.java +55 -0
  132. data/gems/websocket-driver-0.6.5/ext/websocket-driver/extconf.rb +4 -0
  133. data/gems/websocket-driver-0.6.5/ext/websocket-driver/websocket_mask.bundle +0 -0
  134. data/gems/websocket-driver-0.6.5/ext/websocket-driver/websocket_mask.c +41 -0
  135. data/gems/websocket-driver-0.6.5/ext/websocket-driver/websocket_mask.o +0 -0
  136. data/gems/websocket-driver-0.6.5/lib/websocket/driver/client.rb +140 -0
  137. data/gems/websocket-driver-0.6.5/lib/websocket/driver/draft75.rb +102 -0
  138. data/gems/websocket-driver-0.6.5/lib/websocket/driver/draft76.rb +96 -0
  139. data/gems/websocket-driver-0.6.5/lib/websocket/driver/event_emitter.rb +54 -0
  140. data/gems/websocket-driver-0.6.5/lib/websocket/driver/headers.rb +45 -0
  141. data/gems/websocket-driver-0.6.5/lib/websocket/driver/hybi/frame.rb +20 -0
  142. data/gems/websocket-driver-0.6.5/lib/websocket/driver/hybi/message.rb +31 -0
  143. data/gems/websocket-driver-0.6.5/lib/websocket/driver/hybi.rb +406 -0
  144. data/gems/websocket-driver-0.6.5/lib/websocket/driver/proxy.rb +68 -0
  145. data/gems/websocket-driver-0.6.5/lib/websocket/driver/server.rb +80 -0
  146. data/gems/websocket-driver-0.6.5/lib/websocket/driver/stream_reader.rb +55 -0
  147. data/gems/websocket-driver-0.6.5/lib/websocket/driver.rb +199 -0
  148. data/gems/websocket-driver-0.6.5/lib/websocket/http/headers.rb +112 -0
  149. data/gems/websocket-driver-0.6.5/lib/websocket/http/request.rb +45 -0
  150. data/gems/websocket-driver-0.6.5/lib/websocket/http/response.rb +29 -0
  151. data/gems/websocket-driver-0.6.5/lib/websocket/http.rb +15 -0
  152. data/gems/websocket-driver-0.6.5/lib/websocket/mask.rb +14 -0
  153. data/gems/websocket-driver-0.6.5/lib/websocket/websocket_mask.rb +2 -0
  154. data/gems/websocket-driver-0.6.5/lib/websocket_mask.bundle +0 -0
  155. data/gems/websocket-driver-0.6.5-java/CHANGELOG.md +123 -0
  156. data/gems/websocket-driver-0.6.5-java/LICENSE.md +22 -0
  157. data/gems/websocket-driver-0.6.5-java/README.md +369 -0
  158. data/gems/websocket-driver-0.6.5-java/examples/tcp_server.rb +28 -0
  159. data/gems/websocket-driver-0.6.5-java/ext/websocket-driver/WebsocketMaskService.java +55 -0
  160. data/gems/websocket-driver-0.6.5-java/ext/websocket-driver/extconf.rb +4 -0
  161. data/gems/websocket-driver-0.6.5-java/ext/websocket-driver/websocket_mask.c +41 -0
  162. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/client.rb +140 -0
  163. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/draft75.rb +102 -0
  164. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/draft76.rb +96 -0
  165. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/event_emitter.rb +54 -0
  166. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/headers.rb +45 -0
  167. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/hybi/frame.rb +20 -0
  168. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/hybi/message.rb +31 -0
  169. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/hybi.rb +406 -0
  170. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/proxy.rb +68 -0
  171. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/server.rb +80 -0
  172. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/stream_reader.rb +55 -0
  173. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver.rb +199 -0
  174. data/gems/websocket-driver-0.6.5-java/lib/websocket/http/headers.rb +112 -0
  175. data/gems/websocket-driver-0.6.5-java/lib/websocket/http/request.rb +45 -0
  176. data/gems/websocket-driver-0.6.5-java/lib/websocket/http/response.rb +29 -0
  177. data/gems/websocket-driver-0.6.5-java/lib/websocket/http.rb +15 -0
  178. data/gems/websocket-driver-0.6.5-java/lib/websocket/mask.rb +14 -0
  179. data/gems/websocket-driver-0.6.5-java/lib/websocket/websocket_mask.rb +2 -0
  180. data/gems/websocket-driver-0.6.5-java/lib/websocket_mask.jar +0 -0
  181. data/gems/websocket-extensions-0.1.3/CHANGELOG.md +15 -0
  182. data/gems/websocket-extensions-0.1.3/LICENSE.md +20 -0
  183. data/gems/websocket-extensions-0.1.3/README.md +313 -0
  184. data/gems/websocket-extensions-0.1.3/lib/websocket/extensions/parser.rb +111 -0
  185. data/gems/websocket-extensions-0.1.3/lib/websocket/extensions.rb +181 -0
  186. data/lib/kinetic-sdk.rb +1 -0
  187. data/lib/kinetic_sdk/bridgehub/bridgehub-sdk.rb +80 -0
  188. data/lib/kinetic_sdk/bridgehub/lib/access_keys.rb +67 -0
  189. data/lib/kinetic_sdk/bridgehub/lib/bridge.rb +69 -0
  190. data/lib/kinetic_sdk/discussions/discussions-sdk.rb +165 -0
  191. data/lib/kinetic_sdk/discussions/lib/discussions.rb +107 -0
  192. data/lib/kinetic_sdk/discussions/lib/invitations.rb +120 -0
  193. data/lib/kinetic_sdk/discussions/lib/messages.rb +190 -0
  194. data/lib/kinetic_sdk/discussions/lib/meta.rb +14 -0
  195. data/lib/kinetic_sdk/discussions/lib/participants.rb +64 -0
  196. data/lib/kinetic_sdk/discussions/lib/related_items.rb +54 -0
  197. data/lib/kinetic_sdk/discussions/lib/websockets.rb +96 -0
  198. data/lib/kinetic_sdk/filehub/filehub-sdk.rb +80 -0
  199. data/lib/kinetic_sdk/filehub/lib/access_keys.rb +67 -0
  200. data/lib/kinetic_sdk/filehub/lib/filestores.rb +67 -0
  201. data/lib/kinetic_sdk/request_ce/lib/attribute_definitions.rb +153 -0
  202. data/lib/kinetic_sdk/request_ce/lib/bridges.rb +66 -0
  203. data/lib/kinetic_sdk/request_ce/lib/categories.rb +34 -0
  204. data/lib/kinetic_sdk/request_ce/lib/datastore_form.rb +110 -0
  205. data/lib/kinetic_sdk/request_ce/lib/datastore_submissions.rb +157 -0
  206. data/lib/kinetic_sdk/request_ce/lib/form.rb +99 -0
  207. data/lib/kinetic_sdk/request_ce/lib/form_types.rb +51 -0
  208. data/lib/kinetic_sdk/request_ce/lib/jwt.rb +55 -0
  209. data/lib/kinetic_sdk/request_ce/lib/kapp.rb +93 -0
  210. data/lib/kinetic_sdk/request_ce/lib/meta.rb +14 -0
  211. data/lib/kinetic_sdk/request_ce/lib/oauth.rb +37 -0
  212. data/lib/kinetic_sdk/request_ce/lib/security_policy_definitions.rb +157 -0
  213. data/lib/kinetic_sdk/request_ce/lib/space.rb +89 -0
  214. data/lib/kinetic_sdk/request_ce/lib/submissions.rb +215 -0
  215. data/lib/kinetic_sdk/request_ce/lib/system_api.rb +69 -0
  216. data/lib/kinetic_sdk/request_ce/lib/teams.rb +113 -0
  217. data/lib/kinetic_sdk/request_ce/lib/users.rb +245 -0
  218. data/lib/kinetic_sdk/request_ce/lib/webhook_jobs.rb +142 -0
  219. data/lib/kinetic_sdk/request_ce/lib/webhooks.rb +192 -0
  220. data/lib/kinetic_sdk/request_ce/request-ce-sdk.rb +153 -0
  221. data/lib/kinetic_sdk/task/lib/access_keys.rb +94 -0
  222. data/lib/kinetic_sdk/task/lib/categories.rb +190 -0
  223. data/lib/kinetic_sdk/task/lib/config.rb +202 -0
  224. data/lib/kinetic_sdk/task/lib/engine.rb +42 -0
  225. data/lib/kinetic_sdk/task/lib/environment.rb +14 -0
  226. data/lib/kinetic_sdk/task/lib/errors.rb +165 -0
  227. data/lib/kinetic_sdk/task/lib/groups.rb +112 -0
  228. data/lib/kinetic_sdk/task/lib/handlers.rb +105 -0
  229. data/lib/kinetic_sdk/task/lib/health.rb +28 -0
  230. data/lib/kinetic_sdk/task/lib/license.rb +52 -0
  231. data/lib/kinetic_sdk/task/lib/policy_rules.rb +166 -0
  232. data/lib/kinetic_sdk/task/lib/setup.rb +56 -0
  233. data/lib/kinetic_sdk/task/lib/sources.rb +134 -0
  234. data/lib/kinetic_sdk/task/lib/tasks.rb +17 -0
  235. data/lib/kinetic_sdk/task/lib/trees.rb +274 -0
  236. data/lib/kinetic_sdk/task/lib/users.rb +75 -0
  237. data/lib/kinetic_sdk/task/task-sdk.rb +92 -0
  238. data/lib/kinetic_sdk/utils/kinetic-http-headers.rb +150 -0
  239. data/lib/kinetic_sdk/utils/kinetic-http-response.rb +75 -0
  240. data/lib/kinetic_sdk/utils/kinetic-http.rb +552 -0
  241. data/lib/kinetic_sdk/utils/logger.rb +70 -0
  242. data/lib/kinetic_sdk/utils/random.rb +30 -0
  243. data/lib/kinetic_sdk/version.rb +7 -0
  244. data/lib/kinetic_sdk.rb +57 -0
  245. metadata +414 -0
@@ -0,0 +1,274 @@
1
+ module KineticSdk
2
+ class Task
3
+
4
+ # Delete a tree.
5
+ #
6
+ # @param tree [String|Hash] either the tree title, or a hash consisting of component names
7
+ # @param headers [Hash] hash of headers to send, default is basic authentication
8
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
9
+ #
10
+ # Example
11
+ #
12
+ # delete_tree("Kinetic Request CE :: Win a Car :: Complete")
13
+ #
14
+ # Example
15
+ #
16
+ # delete_tree({
17
+ # "source_name" => "Kinetic Request CE",
18
+ # "group_name" => "Win a Car",
19
+ # "tree_name" => "Complete"
20
+ # })
21
+ #
22
+ def delete_tree(tree, headers=header_basic_auth)
23
+ if tree.is_a? Hash
24
+ title = "#{tree['source_name']} :: #{tree['group_name']} :: #{tree['tree_name']}"
25
+ else
26
+ title = "#{tree.to_s}"
27
+ end
28
+ info("Deleting Tree \"#{title}\"")
29
+ delete("#{@api_url}/trees/#{encode(title)}", headers)
30
+ end
31
+
32
+ # Delete trees.
33
+ #
34
+ # If the source_name is provided, only trees that belong to the source
35
+ # will be deleted, otherwise all trees will be deleted.
36
+ #
37
+ # @param source_name [String] the name of the source, or nil to delete all trees
38
+ # @param headers [Hash] hash of headers to send, default is basic authentication
39
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
40
+ #
41
+ # Example
42
+ #
43
+ # delete_trees("Kinetic Request CE")
44
+ #
45
+ def delete_trees(source_name=nil, headers=header_basic_auth)
46
+ if source_name.nil?
47
+ info("Deleting all trees")
48
+ params = {}
49
+ else
50
+ info("Deleting trees for Source \"#{source_name}\"")
51
+ params = { "source" => source_name }
52
+ end
53
+
54
+ (find_trees(params, headers).content['trees'] || []).each do |tree|
55
+ info("Deleting tree \"#{tree['title']}\"")
56
+ delete("#{@api_url}/trees/#{encode(tree['title'])}", headers)
57
+ end
58
+ end
59
+
60
+
61
+ # Find trees.
62
+ #
63
+ # @param params [Hash] Query parameters that are added to the URL, such as +include+
64
+ # @param headers [Hash] hash of headers to send, default is basic authentication
65
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
66
+ #
67
+ # Example
68
+ #
69
+ # find_trees({ "source" => "Kinetic Request CE" })
70
+ #
71
+ # Example
72
+ #
73
+ # find_trees({ "include" => "details" })
74
+ #
75
+ # Example
76
+ #
77
+ # find_trees({ "source" => "Kinetic Request CE", "include" => "details" })
78
+ #
79
+ def find_trees(params={}, headers=header_basic_auth)
80
+ info("Finding Trees")
81
+ get("#{@api_url}/trees", params, headers)
82
+ end
83
+
84
+ # Find routines.
85
+ #
86
+ # @param params [Hash] Query parameters that are added to the URL, such as +include+
87
+ # @param headers [Hash] hash of headers to send, default is basic authentication
88
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
89
+ #
90
+ # Example
91
+ #
92
+ # find_routines({ "source" => "Kinetic Request CE" })
93
+ #
94
+ # Example
95
+ #
96
+ # find_routines({ "include" => "details" })
97
+ #
98
+ # Example
99
+ #
100
+ # find_routines({ "source" => "Kinetic Request CE", "include" => "details" })
101
+ #
102
+ def find_routines(params={}, headers=header_basic_auth)
103
+ info("Finding Routines")
104
+ response = get("#{@api_url}/trees", params, headers)
105
+
106
+ routines = []
107
+ (response.content["trees"] || []).each do |tree|
108
+ routines.push(tree) unless tree['definitionId'].nil?
109
+ end
110
+ final_content = { "trees" => routines }
111
+ response.content= final_content
112
+ response.content_string= final_content.to_json
113
+ response
114
+ end
115
+
116
+ # Import a tree
117
+ #
118
+ # If the tree already exists on the server, this will fail unless forced
119
+ # to overwrite.
120
+ #
121
+ # The source named in the tree content must also exist on the server, or
122
+ # the import will fail.
123
+ #
124
+ # @param tree [String] content from tree file
125
+ # @param force_overwrite [Boolean] whether to overwrite a tree if it exists, default is false
126
+ # @param headers [Hash] hash of headers to send, default is basic authentication
127
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
128
+ def import_tree(tree, force_overwrite=false, headers=header_basic_auth)
129
+ body = { "content" => tree }
130
+ info("Importing Tree #{File.basename(tree)}")
131
+ post_multipart("#{@api_url}/trees?force=#{force_overwrite}", body, headers)
132
+ end
133
+
134
+ # Import a routine
135
+ #
136
+ # If the routine already exists on the server, this will fail unless
137
+ # forced to overwrite.
138
+ #
139
+ # @param routine [String] content from routine file
140
+ # @param force_overwrite [Boolean] whether to overwrite a routine if it exists, default is false
141
+ # @param headers [Hash] hash of headers to send, default is basic authentication
142
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
143
+ def import_routine(routine, force_overwrite=false, headers=header_basic_auth)
144
+ body = { "content" => routine }
145
+ info("Importing Routine #{File.basename(routine)}")
146
+ post_multipart("#{@api_url}/trees?force=#{force_overwrite}", body, headers)
147
+ end
148
+
149
+ # Find a single tree by title (Source Name :: Group Name :: Tree Name)
150
+ #
151
+ # @param title [String] The tree title
152
+ # @param params [Hash] Query parameters that are added to the URL, such as +include+
153
+ # @param headers [Hash] hash of headers to send, default is basic authentication
154
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
155
+ #
156
+ # Example
157
+ #
158
+ # find_tree(
159
+ # "Kinetic Request CE :: Win a Car :: Complete",
160
+ # { "include" => "details" }
161
+ # )
162
+ #
163
+ def find_tree(title, params={}, headers=header_basic_auth)
164
+ info("Finding the \"#{title}\" Tree")
165
+ get("#{@api_url}/trees/#{encode(title)}", params, headers)
166
+ end
167
+
168
+ # Export a single tree or routine
169
+ #
170
+ # @param title [String] the title of the tree or routine
171
+ # @param headers [Hash] hash of headers to send, default is basic authentication
172
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
173
+ #
174
+ def export_tree(title, headers=header_basic_auth)
175
+ raise StandardError.new "An export directory must be defined to export a tree." if @options[:export_directory].nil?
176
+ info("Exporting tree \"#{title}\" to #{@options[:export_directory]}.")
177
+ # Get the tree
178
+ response = find_tree(title, { "include" => "export" })
179
+ # Parse the response and export the tree
180
+ tree = response.content
181
+
182
+ # determine which directory to write the file to
183
+ if tree['sourceGroup'] == "-"
184
+ # Create the directory if it doesn't yet exist
185
+ routine_dir = FileUtils::mkdir_p(File.join(@options[:export_directory], "routines"))
186
+ tree_file = File.join(routine_dir, "#{tree['name'].slugify}.xml")
187
+ else
188
+ # Create the directory if it doesn't yet exist
189
+ tree_dir = FileUtils::mkdir_p(File.join(@options[:export_directory], "trees", tree['sourceName'].slugify))
190
+ tree_file = File.join(tree_dir, "#{tree['sourceName'].slugify}.#{tree['sourceGroup'].slugify}.#{tree['name'].slugify}.xml")
191
+ end
192
+ # write the file
193
+ File.write(tree_file, tree['export'])
194
+ info("Exported #{tree['type']}: #{tree['title']} to #{tree_file}")
195
+ end
196
+
197
+ # Export all trees and local routines for a source, and global routines
198
+ #
199
+ # @param source_name [String] Name of the source to export trees and local routines
200
+ # - Leave blank or pass nil to export all trees and global routines
201
+ # - Pass "-" to export only global routines
202
+ # @param headers [Hash] hash of headers to send, default is basic authentication
203
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
204
+ def export_trees(source_name=nil, headers=header_basic_auth)
205
+ raise StandardError.new "An export directory must be defined to export trees." if @options[:export_directory].nil?
206
+ if source_name.nil?
207
+ info("Exporting all trees and routines to #{@options[:export_directory]}.")
208
+ (find_sources.content["sourceRoots"] || []).each do |sourceRoot|
209
+ export_trees(sourceRoot['name'])
210
+ end
211
+ return
212
+ elsif source_name == "-"
213
+ info("Exporting global routines to #{@options[:export_directory]}.")
214
+ else
215
+ info("Exporting trees and routines for source \"#{source_name}\" to #{@options[:export_directory]}.")
216
+ end
217
+
218
+ # Get all the trees and routines for the source
219
+ response = find_trees({ "source" => source_name, "include" => "export" })
220
+ # Parse the response and export each tree
221
+ (response.content["trees"] || []).each do |tree|
222
+ # determine which directory to write the file to
223
+ if tree['sourceGroup'] == "-"
224
+ # create the directory if it doesn't yet exist
225
+ routine_dir = FileUtils::mkdir_p(File.join(@options[:export_directory], "routines"))
226
+ tree_file = File.join(routine_dir, "#{tree['name'].slugify}.xml")
227
+ else
228
+ # create the directory if it doesn't yet exist
229
+ tree_dir = FileUtils::mkdir_p(File.join(@options[:export_directory], "trees", source_name.slugify))
230
+ tree_file = File.join(tree_dir, "#{source_name.slugify}.#{tree['sourceGroup'].slugify}.#{tree['name'].slugify}.xml")
231
+ end
232
+ # write the file
233
+ File.write(tree_file, tree['export'])
234
+ info("Exported #{tree['type']}: #{tree['title']} to #{tree_file}")
235
+ end
236
+ end
237
+
238
+
239
+ # Export all global routines
240
+ #
241
+ # @param headers [Hash] hash of headers to send, default is basic authentication
242
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
243
+ def export_routines(headers=header_basic_auth)
244
+ export_trees("-", headers)
245
+ end
246
+
247
+ # Create a new run of a tree
248
+ #
249
+ # @param title [String] title of the tree: Source Name, Group Name, Tree Name
250
+ # @param body [Hash] properties to pass to the tree, what can be used/accepted
251
+ # depends on the source.
252
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
253
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
254
+ def run_tree(title, body={}, headers=default_headers)
255
+ info("Running tree #{title}")
256
+ parts = title.split(" :: ")
257
+ raise StandardError.new "Title is invalid: #{title}" if parts.size != 3
258
+ url = "#{@api_v1_url}/run-tree/#{encode(parts[0])}/#{encode(parts[1])}/#{encode(parts[2])}"
259
+ post(url, body, headers)
260
+ end
261
+
262
+ # Update a tree
263
+ #
264
+ # @param title [String] title of the tree: Source Name, Group Name, Tree Name
265
+ # @param body [Hash] properties to pass to the tree
266
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
267
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
268
+ def update_tree(title, body={}, headers=default_headers)
269
+ info("Updating the \"#{title}\" Tree")
270
+ put("#{@api_url}/trees/#{encode(title)}", body, headers)
271
+ end
272
+
273
+ end
274
+ end
@@ -0,0 +1,75 @@
1
+ module KineticSdk
2
+ class Task
3
+
4
+ # Add a user
5
+ #
6
+ # @param user [Hash] user properties
7
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
8
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
9
+ #
10
+ # Example
11
+ #
12
+ # add_user({
13
+ # "loginId" => "foo",
14
+ # "password" => "bar",
15
+ # "email" => "foo@bar.com"
16
+ # })
17
+ #
18
+ def add_user(user, headers=default_headers)
19
+ info("Add user \"#{user['loginId']}\"")
20
+ post("#{@api_url}/users", user, headers)
21
+ end
22
+
23
+ # Delete a User
24
+ #
25
+ # @param login_id [String] login id of the user
26
+ # @param headers [Hash] hash of headers to send, default is basic authentication
27
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
28
+ def delete_user(login_id, headers=header_basic_auth)
29
+ info("Deleting User \"#{login_id}\"")
30
+ delete("#{@api_url}/users/#{encode(login_id)}", headers)
31
+ end
32
+
33
+ # Delete all Users
34
+ #
35
+ # @param headers [Hash] hash of headers to send, default is basic authentication
36
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
37
+ def delete_users(headers=header_basic_auth)
38
+ info("Deleting all users")
39
+ (find_users(headers).content["users"] || []).each do |user|
40
+ delete("#{@api_url}/users/#{encode(user['login_id'])}", headers)
41
+ end
42
+ end
43
+
44
+ # Find all users
45
+ #
46
+ # @param params [Hash] Query parameters that are added to the URL, such as +include+
47
+ # @param headers [Hash] hash of headers to send, default is basic authentication
48
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
49
+ def find_users(params={}, headers=header_basic_auth)
50
+ info("Finding all users")
51
+ get("#{@api_url}/users", params, headers)
52
+ end
53
+
54
+ # Update a user
55
+ #
56
+ # @param login_id [String] Login Id for the user
57
+ # @param user [Hash] updated properties of the user
58
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
59
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
60
+ #
61
+ # Example
62
+ #
63
+ # update_user({
64
+ # "loginId" => "foo",
65
+ # "password" => "bar",
66
+ # "email" => "foo@bar.com"
67
+ # })
68
+ #
69
+ def update_user(login_id, user, headers=default_headers)
70
+ info("Updating user \"#{login_id}\"")
71
+ put("#{@api_url}/users/#{encode(login_id)}", user, headers)
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,92 @@
1
+ Dir[File.join(File.dirname(File.expand_path(__FILE__)), "lib", "**", "*.rb")].each {|file| require file }
2
+
3
+ module KineticSdk
4
+
5
+ # Task is a Ruby class that acts as a wrapper for the Kinetic Task REST API
6
+ # without having to make explicit HTTP requests.
7
+ #
8
+ class Task
9
+
10
+ # Include the KineticHttpUtils module
11
+ include KineticSdk::Utils::KineticHttpUtils
12
+
13
+ attr_reader :api_url, :api_v1_url, :config_user, :options, :server, :version, :username, :password
14
+
15
+ # Initalize the Task SDK with the web server URL and user credentials,
16
+ # along with any custom option values.
17
+ #
18
+ # @param [Hash] opts Kinetic Task properties
19
+ # @option opts [String] :config_file optional - path to the YAML configuration file
20
+ #
21
+ # * Ex: /opt/config/task-configuration1.yaml
22
+ #
23
+ # @option opts [String] :app_server_url the URL to the Kinetic Task web application.
24
+ #
25
+ # * Ex: <http://192.168.0.1:8080/kinetic-task>
26
+ #
27
+ # @option opts [String] :username the username for the user
28
+ # @option opts [String] :password the password for the user
29
+ # @option opts [Hash<Symbol, Object>] :options ({}) optional settings
30
+ #
31
+ # * :export_directory (String) (_example: /opt/exports/kinetic-task) directory to write files when exporting,
32
+ # * :log_level (String) (_defaults to: off_) level of logging - off | info | debug | trace
33
+ # * :max_redirects (Fixnum) (_defaults to: 10_) maximum number of redirects to follow
34
+ # * :ssl_ca_file (String) full path to PEM certificate used to verify the server
35
+ # * :ssl_verify_mode (String) (_defaults to: none_) - none | peer
36
+ #
37
+ # Example: using a configuration file
38
+ #
39
+ # KineticSdk::Task.new({
40
+ # config_file: "/opt/config1.yaml"
41
+ # })
42
+ #
43
+ # Example: using a properties hash
44
+ #
45
+ # KineticSdk::Task.new({
46
+ # app_server_url: "http://localhost:8080/kinetic-task",
47
+ # username: "admin",
48
+ # password: "admin",
49
+ # options: {
50
+ # log_level: "debug",
51
+ # export_directory: "/opt/exports/task-server-a",
52
+ # ssl_verify_mode: "peer",
53
+ # ssl_ca_file: "/usr/local/self_signing_ca.pem"
54
+ # }
55
+ # })
56
+ #
57
+ # If the +config_file+ option is present, it will be loaded first, and any additional
58
+ # options will overwrite any values in the config file
59
+ #
60
+ def initialize(opts)
61
+ # initialize any variables
62
+ options = {}
63
+ @config_user = {}
64
+ @server = nil
65
+
66
+ # process the configuration file if it was provided
67
+ unless opts[:config_file].nil?
68
+ options.merge!(YAML::load_file opts[:config_file])
69
+ end
70
+
71
+ # process the configuration hash if it was provided
72
+ options.merge!(opts)
73
+
74
+ # process any individual options
75
+ @options = options.delete(:options) || {}
76
+ @config_user[:username] = options[:username]
77
+ @config_user[:password] = options[:password]
78
+ @server = options[:app_server_url].chomp('/')
79
+ @username = @config_user[:username]
80
+ @password = @config_user[:password]
81
+
82
+ # TODO: Better separation of APIv1 and APIv2
83
+ @api_v1_url = "#{@server}/app/api/v1"
84
+ @api_v2_url = "#{@server}/app/api/v2"
85
+
86
+ # set any constants or calculated values
87
+ @api_url = @api_v2_url
88
+ @version = 2
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,150 @@
1
+ module KineticSdk
2
+ module Utils
3
+ module KineticHttpUtils
4
+
5
+ #-------------------------------------------------------------------------
6
+ # Instance methods that are duplicated as module/class methods
7
+ #-------------------------------------------------------------------------
8
+
9
+ # Provides an Accept header set to application/json
10
+ #
11
+ # @return [Hash] Accept header set to application/json
12
+ def header_accept_json
13
+ { "Accept" => "application/json" }
14
+ end
15
+
16
+ # Provides a basic authentication header
17
+ #
18
+ # @param username [String] username to authenticate
19
+ # @param password [String] password associated to the username
20
+ # @return [Hash] Authorization: Basic base64 hash of username and password
21
+ def header_basic_auth(username=@username, password=@password)
22
+ { "Authorization" => "Basic #{Base64.encode64(username.to_s + ":" + password.to_s).gsub("\n", "")}" }
23
+ end
24
+
25
+ # Provides a Bearer authentication header
26
+ #
27
+ # @param token [String] JSON Web Token (jwt)
28
+ # @return [Hash] Authorization: Bearer jwt
29
+ def header_bearer_auth(token=@jwt)
30
+ { "Authorization" => "Bearer #{token}" }
31
+ end
32
+
33
+ # Provides a content-type header set to application/json
34
+ #
35
+ # @return [Hash] Content-Type header set to application/json
36
+ def header_content_json
37
+ { "Content-Type" => "application/json" }
38
+ end
39
+
40
+ # Provides a user-agent header set to Kinetic Ruby SDK
41
+ #
42
+ # @return [Hash] User-Agent header set to Kinetic Reuby SDK
43
+ def header_user_agent
44
+ { "User-Agent" => "Kinetic Ruby SDK #{KineticSdk::VERSION}" }
45
+ end
46
+
47
+ # Provides a hash of default headers
48
+ #
49
+ # @param username [String] username to authenticate
50
+ # @param password [String] password associated to the username
51
+ # @return [Hash] Hash of headers
52
+ # - Accepts: application/json
53
+ # - Authorization: Basic base64 hash of username and password if username is provided
54
+ # - Content-Type: application/json
55
+ # - User-Agent: Kinetic Ruby SDK {KineticSdk::VERSION}
56
+ def default_headers(username=@username, password=@password)
57
+ headers = header_accept_json.merge(header_content_json).merge(header_user_agent)
58
+ headers.merge!(header_basic_auth(username, password)) unless username.nil?
59
+ headers
60
+ end
61
+
62
+ # Provides a hash of default headers with bearer auth instead of basic auth
63
+ #
64
+ # @param token [String] JSON Web Token (jwt)
65
+ # @return [Hash] Hash of headers
66
+ # - Accepts: application/json
67
+ # - Authorization: Bearer jwt
68
+ # - Content-Type: application/json
69
+ # - User-Agent: Kinetic Ruby SDK {KineticSdk::VERSION}
70
+ def default_jwt_headers(token=@jwt)
71
+ headers = header_accept_json.merge(header_content_json).merge(header_user_agent)
72
+ headers.merge!(header_bearer_auth(token)) unless token.nil?
73
+ headers
74
+ end
75
+
76
+
77
+ #------------------------------------------
78
+ # Class methods
79
+ #------------------------------------------
80
+
81
+ # Provides a accepts header set to application/json
82
+ #
83
+ # @return [Hash] Accepts header set to application/json
84
+ def self.header_accept_json
85
+ { "Accepts" => "application/json" }
86
+ end
87
+
88
+ # Provides a basic authentication header
89
+ #
90
+ # @param username [String] username to authenticate
91
+ # @param password [String] password associated to the username
92
+ # @return [Hash] Authorization: Basic base64 hash of username and password
93
+ def self.header_basic_auth(username=@username, password=@password)
94
+ { "Authorization" => "Basic #{Base64.encode64(username.to_s + ":" + password.to_s).gsub("\n", "")}" }
95
+ end
96
+
97
+ # Provides a Bearer authentication header
98
+ #
99
+ # @param token [String] JSON Web Token (jwt)
100
+ # @return [Hash] Authorization: Bearer jwt
101
+ def self.header_bearer_auth(token=@jwt)
102
+ { "Authorization" => "Bearer #{token}" }
103
+ end
104
+
105
+ # Provides a content-type header set to application/json
106
+ #
107
+ # @return [Hash] Content-Type header set to application/json
108
+ def self.header_content_json
109
+ { "Content-Type" => "application/json" }
110
+ end
111
+
112
+ # Provides a user-agent header set to Kinetic Ruby SDK
113
+ #
114
+ # @return [Hash] User-Agent header set to Kinetic Reuby SDK
115
+ def self.header_user_agent
116
+ { "User-Agent" => "Kinetic Ruby SDK #{KineticSdk::VERSION}" }
117
+ end
118
+
119
+ # Provides a hash of default headers
120
+ #
121
+ # @param username [String] username to authenticate
122
+ # @param password [String] password associated to the username
123
+ # @return [Hash] Hash of headers
124
+ # - Accept: application/json
125
+ # - Authorization: Basic base64 hash of username and password if username is provided
126
+ # - Content-Type: application/json
127
+ # - User-Agent: Kinetic Ruby SDK {KineticSdk::VERSION}
128
+ def self.default_headers(username=@username, password=@password)
129
+ headers = self.header_accept_json.merge(self.header_content_json).merge(self.header_user_agent)
130
+ headers.merge!(self.header_basic_auth(username, password)) unless username.nil?
131
+ headers
132
+ end
133
+
134
+ # Provides a hash of default headers with bearer auth instead of basic auth
135
+ #
136
+ # @param token [String] JSON Web Token (jwt)
137
+ # @return [Hash] Hash of headers
138
+ # - Accepts: application/json
139
+ # - Authorization: Bearer jwt
140
+ # - Content-Type: application/json
141
+ # - User-Agent: Kinetic Ruby SDK {KineticSdk::VERSION}
142
+ def self.default_jwt_headers(token=@jwt)
143
+ headers = self.header_accept_json.merge(self.header_content_json).merge(self.header_user_agent)
144
+ headers.merge!(self.header_bearer_auth(token)) unless token.nil?
145
+ headers
146
+ end
147
+
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,75 @@
1
+ module KineticSdk
2
+ module Utils
3
+
4
+ # The KineticHttpResponse object normalizes the Net::HTTPResponse object
5
+ # properties so they are always consistent.
6
+ #
7
+ # If the object passed in the constructor is a StandardError, the status code is
8
+ # set to 0, and the {#exception} and {#backtrace} methods can be used to get the
9
+ # details.
10
+ #
11
+ # Regardless of whether a Net::HTTPResponse object or a StandardError object was
12
+ # passed in the constructor, the {#code} and {#message} methods will give information
13
+ # about the response.
14
+ class KineticHttpResponse
15
+ # response code [String] - always '0' if constructor object is a StandardError
16
+ attr_reader :code
17
+ # the parsed JSON response body if content-type is application/json
18
+ attr_accessor :content
19
+ # the raw response body string
20
+ attr_accessor :content_string
21
+ # the response content-type
22
+ attr_reader :content_type
23
+ # the resonse headers
24
+ attr_reader :headers
25
+ # response status message
26
+ attr_reader :message
27
+ # the raw response object
28
+ attr_reader :response
29
+ # response code [Fixnum] - always 0 if constructor object is a StandardError
30
+ attr_reader :status
31
+
32
+ # the StandardError backtrace if constructor object is a StandardError
33
+ attr_reader :backtrace
34
+ # the raw StandardError if constructor object is a StandardError
35
+ attr_reader :exception
36
+
37
+ # Constructor
38
+ #
39
+ # @param object [Net::HTTPResponse | StandardError] either a Net::HTTPResponse or a StandardError
40
+ def initialize(object)
41
+ case object
42
+ when Net::HTTPResponse then
43
+ @code = object.code
44
+ @content_string = object.body
45
+ @content_type = object.content_type
46
+ @headers = object.each_header.inject({}) { |h,(k,v)| h[k] = v; h }
47
+ @message = object.message
48
+ @response = object
49
+ @status = @code.to_i
50
+
51
+ # if content type is json, try to parse the content string
52
+ @content = case @content_type
53
+ when "application/json" then
54
+ # will raise an exception if content_string is not valid json
55
+ JSON.parse(@content_string)
56
+ else
57
+ {}
58
+ end
59
+ when StandardError then
60
+ @code = "0"
61
+ @content = {}
62
+ @content_string = nil
63
+ @content_type = nil
64
+ @backtrace = object.backtrace
65
+ @exception = object.exception
66
+ @message = object.message
67
+ @status = @code.to_i
68
+ else
69
+ raise StandardError.new("Invalid response object: #{object.class}")
70
+ end
71
+ end
72
+ end
73
+
74
+ end
75
+ end