scalingo 3.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.rubocop.yml +16 -0
  4. data/.travis.yml +24 -0
  5. data/CHANGELOG.md +29 -0
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +110 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +147 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +12 -0
  12. data/bin/setup +8 -0
  13. data/lib/scalingo.rb +2 -0
  14. data/lib/scalingo/api/client.rb +79 -0
  15. data/lib/scalingo/api/endpoint.rb +23 -0
  16. data/lib/scalingo/api/response.rb +71 -0
  17. data/lib/scalingo/auth.rb +21 -0
  18. data/lib/scalingo/auth/keys.rb +56 -0
  19. data/lib/scalingo/auth/scm_integrations.rb +57 -0
  20. data/lib/scalingo/auth/tokens.rb +78 -0
  21. data/lib/scalingo/auth/two_factor_auth.rb +61 -0
  22. data/lib/scalingo/auth/user.rb +31 -0
  23. data/lib/scalingo/bearer_token.rb +20 -0
  24. data/lib/scalingo/client.rb +105 -0
  25. data/lib/scalingo/config.rb +38 -0
  26. data/lib/scalingo/error/expired_token.rb +6 -0
  27. data/lib/scalingo/error/unauthenticated.rb +6 -0
  28. data/lib/scalingo/errors.rb +2 -0
  29. data/lib/scalingo/regional.rb +35 -0
  30. data/lib/scalingo/regional/addons.rb +109 -0
  31. data/lib/scalingo/regional/apps.rb +109 -0
  32. data/lib/scalingo/regional/collaborators.rb +57 -0
  33. data/lib/scalingo/regional/containers.rb +57 -0
  34. data/lib/scalingo/regional/deployments.rb +44 -0
  35. data/lib/scalingo/regional/domains.rb +70 -0
  36. data/lib/scalingo/regional/environment.rb +83 -0
  37. data/lib/scalingo/regional/events.rb +55 -0
  38. data/lib/scalingo/regional/logs.rb +38 -0
  39. data/lib/scalingo/regional/metrics.rb +41 -0
  40. data/lib/scalingo/regional/notifiers.rb +96 -0
  41. data/lib/scalingo/regional/operations.rb +18 -0
  42. data/lib/scalingo/regional/scm_repo_links.rb +109 -0
  43. data/lib/scalingo/version.rb +3 -0
  44. data/samples/auth/keys/_meta.json +13 -0
  45. data/samples/auth/keys/all-200.json +62 -0
  46. data/samples/auth/keys/create-201.json +67 -0
  47. data/samples/auth/keys/create-422.json +34 -0
  48. data/samples/auth/keys/destroy-204.json +19 -0
  49. data/samples/auth/keys/destroy-404.json +19 -0
  50. data/samples/auth/keys/show-200.json +60 -0
  51. data/samples/auth/keys/show-404.json +19 -0
  52. data/samples/auth/scm_integrations/_meta.json +14 -0
  53. data/samples/auth/scm_integrations/all-200.json +41 -0
  54. data/samples/auth/scm_integrations/create-201.json +41 -0
  55. data/samples/auth/scm_integrations/create-422.json +36 -0
  56. data/samples/auth/scm_integrations/destroy-204.json +15 -0
  57. data/samples/auth/scm_integrations/destroy-404.json +23 -0
  58. data/samples/auth/scm_integrations/show-200.json +34 -0
  59. data/samples/auth/scm_integrations/show-404.json +23 -0
  60. data/samples/auth/tokens/_meta.json +13 -0
  61. data/samples/auth/tokens/all-200.json +32 -0
  62. data/samples/auth/tokens/create-201.json +37 -0
  63. data/samples/auth/tokens/destroy-204.json +19 -0
  64. data/samples/auth/tokens/destroy-404.json +19 -0
  65. data/samples/auth/tokens/exchange-200.json +25 -0
  66. data/samples/auth/tokens/exchange-401.json +24 -0
  67. data/samples/auth/tokens/renew-200.json +32 -0
  68. data/samples/auth/tokens/renew-404.json +20 -0
  69. data/samples/auth/two_factor_auth/_meta.json +10 -0
  70. data/samples/auth/two_factor_auth/disable-not-initiated.json +23 -0
  71. data/samples/auth/two_factor_auth/disable-success.json +29 -0
  72. data/samples/auth/two_factor_auth/initiate-already-enabled.json +29 -0
  73. data/samples/auth/two_factor_auth/initiate-success.json +36 -0
  74. data/samples/auth/two_factor_auth/initiate-wrong-provider.json +29 -0
  75. data/samples/auth/two_factor_auth/status.json +29 -0
  76. data/samples/auth/two_factor_auth/validate-not-initiated.json +29 -0
  77. data/samples/auth/two_factor_auth/validate-success.json +49 -0
  78. data/samples/auth/two_factor_auth/validate-wrong.json +29 -0
  79. data/samples/auth/user/_meta.json +10 -0
  80. data/samples/auth/user/self.json +54 -0
  81. data/samples/auth/user/update-200.json +59 -0
  82. data/samples/auth/user/update-422.json +33 -0
  83. data/samples/regional/addons/_meta.json +22 -0
  84. data/samples/regional/addons/categories-guest.json +36 -0
  85. data/samples/regional/addons/categories-logged.json +37 -0
  86. data/samples/regional/addons/destroy-204.json +19 -0
  87. data/samples/regional/addons/destroy-404.json +24 -0
  88. data/samples/regional/addons/find-200.json +48 -0
  89. data/samples/regional/addons/find-404.json +24 -0
  90. data/samples/regional/addons/for-200.json +50 -0
  91. data/samples/regional/addons/providers-guest.json +588 -0
  92. data/samples/regional/addons/providers-logged.json +705 -0
  93. data/samples/regional/addons/provision-201.json +58 -0
  94. data/samples/regional/addons/provision-400.json +29 -0
  95. data/samples/regional/addons/sso-200.json +49 -0
  96. data/samples/regional/addons/sso-404.json +24 -0
  97. data/samples/regional/addons/update-200.json +58 -0
  98. data/samples/regional/addons/update-404.json +30 -0
  99. data/samples/regional/apps/_meta.json +52 -0
  100. data/samples/regional/apps/all.json +99 -0
  101. data/samples/regional/apps/create-201.json +66 -0
  102. data/samples/regional/apps/create-422.json +34 -0
  103. data/samples/regional/apps/destroy-204.json +19 -0
  104. data/samples/regional/apps/destroy-404.json +24 -0
  105. data/samples/regional/apps/destroy-422.json +27 -0
  106. data/samples/regional/apps/find-200.json +60 -0
  107. data/samples/regional/apps/find-404.json +24 -0
  108. data/samples/regional/apps/logs_url.json +62 -0
  109. data/samples/regional/apps/rename-200.json +65 -0
  110. data/samples/regional/apps/rename-404.json +29 -0
  111. data/samples/regional/apps/rename-422.json +33 -0
  112. data/samples/regional/apps/transfer-200.json +65 -0
  113. data/samples/regional/apps/transfer-404.json +27 -0
  114. data/samples/regional/apps/transfer-422.json +34 -0
  115. data/samples/regional/apps/update-200.json +66 -0
  116. data/samples/regional/apps/update-stack-404.json +30 -0
  117. data/samples/regional/collaborators/_meta.json +17 -0
  118. data/samples/regional/collaborators/accept-200.json +60 -0
  119. data/samples/regional/collaborators/accept-400.json +24 -0
  120. data/samples/regional/collaborators/accept-404.json +24 -0
  121. data/samples/regional/collaborators/destroy-204.json +19 -0
  122. data/samples/regional/collaborators/destroy-404.json +24 -0
  123. data/samples/regional/collaborators/for-200.json +34 -0
  124. data/samples/regional/collaborators/invite-201.json +37 -0
  125. data/samples/regional/collaborators/invite-422.json +34 -0
  126. data/samples/regional/containers/_meta.json +25 -0
  127. data/samples/regional/containers/for-200.json +39 -0
  128. data/samples/regional/containers/restart-202.json +28 -0
  129. data/samples/regional/containers/restart-422.json +33 -0
  130. data/samples/regional/containers/scale-202.json +48 -0
  131. data/samples/regional/containers/scale-422.json +36 -0
  132. data/samples/regional/containers/sizes-guest.json +115 -0
  133. data/samples/regional/containers/sizes-logged.json +116 -0
  134. data/samples/regional/deployments/_meta.json +8 -0
  135. data/samples/regional/deployments/find-200.json +45 -0
  136. data/samples/regional/deployments/find-404.json +24 -0
  137. data/samples/regional/deployments/for-with-paging.json +35 -0
  138. data/samples/regional/deployments/for-without-pages.json +56 -0
  139. data/samples/regional/deployments/logs-200.json +22 -0
  140. data/samples/regional/deployments/logs-404.json +24 -0
  141. data/samples/regional/domains/_meta.json +21 -0
  142. data/samples/regional/domains/create-201.json +44 -0
  143. data/samples/regional/domains/create-422.json +33 -0
  144. data/samples/regional/domains/destroy-204.json +19 -0
  145. data/samples/regional/domains/destroy-404.json +24 -0
  146. data/samples/regional/domains/find-200.json +38 -0
  147. data/samples/regional/domains/find-404.json +24 -0
  148. data/samples/regional/domains/for-200.json +40 -0
  149. data/samples/regional/domains/update-200.json +44 -0
  150. data/samples/regional/domains/update-404.json +30 -0
  151. data/samples/regional/domains/update-422.json +33 -0
  152. data/samples/regional/environment/_meta.json +43 -0
  153. data/samples/regional/environment/bulk-destroy-204.json +19 -0
  154. data/samples/regional/environment/bulk-update-200.json +70 -0
  155. data/samples/regional/environment/create-201.json +36 -0
  156. data/samples/regional/environment/create-422.json +37 -0
  157. data/samples/regional/environment/destroy-204.json +19 -0
  158. data/samples/regional/environment/destroy-404.json +24 -0
  159. data/samples/regional/environment/for-200.json +31 -0
  160. data/samples/regional/environment/update-200.json +35 -0
  161. data/samples/regional/environment/update-404.json +30 -0
  162. data/samples/regional/events/_meta.json +3 -0
  163. data/samples/regional/events/all-200.json +619 -0
  164. data/samples/regional/events/categories-guest.json +66 -0
  165. data/samples/regional/events/categories-logged.json +67 -0
  166. data/samples/regional/events/for-200.json +404 -0
  167. data/samples/regional/events/types-guest.json +288 -0
  168. data/samples/regional/events/types-logged.json +289 -0
  169. data/samples/regional/logs/_meta.json +11 -0
  170. data/samples/regional/logs/archives-200.json +28 -0
  171. data/samples/regional/logs/get-guest-200.json +18 -0
  172. data/samples/regional/logs/get-logged-200.json +19 -0
  173. data/samples/regional/logs/get-with-limit-200.json +18 -0
  174. data/samples/regional/metrics/_meta.json +15 -0
  175. data/samples/regional/metrics/for-invalid-400.json +23 -0
  176. data/samples/regional/metrics/for-valid-cpu-200.json +747 -0
  177. data/samples/regional/metrics/for-valid-router-404.json +23 -0
  178. data/samples/regional/metrics/types-guest.json +66 -0
  179. data/samples/regional/metrics/types-logged.json +67 -0
  180. data/samples/regional/notifiers/_meta.json +23 -0
  181. data/samples/regional/notifiers/create-201.json +55 -0
  182. data/samples/regional/notifiers/create-404.json +30 -0
  183. data/samples/regional/notifiers/create-422.json +36 -0
  184. data/samples/regional/notifiers/destroy-204.json +19 -0
  185. data/samples/regional/notifiers/destroy-404.json +24 -0
  186. data/samples/regional/notifiers/find-200.json +47 -0
  187. data/samples/regional/notifiers/find-404.json +24 -0
  188. data/samples/regional/notifiers/for-200.json +49 -0
  189. data/samples/regional/notifiers/platforms-guest.json +184 -0
  190. data/samples/regional/notifiers/platforms-logged.json +185 -0
  191. data/samples/regional/notifiers/test-200.json +22 -0
  192. data/samples/regional/notifiers/test-404.json +25 -0
  193. data/samples/regional/notifiers/update-200.json +53 -0
  194. data/samples/regional/operations/_meta.json +5 -0
  195. data/samples/regional/operations/find-200.json +31 -0
  196. data/samples/regional/operations/find-404.json +24 -0
  197. data/samples/regional/scm_repo_links/_meta.json +22 -0
  198. data/samples/regional/scm_repo_links/create-201.json +54 -0
  199. data/samples/regional/scm_repo_links/destroy-204.json +15 -0
  200. data/samples/regional/scm_repo_links/manual-deploy-200.json +32 -0
  201. data/samples/regional/scm_repo_links/show-200.json +43 -0
  202. data/samples/regional/scm_repo_links/update-200.json +50 -0
  203. data/scalingo.gemspec +51 -0
  204. data/spec/scalingo/auth/keys_spec.rb +58 -0
  205. data/spec/scalingo/auth/scm_integrations_spec.rb +58 -0
  206. data/spec/scalingo/auth/tokens_spec.rb +74 -0
  207. data/spec/scalingo/auth/two_factor_auth_spec.rb +69 -0
  208. data/spec/scalingo/auth/user_spec.rb +25 -0
  209. data/spec/scalingo/regional/addons_spec.rb +133 -0
  210. data/spec/scalingo/regional/apps_spec.rb +137 -0
  211. data/spec/scalingo/regional/collaborators_spec.rb +69 -0
  212. data/spec/scalingo/regional/containers_spec.rb +67 -0
  213. data/spec/scalingo/regional/deployments_spec.rb +45 -0
  214. data/spec/scalingo/regional/domains_spec.rb +84 -0
  215. data/spec/scalingo/regional/environment_spec.rb +77 -0
  216. data/spec/scalingo/regional/events_spec.rb +65 -0
  217. data/spec/scalingo/regional/logs_spec.rb +39 -0
  218. data/spec/scalingo/regional/metrics_spec.rb +46 -0
  219. data/spec/scalingo/regional/notifiers_spec.rb +113 -0
  220. data/spec/scalingo/regional/operations_spec.rb +19 -0
  221. data/spec/scalingo/regional/scm_repo_links_spec.rb +48 -0
  222. metadata +488 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9fd4bd22f57705fe4066a2f1de8d830c4557383777a49b7a7258a9e8c7b99077
4
+ data.tar.gz: fbf139e41c1a12c007e08b6c64e4e8d3b54d14500f7b44b14c7ba4ba8bfce7be
5
+ SHA512:
6
+ metadata.gz: 06271d0e9010d2d4835be48fa43b49545600b63f938e75ef504d17cec8434f07a9f8a5efc15cf411c9a1729c308c99a9b3504539d134530bf93acd73ec2f4565
7
+ data.tar.gz: 819dd71a0fb81443f934c5ed6f500c7c03105cc1113f4df60cbdb2655d4cfd057d39d38d8535b78f58d24f6deabe4c4b800c31e1022f82d719547e7646ed33d3
@@ -0,0 +1,6 @@
1
+ *.swp
2
+
3
+ coverage/
4
+ /pkg
5
+
6
+ .rspec_status
@@ -0,0 +1,16 @@
1
+ inherit_from: []
2
+
3
+ inherit_gem:
4
+ standard: config/base.yml
5
+
6
+ require:
7
+ - standard
8
+ - rubocop-performance
9
+
10
+ Style/TrailingCommaInArguments:
11
+ Enabled: true
12
+ EnforcedStyleForMultiline: consistent_comma
13
+
14
+ Style/Alias:
15
+ Enabled: true
16
+ EnforcedStyle: prefer_alias_method
@@ -0,0 +1,24 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.5.8
5
+ - 2.6.6
6
+ - 2.7.1
7
+ before_install:
8
+ - gem install bundler
9
+ install: bundle update --jobs=3 --retry=3
10
+
11
+ stages:
12
+ - lint
13
+ - test
14
+
15
+ jobs:
16
+ include:
17
+ - stage: lint
18
+ name: "Linter"
19
+ language: ruby
20
+ rvm: 2.7.1
21
+ before_install:
22
+ - gem install bundler
23
+ install: bundle update --jobs=3 --retry=3
24
+ script: bundle exec rubocop
@@ -0,0 +1,29 @@
1
+ ## 3.0.0.beta1 - 2020/06/12
2
+
3
+ * Full rewrite of the gem, **zero** backwards compatibility. Refer to the `README` for more information.
4
+
5
+ ## 2.0.1 - 2019/12/11
6
+
7
+ * Bugfix: payload was not correctly serialized to JSON for POST/PUT/PATCH queries
8
+
9
+ ## 2.0.0 - 2019/12/05
10
+
11
+ * Compatibility with new API tokens
12
+ * Compatibility with multi-region infrastructure
13
+ * Add missing resources: `regions`, `autoscalers`, `notifiers`, `alerts`
14
+
15
+ ## 1.1.1 - 2019/01/08
16
+
17
+ * Update metadata on rubygems
18
+
19
+ ## 1.1.0 - 2019/01/08
20
+
21
+ * Add /apps/:id/containers and /apps/:id/stats endpoints
22
+
23
+ ## 1.0.0 - 2017/24/01
24
+
25
+ * First tag 1.0.0, API won't be broken
26
+
27
+ ## 1.0.0.alpha1
28
+
29
+ * Initial alpha release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in scalingo.gemspec
4
+ gemspec
@@ -0,0 +1,110 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ scalingo (3.0.0.beta.1)
5
+ activemodel (>= 5, < 7)
6
+ activesupport (>= 5, < 7)
7
+ dry-configurable (~> 0.11)
8
+ faraday (~> 1.0.1)
9
+ faraday_middleware (~> 1.0.0)
10
+ multi_json (~> 1.0, >= 1.0.3)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ activemodel (6.0.3.1)
16
+ activesupport (= 6.0.3.1)
17
+ activesupport (6.0.3.1)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (>= 0.7, < 2)
20
+ minitest (~> 5.1)
21
+ tzinfo (~> 1.1)
22
+ zeitwerk (~> 2.2, >= 2.2.2)
23
+ addressable (2.7.0)
24
+ public_suffix (>= 2.0.2, < 5.0)
25
+ ast (2.4.0)
26
+ coderay (1.1.2)
27
+ concurrent-ruby (1.1.6)
28
+ crack (0.4.3)
29
+ safe_yaml (~> 1.0.0)
30
+ diff-lcs (1.3)
31
+ dry-configurable (0.11.5)
32
+ concurrent-ruby (~> 1.0)
33
+ dry-core (~> 0.4, >= 0.4.7)
34
+ dry-equalizer (~> 0.2)
35
+ dry-core (0.4.9)
36
+ concurrent-ruby (~> 1.0)
37
+ dry-equalizer (0.3.0)
38
+ faraday (1.0.1)
39
+ multipart-post (>= 1.2, < 3)
40
+ faraday_middleware (1.0.0)
41
+ faraday (~> 1.0)
42
+ hashdiff (1.0.1)
43
+ i18n (1.8.3)
44
+ concurrent-ruby (~> 1.0)
45
+ method_source (1.0.0)
46
+ minitest (5.14.1)
47
+ multi_json (1.14.1)
48
+ multipart-post (2.1.1)
49
+ parallel (1.19.1)
50
+ parser (2.7.1.2)
51
+ ast (~> 2.4.0)
52
+ pry (0.13.1)
53
+ coderay (~> 1.1)
54
+ method_source (~> 1.0)
55
+ public_suffix (4.0.4)
56
+ rainbow (3.0.0)
57
+ rake (10.5.0)
58
+ rexml (3.2.4)
59
+ rspec (3.9.0)
60
+ rspec-core (~> 3.9.0)
61
+ rspec-expectations (~> 3.9.0)
62
+ rspec-mocks (~> 3.9.0)
63
+ rspec-core (3.9.1)
64
+ rspec-support (~> 3.9.1)
65
+ rspec-expectations (3.9.1)
66
+ diff-lcs (>= 1.2.0, < 2.0)
67
+ rspec-support (~> 3.9.0)
68
+ rspec-mocks (3.9.1)
69
+ diff-lcs (>= 1.2.0, < 2.0)
70
+ rspec-support (~> 3.9.0)
71
+ rspec-support (3.9.2)
72
+ rubocop (0.83.0)
73
+ parallel (~> 1.10)
74
+ parser (>= 2.7.0.1)
75
+ rainbow (>= 2.2.2, < 4.0)
76
+ rexml
77
+ ruby-progressbar (~> 1.7)
78
+ unicode-display_width (>= 1.4.0, < 2.0)
79
+ rubocop-performance (1.5.2)
80
+ rubocop (>= 0.71.0)
81
+ ruby-progressbar (1.10.1)
82
+ safe_yaml (1.0.5)
83
+ standard (0.4.2)
84
+ rubocop (~> 0.83.0)
85
+ rubocop-performance (~> 1.5.2)
86
+ thread_safe (0.3.6)
87
+ tzinfo (1.2.7)
88
+ thread_safe (~> 0.1)
89
+ unicode-display_width (1.7.0)
90
+ webmock (3.8.3)
91
+ addressable (>= 2.3.6)
92
+ crack (>= 0.3.2)
93
+ hashdiff (>= 0.4.0, < 2.0.0)
94
+ zeitwerk (2.3.0)
95
+
96
+ PLATFORMS
97
+ ruby
98
+
99
+ DEPENDENCIES
100
+ bundler (~> 2.0)
101
+ pry (~> 0.13.1)
102
+ rake (~> 10.0)
103
+ rspec (~> 3.0)
104
+ rubocop (~> 0.83.0)
105
+ scalingo!
106
+ standard (~> 0.4.2)
107
+ webmock (~> 3.8.0)
108
+
109
+ BUNDLED WITH
110
+ 2.1.4
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 aki017
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,147 @@
1
+ # Scalingo
2
+
3
+ A ruby wrapper for the Scalingo API
4
+
5
+ ### Migration from v2
6
+
7
+ This gem is changing its name from `scalingo-ruby-api` to `scalingo`,
8
+ and the versionning does **not** reset; the first major version of `scalingo`
9
+ will therefore be `3.x.x`.
10
+
11
+ You can check the version 2 at [the v2 branch of this repository](https://github.com/Scalingo/scalingo-ruby-api/tree/v2)
12
+
13
+ ### The road to 3.0.0
14
+
15
+ This gem is still in beta version, but its API should not change a lot until a final release.
16
+ However, configuration may change. An issue will be opened and pinned to follow up the work that remains to be done.
17
+
18
+ ## Installation
19
+
20
+ ```ruby
21
+ gem "scalingo", "3.0.0.beta.1"
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ ```
27
+ bundle
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ```ruby
33
+ require "scalingo"
34
+
35
+ scalingo = Scalingo::Client.new
36
+ scalingo.authenticate_with(access_token: ENV["SCALINGO_TOKEN"])
37
+ scalingo.user.self
38
+ ```
39
+
40
+ ## Conventions
41
+
42
+ Most methods map to one (and only one) request, and their signature follows this format:
43
+
44
+ ```ruby
45
+ client.section.request(id, payload = {}, headers = nil, &block)
46
+ ```
47
+
48
+ * Depending on the request, there may be no id (collection and/or singular resource, such as `user`), one, or two ids (many resources are nested under an app).
49
+ * Most of the time, this library won't do any processing of the payload, but there's a few things to know:
50
+ * the root key shouldn't be specified, the library handles it
51
+ * in some cases, the payload isn't passed as supplied (`metrics`, for instance, extracts the parts that are meant to be used as url fragments)
52
+ * headers can be supplied on a per-request basis, using either the last argument or the block version:
53
+ * when using the last argument, you may have to pass an empty hash payload (`{}`)
54
+ * when using the block form, the faraday object is supplied as argument, and you can do any kind of treatment you would like
55
+
56
+ ## Configuration
57
+
58
+ ```ruby
59
+ Scalingo.configure do |config|
60
+ # Known regions. Each region should have a corresponding entry in the urls settings below
61
+ config.regions = %i[osc_fr1 osc_secnum_fr1]
62
+
63
+ # Default region
64
+ config.defaul_region = :osc_fr1
65
+
66
+ # Endpoints URLS
67
+ config.urls.auth = "https://auth.scalingo.com/v1"
68
+ config.urls.osc_fr1 = "https://api.osc-fr1.scalingo.com/v1"
69
+ config.urls.osc_secnum_fr1 = "https://api.osc-secnum-fr1.scalingo.com/v1"
70
+
71
+ # Configure the User Agent header
72
+ config.user_agent = "Scalingo Ruby Client v#{Scalingo::VERSION}"
73
+
74
+ # For how long is a bearer token considered valid (it will raise passed this delay).
75
+ # Set to nil to never raise.
76
+ config.exchanged_token_validity = 1.hour
77
+
78
+ # Raise an exception when trying to use an authenticated connection without a bearer token set
79
+ # Having this setting to true prevents performing requests that would fail due to lack of authentication headers.
80
+ config.raise_on_missing_authentication = true
81
+
82
+ # These headers will be added to every request. Individual methods may override them.
83
+ # This should be a hash or a callable object that returns a hash.
84
+ config.additional_headers = {}
85
+
86
+ # Raise an exception when the bearer token in use is supposed to be invalid
87
+ config.raise_on_expired_token = false
88
+ end
89
+ ```
90
+
91
+ :warning: If you change the settings for the list of regions, you **cannot** use `require "scalingo"`; you must follow this template :
92
+
93
+ ```ruby
94
+
95
+ require "scalingo/config"
96
+
97
+ Scalingo.configure do |config|
98
+ config.regions = %i[my-regions]
99
+ end
100
+
101
+ require "scalingo/client"
102
+ ```
103
+
104
+ ## Response object
105
+
106
+ Responses are parsed with the keys symbolized and then encapsulated in a `Scalingo::API::Response` object:
107
+ * `response.status` containts the HTTP status code
108
+ * `response.data` contains the "relevant" data, without the json root key (when relevant)
109
+ * `response.full_data` contains the full response body
110
+ * `response.meta` contains the meta object, if there's any
111
+ * `response.headers` containts all the response headers
112
+
113
+ Some helper methods are defined on this object:
114
+ * `response.successful?` returns true when the code is 2XX
115
+ * `response.paginated?` returns true if the reponse has metadata relative to pagination
116
+ * `response.operation?` returns true if the response contains a header relative to an ongoing operation
117
+ * `response.operation` returns the URL to query to get the status of the operation
118
+
119
+ ## Examples
120
+
121
+ ```ruby
122
+ require "scalingo"
123
+
124
+ scalingo = Scalingo::Client.new
125
+
126
+ scalingo.authenticate_with(access_token: "my_access_token")
127
+ # OR
128
+ scalingo.authenticate_with(bearer_token: "my_bearer_jwt")
129
+
130
+ # Return your profile
131
+ scalingo.self
132
+
133
+ # List your SSH Keys
134
+ scalingo.keys.all # OR scalingo.auth.keys.all
135
+
136
+ # Show one SSH Key
137
+ scalingo.keys.show("my-key-id")
138
+
139
+ # List your apps on the default region
140
+ scalingo.apps.all # OR scalingo.region.apps.all
141
+
142
+ # List your apps on osc-fr1
143
+ scalingo.osc_fr1.apps.all
144
+
145
+ # Preview the creation of an app on the default region
146
+ scalingo.apps.create(name: "my-new-app", dry_run: true)
147
+ ```
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "scalingo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+
12
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,2 @@
1
+ require "scalingo/config"
2
+ require "scalingo/client"
@@ -0,0 +1,79 @@
1
+ module Scalingo
2
+ module API
3
+ class Client
4
+ attr_reader :scalingo, :url
5
+
6
+ def initialize(scalingo, url)
7
+ @scalingo = scalingo
8
+ @url = url
9
+ end
10
+
11
+ def self.register_handlers!(handlers)
12
+ handlers.each do |method_name, klass|
13
+ define_method(method_name) do
14
+ value = instance_variable_get("@#{method_name}")
15
+
16
+ if value.nil?
17
+ value = klass.new(self)
18
+ instance_variable_set("@#{method_name}", value)
19
+ end
20
+
21
+ value
22
+ end
23
+ end
24
+ end
25
+
26
+ ## Faraday objects
27
+ def connection_options
28
+ headers = {
29
+ "User-Agent" => Scalingo.config.user_agent
30
+ }
31
+
32
+ if (extra = Scalingo.config.additional_headers).present?
33
+ extra.respond_to?(:call) ? headers.update(extra.call) : headers.update(extra)
34
+ end
35
+
36
+ {
37
+ url: url,
38
+ headers: headers
39
+ }
40
+ end
41
+
42
+ def connection(allow_guest: false)
43
+ if allow_guest
44
+ begin
45
+ authenticated_connection
46
+ rescue
47
+ unauthenticated_connection
48
+ end
49
+ else
50
+ authenticated_connection
51
+ end
52
+ end
53
+
54
+ def unauthenticated_connection
55
+ @unauthenticated_conn ||= Faraday.new(connection_options) { |conn|
56
+ conn.response :json, content_type: /\bjson$/, parser_options: {symbolize_names: true}
57
+ }
58
+ end
59
+
60
+ def authenticated_connection
61
+ return @connection if @connection
62
+
63
+ if Scalingo.config.raise_on_missing_authentication && !scalingo.token&.value
64
+ raise Error::Unauthenticated
65
+ end
66
+
67
+ @connection = Faraday.new(connection_options) { |conn|
68
+ conn.response :json, content_type: /\bjson$/, parser_options: {symbolize_names: true}
69
+ conn.request :json
70
+
71
+ if scalingo.token&.value
72
+ auth_header = Faraday::Request::Authorization.header "Bearer", scalingo.token.value
73
+ conn.headers[Faraday::Request::Authorization::KEY] = auth_header
74
+ end
75
+ }
76
+ end
77
+ end
78
+ end
79
+ end