ngrok-api 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +21 -0
- data/.gitignore +13 -0
- data/.rubocop.yml +28 -0
- data/.rubocop_airbnb.yml +2 -0
- data/.simplecov +1 -0
- data/Gemfile +33 -0
- data/Guardfile +16 -0
- data/README.md +61 -0
- data/Rakefile +7 -0
- data/doc/NgrokAPI/Client.html +542 -0
- data/doc/NgrokAPI/Error.html +305 -0
- data/doc/NgrokAPI/Errors/NotFoundError.html +309 -0
- data/doc/NgrokAPI/Errors.html +115 -0
- data/doc/NgrokAPI/HttpClient.html +1104 -0
- data/doc/NgrokAPI/Models/ApiKey.html +1138 -0
- data/doc/NgrokAPI/Models/EndpointConfiguration.html +1366 -0
- data/doc/NgrokAPI/Models/Listable.html +934 -0
- data/doc/NgrokAPI/Models/ReservedDomain.html +2498 -0
- data/doc/NgrokAPI/Models/TlsCertificate.html +1064 -0
- data/doc/NgrokAPI/Models.html +117 -0
- data/doc/NgrokAPI/PagedIterator.html +631 -0
- data/doc/NgrokAPI/Services/ApiKeysClient.html +1333 -0
- data/doc/NgrokAPI/Services/EndpointConfigurationsClient.html +2201 -0
- data/doc/NgrokAPI/Services/ReservedDomainsClient.html +2541 -0
- data/doc/NgrokAPI/Services/TlsCertificatesClient.html +1417 -0
- data/doc/NgrokAPI/Services.html +117 -0
- data/doc/NgrokAPI.html +157 -0
- data/doc/_index.html +309 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +497 -0
- data/doc/file.README.html +126 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +126 -0
- data/doc/js/app.js +314 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +1227 -0
- data/doc/top-level-namespace.html +110 -0
- data/docs/NgrokAPI/Client.html +542 -0
- data/docs/NgrokAPI/Error.html +305 -0
- data/docs/NgrokAPI/Errors/NotFoundError.html +309 -0
- data/docs/NgrokAPI/Errors.html +115 -0
- data/docs/NgrokAPI/HttpClient.html +1104 -0
- data/docs/NgrokAPI/Models/ApiKey.html +1138 -0
- data/docs/NgrokAPI/Models/EndpointConfiguration.html +1366 -0
- data/docs/NgrokAPI/Models/Listable.html +934 -0
- data/docs/NgrokAPI/Models/ReservedDomain.html +2498 -0
- data/docs/NgrokAPI/Models/TlsCertificate.html +1064 -0
- data/docs/NgrokAPI/Models.html +117 -0
- data/docs/NgrokAPI/PagedIterator.html +631 -0
- data/docs/NgrokAPI/Services/ApiKeysClient.html +1333 -0
- data/docs/NgrokAPI/Services/EndpointConfigurationsClient.html +2201 -0
- data/docs/NgrokAPI/Services/ReservedDomainsClient.html +2541 -0
- data/docs/NgrokAPI/Services/TlsCertificatesClient.html +1417 -0
- data/docs/NgrokAPI/Services.html +117 -0
- data/docs/NgrokAPI.html +157 -0
- data/docs/_index.html +309 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +497 -0
- data/docs/file.README.html +126 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +126 -0
- data/docs/js/app.js +314 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +1227 -0
- data/docs/top-level-namespace.html +110 -0
- data/lib/ngrokapi/client.rb +49 -0
- data/lib/ngrokapi/error.rb +14 -0
- data/lib/ngrokapi/errors/not_found_error.rb +16 -0
- data/lib/ngrokapi/http_client.rb +132 -0
- data/lib/ngrokapi/models/api_key.rb +64 -0
- data/lib/ngrokapi/models/endpoint_configuration.rb +119 -0
- data/lib/ngrokapi/models/listable.rb +42 -0
- data/lib/ngrokapi/models/reserved_domain.rb +211 -0
- data/lib/ngrokapi/models/tls_certificate.rb +62 -0
- data/lib/ngrokapi/paged_iterator.rb +40 -0
- data/lib/ngrokapi/services/api_keys_client.rb +144 -0
- data/lib/ngrokapi/services/endpoint_configurations_client.rb +313 -0
- data/lib/ngrokapi/services/reserved_domains_client.rb +313 -0
- data/lib/ngrokapi/services/tls_certificates_client.rb +161 -0
- data/lib/ngrokapi/version.rb +7 -0
- data/lib/ngrokapi.rb +13 -0
- data/ngrok-api.gemspec +27 -0
- data/spec/ngrokapi/client_spec.rb +33 -0
- data/spec/ngrokapi/http_client_spec.rb +75 -0
- data/spec/ngrokapi/models/api_key_spec.rb +43 -0
- data/spec/ngrokapi/models/listable_spec.rb +43 -0
- data/spec/ngrokapi/models/reserved_domain_spec.rb +100 -0
- data/spec/ngrokapi/paged_iterator_spec.rb +84 -0
- data/spec/ngrokapi/services/api_keys_client_spec.rb +127 -0
- data/spec/spec_helper.rb +80 -0
- metadata +144 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module NgrokAPI
|
|
4
|
+
module Services
|
|
5
|
+
##
|
|
6
|
+
# A client for interacting with the tls_certificates API
|
|
7
|
+
#
|
|
8
|
+
# https://ngrok.com/docs/api#api-tls-certificates
|
|
9
|
+
class TlsCertificatesClient
|
|
10
|
+
# The List Property from the resulting API for list calls
|
|
11
|
+
LIST_PROPERTY = 'tls_certificates'
|
|
12
|
+
# The API path for tls certificates
|
|
13
|
+
PATH = '/tls_certificates'
|
|
14
|
+
|
|
15
|
+
attr_reader :client
|
|
16
|
+
|
|
17
|
+
def initialize(client:)
|
|
18
|
+
@client = client
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# rubocop:disable LineLength
|
|
22
|
+
|
|
23
|
+
##
|
|
24
|
+
# Upload a new TLS certificate.
|
|
25
|
+
#
|
|
26
|
+
# @param [string] description human-readable description of this TLS certificate. optional, max 255 bytes.
|
|
27
|
+
# @param [string] metadata arbitrary user-defined machine-readable data of this TLS certificate. optional, max 4096 bytes.
|
|
28
|
+
# @param [string] certificate_pem chain of PEM-encoded certificates, leaf first. See `Certificate Bundles` <https://ngrok.com/docs/api#tls-certificates-pem>`_.
|
|
29
|
+
# @param [string] private_key_pem private key for the TLS certificate, PEM-encoded. See `Private Keys` <https://ngrok.com/docs/ngrok-link#tls-certificates-key>`_.
|
|
30
|
+
# @return [NgrokAPI::Models::TlsCertificate] result from create request
|
|
31
|
+
#
|
|
32
|
+
# https://ngrok.com/docs/api#api-tls-certificates-create
|
|
33
|
+
def create(
|
|
34
|
+
certificate_pem: '',
|
|
35
|
+
description: '',
|
|
36
|
+
metadata: '',
|
|
37
|
+
private_key_pem: ''
|
|
38
|
+
)
|
|
39
|
+
data = {
|
|
40
|
+
certificate_pem: certificate_pem,
|
|
41
|
+
description: description,
|
|
42
|
+
metadata: metadata,
|
|
43
|
+
private_key_pem: private_key_pem,
|
|
44
|
+
}
|
|
45
|
+
result = @client.post(PATH, data: data)
|
|
46
|
+
NgrokAPI::Models::TlsCertificate.new(client: self, result: result)
|
|
47
|
+
end
|
|
48
|
+
# rubocop:enable LineLength
|
|
49
|
+
|
|
50
|
+
##
|
|
51
|
+
# Delete a TLS certificate by ID.
|
|
52
|
+
#
|
|
53
|
+
# @param [string] id a resource identifier
|
|
54
|
+
# @return [nil] result from delete request
|
|
55
|
+
#
|
|
56
|
+
# https://ngrok.com/docs/api#api-tls-certificates-delete
|
|
57
|
+
def delete(id: nil)
|
|
58
|
+
@client.delete("#{PATH}/#{id}")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
##
|
|
62
|
+
# Delete a TLS certificate by ID. Throw an exception if 404.
|
|
63
|
+
#
|
|
64
|
+
# @param [string] id a resource identifier
|
|
65
|
+
# @return [nil] result from delete request
|
|
66
|
+
#
|
|
67
|
+
# https://ngrok.com/docs/api#api-tls-certificates-delete
|
|
68
|
+
def delete!(id: nil)
|
|
69
|
+
@client.delete("#{PATH}/#{id}", danger: true)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
##
|
|
73
|
+
# Get detailed information about a TLS certificate by ID.
|
|
74
|
+
#
|
|
75
|
+
# @param [string] id a resource identifier
|
|
76
|
+
# @return [NgrokAPI::Models::TlsCertificate] result from get request
|
|
77
|
+
#
|
|
78
|
+
# https://ngrok.com/docs/api#api-tls-certificates-get
|
|
79
|
+
def get(id: nil)
|
|
80
|
+
result = @client.get("#{PATH}/#{id}")
|
|
81
|
+
NgrokAPI::Models::TlsCertificate.new(client: self, result: result)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
##
|
|
85
|
+
# Get detailed information about a TLS certificate by ID. Throw an exception if 404.
|
|
86
|
+
#
|
|
87
|
+
# @param [string] id a resource identifier
|
|
88
|
+
# @return [NgrokAPI::Models::TlsCertificate] result from get request
|
|
89
|
+
#
|
|
90
|
+
# https://ngrok.com/docs/api#api-tls-certificates-get
|
|
91
|
+
def get!(id: nil)
|
|
92
|
+
result = @client.get("#{PATH}/#{id}", danger: true)
|
|
93
|
+
NgrokAPI::Models::TlsCertificate.new(client: self, result: result)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
##
|
|
97
|
+
# List all TLS certificates on this account.
|
|
98
|
+
#
|
|
99
|
+
# @param [string] before_id
|
|
100
|
+
# @param [integer] limit
|
|
101
|
+
# @param [string] url optional and mutually exclusive from before_id and limit
|
|
102
|
+
# @return [NgrokAPI::Models::Listable] the result listable
|
|
103
|
+
#
|
|
104
|
+
# https://ngrok.com/docs/api#api-tls-certificates-list
|
|
105
|
+
def list(before_id: nil, limit: nil, url: nil)
|
|
106
|
+
result = @client.list(before_id: before_id, limit: limit, url: url, path: PATH)
|
|
107
|
+
NgrokAPI::Models::Listable.new(
|
|
108
|
+
client: self,
|
|
109
|
+
result: result,
|
|
110
|
+
list_property: LIST_PROPERTY,
|
|
111
|
+
klass: NgrokAPI::Models::TlsCertificate
|
|
112
|
+
)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# rubocop:disable LineLength
|
|
116
|
+
|
|
117
|
+
##
|
|
118
|
+
# Update attributes of a TLS Certificate by ID.
|
|
119
|
+
#
|
|
120
|
+
# @param [string] id
|
|
121
|
+
# @param [string] description human-readable description of this TLS certificate. optional, max 255 bytes.
|
|
122
|
+
# @param [string] metadata arbitrary user-defined machine-readable data of this TLS certificate. optional, max 4096 bytes.
|
|
123
|
+
# @return [NgrokAPI::Models::TlsCertificate] result from update request
|
|
124
|
+
#
|
|
125
|
+
# https://ngrok.com/docs/api#api-tls-certificates-update
|
|
126
|
+
def update(
|
|
127
|
+
id: nil,
|
|
128
|
+
description: nil,
|
|
129
|
+
metadata: nil
|
|
130
|
+
)
|
|
131
|
+
data = {}
|
|
132
|
+
data[:description] = description if description
|
|
133
|
+
data[:metadata] = metadata if metadata
|
|
134
|
+
result = @client.patch("#{PATH}/#{id}", data: data)
|
|
135
|
+
NgrokAPI::Models::TlsCertificate.new(client: self, result: result)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
##
|
|
139
|
+
# Update attributes of a TLS Certificate by ID. Throw an exception if 404.
|
|
140
|
+
#
|
|
141
|
+
# @param [string] id
|
|
142
|
+
# @param [string] description human-readable description of this TLS certificate. optional, max 255 bytes.
|
|
143
|
+
# @param [string] metadata arbitrary user-defined machine-readable data of this TLS certificate. optional, max 4096 bytes.
|
|
144
|
+
# @return [NgrokAPI::Models::TlsCertificate] result from update request
|
|
145
|
+
#
|
|
146
|
+
# https://ngrok.com/docs/api#api-tls-certificates-update
|
|
147
|
+
def update!(
|
|
148
|
+
id: nil,
|
|
149
|
+
description: nil,
|
|
150
|
+
metadata: nil
|
|
151
|
+
)
|
|
152
|
+
data = {}
|
|
153
|
+
data[:description] = description if description
|
|
154
|
+
data[:metadata] = metadata if metadata
|
|
155
|
+
result = @client.patch("#{PATH}/#{id}", danger: true, data: data)
|
|
156
|
+
NgrokAPI::Models::TlsCertificate.new(client: self, result: result)
|
|
157
|
+
end
|
|
158
|
+
# rubocop:enable LineLength
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
data/lib/ngrokapi.rb
ADDED
data/ngrok-api.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
|
4
|
+
require 'ngrokapi/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = 'ngrok-api'
|
|
8
|
+
s.version = NgrokAPI::VERSION
|
|
9
|
+
s.platform = Gem::Platform::RUBY
|
|
10
|
+
s.licenses = ['MIT']
|
|
11
|
+
s.authors = ['']
|
|
12
|
+
s.email = ['']
|
|
13
|
+
s.homepage = 'https://github.com/ngrok/ngrok-api-ruby'
|
|
14
|
+
s.summary = 'This library wraps the [ngrok HTTP API](https://ngrok.com/docs/api) to make
|
|
15
|
+
it easier to consume in Ruby.'
|
|
16
|
+
s.description = 'This library wraps the [ngrok HTTP API](https://ngrok.com/docs/api) to make
|
|
17
|
+
it easier to consume in Ruby.'
|
|
18
|
+
|
|
19
|
+
s.required_ruby_version = '>= 3.0.0'
|
|
20
|
+
|
|
21
|
+
all_files = `git ls-files`.split("\n")
|
|
22
|
+
test_files = `git ls-files -- {test,spec,features}/*`.split('\n')
|
|
23
|
+
|
|
24
|
+
s.files = all_files - test_files
|
|
25
|
+
s.executables = `git ls-files -- bin/*`.split('\n').map { |f| File.basename(f) }
|
|
26
|
+
s.require_paths = ['lib']
|
|
27
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe NgrokAPI::Client do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@client = NgrokAPI::Client.new(api_key: 'abc')
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
describe "#api_keys" do
|
|
9
|
+
it "returns an instance of the api_keys_client" do
|
|
10
|
+
expect(@client.api_keys.class).to eq(NgrokAPI::Services::ApiKeysClient)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "#endpoint_configurations" do
|
|
15
|
+
it "returns an instance of the endpoint_configurations_client" do
|
|
16
|
+
expect(@client.endpoint_configurations.class).to eq(
|
|
17
|
+
NgrokAPI::Services::EndpointConfigurationsClient
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe "#reserved_domains" do
|
|
23
|
+
it "returns an instance of the reserved_domains_client" do
|
|
24
|
+
expect(@client.reserved_domains.class).to eq(NgrokAPI::Services::ReservedDomainsClient)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "#tls_certificates" do
|
|
29
|
+
it "returns an instance of the tls_certificates_client" do
|
|
30
|
+
expect(@client.tls_certificates.class).to eq(NgrokAPI::Services::TlsCertificatesClient)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe NgrokAPI::HttpClient do
|
|
4
|
+
let(:base_url) { 'https://api.ngrok.com' }
|
|
5
|
+
let(:path) { '/api_keys' }
|
|
6
|
+
|
|
7
|
+
before(:each) do
|
|
8
|
+
api_key = 'abc'
|
|
9
|
+
@client = NgrokAPI::HttpClient.new(api_key: api_key)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "#delete" do
|
|
13
|
+
it "will delete and return an empty body" do
|
|
14
|
+
url = "#{base_url}#{path}/#{api_key_result["id"]}"
|
|
15
|
+
stub_request(:delete, url).to_return(body: nil)
|
|
16
|
+
expect(@client.delete(url)).to eq(nil)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe "#get" do
|
|
21
|
+
it "will get the returned resource json" do
|
|
22
|
+
url = "#{base_url}#{path}/#{api_key_result["id"]}"
|
|
23
|
+
stub_request(:get, url).to_return(body: api_key_result.to_json)
|
|
24
|
+
expect(@client.get(url)).to eq(api_key_result)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "will raise a NotFoundError if 404" do
|
|
28
|
+
url = "#{base_url}#{path}/#{api_key_result["id"]}"
|
|
29
|
+
stub_request(:get, url).to_return(body: nil, status: 404)
|
|
30
|
+
expect do
|
|
31
|
+
@client.get(url, danger: true)
|
|
32
|
+
end.to raise_error(NgrokAPI::Errors::NotFoundError)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "will raise a NgrokAPI::Error if >= 400" do
|
|
36
|
+
url = "#{base_url}#{path}/#{api_key_result["id"]}"
|
|
37
|
+
stub_request(:get, url).to_return(body: nil, status: 400)
|
|
38
|
+
expect do
|
|
39
|
+
@client.get(url, danger: true)
|
|
40
|
+
end.to raise_error(NgrokAPI::Error)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe "#list" do
|
|
45
|
+
it "with a url will return based on the absolute URL" do
|
|
46
|
+
url = "#{base_url}#{path}?before_id=#{api_key_result["id"]}&limit=1"
|
|
47
|
+
stub_request(:get, url).to_return(body: api_key_results.to_json)
|
|
48
|
+
expect(@client.list(url: url)).to eq(api_key_results)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "without a url will return based on the path, before_id, and limit" do
|
|
52
|
+
url = "#{base_url}#{path}?before_id=#{api_key_result["id"]}&limit=1"
|
|
53
|
+
stub_request(:get, url).to_return(body: api_key_results.to_json)
|
|
54
|
+
expect(@client.list(before_id: api_key_result["id"], limit: 1, path: path)).to eq(api_key_results)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe "#patch" do
|
|
59
|
+
it "updates an existing resource" do
|
|
60
|
+
merged = api_key_result
|
|
61
|
+
merged['metadata'] = 'updated'
|
|
62
|
+
url = "#{base_url}#{path}/#{api_key_result["id"]}"
|
|
63
|
+
stub_request(:patch, url).to_return(body: merged.to_json)
|
|
64
|
+
expect(@client.patch(url)).to eq(merged)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe "#post" do
|
|
69
|
+
it "creates a new resource" do
|
|
70
|
+
url = "#{base_url}#{path}/#{api_key_result["id"]}"
|
|
71
|
+
stub_request(:post, url).to_return(body: api_key_result.to_json)
|
|
72
|
+
expect(@client.post(url)).to eq(api_key_result)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe NgrokAPI::Models::ApiKey do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@client = class_double("ApiKeysClient")
|
|
6
|
+
@api_key = NgrokAPI::Models::ApiKey.new(client: @client, result: api_key_result)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe "#==" do
|
|
10
|
+
it "is equal if the results are the same" do
|
|
11
|
+
key2 = NgrokAPI::Models::ApiKey.new(client: @client, result: api_key_result)
|
|
12
|
+
expect(@api_key == key2).to eq true
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "#to_s" do
|
|
17
|
+
it "stringifies as result.to_s" do
|
|
18
|
+
expect(@api_key.to_s).to eq api_key_result.to_s
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe "#delete" do
|
|
23
|
+
it "calls delete on the client" do
|
|
24
|
+
expect(@api_key.client).to receive(:delete)
|
|
25
|
+
@api_key.delete
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "#update" do
|
|
30
|
+
it "updates instance's description and metadata and call update on the client" do
|
|
31
|
+
new_description = 'new description'
|
|
32
|
+
new_metadata = 'new metadata'
|
|
33
|
+
expect(@api_key.client).to receive(:update)
|
|
34
|
+
|
|
35
|
+
@api_key.update(
|
|
36
|
+
description: new_description,
|
|
37
|
+
metadata: new_metadata,
|
|
38
|
+
)
|
|
39
|
+
expect(@api_key.description).to eq new_description
|
|
40
|
+
expect(@api_key.metadata).to eq new_metadata
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe NgrokAPI::Models::Listable do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@client = class_double("ApiKeysClient")
|
|
6
|
+
@listable = NgrokAPI::Models::Listable.new(
|
|
7
|
+
client: @client,
|
|
8
|
+
result: api_key_results,
|
|
9
|
+
list_property: 'keys',
|
|
10
|
+
klass: NgrokAPI::Models::ApiKey
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "#==" do
|
|
15
|
+
it "is equal if the results are the same" do
|
|
16
|
+
listable2 = NgrokAPI::Models::Listable.new(
|
|
17
|
+
client: @client,
|
|
18
|
+
result: api_key_results,
|
|
19
|
+
list_property: 'keys',
|
|
20
|
+
klass: NgrokAPI::Models::ApiKey
|
|
21
|
+
)
|
|
22
|
+
expect(@listable == listable2).to eq true
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "#to_s" do
|
|
27
|
+
it "stringifies as result.to_s" do
|
|
28
|
+
expect(@listable.to_s).to eq api_key_results.to_s
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe "keys" do
|
|
33
|
+
it "consistent of ApiKeys" do
|
|
34
|
+
expect(@listable.items.size).to eq api_key_results['keys'].size
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "iter" do
|
|
39
|
+
it "is a PagedIterator" do
|
|
40
|
+
expect(@listable.iter.class).to eq NgrokAPI::PagedIterator
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe NgrokAPI::Models::ReservedDomain do
|
|
4
|
+
let(:result) do
|
|
5
|
+
{
|
|
6
|
+
"id" => "rd_1xxLksFRG6o5MoAKX8UrtPnXbmz",
|
|
7
|
+
"uri" => "https://api.ngrok.com/reserved_domains/rd_1xxLksFRG6o5MoAKX8UrtPnXbmz",
|
|
8
|
+
"created_at" => "2021-09-10T16:38:58Z",
|
|
9
|
+
"description" => "",
|
|
10
|
+
"metadata" => "",
|
|
11
|
+
"domain" => "tahouetnaoh.ngrok.io",
|
|
12
|
+
"region" => "us",
|
|
13
|
+
"cname_target" => nil,
|
|
14
|
+
"http_endpoint_configuration" => {
|
|
15
|
+
"id" => "ec_1xv9oZpu0g1sbaZvxuqKQJVCLW5",
|
|
16
|
+
"uri" => "https://api.ngrok.com/endpoint_configurations/ec_1xv9oZpu0g1sbaZvxuqKQJVCLW5",
|
|
17
|
+
},
|
|
18
|
+
"https_endpoint_configuration" => nil,
|
|
19
|
+
"certificate" => nil,
|
|
20
|
+
"certificate_management_policy" => nil,
|
|
21
|
+
"certificate_management_status" => nil,
|
|
22
|
+
}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
before(:each) do
|
|
26
|
+
@client = class_double("ReservedDomainsClient")
|
|
27
|
+
@domain = NgrokAPI::Models::ReservedDomain.new(client: @client, result: result)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe "#==" do
|
|
31
|
+
it "is equal if the results are the same" do
|
|
32
|
+
domain2 = NgrokAPI::Models::ReservedDomain.new(client: @client, result: result)
|
|
33
|
+
expect(@domain == domain2).to eq true
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe "#to_s" do
|
|
38
|
+
it "stringifies as result.to_s" do
|
|
39
|
+
expect(@domain.to_s).to eq result.to_s
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe "#delete" do
|
|
44
|
+
it "calls delete on the client" do
|
|
45
|
+
expect(@domain.client).to receive(:delete)
|
|
46
|
+
@domain.delete
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe "#update" do
|
|
51
|
+
it "updates the instance's description and metadata and call update on the client" do
|
|
52
|
+
# new_certificate_id = 'new certificate_id'
|
|
53
|
+
# new_http_endpoint_configuration_id = 'new http_endpoint_configuration_id'
|
|
54
|
+
# new_https_endpoint_configuration_id = 'new https_endpoint_configuration_id'
|
|
55
|
+
new_certificate_management_policy = 'new certificate_management_policy'
|
|
56
|
+
new_description = 'new description'
|
|
57
|
+
new_metadata = 'new metadata'
|
|
58
|
+
expect(@domain.client).to receive(:update)
|
|
59
|
+
|
|
60
|
+
# certificate_id: new_certificate_id,
|
|
61
|
+
# http_endpoint_configuration_id: new_http_endpoint_configuration_id,
|
|
62
|
+
# https_endpoint_configuration_id: new_https_endpoint_configuration_id
|
|
63
|
+
@domain.update(
|
|
64
|
+
description: new_description,
|
|
65
|
+
metadata: new_metadata,
|
|
66
|
+
certificate_management_policy: new_certificate_management_policy
|
|
67
|
+
)
|
|
68
|
+
expect(@domain.description).to eq new_description
|
|
69
|
+
expect(@domain.metadata).to eq new_metadata
|
|
70
|
+
expect(@domain.certificate_management_policy).to eq new_certificate_management_policy
|
|
71
|
+
# expect(@domain.certificate_id).to eq new_certificate_id
|
|
72
|
+
# expect(@domain.http_endpoint_configuration_id).to eq new_http_endpoint_configuration_id
|
|
73
|
+
# expect(@domain.https_endpoint_configuration_id).to eq new_https_endpoint_configuration_id
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
describe "#delete_certificate" do
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe "#delete_certificate_management_policy" do
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
describe "#delete_http_endpoint_config" do
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe "#delete_https_endpoint_config" do
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe "#restore_certificate" do
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
describe "#restore_certificate_management_policy" do
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe "#restore_http_endpoint_config" do
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe "#restore_https_endpoint_config" do
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe NgrokAPI::PagedIterator do
|
|
4
|
+
let(:client) { class_double("ApiKeysClient") }
|
|
5
|
+
let(:uri) { "https://api.ngrok.com/api_keys" }
|
|
6
|
+
let(:next_page_uri) { "#{uri}?before_id=ak_1xuyYBCA83z5zo2MkBJ0JjvxPIs&limit=1" }
|
|
7
|
+
let(:results) do
|
|
8
|
+
{ "keys" => [api_key_result], "uri" => uri, "next_page_uri" => next_page_uri }
|
|
9
|
+
end
|
|
10
|
+
let(:empty_results) do
|
|
11
|
+
{ "keys" => [], "uri" => uri, "next_page_uri" => next_page_uri }
|
|
12
|
+
end
|
|
13
|
+
let(:empty_last_results) do
|
|
14
|
+
{ "keys" => [], "uri" => uri, "next_page_uri" => nil }
|
|
15
|
+
end
|
|
16
|
+
let(:item) { NgrokAPI::Models::ApiKey.new(client: client, result: api_key_result) }
|
|
17
|
+
let(:page) do
|
|
18
|
+
NgrokAPI::Models::Listable.new(
|
|
19
|
+
client: client,
|
|
20
|
+
result: results,
|
|
21
|
+
list_property: 'keys',
|
|
22
|
+
klass: NgrokAPI::Models::ApiKey
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
let(:empty_page) do
|
|
26
|
+
NgrokAPI::Models::Listable.new(
|
|
27
|
+
client: client,
|
|
28
|
+
result: empty_results,
|
|
29
|
+
list_property: 'keys',
|
|
30
|
+
klass: NgrokAPI::Models::ApiKey
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
let(:empty_last_page) do
|
|
34
|
+
NgrokAPI::Models::Listable.new(
|
|
35
|
+
client: client,
|
|
36
|
+
result: empty_last_results,
|
|
37
|
+
list_property: 'keys',
|
|
38
|
+
klass: NgrokAPI::Models::ApiKey
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe "#get_next" do
|
|
43
|
+
it "gets the next result from cache" do
|
|
44
|
+
paged_iterator = NgrokAPI::PagedIterator.new(
|
|
45
|
+
client: client,
|
|
46
|
+
page: page,
|
|
47
|
+
list_property: 'keys'
|
|
48
|
+
)
|
|
49
|
+
expect(page).not_to receive(:next_page_uri)
|
|
50
|
+
expect(paged_iterator.get_next).to eq(api_key_result)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "gets the next result based on next_page_uri if not in cache" do
|
|
54
|
+
paged_iterator = NgrokAPI::PagedIterator.new(
|
|
55
|
+
client: client,
|
|
56
|
+
page: empty_page,
|
|
57
|
+
list_property: 'keys'
|
|
58
|
+
)
|
|
59
|
+
expect(empty_page).to receive(:result).and_return(item)
|
|
60
|
+
expect(empty_page).to receive(:next_page_uri)
|
|
61
|
+
expect(paged_iterator.get_next).to eq(nil)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "gets the next result based on next_page_uri if not in cache (with data)" do
|
|
65
|
+
paged_iterator = NgrokAPI::PagedIterator.new(
|
|
66
|
+
client: client,
|
|
67
|
+
page: empty_page,
|
|
68
|
+
list_property: 'keys'
|
|
69
|
+
)
|
|
70
|
+
expect(client).to receive(:list).with({ url: next_page_uri }).and_return(page)
|
|
71
|
+
expect(paged_iterator.get_next).to eq(api_key_result)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "gets the next result based on next_page_uri if not in cache (without data)" do
|
|
75
|
+
paged_iterator = NgrokAPI::PagedIterator.new(
|
|
76
|
+
client: client,
|
|
77
|
+
page: empty_page,
|
|
78
|
+
list_property: 'keys'
|
|
79
|
+
)
|
|
80
|
+
expect(client).to receive(:list).with({ url: next_page_uri }).and_return(empty_last_page)
|
|
81
|
+
expect(paged_iterator.get_next).to eq(nil)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|