gandi_v5 0.1.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 +7 -0
- data/.gitignore +24 -0
- data/.rspec +3 -0
- data/.rubocop.yml +20 -0
- data/.travis.yml +23 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +6 -0
- data/Guardfile +40 -0
- data/LICENSE.md +32 -0
- data/README.md +94 -0
- data/Rakefile +3 -0
- data/TODO.md +29 -0
- data/bin/console +13 -0
- data/gandi_v5.gemspec +41 -0
- data/lib/gandi_v5/billing/info/prepaid.rb +33 -0
- data/lib/gandi_v5/billing/info.rb +26 -0
- data/lib/gandi_v5/billing.rb +28 -0
- data/lib/gandi_v5/data/converter/array_of.rb +35 -0
- data/lib/gandi_v5/data/converter/symbol.rb +26 -0
- data/lib/gandi_v5/data/converter/time.rb +28 -0
- data/lib/gandi_v5/data/converter.rb +41 -0
- data/lib/gandi_v5/data.rb +244 -0
- data/lib/gandi_v5/domain/auto_renew.rb +64 -0
- data/lib/gandi_v5/domain/contact.rb +102 -0
- data/lib/gandi_v5/domain/contract.rb +22 -0
- data/lib/gandi_v5/domain/dates.rb +44 -0
- data/lib/gandi_v5/domain/renewal_information.rb +41 -0
- data/lib/gandi_v5/domain/restore_information.rb +18 -0
- data/lib/gandi_v5/domain/sharing_space.rb +21 -0
- data/lib/gandi_v5/domain.rb +431 -0
- data/lib/gandi_v5/email/mailbox/responder.rb +36 -0
- data/lib/gandi_v5/email/mailbox.rb +236 -0
- data/lib/gandi_v5/email/offer.rb +27 -0
- data/lib/gandi_v5/email/slot.rb +134 -0
- data/lib/gandi_v5/email.rb +11 -0
- data/lib/gandi_v5/error/gandi_error.rb +21 -0
- data/lib/gandi_v5/error.rb +9 -0
- data/lib/gandi_v5/live_dns/domain.rb +211 -0
- data/lib/gandi_v5/live_dns/record_set.rb +79 -0
- data/lib/gandi_v5/live_dns/zone/snapshot.rb +62 -0
- data/lib/gandi_v5/live_dns/zone.rb +301 -0
- data/lib/gandi_v5/live_dns.rb +30 -0
- data/lib/gandi_v5/organization.rb +66 -0
- data/lib/gandi_v5/version.rb +5 -0
- data/lib/gandi_v5.rb +178 -0
- data/spec/.rubocop.yml +4 -0
- data/spec/features/domain_spec.rb +45 -0
- data/spec/features/livedns_domain_spec.rb +8 -0
- data/spec/features/livedns_zone_spec.rb +45 -0
- data/spec/features/mailbox_spec.rb +18 -0
- data/spec/fixtures/bodies/GandiV5_Billing/info.yaml +10 -0
- data/spec/fixtures/bodies/GandiV5_Domain/availability.yaml +15 -0
- data/spec/fixtures/bodies/GandiV5_Domain/fetch_contacts.yaml +8 -0
- data/spec/fixtures/bodies/GandiV5_Domain/get.yaml +37 -0
- data/spec/fixtures/bodies/GandiV5_Domain/list.yaml +20 -0
- data/spec/fixtures/bodies/GandiV5_Domain/renewal_info.yaml +12 -0
- data/spec/fixtures/bodies/GandiV5_Domain/restore_info.yaml +5 -0
- data/spec/fixtures/bodies/GandiV5_Domain/tld.yaml +10 -0
- data/spec/fixtures/bodies/GandiV5_Domain/tlds.yaml +7 -0
- data/spec/fixtures/bodies/GandiV5_Email_Mailbox/get.yaml +16 -0
- data/spec/fixtures/bodies/GandiV5_Email_Mailbox/list.yaml +8 -0
- data/spec/fixtures/bodies/GandiV5_Email_Slot/get.yaml +10 -0
- data/spec/fixtures/bodies/GandiV5_Email_Slot/list.yaml +8 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/get.yaml +4 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list.yaml +2 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/get.yaml +11 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yaml +11 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/get.yaml +9 -0
- data/spec/fixtures/bodies/GandiV5_Organization/get.yaml +17 -0
- data/spec/fixtures/vcr/Domain_features/List_domains.yml +54 -0
- data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +133 -0
- data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +32 -0
- data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +42 -0
- data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +72 -0
- data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +28 -0
- data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +39 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/test.env +1 -0
- data/spec/units/gandi_v5/billing/info/prepaid_spec.rb +20 -0
- data/spec/units/gandi_v5/billing/info_spec.rb +4 -0
- data/spec/units/gandi_v5/billing_spec.rb +41 -0
- data/spec/units/gandi_v5/data/converter/array_of_spec.rb +18 -0
- data/spec/units/gandi_v5/data/converter/symbol_spec.rb +16 -0
- data/spec/units/gandi_v5/data/converter/time_spec.rb +16 -0
- data/spec/units/gandi_v5/data/converter_spec.rb +31 -0
- data/spec/units/gandi_v5/data_spec.rb +340 -0
- data/spec/units/gandi_v5/domain/auto_renew_spec.rb +70 -0
- data/spec/units/gandi_v5/domain/contact_spec.rb +36 -0
- data/spec/units/gandi_v5/domain/contract_spec.rb +4 -0
- data/spec/units/gandi_v5/domain/dates_spec.rb +4 -0
- data/spec/units/gandi_v5/domain/renewal_information_spec.rb +81 -0
- data/spec/units/gandi_v5/domain/restore_information_spec.rb +4 -0
- data/spec/units/gandi_v5/domain/sharing_space_spec.rb +4 -0
- data/spec/units/gandi_v5/domain_spec.rb +451 -0
- data/spec/units/gandi_v5/email/mailbox/responder_spec.rb +131 -0
- data/spec/units/gandi_v5/email/mailbox_spec.rb +384 -0
- data/spec/units/gandi_v5/email/offer_spec.rb +17 -0
- data/spec/units/gandi_v5/email/slot_spec.rb +102 -0
- data/spec/units/gandi_v5/error/gandi_error_spec.rb +30 -0
- data/spec/units/gandi_v5/error_spec.rb +4 -0
- data/spec/units/gandi_v5/live_dns/domain_spec.rb +247 -0
- data/spec/units/gandi_v5/live_dns/record_set_spec.rb +74 -0
- data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +37 -0
- data/spec/units/gandi_v5/live_dns/zone_spec.rb +329 -0
- data/spec/units/gandi_v5/live_dns_spec.rb +17 -0
- data/spec/units/gandi_v5/organization_spec.rb +30 -0
- data/spec/units/gandi_v5_spec.rb +204 -0
- metadata +406 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d32f073e157edcd88519f82b4dd082943d4ea049e0232de31dc80d6585070fd7
|
4
|
+
data.tar.gz: ed3c8d5156a3efed4980f62775affc680e73c59890c3430740e41e27dca04763
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a15a87d90b92a53b37544862adb13cf11d21fa7d3737300f2b392b2abc9fa28cc150da48d40d0bb1d63c9a7f5b65dbf13cde7ed8d002e51ab78aac084fb17567
|
7
|
+
data.tar.gz: 91812fc13dabdb21e84164a478376d411271aaec1a30be651f1c9af78c9c1d0e521a5af5f6b4162adb1e5a46ff1cd0bc6ce6231bc80e41cd86d2a33d45060f38
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Because this is a gem, ignore Gemfile.lock:
|
2
|
+
|
3
|
+
Gemfile.lock
|
4
|
+
|
5
|
+
# And because this is Ruby, ignore the following
|
6
|
+
# (source: https://github.com/github/gitignore/blob/master/Ruby.gitignore):
|
7
|
+
|
8
|
+
notes.txt
|
9
|
+
todo.txt
|
10
|
+
*.gem
|
11
|
+
*.rbc
|
12
|
+
.bundle
|
13
|
+
.config
|
14
|
+
coverage
|
15
|
+
InstalledFiles
|
16
|
+
lib/bundler/man
|
17
|
+
pkg
|
18
|
+
rdoc
|
19
|
+
spec/reports
|
20
|
+
test/tmp
|
21
|
+
test/version_tmp
|
22
|
+
tmp
|
23
|
+
gemfiles/*.lock
|
24
|
+
.yardoc
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.6.0
|
5
|
+
Gemspec/RequiredRubyVersion:
|
6
|
+
Enabled: false
|
7
|
+
Metrics/AbcSize:
|
8
|
+
Max: 17
|
9
|
+
Metrics/ClassLength:
|
10
|
+
Max: 200
|
11
|
+
Metrics/LineLength:
|
12
|
+
Max: 100
|
13
|
+
Metrics/MethodLength:
|
14
|
+
Max: 15
|
15
|
+
Metrics/ModuleLength:
|
16
|
+
Max: 200
|
17
|
+
Style/DocumentationMethod:
|
18
|
+
Enabled: true
|
19
|
+
Style/SignalException:
|
20
|
+
Enabled: false
|
data/.travis.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.6.0
|
4
|
+
- 2.6.1
|
5
|
+
- 2.6.2
|
6
|
+
gemfile:
|
7
|
+
- Gemfile
|
8
|
+
branches:
|
9
|
+
only:
|
10
|
+
- master
|
11
|
+
- staging
|
12
|
+
- /gh(?:\d)+(?:-.+)?/
|
13
|
+
- /dev_ver_\d+\.\d+/
|
14
|
+
before_install: gem update bundler
|
15
|
+
script:
|
16
|
+
- bundle exec rubocop
|
17
|
+
- bundle exec rspec
|
18
|
+
notifications:
|
19
|
+
slack:
|
20
|
+
on_success: always
|
21
|
+
on_failure: always
|
22
|
+
rooms:
|
23
|
+
- secure: Nx1TmVs32ILAvH3Cv+jX6rZh1hgx3YaY9azC3PIaJba/bF9xXY1l8L4wF0dJGupQlFP3lWN3Y/aPIJo3SNbH+qll9o317105FfTecPWloyiDgWvz5qPz+oh5MImBUs220jW2XsaACfZkGTUsQt8OUCfhtUeUiW+YqqfAZEwnl+0TyTSFBSLKSNdMcT0sKYPb0IuX5WrOspokSoE9+QL5k0cNN8d78MvtUIC6Em5/ffKVbk4TulQhbzyUhIlPDoxVELq16dQ7njyWJb58khOCaJGV7a2NdFvFCJqImFVQPRT5Ad6EJMQ461cdPY5+ZwxDGlIkA5Srt1L+CyV2wJtMarCIPoGQaxuOTVjNiedEmzblg3K9VXkI7Q5LupJ+vOBhtUS54ODYVBnQgoNVPuRe6T81VZ7NCejeest9bqga8QAVVNhKvMvb6l+YXabnPo7okDZM4+4AlaG/pBKWKjxDJ5QXlbRUZqnJt36sA7y3wvIxnYMX45oaqLD9OS8DQ7Va9+9bsPGZnI0oQrkoPGazGnCryvNtEdl+Qy2KSFaocJL7XLavmAYCmqnNGIaO0eiI+VoX9rvOadDNaPJoa6G4YpO+yTBlx1mxLjneY3FfCHZ1lma7UxzV0t0AVYZtnYBalXbw3mvIWEg6PPRI2uXGCvwUBrNCQqonULsRTFSseMw=
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
guard :bundler do
|
4
|
+
watch(/^Gemfile(?:\.lock)$'/)
|
5
|
+
watch(/^.+\.gemspec$'/)
|
6
|
+
end
|
7
|
+
|
8
|
+
# rubocop:disable Metrics/BlockLength
|
9
|
+
group :red_green_refactor, halt_on_fail: true do
|
10
|
+
group :rspec do
|
11
|
+
guard(
|
12
|
+
'rspec',
|
13
|
+
all_on_start: true,
|
14
|
+
all_after_pass: false,
|
15
|
+
notification: :failed,
|
16
|
+
cmd: 'bundle exec rspec'
|
17
|
+
) do
|
18
|
+
watch(%r{^spec/.+_spec\.rb$})
|
19
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/units/#{m[1]}_spec.rb" }
|
20
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
21
|
+
watch(%r{^spec/.+_shared\.rb$}) { 'spec' }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
group :rubocop do
|
26
|
+
guard(
|
27
|
+
'rubocop',
|
28
|
+
all_on_start: true,
|
29
|
+
all_after_pass: false,
|
30
|
+
notification: :failed,
|
31
|
+
keep_failed: false,
|
32
|
+
cmd: 'bundle exec rubocop'
|
33
|
+
) do
|
34
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| [m[0], "spec/units/#{m[1]}_spec.rb"] }
|
35
|
+
watch(%r{^spec/.+?/(.+)_spec\.rb$}) { |m| [m[0], "lib/#{m[1]}.rb"] }
|
36
|
+
watch(%r{^(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
# rubocop:enable Metrics/BlockLength
|
data/LICENSE.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
##Copyright
|
2
|
+
Copyright (c) 2018, Robert Gauld. All rights reserved.
|
3
|
+
|
4
|
+
|
5
|
+
##License
|
6
|
+
This code can be used under the BSD License (reproduced below).
|
7
|
+
Commiters to the project give Robert Gauld the right to redistribute their commits
|
8
|
+
under the BSD license.
|
9
|
+
|
10
|
+
|
11
|
+
###BSD License
|
12
|
+
Redistribution and use in source and binary forms, with or without modification,
|
13
|
+
are permitted provided that the following conditions are met:
|
14
|
+
|
15
|
+
- Redistributions of source code must retain the above copyright notice,
|
16
|
+
this list of conditions and the following disclaimer.
|
17
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
18
|
+
this list of conditions and the following disclaimer in the documentation and/or
|
19
|
+
other materials provided with the distribution.
|
20
|
+
- Neither the name of the project nor the names of its contributors
|
21
|
+
may be used to endorse or promote products derived from this software
|
22
|
+
without specific prior written permission.
|
23
|
+
|
24
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
25
|
+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
26
|
+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
27
|
+
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
28
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
29
|
+
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
31
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
32
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
[](http://badge.fury.io/rb/gandi_v5)
|
2
|
+
|
3
|
+
Master branch:
|
4
|
+
[](http://travis-ci.org/robertgauld/gandi_v5)
|
5
|
+
[](https://coveralls.io/r/robertgauld/gandi_v5)
|
6
|
+
[](https://codeclimate.com/github/robertgauld/gandi_v5)
|
7
|
+
|
8
|
+
Staging branch:
|
9
|
+
[](http://travis-ci.org/robertgauld/gandi_v5)
|
10
|
+
[](https://coveralls.io/r/robertgauld/gandi_v5)
|
11
|
+
|
12
|
+
|
13
|
+
## Build State
|
14
|
+
This project uses continuous integration to help ensure that a quality product is delivered.
|
15
|
+
Travis CI monitors two branches (versions) of the code:
|
16
|
+
|
17
|
+
* Master (which is what gets released)
|
18
|
+
* Staging (which is what is currently being developed ready for moving to master).
|
19
|
+
|
20
|
+
|
21
|
+
## Ruby Versions
|
22
|
+
This gem supports the following versions of ruby, it may work on other versions but is not tested against them so don't rely on it.
|
23
|
+
|
24
|
+
* ruby:
|
25
|
+
* 2.6.0 - 2.6.2
|
26
|
+
* jruby, once it's reached parity with ruby 2.6.x
|
27
|
+
|
28
|
+
|
29
|
+
## Gandi V5
|
30
|
+
|
31
|
+
Make use of Gandi's V5 API.
|
32
|
+
See the table in the [Versioning section](#Versioning) to see what Gandi
|
33
|
+
API Changes each version is current for.
|
34
|
+
|
35
|
+
Gandi say: **_"Please note that this API is currently in BETA testing, so care should be taken when used in production._"**
|
36
|
+
|
37
|
+
But then you were going to be careful anyway as this gem is currently in the version 0.something range weren't you!
|
38
|
+
|
39
|
+
Details of the API can be found at:
|
40
|
+
|
41
|
+
* (https://api.gandi.net/docs/)
|
42
|
+
* (https://doc.livedns.gandi.net/)
|
43
|
+
|
44
|
+
|
45
|
+
## Installation
|
46
|
+
|
47
|
+
If you're using bundler then add it to your Gemfile and run the bundle command.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
gem 'gandi_v5', '~> 0.1'
|
51
|
+
```
|
52
|
+
|
53
|
+
If you're not using bundler then install it from the command line.
|
54
|
+
```bash
|
55
|
+
gem install gandi_v5 -v '~> 0.1'
|
56
|
+
```
|
57
|
+
|
58
|
+
## Usage
|
59
|
+
|
60
|
+
### Setup
|
61
|
+
|
62
|
+
You'll need you Gandi API KEY, you can get this by logging into Gandi and
|
63
|
+
navigating to User Settings -> Change password & configure access restrictions.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
require 'gandi_v5' # Unless you're using Bundler
|
67
|
+
GandiV5.api_key = '…' # Unless you've set it in the environment variable GANDI_API_KEY
|
68
|
+
```
|
69
|
+
|
70
|
+
### Examples
|
71
|
+
|
72
|
+
#### Domains
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
# Get an array of all your domains.
|
76
|
+
domains = GandiV5::Domain.list
|
77
|
+
|
78
|
+
# Since each domain has only basic information, lets get all of the information.
|
79
|
+
domains.map!(&:refresh)
|
80
|
+
```
|
81
|
+
|
82
|
+
TODO: More examples!
|
83
|
+
|
84
|
+
|
85
|
+
## Versioning
|
86
|
+
|
87
|
+
We follow the [Semantic Versioning](http://semver.org/) concept.
|
88
|
+
|
89
|
+
| Gem Version | Gandi API Release Date |
|
90
|
+
| --------------- | ---------------------- |
|
91
|
+
| 0.1.0 | 2019-05-16 |
|
92
|
+
|
93
|
+
See (https://api.gandi.net/docs/reference#API-Changelog) to find out what
|
94
|
+
Gandi changed on each date.
|
data/Rakefile
ADDED
data/TODO.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# To Do List
|
2
|
+
|
3
|
+
* Domain:
|
4
|
+
* [ ] .restore_information - test when I have a restorable domain
|
5
|
+
* [ ] .create - return created domain
|
6
|
+
* [ ] .availability - return a new type of object
|
7
|
+
* [ ] .tld * return a new type of object
|
8
|
+
* Email Mailbox:
|
9
|
+
* [ ] .create - check type is valid
|
10
|
+
* [ ] .create - check a slot is available
|
11
|
+
* [ ] .create - fetch created mailbox
|
12
|
+
* Email Slot:
|
13
|
+
* [ ] #delete - check for inactiveness
|
14
|
+
* [ ] #delete - check for refundableness
|
15
|
+
* [ ] .create - fetch created slot
|
16
|
+
* LiveDNS Domain:
|
17
|
+
* [ ] #replace_??_records_for - incorporate into #replace_records_for
|
18
|
+
* [ ] Make record type a symbol
|
19
|
+
* [ ] Add #zone method
|
20
|
+
* LiveDNS Zone:
|
21
|
+
* [ ] .create - fetch created zone
|
22
|
+
* [ ] #replace_??_records_for - incorporate into #replace_records_for
|
23
|
+
* [ ] Make record type a symbol
|
24
|
+
* [ ] Add #zone method
|
25
|
+
* LiveDNS Zone Snapshot:
|
26
|
+
* [ ] Move method for getting listing to here
|
27
|
+
* Gandi updates from 2019-05-23:
|
28
|
+
* [ ] Domain API: Domain hosts (glue records)
|
29
|
+
* [ ] Domain API: Domain nameservers
|
data/bin/console
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
Dotenv.load
|
5
|
+
|
6
|
+
unless ENV.key?('GANDI_API_KEY')
|
7
|
+
puts 'YOU MUST SET YOUR API KEY -> GandiV5.api_key = \'…\''
|
8
|
+
puts 'You can avoid having to do this by'
|
9
|
+
puts 'setting the environment variable GANDI_API_KEY.'
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'irb'
|
13
|
+
IRB.start
|
data/gandi_v5.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
|
+
require File.join(File.dirname(__FILE__), 'lib', 'gandi_v5', 'version')
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'gandi_v5'
|
8
|
+
gem.license = 'BSD 3 clause'
|
9
|
+
gem.version = GandiV5::VERSION
|
10
|
+
gem.authors = ['Robert Gauld']
|
11
|
+
gem.email = ['robert@robertgauld.co.uk']
|
12
|
+
gem.homepage = 'https://github.com/robertgauld/gandi_v5'
|
13
|
+
gem.summary = 'Make use of Gandi\'s V5 API.'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split("\n")
|
16
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.required_ruby_version = '>= 2.4'
|
21
|
+
gem.required_rubygems_version = '>= 2.6.14'
|
22
|
+
|
23
|
+
gem.add_dependency 'dotenv', '~> 2.5'
|
24
|
+
gem.add_dependency 'rest-client', '>= 2', '< 3'
|
25
|
+
|
26
|
+
gem.add_development_dependency 'coveralls', '~> 0.7'
|
27
|
+
gem.add_development_dependency 'guard', '~> 2.15'
|
28
|
+
gem.add_development_dependency 'guard-bundler', '~> 2.2'
|
29
|
+
gem.add_development_dependency 'guard-rspec', '~> 4.2', '>= 4.2.5'
|
30
|
+
gem.add_development_dependency 'guard-rubocop', '~> 1.3'
|
31
|
+
gem.add_development_dependency 'rake', '~> 12.0'
|
32
|
+
gem.add_development_dependency 'rb-inotify', '~> 0.9'
|
33
|
+
gem.add_development_dependency 'rspec', '>= 3.7', '< 4'
|
34
|
+
gem.add_development_dependency 'rspec-its', '~> 1.3'
|
35
|
+
gem.add_development_dependency 'rubocop', '~> 0.67'
|
36
|
+
gem.add_development_dependency 'rubocop-performance', '~> 1.1'
|
37
|
+
gem.add_development_dependency 'simplecov', '~> 0.7'
|
38
|
+
gem.add_development_dependency 'timecop', '~> 0.5'
|
39
|
+
gem.add_development_dependency 'vcr', '~> 4.0'
|
40
|
+
gem.add_development_dependency 'webmock', '~> 3.5'
|
41
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
class Billing
|
5
|
+
class Info
|
6
|
+
# Account's prepaid information.
|
7
|
+
# @!attribute [r] amount
|
8
|
+
# @return [Numeric] current amount available in the prepaid account.
|
9
|
+
# @!attribute [r] currency
|
10
|
+
# @return [String] currency in use for the prepaid account.
|
11
|
+
# @!attribute [r] warning_threshold
|
12
|
+
# @return [Numeric] amount under which a warning email is sent.
|
13
|
+
# @!attribute [r] created_at
|
14
|
+
# @return [Time] creation date of the prepaid account.
|
15
|
+
# @!attribute [r] updated_at
|
16
|
+
# @return [Time] last modification date of the prepaid account.
|
17
|
+
class Prepaid
|
18
|
+
include GandiV5::Data
|
19
|
+
|
20
|
+
members :amount, :currency, :warning_threshold
|
21
|
+
member :created_at, converter: GandiV5::Data::Converter::Time
|
22
|
+
member :updated_at, converter: GandiV5::Data::Converter::Time
|
23
|
+
|
24
|
+
# Check if current balance is below the warning threshold.
|
25
|
+
def warning?
|
26
|
+
return nil if warning_threshold.nil?
|
27
|
+
|
28
|
+
amount < warning_threshold
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'info/prepaid'
|
4
|
+
|
5
|
+
class GandiV5
|
6
|
+
class Billing
|
7
|
+
# Account's information.
|
8
|
+
# @!attribute [r] annual_balance
|
9
|
+
# @return [Numeric] amount of purchased over the past 12 months since the request.
|
10
|
+
# @!attribute [r] outstanding_amount
|
11
|
+
# @return [Numeric] amount of outstanding orders (payment by terms) since the last invoice.
|
12
|
+
# @!attribute [r] grid
|
13
|
+
# @return [String] price rate that is applied
|
14
|
+
# depending on the amount purchased over the last 12 months.
|
15
|
+
# @!attribute [r] prepaid_monthly_invoice
|
16
|
+
# @return [nil, Boolean] whether orders are gathered into a single monthly invoice.
|
17
|
+
# @!attribute [r] prepaid
|
18
|
+
# @return [nil, Gandiv5::Billing::Info::Prepaid]
|
19
|
+
class Info
|
20
|
+
include GandiV5::Data
|
21
|
+
|
22
|
+
members :annual_balance, :grid, :outstanding_amount, :prepaid_monthly_invoice
|
23
|
+
member :prepaid, converter: GandiV5::Billing::Info::Prepaid
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'billing/info'
|
4
|
+
|
5
|
+
class GandiV5
|
6
|
+
# Gandi Billing API.
|
7
|
+
# @see https://api.gandi.net/docs/billing
|
8
|
+
class Billing
|
9
|
+
# Get account info (defaults to currently authenticated user).
|
10
|
+
# @see https://api.gandi.net/docs/billing#get-v5-billing-info
|
11
|
+
# @param url [sharing_id] the Sharing ID of the organisation to get info for
|
12
|
+
# defaults to the user the api key belomgs to.
|
13
|
+
# @return [GandiV5::Billing::Info]
|
14
|
+
# @raise [GandiV5::Error::GandiError::GandiError] if Gandi returns an error.
|
15
|
+
def self.info(sharing_id = nil)
|
16
|
+
data = GandiV5.get url(sharing_id)
|
17
|
+
GandiV5::Billing::Info.from_gandi data
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def self.url(sharing_id = nil)
|
23
|
+
"#{BASE}billing/info" +
|
24
|
+
(sharing_id ? "/#{CGI.escape sharing_id}" : '')
|
25
|
+
end
|
26
|
+
private_class_method :url
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
module Data
|
5
|
+
class Converter
|
6
|
+
# Used for applying the same converter to each item in an array.
|
7
|
+
class ArrayOf
|
8
|
+
# @param converter the converter to apply to each item in the array.
|
9
|
+
def initialize(converter)
|
10
|
+
@converter = converter
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param value [Array<Object>]
|
14
|
+
# @return [Array<Object>]
|
15
|
+
def to_gandi(value)
|
16
|
+
return nil if value.nil?
|
17
|
+
|
18
|
+
value.map { |item| converter.to_gandi(item) }
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param [Array<Object>]
|
22
|
+
# @return value [Array<Object>]
|
23
|
+
def from_gandi(value)
|
24
|
+
return nil if value.nil?
|
25
|
+
|
26
|
+
value.map { |item| converter.from_gandi(item) }
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :converter
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
module Data
|
5
|
+
class Converter
|
6
|
+
# Methods for converting strings to/from symbols.
|
7
|
+
class Symbol
|
8
|
+
# @param value [Symbol]
|
9
|
+
# @return [String]
|
10
|
+
def self.to_gandi(value)
|
11
|
+
return nil if value.nil?
|
12
|
+
|
13
|
+
value.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param [String]
|
17
|
+
# @return value [Symbol]
|
18
|
+
def self.from_gandi(value)
|
19
|
+
return nil if value.nil?
|
20
|
+
|
21
|
+
value.to_sym
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
module Data
|
5
|
+
class Converter
|
6
|
+
# Methods for converting times to/from Gandi ("2019-02-13T11:04:18Z").
|
7
|
+
class Time
|
8
|
+
# Convert a time to Gandi's prefered string format.
|
9
|
+
# @param value [Time]
|
10
|
+
# @return [String]
|
11
|
+
def self.to_gandi(value)
|
12
|
+
return nil if value.nil?
|
13
|
+
|
14
|
+
value.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
15
|
+
end
|
16
|
+
|
17
|
+
# Convert a time from Gandi's prefered string format.
|
18
|
+
# @param [String]
|
19
|
+
# @return value [Time]
|
20
|
+
def self.from_gandi(value)
|
21
|
+
return nil if value.nil?
|
22
|
+
|
23
|
+
::Time.parse value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'converter/array_of'
|
4
|
+
require_relative 'converter/symbol'
|
5
|
+
require_relative 'converter/time'
|
6
|
+
|
7
|
+
class GandiV5
|
8
|
+
module Data
|
9
|
+
# Namespace for converters to/from Gandi's format.
|
10
|
+
class Converter
|
11
|
+
# Initialize a new simple converter.
|
12
|
+
# The passed procs will be run at the appropriate time.
|
13
|
+
# @param from_gandi [Proc]
|
14
|
+
# @param to_gandi [Proc]
|
15
|
+
def initialize(from_gandi: nil, to_gandi: nil)
|
16
|
+
@from_gandi_proc = from_gandi
|
17
|
+
@to_gandi_proc = to_gandi
|
18
|
+
end
|
19
|
+
|
20
|
+
# @param value [Object]
|
21
|
+
# @return [Object]
|
22
|
+
def to_gandi(value)
|
23
|
+
return value unless to_gandi_proc
|
24
|
+
|
25
|
+
to_gandi_proc.call value
|
26
|
+
end
|
27
|
+
|
28
|
+
# @param [Object]
|
29
|
+
# @return value [Object]
|
30
|
+
def from_gandi(value)
|
31
|
+
return value unless from_gandi_proc
|
32
|
+
|
33
|
+
from_gandi_proc.call value
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_reader :from_gandi_proc, :to_gandi_proc
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|