heroku-api-postgres 0.1.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.example.env +3 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +9 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +67 -0
- data/LICENSE.txt +21 -0
- data/README.md +110 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/models.md +70 -0
- data/heroku-api-postgres.gemspec +31 -0
- data/lib/heroku/api/postgres.rb +4 -0
- data/lib/heroku/api/postgres/backups.rb +25 -0
- data/lib/heroku/api/postgres/client.rb +46 -0
- data/lib/heroku/api/postgres/databases.rb +18 -0
- data/lib/heroku/api/postgres/version.rb +7 -0
- metadata +162 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 70ef3b3e8b9dcbb7ff26bb3ab2955139c37b2ac033d42659ebe5171b64a71b93
|
4
|
+
data.tar.gz: 3dd3c311b97514fd01d402f243714f5882586cf4043ee9fcaca9fc78cd2e86cb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 948656e81085acabfef33754d325d2c2d25cfecb58ecf921f07f83451909aa05d53bca1c64cde4e2803cfa1da3ae426739501b4c106a7c8fa566365d2bb844d0
|
7
|
+
data.tar.gz: 27d7e102d98ea4fd8eccd7d920d942014232a193c3c88294a13fe75f2cbe018dfc51212e20dbc6de0c4886949275857144904b67b0431b32ab0ed288f97328a7
|
data/.example.env
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at alessandro.rodi@renuo.ch. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
heroku-api-postgres (0.1.0.alpha1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.5.2)
|
10
|
+
public_suffix (>= 2.0.2, < 4.0)
|
11
|
+
ast (2.4.0)
|
12
|
+
crack (0.4.3)
|
13
|
+
safe_yaml (~> 1.0.0)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
dotenv (2.2.1)
|
16
|
+
hashdiff (0.3.7)
|
17
|
+
parallel (1.12.1)
|
18
|
+
parser (2.5.0.2)
|
19
|
+
ast (~> 2.4.0)
|
20
|
+
powerpack (0.1.1)
|
21
|
+
public_suffix (3.0.2)
|
22
|
+
rainbow (3.0.0)
|
23
|
+
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)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.7.0)
|
33
|
+
rspec-mocks (3.7.0)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.7.0)
|
36
|
+
rspec-support (3.7.1)
|
37
|
+
rubocop (0.52.1)
|
38
|
+
parallel (~> 1.10)
|
39
|
+
parser (>= 2.4.0.2, < 3.0)
|
40
|
+
powerpack (~> 0.1)
|
41
|
+
rainbow (>= 2.2.2, < 4.0)
|
42
|
+
ruby-progressbar (~> 1.7)
|
43
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
44
|
+
ruby-progressbar (1.9.0)
|
45
|
+
safe_yaml (1.0.4)
|
46
|
+
unicode-display_width (1.3.0)
|
47
|
+
vcr (4.0.0)
|
48
|
+
webmock (3.3.0)
|
49
|
+
addressable (>= 2.3.6)
|
50
|
+
crack (>= 0.3.2)
|
51
|
+
hashdiff
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
ruby
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
bundler (~> 1.16)
|
58
|
+
dotenv
|
59
|
+
heroku-api-postgres!
|
60
|
+
rake (~> 10.0)
|
61
|
+
rspec (~> 3.0)
|
62
|
+
rubocop (= 0.52.1)
|
63
|
+
vcr (~> 4.0.0)
|
64
|
+
webmock (~> 3.3.0)
|
65
|
+
|
66
|
+
BUNDLED WITH
|
67
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Alessandro Rodi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# Heroku::Api::Postgres
|
2
|
+
|
3
|
+
Ruby library to invoke Heroku Postgres APIs.
|
4
|
+
An extension to the official [Platform API]() gem to introduce the missing APIs for Postgres.
|
5
|
+
|
6
|
+
[![Build Status](https://travis-ci.org/coorasse/heroku-api-postgres.svg?branch=master)](https://travis-ci.org/coorasse/heroku-api-postgres)
|
7
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/4eead5d8263c37498953/maintainability)](https://codeclimate.com/github/coorasse/heroku-api-postgres/maintainability)
|
8
|
+
|
9
|
+
**This gem is not officialy supported**. We use the same APIs that the offical Heroku Toolbelt uses,
|
10
|
+
therefore is unrealistic that a breaking change in the APIs would break it, since it means it would break
|
11
|
+
both this gem and the official Heroku CLI.
|
12
|
+
|
13
|
+
Not all APIs are implemented at the moment but we are working hard on implementing all of them.
|
14
|
+
|
15
|
+
Contributes and Pull Requests are welcome.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'heroku-api-postgres'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install heroku-api-postgres
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
Even if this gem does not require `platform-api` to be installed, you probably want to have it installed as well.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
# from platform api gem
|
39
|
+
platform_api_client = PlatformAPI.connect_oauth(ENV['HEROKU_OAUTH_TOKEN'])
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
this gem client needs to be instantiated as well in a similar way
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
postgres_api_client = Heroku::Api::Postgres.connect_oauth(ENV['HEROKU_OAUTH_TOKEN'])
|
47
|
+
```
|
48
|
+
|
49
|
+
Look into [Models](docs/models.rb) for a detailed description of the JSON objects returned by the APIs.
|
50
|
+
Those are the bare objects returned by the official Heroku API.
|
51
|
+
|
52
|
+
### Backups
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
backups_client = postgres_api_client.backups
|
56
|
+
```
|
57
|
+
|
58
|
+
#### List
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
backups = backups_client.list(app_id)
|
62
|
+
```
|
63
|
+
|
64
|
+
returns an array of [Backup](docs/models.md#backup).
|
65
|
+
|
66
|
+
The app_id can be either the name of your heroku app or the id. [Check official API](https://devcenter.heroku.com/articles/platform-api-reference#app)
|
67
|
+
|
68
|
+
#### Schedules
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
schedules = backups_client.schedules(database_id)
|
72
|
+
```
|
73
|
+
|
74
|
+
returns an array of [Schedule](docs/models.md#schedule)
|
75
|
+
|
76
|
+
|
77
|
+
To get the backup schedules of a database you need a database id. You can obtain a database id by calling the Heroku Platform API
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
addons = heroku.addon.list
|
81
|
+
databases = addons.select { |addon| addon['addon_service']['name'] == 'heroku-postgresql' }
|
82
|
+
databases_ids = databases.map{ |addon| addon['id'] }
|
83
|
+
```
|
84
|
+
|
85
|
+
Check also the [Offical API](https://devcenter.heroku.com/articles/platform-api-reference#add-on)
|
86
|
+
|
87
|
+
## Development
|
88
|
+
|
89
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
90
|
+
Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
91
|
+
|
92
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
93
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
|
94
|
+
which will create a git tag for the version, push git commits and tags,
|
95
|
+
and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
96
|
+
|
97
|
+
## Contributing
|
98
|
+
|
99
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/coorasse/heroku-api-postgres.
|
100
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
|
101
|
+
the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
102
|
+
|
103
|
+
## License
|
104
|
+
|
105
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
106
|
+
|
107
|
+
## Code of Conduct
|
108
|
+
|
109
|
+
Everyone interacting in the Heroku::Api::Postgres project’s codebases, issue trackers, chat rooms and mailing lists is
|
110
|
+
expected to follow the [code of conduct](https://github.com/[USERNAME]/heroku-api-postgres/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'heroku/api/postgres'
|
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
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/docs/models.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Models list and description
|
2
|
+
|
3
|
+
## Database
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
{ :addon_id=>"database_id",
|
7
|
+
:name=>"postgresql-horizontal-25349",
|
8
|
+
:info=>[ { :name=>"Plan", :values=>["Hobby-basic"] },
|
9
|
+
{ :name=>"Status", :values=>["Available"] },
|
10
|
+
{ :name=>"Connections", :values=>["3/20"] },
|
11
|
+
{ :name=>"PG Version", :values=>["9.5.5"] },
|
12
|
+
{ :name=>"Created", :values=>["2016-11-12 09:59 UTC"] },
|
13
|
+
{ :name=>"Data Size", :values=>["915.2 MB"] },
|
14
|
+
{ :name=>"Tables", :values=>[140] },
|
15
|
+
{ :name=>"Rows", :values=>["1788360/10000000 (In compliance)"] },
|
16
|
+
{ :name=>"Fork/Follow", :values=>["Unsupported"]},
|
17
|
+
{ :name=>"Rollback", :values=>["Unsupported"]},
|
18
|
+
{ :name=>"Continuous Protection", :values=>["Off"]},
|
19
|
+
{ :name=>"Region", :values=>["Europe"]}
|
20
|
+
],
|
21
|
+
:plan=>"Hobby-basic",
|
22
|
+
:created_at=>"2016-11-12T09:59:55.349+00:00",
|
23
|
+
:database_user=>"username",
|
24
|
+
:database_name=>"schema_name",
|
25
|
+
:available_for_ingress=>true,
|
26
|
+
:standalone?=>false,
|
27
|
+
:resource_url=>"postgres://username:password@url:5432/schema_name",
|
28
|
+
:waiting?=>false,
|
29
|
+
:num_bytes=>959652012 }
|
30
|
+
```
|
31
|
+
## Backup
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
{ :uuid=>"backup_id",
|
35
|
+
:num=>1,
|
36
|
+
:from_name=>"DATABASE",
|
37
|
+
:from_type=>"pg_dump",
|
38
|
+
:from_url=>"from_url",
|
39
|
+
:to_name=>"BACKUP",
|
40
|
+
:to_type=>"gof3r",
|
41
|
+
:to_url=>"to_url",
|
42
|
+
:options=>{},
|
43
|
+
:source_bytes=>9134252,
|
44
|
+
:processed_bytes=>50850,
|
45
|
+
:succeeded=>true,
|
46
|
+
:warnings=>0,
|
47
|
+
:created_at=>"2016-10-21 10:15:36 +0000",
|
48
|
+
:started_at=>"2016-10-21 10:15:36 +0000",
|
49
|
+
:canceled_at=>nil,
|
50
|
+
:updated_at=>"2016-10-21 10:16:08 +0000",
|
51
|
+
:finished_at=>"2016-10-21 10:16:05 +0000",
|
52
|
+
:deleted_at=>nil,
|
53
|
+
:purged_at=>nil,
|
54
|
+
:num_keep=>2 }
|
55
|
+
```
|
56
|
+
|
57
|
+
## Schedule
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
{ :uuid=>"schedule_id",
|
61
|
+
:name=>"DATABASE_URL",
|
62
|
+
:hour=>2,
|
63
|
+
:days=>["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
|
64
|
+
:timezone=>"Europe/Zurich",
|
65
|
+
:created_at=>"2018-01-09 11:28:57 +0000",
|
66
|
+
:updated_at=>"2018-03-02 01:19:52 +0000",
|
67
|
+
:deleted_at=>nil,
|
68
|
+
:retain_weeks=>1,
|
69
|
+
:retain_months=>0 }
|
70
|
+
```
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'heroku/api/postgres/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'heroku-api-postgres'
|
8
|
+
spec.version = Heroku::Api::Postgres::VERSION
|
9
|
+
spec.authors = ['Alessandro Rodi']
|
10
|
+
spec.email = ['coorasse@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Ruby library to invoke Heroku Postgres APIs'
|
13
|
+
spec.description = 'Ruby library to invoke Heroku Postgres APIs'
|
14
|
+
spec.homepage = 'https://github.com/coorasse/heroku-api-postgres'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
25
|
+
spec.add_development_dependency 'dotenv'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
spec.add_development_dependency 'rubocop', '0.52.1'
|
29
|
+
spec.add_development_dependency 'vcr', '~> 4.0.0'
|
30
|
+
spec.add_development_dependency 'webmock', '~> 3.3.0'
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Heroku
|
5
|
+
module Api
|
6
|
+
module Postgres
|
7
|
+
class Backups
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
# backups: from_type == 'pg_dump' && to_type == 'gof3r'
|
13
|
+
# restores: from_type != 'pg_dump' && to_type == 'pg_restore'
|
14
|
+
# copies: from_type == 'pg_dump' && to_type == 'pg_restore'
|
15
|
+
def list(app_id)
|
16
|
+
@client.perform_get_request("/client/v11/apps/#{app_id}/transfers")
|
17
|
+
end
|
18
|
+
|
19
|
+
def schedules(database_id)
|
20
|
+
@client.perform_get_request("/client/v11/databases/#{database_id}/transfer-schedules")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Heroku
|
2
|
+
module Api
|
3
|
+
module Postgres
|
4
|
+
|
5
|
+
def self.connect_oauth(oauth_client_key = ENV['HEROKU_OAUTH_TOKEN'])
|
6
|
+
Client.new(oauth_client_key)
|
7
|
+
end
|
8
|
+
|
9
|
+
class Client
|
10
|
+
def initialize(oauth_client_key)
|
11
|
+
@oauth_client_key = oauth_client_key
|
12
|
+
@basic_url = 'https://postgres-starter-api.heroku.com'
|
13
|
+
end
|
14
|
+
|
15
|
+
def backups
|
16
|
+
@backups ||= Backups.new(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def databases
|
20
|
+
@backups ||= Databases.new(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def perform_get_request(path)
|
24
|
+
url = URI.join(@basic_url, path)
|
25
|
+
req = Net::HTTP::Get.new(url)
|
26
|
+
req['Accept'] = 'application/vnd.heroku+json; version=3'
|
27
|
+
req.basic_auth '', @oauth_client_key
|
28
|
+
http_new = Net::HTTP.new(url.hostname, url.port)
|
29
|
+
http_new.use_ssl = true
|
30
|
+
response = http_new.start { |http| http.request(req) }
|
31
|
+
parse_response(response)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def parse_response(response)
|
37
|
+
if response.code == '200'
|
38
|
+
JSON.parse(response.body, symbolize_names: true)
|
39
|
+
else
|
40
|
+
{ error: { status: response.code.to_i } }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Heroku
|
5
|
+
module Api
|
6
|
+
module Postgres
|
7
|
+
class Databases
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
def info(database_id)
|
13
|
+
@client.perform_get_request("/client/v11/databases/#{database_id}")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: heroku-api-postgres
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.alpha1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alessandro Rodi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dotenv
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.52.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.52.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 4.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 4.0.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.3.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.3.0
|
111
|
+
description: Ruby library to invoke Heroku Postgres APIs
|
112
|
+
email:
|
113
|
+
- coorasse@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".example.env"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
122
|
+
- ".travis.yml"
|
123
|
+
- CODE_OF_CONDUCT.md
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- bin/console
|
130
|
+
- bin/setup
|
131
|
+
- docs/models.md
|
132
|
+
- heroku-api-postgres.gemspec
|
133
|
+
- lib/heroku/api/postgres.rb
|
134
|
+
- lib/heroku/api/postgres/backups.rb
|
135
|
+
- lib/heroku/api/postgres/client.rb
|
136
|
+
- lib/heroku/api/postgres/databases.rb
|
137
|
+
- lib/heroku/api/postgres/version.rb
|
138
|
+
homepage: https://github.com/coorasse/heroku-api-postgres
|
139
|
+
licenses:
|
140
|
+
- MIT
|
141
|
+
metadata: {}
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">"
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: 1.3.1
|
156
|
+
requirements: []
|
157
|
+
rubyforge_project:
|
158
|
+
rubygems_version: 2.7.3
|
159
|
+
signing_key:
|
160
|
+
specification_version: 4
|
161
|
+
summary: Ruby library to invoke Heroku Postgres APIs
|
162
|
+
test_files: []
|