platform-api 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +23 -20
- data/lib/platform-api/client.rb +3 -3
- data/lib/platform-api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc573a7f60a0a23121a4884dc04541d9fc11e47a
|
4
|
+
data.tar.gz: 1ebd353900700ec76f53f2df7d97795c0bbdc9b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f671726d70cc5228706cb0f997021c584ce1400491e752ce7063c4be1fcd19cee2bfc82510385f732b86d2f81f41fdf90b91158b07ee03a81c52beb703e14e0d
|
7
|
+
data.tar.gz: 3374fc2827b622e901a7c9ab1ce1035b0e0db5a7cededf4e4e570d47e28759d8ea370090058c511118614aaaca2ab65db9fd1641101bf4da21b8f29f6d243e8d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -36,15 +36,15 @@ information about the support actions. For example, the [Formation](https://dev
|
|
36
36
|
resource has [Info](https://devcenter.heroku.com/articles/platform-api-reference#formation-info), [List](https://devcenter.heroku.com/articles/platform-api-reference#formation-list), [Batch update](https://devcenter.heroku.com/articles/platform-api-reference#formation-batch-update), and [Update](https://devcenter.heroku.com/articles/platform-api-reference#formation-update) actions.
|
37
37
|
|
38
38
|
You can easily map any resource and its related action client methods. The
|
39
|
-
formation actions above are accessed as `
|
40
|
-
`
|
41
|
-
`
|
39
|
+
formation actions above are accessed as `heroku.formation.info`,
|
40
|
+
`heroku.formation.list`, `heroku.formation.batch_update` and
|
41
|
+
`heroku.formation.update`. When the URL for one of these actions includes
|
42
42
|
parameters they should be passed as arguments to the method. When the request
|
43
43
|
expects a request payload it should be passed as a Ruby Hash in the final
|
44
44
|
argument to the method.
|
45
45
|
|
46
46
|
For example, to get information about the `web` formation on the `sushi` app
|
47
|
-
you'd invoke `
|
47
|
+
you'd invoke `heroku.formation.info('sushi', 'web')` and it would return a
|
48
48
|
Ruby object that matches the one given in the [response example](https://devcenter.heroku.com/articles/platform-api-reference#formation-info).
|
49
49
|
|
50
50
|
Once you get used to these basic patterns using the client is quite easy
|
@@ -60,19 +60,19 @@ raises `Excon::Error` exceptions when errors occur. You can catch specific
|
|
60
60
|
### A real world example
|
61
61
|
|
62
62
|
Let's go through an example of creating an app and using the API to work with
|
63
|
-
it. The first thing you need is a client that's setup with your
|
64
|
-
|
63
|
+
it. The first thing you need is a client that's setup with your API token.
|
64
|
+
You can find your API token by clicking the *Show API Key* on your
|
65
65
|
[account page](https://dashboard.heroku.com/account).
|
66
66
|
|
67
67
|
```ruby
|
68
68
|
require 'platform-api'
|
69
|
-
|
69
|
+
heroku = PlatformAPI.connect('token')
|
70
70
|
```
|
71
71
|
|
72
72
|
Now let's create an app:
|
73
73
|
|
74
74
|
```ruby
|
75
|
-
|
75
|
+
heroku.app.create
|
76
76
|
=> {"id"=>22979756,
|
77
77
|
"name"=>"floating-retreat-4255",
|
78
78
|
"dynos"=>0,
|
@@ -107,7 +107,7 @@ client.app.create
|
|
107
107
|
We can read the same information back with the `info` method.
|
108
108
|
|
109
109
|
```ruby
|
110
|
-
|
110
|
+
heroku.app.info('floating-retreat-4255')
|
111
111
|
=> {"id"=>22979756,
|
112
112
|
"name"=>"floating-retreat-4255",
|
113
113
|
"dynos"=>0,
|
@@ -142,7 +142,7 @@ client.app.info('floating-retreat-4255')
|
|
142
142
|
Let's add a Heroku PostgreSQL database to our app now:
|
143
143
|
|
144
144
|
```ruby
|
145
|
-
|
145
|
+
heroku.addon.create('floating-retreat-4255', {'plan' => 'heroku-postgresql:dev'})
|
146
146
|
=> {"config_vars"=>["HEROKU_POSTGRESQL_COBALT_URL"],
|
147
147
|
"created_at"=>"2014-03-13T00:28:55Z",
|
148
148
|
"id"=>"79a0c826-06be-4dcd-8bb5-f2c1b1bc2beb",
|
@@ -157,16 +157,15 @@ client.addon.create('floating-retreat-4255', {'plan' => 'heroku-postgresql:dev'}
|
|
157
157
|
Excellent! That will have added a config var which we can now see:
|
158
158
|
|
159
159
|
```ruby
|
160
|
-
|
161
|
-
=>
|
162
|
-
{"HEROKU_POSTGRESQL_COBALT_URL"=>"postgres://<redacted>"}
|
160
|
+
heroku.config_var.info('floating-retreat-4255')
|
161
|
+
=> {"HEROKU_POSTGRESQL_COBALT_URL"=>"postgres://<redacted>"}
|
163
162
|
```
|
164
163
|
|
165
164
|
And there we go, we have the config var. Let's set an additional config var,
|
166
|
-
which will also demonstrate
|
165
|
+
which will also demonstrate how to make a request that needs a payload:
|
167
166
|
|
168
167
|
```ruby
|
169
|
-
|
168
|
+
heroku.config_var.update('floating-retreat-4255', {'MYAPP' => 'ROCKS'})
|
170
169
|
=> {"HEROKU_POSTGRESQL_COBALT_URL"=>"postgres://<redacted>",
|
171
170
|
"MYAPP"=>"ROCKS"}
|
172
171
|
```
|
@@ -204,7 +203,7 @@ Total 489 (delta 244), reused 489 (delta 244)
|
|
204
203
|
We can now use the API to see our `web` process running:
|
205
204
|
|
206
205
|
```ruby
|
207
|
-
|
206
|
+
heroku.formation.list('floating-retreat-4255')
|
208
207
|
=> [{"command"=>"coffee index.coffee",
|
209
208
|
"created_at"=>"2014-03-13T04:13:37Z",
|
210
209
|
"id"=>"f682b260-8089-4e18-b792-688cc02bf923",
|
@@ -217,7 +216,10 @@ client.formation.list('floating-retreat-4255')
|
|
217
216
|
Let's change `web` process to run on a 2X dyno:
|
218
217
|
|
219
218
|
```ruby
|
220
|
-
|
219
|
+
heroku.formation.batch_update('floating-retreat-4255',
|
220
|
+
{"updates" => [{"process" => "web",
|
221
|
+
"quantity" => 1,
|
222
|
+
"size" => "2X"}]})
|
221
223
|
=> [{"command"=>"coffee index.coffee",
|
222
224
|
"created_at"=>"2014-03-13T04:13:37Z",
|
223
225
|
"id"=>"f682b260-8089-4e18-b792-688cc02bf923",
|
@@ -232,7 +234,7 @@ command. We can use the singular update action to modify a single formation
|
|
232
234
|
type:
|
233
235
|
|
234
236
|
```ruby
|
235
|
-
|
237
|
+
heroku.formation.update('floating-retreat-4255', 'web', {"size" => "1X"})
|
236
238
|
=> {"command"=>"coffee index.coffee",
|
237
239
|
"created_at"=>"2014-03-13T04:13:37Z",
|
238
240
|
"id"=>"f682b260-8089-4e18-b792-688cc02bf923",
|
@@ -242,8 +244,9 @@ client.formation.update('floating-retreat-4255', 'web', {"size" => "1X"})
|
|
242
244
|
"updated_at"=>"2014-03-13T04:24:46Z"}
|
243
245
|
```
|
244
246
|
|
245
|
-
Hopefully this has given you a taste of how the client works
|
246
|
-
|
247
|
+
Hopefully this has given you a taste of how the client works and an
|
248
|
+
understanding of how resources and actions are mapped from the documentation.
|
249
|
+
If you have questions please feel free to file issues.
|
247
250
|
|
248
251
|
### Debugging
|
249
252
|
|
data/lib/platform-api/client.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module PlatformAPI
|
2
|
-
# Get a client configured with the specified
|
3
|
-
def self.connect(
|
4
|
-
url = "https
|
2
|
+
# Get a client configured with the specified token.
|
3
|
+
def self.connect( token)
|
4
|
+
url = "https://:#{token}@api.heroku.com"
|
5
5
|
default_headers = {'Accept' => 'application/vnd.heroku+json; version=3'}
|
6
6
|
cache = Moneta.new(:File, dir: "#{Dir.home}/.heroku/platform-api")
|
7
7
|
options = {default_headers: default_headers, cache: cache}
|
data/lib/platform-api/version.rb
CHANGED