ns-1 0.3.4
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 +16 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +18 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +77 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/nsone/api/account.rb +27 -0
- data/lib/nsone/api/jobs.rb +30 -0
- data/lib/nsone/api/records.rb +137 -0
- data/lib/nsone/api/stats.rb +174 -0
- data/lib/nsone/api/zones.rb +94 -0
- data/lib/nsone/api.rb +22 -0
- data/lib/nsone/client.rb +65 -0
- data/lib/nsone/error.rb +4 -0
- data/lib/nsone/response/base.rb +14 -0
- data/lib/nsone/response/error.rb +9 -0
- data/lib/nsone/response/success.rb +8 -0
- data/lib/nsone/response.rb +7 -0
- data/lib/nsone/transport/net_http.rb +59 -0
- data/lib/nsone/transport.rb +8 -0
- data/lib/nsone/version.rb +3 -0
- data/lib/nsone.rb +5 -0
- data/nsone.gemspec +25 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fd79d309501f2a7050ac268294910f89adcd0460b6878c4a2e925871ec03983b
|
4
|
+
data.tar.gz: a18251a62183147f61fc237ce07098c435ebf60c2fc20a1ef1cbf9b72207bbc6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e951b30fe33df1be2888a6b952c8c20045b3a4960f56ae9cc915f8aa11f45d218025e2f9600330495e3c1995bcf0842d5fa098fe68be73b187a7a52b4f36dba6
|
7
|
+
data.tar.gz: b1b2b1a6c490da1e1ee40f9e681c22d3434c7840bc1f899b503095289b830b3a4487c2ea9cb743b7756ab63828552ddba8cc14857d98cfe4a4328953606d9612
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
## 0.3.4 - 2019-08-06
|
5
|
+
- change module name
|
6
|
+
|
7
|
+
## 0.3.3 - 2019-08-06
|
8
|
+
- Added jobs and job API calls for NS1 monitoring jobs
|
9
|
+
- Added account and account_overage calls
|
10
|
+
- Added Stats calls (per account, zone, record, network and region) for QPS and Usage
|
11
|
+
- Added Docs
|
12
|
+
|
13
|
+
## 0.2.0 - 2018-12-07
|
14
|
+
- [Added] `Response#status` returns status code information as an integer - #1
|
15
|
+
- [Added] Changelog
|
16
|
+
|
17
|
+
## 0.1.0 - 2018-04-10
|
18
|
+
- Initial release supporting CRUD operations for zones and records
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Esteban Pastorino
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# NS-1
|
2
|
+
|
3
|
+
[NS1](https://ns1.com/) API Client
|
4
|
+
|
5
|
+
Based on and Forked from [kitop/ns1-ruby](https://github.com/kitop/ns1-ruby)
|
6
|
+
1. Added few API calls (mainly QPS/Usage)
|
7
|
+
2. Added yarddocs according to [NS1 API](https://ns1.com/api)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'ns-1'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install ns-1
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# Instantiate a client
|
29
|
+
client = NSOne::Client.new("your api key")
|
30
|
+
|
31
|
+
# ZONES
|
32
|
+
|
33
|
+
## Zone string can be: 'example.com.' or 'example.com'
|
34
|
+
|
35
|
+
# Get all active zones and basic zone configuration details for each.
|
36
|
+
client.zones
|
37
|
+
|
38
|
+
# Get a single active Zone and its basic configuration details.
|
39
|
+
client.zone("example.com")
|
40
|
+
|
41
|
+
# Create a new DNS zone
|
42
|
+
# For details on configuration options, see https://ns1.com/api#create-a-new-dns-zone
|
43
|
+
client.create_zone("yourdomain.com", { optional: :params })
|
44
|
+
|
45
|
+
# Modify basic details of a DNS zone
|
46
|
+
client.modify_zone("yourdomain.com", { refresh: 3600 })
|
47
|
+
|
48
|
+
# Delete an existing DNS zone and all records in the zone
|
49
|
+
client.delete_zone("yourdomain.com")
|
50
|
+
|
51
|
+
# RECORDS
|
52
|
+
|
53
|
+
## Record string can be: 'www.example.com.', 'www.example.com' or 'www'
|
54
|
+
|
55
|
+
# Get full configuration for a DNS record
|
56
|
+
client.record("example.com", "www.example.com", "A")
|
57
|
+
|
58
|
+
# Create a new DNS record in the specified zone, for the specified domain, of the given record type
|
59
|
+
# `answers` option is required. For other options, see https://ns1.com/api#create-a-new-dns-record
|
60
|
+
client.create_record("yourdomain.com", "www.yourdomain.com", "A", { answers: [] })
|
61
|
+
|
62
|
+
# Modify configuration details for an existing DNS record.
|
63
|
+
client.modify_record("yourdomain.com", "www.yourdomain.com", "A" { use_client_subnet: false })
|
64
|
+
|
65
|
+
# Remove an existing record and all associated answers and configuration details
|
66
|
+
client.delete_record("yourdomain.com", "www.yourdomain.com", "A")
|
67
|
+
```
|
68
|
+
|
69
|
+
## Development
|
70
|
+
|
71
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
72
|
+
|
73
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/kitop/ns1](https://github.com/kitop/ns1).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nsone"
|
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
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NSOne
|
4
|
+
module API
|
5
|
+
module Account
|
6
|
+
|
7
|
+
#
|
8
|
+
# Returns the basic contact details associated with your account
|
9
|
+
#
|
10
|
+
# @return [NSOne::Response]
|
11
|
+
#
|
12
|
+
def account()
|
13
|
+
perform_request(HTTP_GET, "/v1/account/settings")
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# Returns toggles and thresholds used when sending overage warning
|
18
|
+
#
|
19
|
+
# @return [NSOne::Response]
|
20
|
+
#
|
21
|
+
def account_overage()
|
22
|
+
perform_request(HTTP_GET, "/v1/account/usagewarnings")
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NSOne
|
4
|
+
module API
|
5
|
+
module Jobs
|
6
|
+
|
7
|
+
#
|
8
|
+
# Returns the list of all monitoring jobs for the account
|
9
|
+
#
|
10
|
+
# @return [NSOne::Response]
|
11
|
+
#
|
12
|
+
def jobs()
|
13
|
+
perform_request(HTTP_GET, "/v1/monitoring/jobs")
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# Returns details for a specific monitoring jobs based on its id
|
18
|
+
#
|
19
|
+
# @param [String] job_id the job ID
|
20
|
+
#
|
21
|
+
# @return [NSOne::Response]
|
22
|
+
#
|
23
|
+
def job(job_id)
|
24
|
+
raise NSOne::MissingParameter, "job_id cannot be blank" if blank?(job_id)
|
25
|
+
perform_request(HTTP_GET, "/v1/monitoring/jobs/#{job_id}")
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NSOne
|
4
|
+
module API
|
5
|
+
module Records
|
6
|
+
|
7
|
+
#
|
8
|
+
# Returns full configuration for a DNS record including
|
9
|
+
# basic config, answers, regions, filter chain configuration, and all metadata tables and data feeds attached to entities in the record
|
10
|
+
#
|
11
|
+
# @param [String] zone zone name
|
12
|
+
# @param [String] domain record name
|
13
|
+
# @param [String] type record type (A, CNAME etc)
|
14
|
+
#
|
15
|
+
# @return [NSOne::Response]
|
16
|
+
#
|
17
|
+
def record(zone, domain, type)
|
18
|
+
raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
|
19
|
+
raise NSOne::MissingParameter, "domain cannot be blank" if blank?(domain)
|
20
|
+
raise NSOne::MissingParameter, "type cannot be blank" if blank?(type)
|
21
|
+
normalize_names!(zone, domain)
|
22
|
+
perform_request(HTTP_GET, "/v1/zones/#{zone}/#{domain}/#{type}")
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# <Description>
|
27
|
+
#
|
28
|
+
# @param [String] zone zone name
|
29
|
+
# @param [String] domain record name
|
30
|
+
# @param [String] type record type (A, CNAME etc)
|
31
|
+
# @param [Hash] params will be used as the request body
|
32
|
+
#
|
33
|
+
# @option params [String] :zone zone name
|
34
|
+
#
|
35
|
+
# @option params [String] :domain record name
|
36
|
+
#
|
37
|
+
# @option params [String] :type record type (A, CNAME etc)
|
38
|
+
#
|
39
|
+
# @option params [String] :link record name. This is used to create a `linked` record to another record.
|
40
|
+
# When using :link answers array should be empty and filters arrays should be omitted.
|
41
|
+
#
|
42
|
+
# @option params [Array<Hash>] :answers Array of Hashes with the RDATA values
|
43
|
+
#
|
44
|
+
# @option params [Array<Hash>] :filters Array of Hashes with settings for record filter-chains rules
|
45
|
+
#
|
46
|
+
# @option params [Boolean] :use_client_subnet enable EDNS on the record.
|
47
|
+
#
|
48
|
+
# Default: `true`
|
49
|
+
#
|
50
|
+
# @return [NSOne::Response]
|
51
|
+
#
|
52
|
+
# @example Request body with answers and filter chain arrays. @see [NSOne API](https://ns1.com/api)
|
53
|
+
# {
|
54
|
+
# "zone":"example.com",
|
55
|
+
# "domain":"georegion.example.com",
|
56
|
+
# "type":"A",
|
57
|
+
# "use_client_subnet":false,
|
58
|
+
# "answers":[
|
59
|
+
# {
|
60
|
+
# "answer":[
|
61
|
+
# "1.1.1.1"
|
62
|
+
# ],
|
63
|
+
# "meta":{
|
64
|
+
# "georegion":[
|
65
|
+
# "US-EAST"
|
66
|
+
# ]
|
67
|
+
# }
|
68
|
+
# },
|
69
|
+
# {
|
70
|
+
# "answer":[
|
71
|
+
# "9.9.9.9"
|
72
|
+
# ],
|
73
|
+
# "meta":{
|
74
|
+
# "georegion":[
|
75
|
+
# "US-WEST"
|
76
|
+
# ]
|
77
|
+
# }
|
78
|
+
# }
|
79
|
+
# ],
|
80
|
+
# "filters":[
|
81
|
+
# {
|
82
|
+
# "filter":"geotarget_regional",
|
83
|
+
# "config": {}
|
84
|
+
# },
|
85
|
+
# {
|
86
|
+
# "filter":"select_first_n",
|
87
|
+
# "config":{
|
88
|
+
# "N":1
|
89
|
+
# }
|
90
|
+
# }
|
91
|
+
# ]
|
92
|
+
# }
|
93
|
+
#
|
94
|
+
#
|
95
|
+
def create_record(zone, domain, type, params = {})
|
96
|
+
raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
|
97
|
+
raise NSOne::MissingParameter, "domain cannot be blank" if blank?(domain)
|
98
|
+
raise NSOne::MissingParameter, "type cannot be blank" if blank?(type)
|
99
|
+
validate_required!(params, :answers)
|
100
|
+
normalize_names!(zone, domain)
|
101
|
+
params = params.merge(zone: zone, domain: domain, type: type)
|
102
|
+
perform_request(HTTP_PUT, "/v1/zones/#{zone}/#{domain}/#{type}", params)
|
103
|
+
end
|
104
|
+
|
105
|
+
#
|
106
|
+
# Modify an existing record. See {NSOne::API::Records#create_record} for available options.
|
107
|
+
#
|
108
|
+
# @return [NSOne::Response]
|
109
|
+
#
|
110
|
+
def modify_record(zone, domain, type, params)
|
111
|
+
raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
|
112
|
+
raise NSOne::MissingParameter, "domain cannot be blank" if blank?(domain)
|
113
|
+
raise NSOne::MissingParameter, "type cannot be blank" if blank?(type)
|
114
|
+
normalize_names!(zone, domain)
|
115
|
+
perform_request(HTTP_POST, "/v1/zones/#{zone}/#{domain}/#{type}", params)
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# Removes an existing record and all associated answers and configuration details
|
120
|
+
#
|
121
|
+
# @param [String] zone zone name
|
122
|
+
# @param [String] domain record name
|
123
|
+
# @param [String] type record type (A, CNAME etc)
|
124
|
+
#
|
125
|
+
# @return [NSOne::Response]
|
126
|
+
#
|
127
|
+
def delete_record(zone, domain, type)
|
128
|
+
raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
|
129
|
+
raise NSOne::MissingParameter, "domain cannot be blank" if blank?(domain)
|
130
|
+
raise NSOne::MissingParameter, "type cannot be blank" if blank?(type)
|
131
|
+
normalize_names!(zone, domain)
|
132
|
+
perform_request(HTTP_DELETE, "/v1/zones/#{zone}/#{domain}/#{type}")
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NSOne
|
4
|
+
module API
|
5
|
+
module Stats
|
6
|
+
|
7
|
+
#
|
8
|
+
# Returns current queries per second (QPS) for the account
|
9
|
+
#
|
10
|
+
# @return [NSOne::Response]
|
11
|
+
#
|
12
|
+
def qps()
|
13
|
+
perform_request(HTTP_GET, "/v1/stats/qps")
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# Returns current queries per second (QPS) for a specific zone
|
18
|
+
#
|
19
|
+
# @param [<Type>] zone <description>
|
20
|
+
#
|
21
|
+
# @return [NSOne::Response]
|
22
|
+
#
|
23
|
+
def zone_qps(zone)
|
24
|
+
raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
|
25
|
+
normalize_names!(zone)
|
26
|
+
perform_request(HTTP_GET, "/v1/stats/qps/#{zone}")
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Returns current queries per second (QPS) for a specific record
|
31
|
+
#
|
32
|
+
# @param [String] zone zone name
|
33
|
+
# @param [String] domain record name
|
34
|
+
# @param [String] type record type (A, CNAME etc)
|
35
|
+
#
|
36
|
+
# @return [NSOne::Response]
|
37
|
+
#
|
38
|
+
def record_qps(zone, domain, type)
|
39
|
+
raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
|
40
|
+
raise NSOne::MissingParameter, "domain cannot be blank" if blank?(domain)
|
41
|
+
raise NSOne::MissingParameter, "type cannot be blank" if blank?(type)
|
42
|
+
normalize_names!(zone, domain)
|
43
|
+
perform_request(HTTP_GET, "/v1/stats/qps/#{zone}/#{domain}/#{type}")
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Returns statistics and graphs for the entire account over a given period
|
48
|
+
#
|
49
|
+
# @param [Hash] params will be used as the request body
|
50
|
+
#
|
51
|
+
# @option params [String] :period one of `1h`, `24h`, or `30d`
|
52
|
+
#
|
53
|
+
# Default: 24h
|
54
|
+
#
|
55
|
+
# @option params [Boolean] :expand if `true` breaks down stats by zone.
|
56
|
+
#
|
57
|
+
# Default: `false`
|
58
|
+
#
|
59
|
+
# @option params [Boolean] :aggregate if `true` returns aggregated stats across all zones and billing tiers
|
60
|
+
#
|
61
|
+
# Default: `false`
|
62
|
+
#
|
63
|
+
# @return [NSOne::Response]
|
64
|
+
#
|
65
|
+
def usage(params = {})
|
66
|
+
perform_request(HTTP_GET, "/v1/stats/usage", params)
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# Returns statistics and graphs on `NSOne Network` level (Managed/Dedicated)
|
71
|
+
#
|
72
|
+
# @param [Hash] params will be used as the request body
|
73
|
+
#
|
74
|
+
# @option params [String] :period one of `1h`, `24h`, or `30d`
|
75
|
+
#
|
76
|
+
# Default: 24h
|
77
|
+
#
|
78
|
+
# @option params [Boolean] :expand if `true` breaks down stats by zone.
|
79
|
+
#
|
80
|
+
# Default: `false`
|
81
|
+
#
|
82
|
+
# @option params [Boolean] :aggregate if `true` returns aggregated stats across all zones and billing tiers
|
83
|
+
#
|
84
|
+
# Default: `false`
|
85
|
+
#
|
86
|
+
# @return [NSOne::Response]
|
87
|
+
#
|
88
|
+
def network_usage(params = {})
|
89
|
+
perform_request(HTTP_GET, "/v1/stats/network/usage", params)
|
90
|
+
end
|
91
|
+
|
92
|
+
#
|
93
|
+
# Returns total usage (Queries) during `:period` per region/Geo-Location. At the moment NSOne API return the following areas:
|
94
|
+
# Europe, North America, Oceania, Africa, Asia
|
95
|
+
#
|
96
|
+
# @param [Hash] params will be used as the request body
|
97
|
+
#
|
98
|
+
# @option params [String] :period one of `1h`, `24h`, or `30d`
|
99
|
+
#
|
100
|
+
# Default: 24h
|
101
|
+
#
|
102
|
+
# @option params [Boolean] :expand if `true` breaks down stats by zone.
|
103
|
+
#
|
104
|
+
# Default: `false`
|
105
|
+
#
|
106
|
+
# @option params [Boolean] :aggregate if `true` returns aggregated stats across all zones and billing tiers
|
107
|
+
#
|
108
|
+
# Default: `false`
|
109
|
+
#
|
110
|
+
# @return [NSOne::Response]
|
111
|
+
#
|
112
|
+
def region_usage(params = {})
|
113
|
+
perform_request(HTTP_GET, "/v1/stats/region/usage", params)
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Returns statistics and graphs for a given zone over a given period
|
118
|
+
#
|
119
|
+
# @param [Hash] params will be used as the request body
|
120
|
+
# @param [String] zone NSOne zone name
|
121
|
+
#
|
122
|
+
# @option params [String] :period one of `1h`, `24h`, or `30d`
|
123
|
+
#
|
124
|
+
# Default: 24h
|
125
|
+
#
|
126
|
+
# @option params [Boolean] :expand if `true` breaks down stats by zone.
|
127
|
+
#
|
128
|
+
# Default: `false`
|
129
|
+
#
|
130
|
+
# @option params [Boolean] :aggregate if `true` returns aggregated stats across all zones and billing tiers
|
131
|
+
#
|
132
|
+
# Default: `false`
|
133
|
+
#
|
134
|
+
# @return [NSOne::Response]
|
135
|
+
#
|
136
|
+
def zone_usage(zone, params = {})
|
137
|
+
raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
|
138
|
+
normalize_names!(zone)
|
139
|
+
perform_request(HTTP_GET, "/v1/stats/usage/#{zone}", params)
|
140
|
+
end
|
141
|
+
|
142
|
+
#
|
143
|
+
# Returns statistics and graphs for a given record over a given period
|
144
|
+
#
|
145
|
+
# @param [Hash] params will be used as the request body
|
146
|
+
# @param [String] zone zone name
|
147
|
+
# @param [String] domain record name
|
148
|
+
# @param [String] type record type (A, CNAME etc)
|
149
|
+
#
|
150
|
+
# @option params [String] :period one of `1h`, `24h`, or `30d`
|
151
|
+
#
|
152
|
+
# Default: 24h
|
153
|
+
#
|
154
|
+
# @option params [Boolean] :expand if `true` breaks down stats by zone.
|
155
|
+
#
|
156
|
+
# Default: `false`
|
157
|
+
#
|
158
|
+
# @option params [Boolean] :aggregate if `true` returns aggregated stats across all zones and billing tiers
|
159
|
+
#
|
160
|
+
# Default: `false`
|
161
|
+
#
|
162
|
+
# @return [NSOne::Response]
|
163
|
+
#
|
164
|
+
def record_usage(zone, domain, type, params = {})
|
165
|
+
raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
|
166
|
+
raise NSOne::MissingParameter, "domain cannot be blank" if blank?(domain)
|
167
|
+
raise NSOne::MissingParameter, "type cannot be blank" if blank?(type)
|
168
|
+
normalize_names!(zone, domain)
|
169
|
+
perform_request(HTTP_GET, "/v1/stats/usage/#{zone}/#{domain}/#{type}", params)
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NSOne
|
4
|
+
module API
|
5
|
+
module Zones
|
6
|
+
|
7
|
+
#
|
8
|
+
# Returns all active zones and basic zone configuration details for each
|
9
|
+
#
|
10
|
+
# @return [NSOne::Response]
|
11
|
+
#
|
12
|
+
def zones
|
13
|
+
perform_request(HTTP_GET, "/v1/zones")
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# Returns a single active Zone and its basic configuration details including all the zones records in a "records" array.
|
18
|
+
#
|
19
|
+
# @param [required, String] zone zone name
|
20
|
+
#
|
21
|
+
# @return [NSOne::Response]
|
22
|
+
#
|
23
|
+
def zone(zone)
|
24
|
+
raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
|
25
|
+
perform_request(HTTP_GET, "/v1/zones/#{zone}")
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Create a new DNS zone. You must include a JSON body in the request with basic details of the zone.
|
30
|
+
# The only required element in the body is zone.
|
31
|
+
#
|
32
|
+
# @param [required, String] zone zone name
|
33
|
+
# @param [Hash] params
|
34
|
+
#
|
35
|
+
# For all the zone options @see [NSOne API - create-a-new-dns-zone](https://jsapi.apiary.io/apis/ns1api/reference/zones-and-records/zone/create-a-new-dns-zone.html)
|
36
|
+
#
|
37
|
+
# @return [NSOne::Response]
|
38
|
+
#
|
39
|
+
def create_zone(zone, params = {})
|
40
|
+
raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
|
41
|
+
params = params.merge(zone: zone)
|
42
|
+
perform_request(HTTP_PUT, "/v1/zones/#{zone}", params)
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Modifies basic details of a DNS zone.
|
47
|
+
# You must include a JSON body in the request, in which you may include ttl (SOA record TTL), refresh, retry, expiry, or nx_ttl values,
|
48
|
+
# as in a SOA record. You may not change the zone name or other details.
|
49
|
+
#
|
50
|
+
# @param [required, String] zone zone name
|
51
|
+
# @param [required, Hash] params for all params @see [NSOne API - modify-a-zone](https://jsapi.apiary.io/apis/ns1api/reference/zones-and-records/zone/modify-a-zone.html)
|
52
|
+
#
|
53
|
+
# @return [NSOne::Response]
|
54
|
+
#
|
55
|
+
def modify_zone(zone, params = {})
|
56
|
+
raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
|
57
|
+
raise NSOne::MissingParameter, "params hash must contain valid zone settings" if !params.is_a?(Hash) || params.empty?
|
58
|
+
perform_request(HTTP_POST, "/v1/zones/#{zone}", params)
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# Destroys an existing DNS zone and all records in the zone
|
63
|
+
#
|
64
|
+
# @param [required, String] zone zone name
|
65
|
+
#
|
66
|
+
# @return [NSOne::Response]
|
67
|
+
#
|
68
|
+
def delete_zone(zone)
|
69
|
+
raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
|
70
|
+
perform_request(HTTP_DELETE, "/v1/zones/#{zone}")
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# Returns all zones and records that match the given `string`.
|
75
|
+
# You can limit the max number of results and you can restrict the type of results to zone, record, or all.
|
76
|
+
# Entries in the response without domain/type are zones, and those with domain/type are records.
|
77
|
+
#
|
78
|
+
# @param [required, String] string search string
|
79
|
+
# @param [Hash] params
|
80
|
+
#
|
81
|
+
# @option params [Integer] :max the max results to return
|
82
|
+
# @option params [String] :type to limit the search. valid options are `zone`, `record` or `all`
|
83
|
+
#
|
84
|
+
# @return [NSOne::Response]
|
85
|
+
#
|
86
|
+
def search(string, params = {})
|
87
|
+
raise NSOne::MissingParameter, "search string cannot be blank" if blank?(string)
|
88
|
+
params = params.merge(q: string)
|
89
|
+
perform_request(HTTP_GET, "/v1/search", params)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/nsone/api.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Dir[ File.expand_path('../api/*.rb', __FILE__) ].each { |f| require f }
|
4
|
+
|
5
|
+
module NSOne
|
6
|
+
module API
|
7
|
+
HTTP_GET = "GET"
|
8
|
+
HTTP_POST = "POST"
|
9
|
+
HTTP_PUT = "PUT"
|
10
|
+
HTTP_DELETE = "DELETE"
|
11
|
+
|
12
|
+
def self.included(base)
|
13
|
+
base.send :include,
|
14
|
+
NSOne::API::Zones,
|
15
|
+
NSOne::API::Records,
|
16
|
+
NSOne::API::Account,
|
17
|
+
NSOne::API::Stats,
|
18
|
+
NSOne::API::Jobs
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/nsone/client.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "nsone/api"
|
4
|
+
require "nsone/transport/net_http"
|
5
|
+
require "nsone/error"
|
6
|
+
|
7
|
+
module NSOne
|
8
|
+
class Client
|
9
|
+
|
10
|
+
include NSOne::API
|
11
|
+
|
12
|
+
BASE_URL = "https://api.nsone.net"
|
13
|
+
|
14
|
+
def initialize(api_key, base_url: BASE_URL, logger: nil)
|
15
|
+
@api_key = api_key
|
16
|
+
@base_url = base_url
|
17
|
+
@logger = logger
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def perform_request(method, path, body = nil)
|
23
|
+
body = JSON.dump(body) if body.is_a? Hash
|
24
|
+
log("[NSOne] > #{method} #{path}")
|
25
|
+
log("[NSOne] > #{body}") if body
|
26
|
+
response = transport.request(method, path, body)
|
27
|
+
log("[NSOne] < #{response.inspect}")
|
28
|
+
response
|
29
|
+
end
|
30
|
+
|
31
|
+
def log(message)
|
32
|
+
@logger && @logger.debug(message)
|
33
|
+
end
|
34
|
+
|
35
|
+
def transport
|
36
|
+
@transport ||= NSOne::Transport::NetHttp.new(@base_url, @api_key)
|
37
|
+
end
|
38
|
+
|
39
|
+
def blank?(object)
|
40
|
+
object.respond_to?(:empty?) ? !!object.empty? : !object
|
41
|
+
end
|
42
|
+
|
43
|
+
def validate_required!(params, *keys)
|
44
|
+
raise ArgumentError, "Paramenters must be a hash" unless params.is_a? Hash
|
45
|
+
missing = keys.reject { |key| params.has_key?(key) or params.has_key?(key.to_s) }
|
46
|
+
if missing.any?
|
47
|
+
raise MissingParameter, "Missing key(s): #{missing.join(", ")}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Helper to support `domain` name with or without the zone name.
|
52
|
+
# e.g. zone: example.com domain: www will generate domain: www.example.com
|
53
|
+
def normalize_names!(zone, domain = "")
|
54
|
+
no_dot!(zone, domain)
|
55
|
+
domain << ".#{zone}" unless domain.empty? || domain.include?(zone)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Removes trailing dot from all Strings given
|
59
|
+
def no_dot!(*array)
|
60
|
+
array.map {|a| a.chop! if a[/\.$/] != nil}
|
61
|
+
array
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
data/lib/nsone/error.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "openssl"
|
5
|
+
require "json"
|
6
|
+
require "uri"
|
7
|
+
require "nsone/transport"
|
8
|
+
require "nsone/response"
|
9
|
+
|
10
|
+
module NSOne
|
11
|
+
module Transport
|
12
|
+
class NetHttp
|
13
|
+
def initialize(base_url, api_key)
|
14
|
+
@base_url = base_url
|
15
|
+
@api_key = api_key
|
16
|
+
end
|
17
|
+
|
18
|
+
def request(method, path, body = nil)
|
19
|
+
uri = URI.join(@base_url, path)
|
20
|
+
Net::HTTP.start(uri.host, uri.port, opts(uri)) do |http|
|
21
|
+
response = http.send_request(method, uri, body, headers(body))
|
22
|
+
process_response(response)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def process_response(response)
|
29
|
+
body = JSON.parse(response.body)
|
30
|
+
case response
|
31
|
+
when Net::HTTPOK
|
32
|
+
NSOne::Response::Success.new(body, response.code.to_i)
|
33
|
+
else
|
34
|
+
NSOne::Response::Error.new(body, response.code.to_i)
|
35
|
+
end
|
36
|
+
rescue JSON::ParserError
|
37
|
+
raise NSOne::Transport::ResponseParseError
|
38
|
+
end
|
39
|
+
|
40
|
+
def opts(uri)
|
41
|
+
if uri.scheme == "https"
|
42
|
+
{
|
43
|
+
use_ssl: true,
|
44
|
+
ssl_mode: OpenSSL::SSL::VERIFY_PEER
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def headers(body)
|
50
|
+
extra_headers = body.nil? ? {} : { "Content-Type" => "application/json" }
|
51
|
+
default_headers.merge(extra_headers)
|
52
|
+
end
|
53
|
+
|
54
|
+
def default_headers
|
55
|
+
{ "X-NSONE-Key" => @api_key }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/nsone.rb
ADDED
data/nsone.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "nsone/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ns-1"
|
7
|
+
spec.version = NSOne::VERSION
|
8
|
+
spec.authors = ["Esteban Pastorino"]
|
9
|
+
spec.email = ["ejpastorino@gmail.com"]
|
10
|
+
spec.license = "MIT"
|
11
|
+
|
12
|
+
spec.summary = %q{NS1 API Client}
|
13
|
+
spec.description = %q{Based on kitop ns1 gem}
|
14
|
+
spec.homepage = "https://github.com/benkap/ns1-ruby"
|
15
|
+
|
16
|
+
spec.files = `find . -type f`.split("\n").reject { |f| f[/test|spec\/|features|tmp|\.git\/|doc|\.yardopts|^.$|vscode|\.gem$/]}.each {|f| f.slice!(/^.\//)}
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "> 1.16"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
spec.add_development_dependency "webmock", "~> 3.3.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ns-1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Esteban Pastorino
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-06 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: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.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.3.0
|
69
|
+
description: Based on kitop ns1 gem
|
70
|
+
email:
|
71
|
+
- ejpastorino@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CHANGELOG.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/nsone.rb
|
87
|
+
- lib/nsone/api.rb
|
88
|
+
- lib/nsone/api/account.rb
|
89
|
+
- lib/nsone/api/jobs.rb
|
90
|
+
- lib/nsone/api/records.rb
|
91
|
+
- lib/nsone/api/stats.rb
|
92
|
+
- lib/nsone/api/zones.rb
|
93
|
+
- lib/nsone/client.rb
|
94
|
+
- lib/nsone/error.rb
|
95
|
+
- lib/nsone/response.rb
|
96
|
+
- lib/nsone/response/base.rb
|
97
|
+
- lib/nsone/response/error.rb
|
98
|
+
- lib/nsone/response/success.rb
|
99
|
+
- lib/nsone/transport.rb
|
100
|
+
- lib/nsone/transport/net_http.rb
|
101
|
+
- lib/nsone/version.rb
|
102
|
+
- nsone.gemspec
|
103
|
+
homepage: https://github.com/benkap/ns1-ruby
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.7.6
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: NS1 API Client
|
127
|
+
test_files: []
|