heroku-api-postgres 0.9.1 → 0.10.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: 7c90ef28a844e1ea19534eeb565472875bbb8c049c19075bad257198a2ec00a5
4
- data.tar.gz: 7d185232a2d4667c267326948ada22bddf479b196825e7a67e1398f789626d66
3
+ metadata.gz: c56338fe1245b0057948e9e73ae0acc50189c919179ff5a14b639acc65c70107
4
+ data.tar.gz: 1a9f93ce79cb56ee9acf15cabcd6801b5ae40799be3b8edf14c46f7ad54470d4
5
5
  SHA512:
6
- metadata.gz: f776c9d1aeb9e6fc4bae092a6b11d9d5db88376a33932fc1e3b315262a44d5b762a971cc0ab0945c53fad4ae421bfce14629d9e0d01457aefdb2fab7c730190f
7
- data.tar.gz: b05b444642bca56f8d69f2bb09a109c87c080a761b7fa85f13376c0a139689a4a3689f461a72af9bb345c761282f9bbc2651d5b20e3ab2990b94247135083c74
6
+ metadata.gz: 549f65ec6c17141d3c1c819ec125112ef739df449f2a9cefdf61bf7f4af11346cda3ab939d99712171192c6a6a6d3b7aa8412096d43c1f1b5f98dda8534e281e
7
+ data.tar.gz: 124fc6dfcbef2aca4476ad24f6c5aaf00e8a5236e2a0fa9fe4e0bce0bc31018de78ed9531104dc91545eb7b6e378ba853c65888499a1bc50ee1b69de0dea65c0
@@ -1,5 +1,6 @@
1
1
  HEROKU_OAUTH_TOKEN=a_valid_oauth_token
2
2
  VALID_APP_ID_WITH_DATABASE=valid_app_id_with_database
3
3
  VALID_DATABASE_ID_WITH_SCHEDULES=a_valid_database_id_with_a_schedule
4
+ VALID_DATABASE_ID_WITH_PRO_PLAN=a_valid_database_id_with_a_pro_plan
4
5
  VALID_APP_ID=valid_app_id
5
6
  VALID_DUMP_URL=valid_dump_public_url
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- heroku-api-postgres (0.9.0)
4
+ heroku-api-postgres (0.10.0)
5
+ platform-api
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
@@ -12,38 +13,52 @@ GEM
12
13
  crack (0.4.3)
13
14
  safe_yaml (~> 1.0.0)
14
15
  diff-lcs (1.3)
15
- dotenv (2.2.1)
16
+ dotenv (2.5.0)
17
+ erubis (2.7.0)
18
+ excon (0.62.0)
16
19
  hashdiff (0.3.7)
20
+ heroics (0.0.25)
21
+ erubis (~> 2.0)
22
+ excon
23
+ moneta
24
+ multi_json (>= 1.9.2)
25
+ jaro_winkler (1.5.1)
26
+ moneta (1.0.0)
27
+ multi_json (1.13.1)
17
28
  parallel (1.12.1)
18
- parser (2.5.0.2)
29
+ parser (2.5.3.0)
19
30
  ast (~> 2.4.0)
20
- powerpack (0.1.1)
21
- public_suffix (3.0.2)
31
+ platform-api (2.2.0)
32
+ heroics (~> 0.0.25)
33
+ moneta (~> 1.0.0)
34
+ powerpack (0.1.2)
35
+ public_suffix (3.0.3)
22
36
  rainbow (3.0.0)
23
37
  rake (10.5.0)
24
- rspec (3.7.0)
25
- rspec-core (~> 3.7.0)
26
- rspec-expectations (~> 3.7.0)
27
- rspec-mocks (~> 3.7.0)
28
- rspec-core (3.7.1)
29
- rspec-support (~> 3.7.0)
30
- rspec-expectations (3.7.0)
38
+ rspec (3.8.0)
39
+ rspec-core (~> 3.8.0)
40
+ rspec-expectations (~> 3.8.0)
41
+ rspec-mocks (~> 3.8.0)
42
+ rspec-core (3.8.0)
43
+ rspec-support (~> 3.8.0)
44
+ rspec-expectations (3.8.2)
31
45
  diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.7.0)
33
- rspec-mocks (3.7.0)
46
+ rspec-support (~> 3.8.0)
47
+ rspec-mocks (3.8.0)
34
48
  diff-lcs (>= 1.2.0, < 2.0)
35
- rspec-support (~> 3.7.0)
36
- rspec-support (3.7.1)
37
- rubocop (0.52.1)
49
+ rspec-support (~> 3.8.0)
50
+ rspec-support (3.8.0)
51
+ rubocop (0.60.0)
52
+ jaro_winkler (~> 1.5.1)
38
53
  parallel (~> 1.10)
39
- parser (>= 2.4.0.2, < 3.0)
54
+ parser (>= 2.5, != 2.5.1.1)
40
55
  powerpack (~> 0.1)
41
56
  rainbow (>= 2.2.2, < 4.0)
42
57
  ruby-progressbar (~> 1.7)
43
- unicode-display_width (~> 1.0, >= 1.0.1)
44
- ruby-progressbar (1.9.0)
58
+ unicode-display_width (~> 1.4.0)
59
+ ruby-progressbar (1.10.0)
45
60
  safe_yaml (1.0.4)
46
- unicode-display_width (1.3.0)
61
+ unicode-display_width (1.4.0)
47
62
  vcr (4.0.0)
48
63
  webmock (3.3.0)
49
64
  addressable (>= 2.3.6)
@@ -54,14 +69,14 @@ PLATFORMS
54
69
  ruby
55
70
 
56
71
  DEPENDENCIES
57
- bundler (~> 1.16)
72
+ bundler (~> 1.17)
58
73
  dotenv
59
74
  heroku-api-postgres!
60
75
  rake (~> 10.0)
61
76
  rspec (~> 3.0)
62
- rubocop (= 0.52.1)
77
+ rubocop (= 0.60.0)
63
78
  vcr (~> 4.0.0)
64
79
  webmock (~> 3.3.0)
65
80
 
66
81
  BUNDLED WITH
67
- 1.16.2
82
+ 1.17.1
data/README.md CHANGED
@@ -34,20 +34,13 @@ Or install it yourself as:
34
34
 
35
35
  ## Usage
36
36
 
37
- Even if this gem does not require `platform-api` to be installed, you probably want to have it installed as well.
38
-
39
- ```ruby
40
- # from platform api gem
41
- platform_api_client = PlatformAPI.connect_oauth(ENV['HEROKU_OAUTH_TOKEN'])
42
- ```
43
-
44
- this gem client needs to be instantiated as well in a similar way
37
+ This gem client needs to be instantiated in a similar way to the PlatformAPI
45
38
 
46
39
  ```ruby
47
40
  postgres_api_client = Heroku::Api::Postgres.connect_oauth(ENV['HEROKU_OAUTH_TOKEN'])
48
41
  ```
49
42
 
50
- Look into [Models](docs/models.rb) for a detailed description of the JSON objects returned by the APIs.
43
+ Look into [Models](docs/models.md) for a detailed description of the JSON objects returned by the APIs.
51
44
  Those are the bare objects returned by the official Heroku API.
52
45
 
53
46
  ### Databases
@@ -69,11 +62,11 @@ returns a [Database](docs/models.md#database).
69
62
  ```ruby
70
63
  database = postgres_api_client.databases.wait(database_id, wait_interval: 5)
71
64
  ```
65
+
72
66
  Waits for the given database to be ready.
73
67
 
74
68
  Polls every `wait_interval` seconds (default 3).
75
69
 
76
-
77
70
  ### Backups
78
71
 
79
72
  ```ruby
@@ -103,7 +96,7 @@ The app_id can be either the name of your heroku app or the id.
103
96
  ---
104
97
 
105
98
  ```ruby
106
- schedules = backups_client.schedules(database_id)
99
+ schedules = backups_client.schedules(app_id, database_id)
107
100
  ```
108
101
 
109
102
  Returns all the backup schedules associated with the database.
@@ -113,7 +106,7 @@ Returns an array of [Schedule](docs/models.md#schedule)
113
106
  ---
114
107
 
115
108
  ```ruby
116
- schedule = backups_client.schedule(database_id)
109
+ schedule = backups_client.schedule(app_id, database_id)
117
110
  ```
118
111
 
119
112
  Schedules the backups at 00:00 UTC.
@@ -124,7 +117,7 @@ Returns a [Schedule](docs/models.md#schedule)
124
117
 
125
118
 
126
119
  ```ruby
127
- backup = backups_client.capture(database_id)
120
+ backup = backups_client.capture(app_id, database_id)
128
121
  ```
129
122
  Captures a new backup for the given database
130
123
 
@@ -142,7 +135,7 @@ Returns a [BackupUrl](docs/models.md#backup_url)
142
135
  ---
143
136
 
144
137
  ```ruby
145
- backup = backups_client.restore(database_id, dump_url)
138
+ backup = backups_client.restore(app_id, database_id, dump_url)
146
139
  ```
147
140
  Restores a dump from a public URL.
148
141
 
@@ -180,7 +173,9 @@ Check also the [Offical API](https://devcenter.heroku.com/articles/platform-api-
180
173
  ## Development
181
174
 
182
175
  After checking out the repo, run `bin/setup` to install dependencies.
183
- Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
176
+ Then, run `rake spec` to run the tests.
177
+ You can run `bin/check` to run linter and the tests together.
178
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
184
179
 
185
180
  To install this gem onto your local machine, run `bundle exec rake install`.
186
181
  To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
@@ -200,4 +195,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
200
195
  ## Code of Conduct
201
196
 
202
197
  Everyone interacting in the Heroku::Api::Postgres project’s codebases, issue trackers, chat rooms and mailing lists is
203
- expected to follow the [code of conduct](https://github.com/[USERNAME]/heroku-api-postgres/blob/master/CODE_OF_CONDUCT.md).
198
+ expected to follow the [code of conduct](https://github.com/coorasse/heroku-api-postgres/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+
5
+ bundle exec rubocop -a
6
+
7
+ bundle exec rake spec
@@ -1,5 +1,4 @@
1
-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'heroku/api/postgres/version'
5
4
 
@@ -21,11 +20,12 @@ Gem::Specification.new do |spec|
21
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
21
  spec.require_paths = ['lib']
23
22
 
24
- spec.add_development_dependency 'bundler', '~> 1.16'
23
+ spec.add_dependency 'platform-api'
24
+ spec.add_development_dependency 'bundler', '~> 1.17'
25
25
  spec.add_development_dependency 'dotenv'
26
26
  spec.add_development_dependency 'rake', '~> 10.0'
27
27
  spec.add_development_dependency 'rspec', '~> 3.0'
28
- spec.add_development_dependency 'rubocop', '0.52.1'
28
+ spec.add_development_dependency 'rubocop', '0.60.0'
29
29
  spec.add_development_dependency 'vcr', '~> 4.0.0'
30
30
  spec.add_development_dependency 'webmock', '~> 3.3.0'
31
31
  end
@@ -1,5 +1,6 @@
1
1
  require 'net/http'
2
2
  require 'json'
3
+ require 'platform-api'
3
4
 
4
5
  module Heroku
5
6
  module Api
@@ -20,19 +21,20 @@ module Heroku
20
21
  @client.perform_get_request("/client/v11/apps/#{app_id}/transfers/#{backup_id}")
21
22
  end
22
23
 
23
- def schedules(database_id)
24
- @client.perform_get_request("/client/v11/databases/#{database_id}/transfer-schedules")
24
+ def schedules(app_id, database_id)
25
+ @client.perform_get_request("/client/v11/databases/#{database_id}/transfer-schedules",
26
+ host: db_host(app_id))
25
27
  end
26
28
 
27
- def schedule(database_id)
29
+ def schedule(app_id, database_id)
28
30
  @client.perform_post_request("/client/v11/databases/#{database_id}/transfer-schedules",
29
- hour: 00,
30
- timezone: 'UTC',
31
- schedule_name: 'DATABASE_URL')
31
+ { hour: 0o0,
32
+ timezone: 'UTC',
33
+ schedule_name: 'DATABASE_URL' }, host: db_host(app_id))
32
34
  end
33
35
 
34
- def capture(database_id)
35
- @client.perform_post_request("/client/v11/databases/#{database_id}/backups")
36
+ def capture(app_id, database_id)
37
+ @client.perform_post_request("/client/v11/databases/#{database_id}/backups", {}, host: db_host(app_id))
36
38
  end
37
39
 
38
40
  def url(app_id, backup_num)
@@ -40,17 +42,37 @@ module Heroku
40
42
  end
41
43
 
42
44
  def wait(app_id, backup_id, options = { wait_interval: 3 })
43
- while true do
45
+ backup = nil
46
+ loop do
44
47
  backup = info(app_id, backup_id)
45
48
  yield(backup) if block_given?
46
- break if backup[:finished_at] && backup[:succeeded]
49
+ break if backup[:finished_at]
50
+
47
51
  sleep(options[:wait_interval])
48
52
  end
49
53
  backup
50
54
  end
51
55
 
52
- def restore(database_id, backup_url)
53
- @client.perform_post_request("/client/v11/databases/#{database_id}/restores", backup_url: backup_url)
56
+ def restore(app_id, database_id, backup_url)
57
+ @client.perform_post_request("/client/v11/databases/#{database_id}/restores",
58
+ { backup_url: backup_url }, host: db_host(app_id))
59
+ end
60
+
61
+ private
62
+
63
+ def databases
64
+ @databases ||= Databases.new(@client)
65
+ end
66
+
67
+ def db_host(app_id)
68
+ database = heroku_client.addon.list_by_app(app_id).find do |addon|
69
+ addon['addon_service']['name'] == 'heroku-postgresql'
70
+ end
71
+ databases.host_for(database)
72
+ end
73
+
74
+ def heroku_client
75
+ @heroku_client ||= PlatformAPI.connect_oauth(@client.oauth_client_key)
54
76
  end
55
77
  end
56
78
  end
@@ -6,9 +6,11 @@ module Heroku
6
6
  end
7
7
 
8
8
  class Client
9
+ attr_reader :oauth_client_key
10
+
9
11
  def initialize(oauth_client_key)
10
12
  @oauth_client_key = oauth_client_key
11
- @basic_url = 'https://postgres-starter-api.heroku.com'
13
+ @basic_url = Databases::STARTER_HOST
12
14
  end
13
15
 
14
16
  def backups
@@ -19,38 +21,30 @@ module Heroku
19
21
  @databases ||= Databases.new(self)
20
22
  end
21
23
 
22
- def perform_get_request(path)
23
- url = build_uri(path)
24
+ def perform_get_request(path, options = {})
25
+ url = build_uri(path, options)
24
26
  req = Net::HTTP::Get.new(url)
25
- set_headers(req)
27
+ add_auth_headers(req)
26
28
  response = start_request(req, url)
27
29
  parse_response(response)
28
30
  end
29
31
 
30
- def perform_post_request(path, params = {})
31
- url = build_uri(path)
32
+ def perform_post_request(path, params = {}, options = {})
33
+ url = build_uri(path, options)
32
34
  req = Net::HTTP::Post.new(url)
33
- set_headers(req)
35
+ add_auth_headers(req)
34
36
  req.body = params.to_json
35
37
  response = start_request(req, url)
36
38
  parse_response(response)
37
39
  end
38
40
 
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
-
47
41
  private
48
42
 
49
43
  def build_uri(path, host: @basic_url)
50
44
  URI.join(host, path)
51
45
  end
52
46
 
53
- def set_headers(req)
47
+ def add_auth_headers(req)
54
48
  req['Accept'] = 'application/vnd.heroku+json; version=3'
55
49
  req.basic_auth '', @oauth_client_key
56
50
  end
@@ -58,7 +52,7 @@ module Heroku
58
52
  def start_request(req, url)
59
53
  http_new = Net::HTTP.new(url.hostname, url.port)
60
54
  http_new.use_ssl = true
61
- response = http_new.start { |http| http.request(req) }
55
+ http_new.start { |http| http.request(req) }
62
56
  end
63
57
 
64
58
  def parse_response(response)
@@ -5,6 +5,9 @@ module Heroku
5
5
  module Api
6
6
  module Postgres
7
7
  class Databases
8
+ STARTER_HOST = 'https://postgres-starter-api.heroku.com'.freeze
9
+ PRO_HOST = 'https://postgres-api.heroku.com'.freeze
10
+
8
11
  def initialize(client)
9
12
  @client = client
10
13
  end
@@ -13,9 +16,10 @@ module Heroku
13
16
  # perform_get_request "/client/v11/databases/#{database_id}/wait_status"
14
17
  def wait(database_id, options = { wait_interval: 3 })
15
18
  waiting = true
16
- while waiting do
19
+ while waiting
17
20
  database = info(database_id)
18
21
  break unless database[:waiting?]
22
+
19
23
  sleep(options[:wait_interval])
20
24
  end
21
25
  database
@@ -24,6 +28,14 @@ module Heroku
24
28
  def info(database_id)
25
29
  @client.perform_get_request("/client/v11/databases/#{database_id}")
26
30
  end
31
+
32
+ def host_for(database)
33
+ starter_plan?(database) ? STARTER_HOST : PRO_HOST
34
+ end
35
+
36
+ def starter_plan?(database)
37
+ database['plan']['name'].match(/(dev|basic)$/)
38
+ end
27
39
  end
28
40
  end
29
41
  end
@@ -1,7 +1,7 @@
1
1
  module Heroku
2
2
  module Api
3
3
  module Postgres
4
- VERSION = '0.9.1'.freeze
4
+ VERSION = '0.10.0'.freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku-api-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.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-07-07 00:00:00.000000000 Z
11
+ date: 2019-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: platform-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.16'
33
+ version: '1.17'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '1.16'
40
+ version: '1.17'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: dotenv
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +86,14 @@ dependencies:
72
86
  requirements:
73
87
  - - '='
74
88
  - !ruby/object:Gem::Version
75
- version: 0.52.1
89
+ version: 0.60.0
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - '='
81
95
  - !ruby/object:Gem::Version
82
- version: 0.52.1
96
+ version: 0.60.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: vcr
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -126,6 +140,7 @@ files:
126
140
  - LICENSE.txt
127
141
  - README.md
128
142
  - Rakefile
143
+ - bin/check
129
144
  - bin/console
130
145
  - bin/setup
131
146
  - docs/models.md
@@ -156,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
171
  version: '0'
157
172
  requirements: []
158
173
  rubyforge_project:
159
- rubygems_version: 2.7.3
174
+ rubygems_version: 2.7.6
160
175
  signing_key:
161
176
  specification_version: 4
162
177
  summary: Ruby library to invoke Heroku Postgres APIs