heroku-api-postgres 0.8.0 → 0.9.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7a09cc3fbeffddb666ebaf4aea6bcbaba6484444324fea9a9e1ebae90cdd60d
4
- data.tar.gz: 37b4d464d7aa946682746bd681d249b734c25c7af135765a5918f1d602871b5b
3
+ metadata.gz: 5e17b99dc543d3fd1e6f2a6715ac43d13755396889f8f31ce0446d2d21a388bf
4
+ data.tar.gz: f3ce7542620d9795cce4be9905ac2eb5858641a1b4e53ae23991dbd4177a3646
5
5
  SHA512:
6
- metadata.gz: c993332ae8a356df764756757fcedf7d49aa434c8798272ace192615efe69df3af8e02ecc7e7d0d0ea6f9f44ca5a83d77ec1acaef728f3a8ab24e1ee3270bf0b
7
- data.tar.gz: 0cf779f3a5dc93ce0b908d1cdc02e086fae30c993d71b1c5020ae2ab27f4ca22f11832ee2e71e2a2e7dcc3ecb9acca33fb90358ddfec769e623f97cda2e2607e
6
+ metadata.gz: 9574ed0d23a7ecfbfa42ad9bdc840adb62c99838000e21c752ca26da8e71add8b2130014560f660b1480e8617672b2b217d597b16e488729262c3159cc12384a
7
+ data.tar.gz: b96833ab4c871a9c6af5fe2a642dafb66c6a011d69e5b6c57c619d64b1f1ec52bb4aed80e2ceeaaaf6dbcf6af360f469fbdfcf2b0b081a5079770caa307edcfe
data/.example.env CHANGED
@@ -1,3 +1,5 @@
1
1
  HEROKU_OAUTH_TOKEN=a_valid_oauth_token
2
+ VALID_APP_ID_WITH_DATABASE=valid_app_id_with_database
2
3
  VALID_DATABASE_ID_WITH_SCHEDULES=a_valid_database_id_with_a_schedule
3
4
  VALID_APP_ID=valid_app_id
5
+ VALID_DUMP_URL=valid_dump_public_url
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- heroku-api-postgres (0.8.0)
4
+ heroku-api-postgres (0.9.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -64,4 +64,4 @@ DEPENDENCIES
64
64
  webmock (~> 3.3.0)
65
65
 
66
66
  BUNDLED WITH
67
- 1.16.1
67
+ 1.16.2
data/README.md CHANGED
@@ -141,13 +141,30 @@ Returns a [BackupUrl](docs/models.md#backup_url)
141
141
 
142
142
  ---
143
143
 
144
+ ```ruby
145
+ backup = backups_client.restore(database_id, dump_url)
146
+ ```
147
+ Restores a dump from a public URL.
148
+
149
+ Returns a [Backup](docs/models.md#backup)
150
+
151
+ ---
152
+
144
153
  ```ruby
145
154
  backup = postgres_api_client.backups.wait(app_id, backup_id, wait_interval: 5)
146
155
  ```
147
- Waits for the given backup to be ready.
156
+ Waits for the given backup/restore to be ready.
148
157
 
149
158
  Polls every `wait_interval` seconds (default 3).
150
159
 
160
+ You can pass a block to be executed at each interval:
161
+
162
+ ```ruby
163
+ backup = postgres_api_client.backups.wait(app_id, backup_id) do |info|
164
+ puts "Processed #{info[:processed_bytes]} bytes"
165
+ end
166
+ ```
167
+
151
168
 
152
169
  ### How do I get the database_id ?
153
170
  You can obtain a database id by calling the Heroku Platform API
@@ -40,14 +40,18 @@ module Heroku
40
40
  end
41
41
 
42
42
  def wait(app_id, backup_id, options = { wait_interval: 3 })
43
- waiting = true
44
- while waiting do
43
+ while true do
45
44
  backup = info(app_id, backup_id)
45
+ yield(backup)
46
46
  break if backup[:finished_at] && backup[:succeeded]
47
47
  sleep(options[:wait_interval])
48
48
  end
49
49
  backup
50
50
  end
51
+
52
+ def restore(database_id, backup_url)
53
+ @client.perform_post_request("/client/v11/databases/#{database_id}/restores", backup_url: backup_url)
54
+ end
51
55
  end
52
56
  end
53
57
  end
@@ -36,9 +36,18 @@ module Heroku
36
36
  parse_response(response)
37
37
  end
38
38
 
39
+ def host_for(database)
40
+ starter_plan?(database) ? 'https://postgres-starter-api.heroku.com' : 'https://postgres-api.heroku.com'
41
+ end
42
+
43
+ def starter_plan?(database)
44
+ database[:plan].match(/(dev|basic)$/)
45
+ end
46
+
39
47
  private
40
- def build_uri(path)
41
- URI.join(@basic_url, path)
48
+
49
+ def build_uri(path, host: @basic_url)
50
+ URI.join(host, path)
42
51
  end
43
52
 
44
53
  def set_headers(req)
@@ -1,7 +1,7 @@
1
1
  module Heroku
2
2
  module Api
3
3
  module Postgres
4
- VERSION = '0.8.0'.freeze
4
+ VERSION = '0.9.0'.freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku-api-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Rodi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-08 00:00:00.000000000 Z
11
+ date: 2018-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler