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,215 @@
1
+ module KineticSdk
2
+ class RequestCe
3
+
4
+ # Add a Submission
5
+ #
6
+ # @param kapp_slug [String] slug of the Kapp
7
+ # @param form_slug [String] slug of the Form
8
+ # @param payload [Hash] payload of the submission
9
+ # - +origin+ - Origin ID of the submission to be added
10
+ # - +parent+ - Parent ID of the submission to be added
11
+ # - +values+ - hash of field values for the submission
12
+ # @param parameters [Hash] hash of query parameters to append to the URL
13
+ # - +include+ - comma-separated list of properties to include in the response
14
+ # - +completed+ - signals that the submission should be completed, default is false
15
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
16
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
17
+ def add_submission(kapp_slug, form_slug, payload={}, parameters={}, headers=default_headers)
18
+ # initialize "values" if nil
19
+ payload["values"] = {} if payload["values"].nil?
20
+ # set origin hash if origin was passed as a string
21
+ payload["origin"] = { "id" => payload["origin"] } if payload["origin"].is_a? String
22
+ # set parent hash if parent was passed as a string
23
+ payload["parent"] = { "id" => payload["parent"] } if payload["parent"].is_a? String
24
+ # build the uri with the encoded parameters
25
+ uri = URI.parse("#{@api_url}/kapps/#{kapp_slug}/forms/#{form_slug}/submissions")
26
+ uri.query = URI.encode_www_form(parameters) unless parameters.empty?
27
+ # Create the submission
28
+ info("Adding a submission in the \"#{form_slug}\" Form.")
29
+ post(uri.to_s, payload, headers)
30
+ end
31
+
32
+ # Add a Submission page
33
+ #
34
+ # @param kapp_slug [String] slug of the Kapp
35
+ # @param form_slug [String] slug of the Form
36
+ # @param page_name [String] name of the Page
37
+ # @param payload [Hash] payload of the submission
38
+ # - +origin+ - Origin ID of the submission to be added
39
+ # - +parent+ - Parent ID of the submission to be added
40
+ # - +values+ - hash of field values for the submission
41
+ # @param parameters [Hash] hash of query parameters to append to the URL
42
+ # - +include+ - comma-separated list of properties to include in the response
43
+ # - +staged+ - Indicates whether field validations and page advancement should occur, default is false
44
+ # - +defer+ - Indicates the submission is for a subform embedded in a parent, default is false
45
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
46
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
47
+ def add_submission_page(kapp_slug, form_slug, page_name, payload={}, parameters={}, headers=default_headers)
48
+ # initialize "values" if nil
49
+ payload["values"] = {} if payload["values"].nil?
50
+ # set origin hash if origin was passed as a string
51
+ payload["origin"] = { "id" => payload["origin"] } if payload["origin"].is_a? String
52
+ # set parent hash if parent was passed as a string
53
+ payload["parent"] = { "id" => payload["parent"] } if payload["parent"].is_a? String
54
+ # add the page name to the parameters
55
+ parameters["page"] = page_name
56
+ # build the uri with the encoded parameters
57
+ uri = URI.parse("#{@api_url}/kapps/#{kapp_slug}/forms/#{form_slug}/submissions")
58
+ uri.query = URI.encode_www_form(parameters)
59
+ # Create the submission
60
+ info("Adding a submission page in the \"#{form_slug}\" Form.")
61
+ post(uri.to_s, payload, headers)
62
+ end
63
+
64
+ # Patch a new Submission
65
+ #
66
+ # @param kapp_slug [String] slug of the Kapp
67
+ # @param form_slug [String] slug of the Form
68
+ # @param payload [Hash] payload of the submission
69
+ # - +origin+ - Origin ID of the submission to be patched
70
+ # - +parent+ - Parent ID of the submission to be patched
71
+ # - +values+ - hash of field values for the submission
72
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
73
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
74
+ def patch_new_submission(kapp_slug, form_slug, payload={}, headers=default_headers)
75
+ # set the currentPage hash if currentPage was passed as a string
76
+ payload["currentPage"] = { "name" => payload["currentPage"] } if payload["currentPage"].is_a? String
77
+ # initialize "values" if nil
78
+ payload["values"] = {} if payload["values"].nil?
79
+ # set origin hash if origin was passed as a string
80
+ payload["origin"] = { "id" => payload["origin"] } if payload["origin"].is_a? String
81
+ # set parent hash if parent was passed as a string
82
+ payload["parent"] = { "id" => payload["parent"] } if payload["parent"].is_a? String
83
+ # Create the submission
84
+ info("Patching a submission in the \"#{form_slug}\" Form.")
85
+ patch("#{@api_url}/kapps/#{kapp_slug}/forms/#{form_slug}/submissions", payload, headers)
86
+ end
87
+
88
+ # Patch an existing Submission
89
+ #
90
+ # @param submission_id [String] id of the Submission
91
+ # @param payload [Hash] payload of the submission
92
+ # - +origin+ - Origin ID of the submission to be patched
93
+ # - +parent+ - Parent ID of the submission to be patched
94
+ # - +values+ - hash of field values for the submission
95
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
96
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
97
+ def patch_existing_submission(submission_id, payload={}, headers=default_headers)
98
+ # set the currentPage hash if currentPage was passed as a string
99
+ payload["currentPage"] = { "name" => payload["currentPage"] } if payload["currentPage"].is_a? String
100
+ # initialize "values" if nil
101
+ payload["values"] = {} if payload["values"].nil?
102
+ # set origin hash if origin was passed as a string
103
+ payload["origin"] = { "id" => payload["origin"] } if payload["origin"].is_a? String
104
+ # set parent hash if parent was passed as a string
105
+ payload["parent"] = { "id" => payload["parent"] } if payload["parent"].is_a? String
106
+ # Create the submission
107
+ info("Patching a submission with id \"#{submission_id}\"")
108
+ patch("#{@api_url}/submissions/#{submission_id}", payload, headers)
109
+ end
110
+
111
+ # Find all Submissions for a form.
112
+ #
113
+ # This method will process pages of form submissions and internally
114
+ # concatenate the results into a single array.
115
+ #
116
+ # Warning - using this method can cause out of memory errors on large
117
+ # result sets.
118
+ #
119
+ # @param kapp_slug [String] slug of the Kapp
120
+ # @param form_slug [String] slug of the Form
121
+ # @param params [Hash] Query parameters that are added to the URL, such as +include+
122
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
123
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
124
+ def find_all_form_submissions(kapp_slug, form_slug, params={}, headers=default_headers)
125
+ info("Finding submissions for the \"#{form_slug}\" Form.")
126
+ # Make the initial request of pages submissions
127
+ response = find_form_submissions(kapp_slug, form_slug, params, headers)
128
+ # Build the Messages Array
129
+ messages = response.content["messages"]
130
+ # Build Submissions Array
131
+ submissions = response.content["submissions"]
132
+ # if a next page token exists, keep retrieving submissions and add them to the results
133
+ while (!response.content["nextPageToken"].nil?)
134
+ params['pageToken'] = response.content["nextPageToken"]
135
+ response = find_form_submissions(kapp_slug, form_slug, params, headers)
136
+ # concat the messages
137
+ messages.concat(response.content["messages"] || [])
138
+ # concat the submissions
139
+ submissions.concat(response.content["submissions"] || [])
140
+ end
141
+ final_content = { "messages" => messages, "submissions" => submissions, "nextPageToken" => nil }
142
+ # Return the results
143
+ response.content=final_content
144
+ response.content_string=final_content.to_json
145
+ response
146
+ end
147
+
148
+ # Find a page of Submissions for a form.
149
+ #
150
+ # The page offset can be defined by passing in the "pageToken" parameter,
151
+ # indicating the value of the token that will represent the first
152
+ # submission in the result set. If not provided, the first page of
153
+ # submissions will be retrieved.
154
+ #
155
+ # @param kapp_slug [String] slug of the Kapp
156
+ # @param form_slug [String] slug of the Form
157
+ # @param params [Hash] Query parameters that are added to the URL, such as +include+
158
+ # - +pageToken+ - used for paginated results
159
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
160
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
161
+ def find_form_submissions(kapp_slug, form_slug, params={}, headers=default_headers)
162
+ # Get next page token
163
+ token = params["pageToken"]
164
+ if token.nil?
165
+ info("Finding first page of submissions for the \"#{form_slug}\" Form.")
166
+ else
167
+ info("Finding page of submissions starting with token \"#{token}\" for the \"#{form_slug}\" Form.")
168
+ end
169
+
170
+ # Build Submission URL
171
+ url = "#{@api_url}/kapps/#{kapp_slug}/forms/#{form_slug}/submissions"
172
+ # Return the response
173
+ get(url, params, headers)
174
+ end
175
+
176
+ # Find a page of Submissions for a kapp.
177
+ #
178
+ # The page offset can be defined by passing in the "pageToken" parameter,
179
+ # indicating the value of the token that will represent the first
180
+ # submission in the result set. If not provided, the first page of
181
+ # submissions will be retrieved.
182
+ #
183
+ # @param kapp_slug [String] slug of the Kapp
184
+ # @param params [Hash] Query parameters that are added to the URL, such as +include+
185
+ # - +pageToken+ - used for paginated results
186
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
187
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
188
+ def find_kapp_submissions(kapp_slug, params={}, headers=default_headers)
189
+ # Get next page token
190
+ token = params["pageToken"]
191
+ if token.nil?
192
+ info("Finding first page of submissions for the \"#{kapp_slug}\" Kapp.")
193
+ else
194
+ info("Finding page of submissions starting with token \"#{token}\" for the \"#{kapp_slug}\" Kapp.")
195
+ end
196
+
197
+ # Build Submission URL
198
+ url = "#{@api_url}/kapps/#{kapp_slug}/submissions"
199
+ # Return the response
200
+ get(url, params, headers)
201
+ end
202
+
203
+ # Update a submission
204
+ #
205
+ # @param submission_id [String] String value of the Submission Id (UUID)
206
+ # @param body [Hash] submission properties to update
207
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
208
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
209
+ def update_submission(submission_id, body={}, headers=default_headers)
210
+ info("Updating Submission \"#{submission_id}\"")
211
+ put("#{@api_url}/submissions/#{encode(submission_id)}", body, headers)
212
+ end
213
+
214
+ end
215
+ end
@@ -0,0 +1,69 @@
1
+ module KineticSdk
2
+ class RequestCe
3
+
4
+ # Add a new Space
5
+ #
6
+ # @param name [String] name of the Space
7
+ # @param slug [String] value that is used in URL routes to identity the Space
8
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
9
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
10
+ def add_space(name, slug, headers=default_headers)
11
+ payload = { "name" => name, "slug" => slug }
12
+ info("Creating Space \"#{name}\" with slug \"#{slug}\"")
13
+ post("#{@api_url}/spaces", payload, headers)
14
+ end
15
+
16
+
17
+ # Delete a Space
18
+ #
19
+ # @param slug [String] slug of the space
20
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
21
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
22
+ def delete_space(slug, headers=default_headers)
23
+ info("Deleting Space \"#{slug}\"")
24
+ delete("#{@api_url}/spaces/#{slug}", headers)
25
+ end
26
+
27
+ # Find all spaces
28
+ #
29
+ # @param params [Hash] Query parameters that are added to the URL, such as +include+
30
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
31
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
32
+ def find_spaces(params={}, headers=default_headers)
33
+ info("Finding Spaces")
34
+ get("#{@api_url}/spaces", params, headers)
35
+ end
36
+
37
+ # Find the space (System API)
38
+ #
39
+ # @param slug [String] slug of the space
40
+ # @param params [Hash] Query parameters that are added to the URL, such as +include+
41
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
42
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
43
+ def find_space_in_system(slug, params={}, headers=default_headers)
44
+ info("Retrieving Space \"#{slug}\"")
45
+ get("#{@api_url}/spaces/#{slug}", params, headers)
46
+ end
47
+
48
+ # Update the space (System API)
49
+ #
50
+ # @param slug [String] slug of the space
51
+ # @param body [Hash] updated properties of the space
52
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
53
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
54
+ def update_space_in_system(slug, body, headers=default_headers)
55
+ info("Updating Space \"#{slug}\"")
56
+ put("#{@api_url}/spaces/#{slug}", body, headers)
57
+ end
58
+
59
+ # Reset the license count (System API)
60
+ #
61
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
62
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
63
+ def reset_license_count(headers=default_headers)
64
+ info("Resetting License Count")
65
+ put("#{@api_url}/license/reset", {}, headers)
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,113 @@
1
+ require 'digest/md5'
2
+
3
+ module KineticSdk
4
+ class RequestCe
5
+
6
+ # Add an attribute to a team
7
+ #
8
+ # @param team_name [String] the team name
9
+ # @param attribute_name [String] the attribute name
10
+ # @param attribute_value [String] the attribute value
11
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
12
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
13
+ def add_team_attribute(team_name, attribute_name, attribute_value, headers=default_headers)
14
+ # first find the team
15
+ response = find_team(team_name, { "include" => "attributes"}, headers)
16
+ team = response.content["team"]
17
+ attributes = team["attributes"]
18
+ # either add or update the attribute value
19
+ exists = false
20
+ attributes.each do |attribute|
21
+ info("Attribute: #{attribute.inspect}")
22
+ # if the attribute already exists, update it
23
+ if attribute["name"] == attribute_name
24
+ attribute["values"] = [ attribute_value ]
25
+ exists = true
26
+ end
27
+ end
28
+ # add the attribute if it didn't exist
29
+ attributes.push({
30
+ "name" => attribute_name,
31
+ "values" => [ attribute_value ]
32
+ }) unless exists
33
+
34
+ # set the updated attributes list
35
+ body = { "attributes" => attributes }
36
+ if exists
37
+ info("Updating attribute \"#{attribute_name}\" = \"#{attribute_value}\" in the \"#{team_name}\" team.")
38
+ else
39
+ info("Adding attribute \"#{attribute_name}\" = \"#{attribute_value}\" to the \"#{team_name}\" team.")
40
+ end
41
+ # Update the space
42
+ put("#{@api_url}/teams/#{team['slug']}", body, headers)
43
+ end
44
+
45
+ # Add a Team
46
+ #
47
+ # @param team_properties [Hash] the property values for the team
48
+ # - +name+ - Name of the team to be added
49
+ # - +description+ - Description of the Team to be added
50
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
51
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
52
+ def add_team(team_properties, headers=default_headers)
53
+ raise StandardError.new "Team properties is not valid, must be a Hash." unless team_properties.is_a? Hash
54
+ info("Adding Team \"#{team_properties['name']}\"")
55
+ post("#{@api_url}/teams", team_properties, headers)
56
+ end
57
+
58
+ # Add a team membership
59
+ #
60
+ # @param team_name [String] the team name
61
+ # @param username [String] the username to add to the team
62
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
63
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
64
+ def add_team_membership(team_name, username, headers=default_headers)
65
+ body = {
66
+ "team" => {
67
+ "name" => team_name
68
+ },
69
+ "user" => {
70
+ "username" => username
71
+ }
72
+ }
73
+ info("Adding user: \"#{username}\" to \"#{team_name}\" team")
74
+ post("#{@api_url}/memberships/", body, headers)
75
+ end
76
+
77
+ # Find teams
78
+ #
79
+ # @param params [Hash] Query parameters that are added to the URL, such as +include+
80
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
81
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
82
+ def find_teams(params={}, headers=default_headers)
83
+ info("Finding Teams")
84
+ get("#{@api_url}/teams", params, headers)
85
+ end
86
+
87
+ # Export a team
88
+ #
89
+ # @param team_name [String] the team name
90
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
91
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
92
+ def export_team(team_name, headers=default_headers)
93
+ team_slug = Digest::MD5.hexdigest(team_name)
94
+ info("Exporting the \"#{team_name}\" (#{team_slug}) Team.")
95
+ get("#{@api_url}/teams/#{team_slug}", { 'export' => true}, headers)
96
+ end
97
+
98
+ # Find the team
99
+ #
100
+ # Attributes
101
+ #
102
+ # @param team_name [String] the team name
103
+ # @param params [Hash] Query parameters that are added to the URL, such as +include+
104
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
105
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
106
+ def find_team(team_name, params={}, headers=default_headers)
107
+ team_slug = Digest::MD5.hexdigest(team_name)
108
+ info("Finding the \"#{team_name}\" (#{team_slug}) Team.")
109
+ get("#{@api_url}/teams/#{team_slug}", params, headers)
110
+ end
111
+
112
+ end
113
+ end
@@ -0,0 +1,245 @@
1
+ module KineticSdk
2
+ class RequestCe
3
+
4
+ # Add a user in a space.
5
+ #
6
+ # If the SDK was initialized as a System user, the space_slug property
7
+ # must be provided in the user hash.
8
+ #
9
+ # If the SDK was initialized as a Space user, the space_slug property
10
+ # is ignored.
11
+ #
12
+ # @param user [Hash] hash of user properties
13
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
14
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
15
+ #
16
+ # Example
17
+ #
18
+ # add_user({
19
+ # "space_slug" => "bar",
20
+ # "username" => "foo",
21
+ # "password" => "bar",
22
+ # "displayName" => "Foo",
23
+ # "email" => "foo@bar.com",
24
+ # "enabled" => true,
25
+ # "preferredLocale" => "en_US",
26
+ # "spaceAdmin" => false
27
+ # })
28
+ #
29
+ def add_user(user, headers=default_headers)
30
+ if !@space_slug.nil?
31
+ info("Adding user \"#{user['username']}\" for Space \"#{@space_slug}\" as system user.")
32
+ post("#{@api_url}/users", user, headers)
33
+ elsif !user['space_slug'].nil?
34
+ space_slug = user.delete('space_slug')
35
+ info("Adding user \"#{user['username']}\" for Space \"#{space_slug}\".")
36
+ post("#{@api_url}/spaces/#{space_slug}/users", user, headers)
37
+ else
38
+ raise StandardError.new "The space slug must be supplied to add the user."
39
+ end
40
+ end
41
+
42
+ # Delete a user in a space.
43
+ #
44
+ # If the SDK was initialized as a System user, the space_slug property
45
+ # must be provided in the user hash.
46
+ #
47
+ # If the SDK was initialized as a Space user, the space_slug property
48
+ # is ignored.
49
+ #
50
+ # @param user [Hash] properties of the user
51
+ # - +space_slug+ - only used when initialized as a System user
52
+ # - +username+ - username of the user
53
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
54
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
55
+ #
56
+ # Example
57
+ #
58
+ # delete_user({
59
+ # "username" => "user1"
60
+ # })
61
+ #
62
+ # Example
63
+ #
64
+ # delete_user({
65
+ # "space_slug" => "foo",
66
+ # "username" => "user1"
67
+ # })
68
+ #
69
+ def delete_user(user, headers=default_headers)
70
+ if !@space_slug.nil?
71
+ info("Deleting user \"#{user['username']}\" for Space \"#{@space_slug}\" as system user.")
72
+ delete("#{@api_url}/users/#{encode(user['username'])}", headers)
73
+ elsif !user['space_slug'].nil?
74
+ space_slug = user.delete('space_slug')
75
+ info("Deleting user \"#{user['username']}\" for Space \"#{space_slug}\".")
76
+ delete("#{@api_url}/spaces/#{space_slug}/users/#{encode(user['username'])}", headers)
77
+ else
78
+ raise StandardError.new "The space slug must be supplied to add the user."
79
+ end
80
+ end
81
+
82
+ # Add an attribute value to the user, or update an attribute if it already exists
83
+ #
84
+ # @param username [String] username of the user
85
+ # @param attribute_name [String] name of the attribute
86
+ # @param attribute_value [String] value of the attribute
87
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
88
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
89
+ def add_user_attribute(username, attribute_name, attribute_value, headers=default_headers)
90
+ # first find the user
91
+ response = find_user(username, { "include" => "attributes"}, headers)
92
+ user = response.content["user"]
93
+ attributes = user["attributes"]
94
+ # either add or update the attribute value
95
+ exists = false
96
+ attributes.each do |attribute|
97
+ # if the attribute already exists, update it
98
+ if attribute["name"] == attribute_name
99
+ attribute["values"] = attribute_value.is_a?(Array) ? attribute_value : [ attribute_value ]
100
+ exists = true
101
+ end
102
+ end
103
+ # add the attribute if it didn't exist
104
+ attributes.push({
105
+ "name" => attribute_name,
106
+ "values" => attribute_value.is_a?(Array) ? attribute_value : [ attribute_value ]
107
+ }) unless exists
108
+
109
+ # set the updated attributes list
110
+ body = { "attributes" => attributes }
111
+ if exists
112
+ info("Updating attribute \"#{attribute_name}\" on user \"#{username}\".")
113
+ else
114
+ info("Adding attribute \"#{attribute_name}\" to user \"#{username}\".")
115
+ end
116
+ # Update the user
117
+ put("#{@api_url}/users/#{encode(username)}", body, headers)
118
+ end
119
+
120
+ # Adds an attribute value to an attribute.
121
+ #
122
+ # @param username [String] username of the user
123
+ # @param attribute_name [String] name of the attribute
124
+ # @param attribute_value [String] value of the attribute
125
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
126
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
127
+ def add_user_attribute_value(username, attribute_name, attribute_value, headers=default_headers)
128
+ # first find the user
129
+ response = find_user(username, { "include" => "attributes"}, headers)
130
+ user = response.content["user"]
131
+ attributes = user["attributes"]
132
+ # either add or update the attribute value
133
+ exists = false
134
+ attributes.each do |attribute|
135
+ # if the attribute already exists, update it
136
+ if attribute["name"] == attribute_name
137
+ if attribute_value.is_a?(Array)
138
+ attribute["values"].concat(attribute_value)
139
+ else
140
+ attribute["values"] << attribute_value
141
+ end
142
+ attribute["values"].uniq!
143
+ exists = true
144
+ end
145
+ end
146
+ # add the attribute if it didn't exist
147
+ attributes.push({
148
+ "name" => attribute_name,
149
+ "values" => attribute_value.is_a?(Array) ? attribute_value : [ attribute_value ]
150
+ }) unless exists
151
+
152
+ # set the updated attributes list
153
+ body = { "attributes" => attributes }
154
+ if exists
155
+ info("Updating attribute \"#{attribute_name}\" on user \"#{username}\".")
156
+ else
157
+ info("Adding attribute \"#{attribute_name}\" to user \"#{username}\".")
158
+ end
159
+ # Update the user
160
+ put("#{@api_url}/users/#{encode(username)}", body, headers)
161
+ end
162
+
163
+ # Find all users
164
+ #
165
+ # @param params [Hash] Query parameters that are added to the URL, such as +include+
166
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
167
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
168
+ def find_users(params={}, headers=default_headers)
169
+ info("Finding Users \"#{username}\"")
170
+ get("#{@api_url}/users", params, headers)
171
+ end
172
+
173
+ # Find the user
174
+ #
175
+ # @param username [String] username of the user
176
+ # @param params [Hash] Query parameters that are added to the URL, such as +include+
177
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
178
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
179
+ def find_user(username, params={}, headers=default_headers)
180
+ info("Finding User \"#{username}\"")
181
+ get("#{@api_url}/users/#{encode(username)}", params, headers)
182
+ end
183
+
184
+ # Update a user in a space.
185
+ #
186
+ # If the SDK was initialized as a System user, the space_slug property
187
+ # must be provided in the user hash.
188
+ #
189
+ # If the SDK was initialized as a Space user, the space_slug property
190
+ # is ignored.
191
+ #
192
+ # @param username [String] username of the user to update
193
+ # @param user [Hash] user properties to update
194
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
195
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
196
+ #
197
+ # Example
198
+ #
199
+ # update_user("xyz", {
200
+ # "space_slug" => "bar",
201
+ # "username" => "foo",
202
+ # "password" => "bar",
203
+ # "displayName" => "Foo",
204
+ # "email" => "foo@bar.com",
205
+ # "enabled" => true,
206
+ # "preferredLocale" => "en_US",
207
+ # "spaceAdmin" => false
208
+ # })
209
+ #
210
+ def update_user(username, user, headers=default_headers)
211
+ if !@space_slug.nil?
212
+ info("Updating user \"#{username}\" for Space \"#{@space_slug}\" as system user.")
213
+ put("#{@api_url}/users/#{encode(username)}", user, headers)
214
+ elsif !user['space_slug'].nil?
215
+ space_slug = user.delete('space_slug')
216
+ info("Updating user \"#{username}\" for Space \"#{space_slug}\".")
217
+ put("#{@api_url}/spaces/#{space_slug}/users/#{encode(username)}", user, headers)
218
+ else
219
+ raise StandardError.new "The space slug must be supplied to update the user."
220
+ end
221
+ end
222
+
223
+ # Generate Password Reset Token.
224
+ #
225
+ # @param username [String] username of the user
226
+ # @param body [Hash] properties
227
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
228
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
229
+ def generate_password_token(username, body={}, headers=default_headers)
230
+ info("Generating PW Token for \"#{username}\"")
231
+ post("#{@api_url}/users/#{encode(username)}/passwordResetToken", body, headers)
232
+ end
233
+
234
+ # Find the current user
235
+ #
236
+ # @param params [Hash] Query parameters that are added to the URL, such as +include+
237
+ # @param headers [Hash] hash of headers to send, default is basic authentication and accept JSON content type
238
+ # @return [KineticSdk::Utils::KineticHttpResponse] object, with +code+, +message+, +content_string+, and +content+ properties
239
+ def me(params={}, headers=default_headers)
240
+ info("Finding Me")
241
+ get("#{@api_url}/me", params, headers)
242
+ end
243
+
244
+ end
245
+ end