New REPP doc

This commit is contained in:
Martin Lensment 2015-04-01 13:32:38 +03:00
parent 7e123f902e
commit 21f07076cd
9 changed files with 113 additions and 153 deletions

View file

@ -7,6 +7,7 @@ module Repp
params do params do
optional :limit, type: Integer, values: (1..20).to_a optional :limit, type: Integer, values: (1..20).to_a
optional :offset, type: Integer optional :offset, type: Integer
optional :details, type: String, values: %w(true false)
end end
get '/' do get '/' do

View file

@ -7,6 +7,7 @@ module Repp
params do params do
optional :limit, type: Integer, values: (1..20).to_a optional :limit, type: Integer, values: (1..20).to_a
optional :offset, type: Integer optional :offset, type: Integer
optional :details, type: String, values: %w(true false)
end end
get '/' do get '/' do

View file

@ -1,7 +1,14 @@
## GET /repp/v1/contacts ## GET /repp/v1/contacts
Returns contacts of the current registrar. Returns contacts of the current registrar.
### Example
#### Parameters
| Field name | Required | Type | Allowed values |
| ---------- | -------- | ---- | -------------- |
| limit | false | Integer | [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
| offset | false | Integer | |
| details | false | String | ["true", "false"] |
#### Request #### Request
``` ```
@ -16,31 +23,36 @@ Content-Type: application/json
``` ```
HTTP/1.1 200 HTTP/1.1 200
Cache-Control: max-age=0, private, must-revalidate Cache-Control: max-age=0, private, must-revalidate
Content-Length: 483 Content-Length: 566
Content-Type: application/json Content-Type: application/json
{ {
"contacts": [ "contacts": [
{ {
"id": 1, "id": 1,
"code": "sh470279120", "code": "sh889404040",
"reg_no": null, "reg_no": null,
"phone": "+372.12345678", "phone": "+372.12345678",
"email": "bettye.feil@ratkegoldner.net", "email": "annetta.toy@mitchell.org",
"fax": null, "fax": null,
"created_at": "2015-03-31T07:39:10.854Z", "created_at": "2015-04-01T10:30:47.470Z",
"updated_at": "2015-03-31T07:39:10.854Z", "updated_at": "2015-04-01T10:30:47.470Z",
"ident": "37605030299", "ident": "37605030299",
"ident_type": "priv", "ident_type": "priv",
"created_by_id": null, "created_by_id": null,
"updated_by_id": null, "updated_by_id": null,
"auth_info": "password", "auth_info": "password",
"name": "Leopoldo Waelchi0", "name": "Rogers Bruen0",
"org_name": null, "org_name": null,
"registrar_id": 1, "registrar_id": 1,
"creator_str": "autotest", "creator_str": "autotest",
"updator_str": "autotest", "updator_str": "autotest",
"ident_country_code": "EE" "ident_country_code": "EE",
"city": "Tallinn",
"street": "Short street 11",
"zip": "11111",
"country_code": "EE",
"state": null
} }
], ],
"total_number_of_records": 2 "total_number_of_records": 2
@ -50,7 +62,6 @@ Content-Type: application/json
## GET /repp/v1/contacts ## GET /repp/v1/contacts
Returns contact names with offset. Returns contact names with offset.
### Example
#### Request #### Request
``` ```
@ -70,64 +81,8 @@ Content-Type: application/json
{ {
"contacts": [ "contacts": [
"sh226475261" "sh914462381"
], ],
"total_number_of_records": 2 "total_number_of_records": 2
} }
``` ```
## GET /repp/v1/contacts
Returns contact names of the current registrar.
### Example
#### Request
```
GET /repp/v1/contacts HTTP/1.1
Accept: application/json
Authorization: Basic Z2l0bGFiOmdoeXQ5ZTRmdQ==
Content-Length: 0
Content-Type: application/json
```
#### Response
```
HTTP/1.1 200
Cache-Control: max-age=0, private, must-revalidate
Content-Length: 70
Content-Type: application/json
{
"contacts": [
"sh470279120",
"sh226475261"
],
"total_number_of_records": 2
}
```
## GET /repp/v1/contacts
Returns an error with invalid parameters in contact index.
### Example
#### Request
```
GET /repp/v1/contacts?limit=0 HTTP/1.1
Accept: application/json
Authorization: Basic Z2l0bGFiOmdoeXQ5ZTRmdQ==
Content-Length: 0
Content-Type: application/json
```
#### Response
```
HTTP/1.1 400
Cache-Control: no-cache
Content-Length: 45
Content-Type: application/json
{
"error": "limit does not have a valid value"
}
```

View file

@ -1,7 +1,14 @@
## GET /repp/v1/domains ## GET /repp/v1/domains
Returns domains of the current registrar. Returns domains of the current registrar.
### Example
#### Parameters
| Field name | Required | Type | Allowed values |
| ---------- | -------- | ---- | -------------- |
| limit | false | Integer | [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
| offset | false | Integer | |
| details | false | String | ["true", "false"] |
#### Request #### Request
``` ```
@ -25,21 +32,21 @@ Content-Type: application/json
"id": 1, "id": 1,
"name": "domain0.ee", "name": "domain0.ee",
"registrar_id": 1, "registrar_id": 1,
"registered_at": "2015-03-31T07:39:11.598Z", "registered_at": "2015-04-01T10:30:48.773Z",
"status": null, "status": null,
"valid_from": "2015-03-31T00:00:00.000Z", "valid_from": "2015-04-01T00:00:00.000Z",
"valid_to": "2016-03-31T00:00:00.000Z", "valid_to": "2016-04-01T00:00:00.000Z",
"owner_contact_id": 1, "owner_contact_id": 1,
"auth_info": "fc7828fbc275ff16b86a31def3e7a60d", "auth_info": "1a93d4599945df52de0a38c64b470e67",
"created_at": "2015-03-31T07:39:11.595Z", "created_at": "2015-04-01T10:30:48.768Z",
"updated_at": "2015-03-31T07:39:11.591Z", "updated_at": "2015-04-01T10:30:48.762Z",
"name_dirty": "domain0.ee", "name_dirty": "domain0.ee",
"name_puny": "domain0.ee", "name_puny": "domain0.ee",
"period": 1, "period": 1,
"period_unit": "y", "period_unit": "y",
"creator_str": null, "creator_str": null,
"updator_str": null, "updator_str": null,
"whois_body": " This Whois Server contains information on\n Estonian Top Level Domain ee TLD\n\n domain: domain0.ee\n registrar: registrar1\n status:\n registered: \n changed: 2015-03-31 07:39:11\n expire:\n outzone:\n delete:\n\n \n\n nsset:\n nserver:\n\n registrar: registrar1\n phone: \n address: Street 111, Town, County, Postal\n created: 2015-03-31 07:39:11\n changed: 2015-03-31 07:39:11\n" "whois_body": " This Whois Server contains information on\n Estonian Top Level Domain ee TLD\n\n domain: domain0.ee\n registrar: registrar1\n status:\n registered: \n changed: 2015-04-01 10:30:48\n expire:\n outzone:\n delete:\n\n \n\n nsset:\n nserver:\n\n registrar: registrar1\n phone: \n address: Street 111, Town, County, Postal\n created: 2015-04-01 10:30:48\n changed: 2015-04-01 10:30:48\n"
} }
], ],
"total_number_of_records": 2 "total_number_of_records": 2
@ -49,7 +56,6 @@ Content-Type: application/json
## GET /repp/v1/domains ## GET /repp/v1/domains
Returns domain names with offset. Returns domain names with offset.
### Example
#### Request #### Request
``` ```
@ -74,59 +80,3 @@ Content-Type: application/json
"total_number_of_records": 2 "total_number_of_records": 2
} }
``` ```
## GET /repp/v1/domains
Returns domain names of the current registrar.
### Example
#### Request
```
GET /repp/v1/domains HTTP/1.1
Accept: application/json
Authorization: Basic Z2l0bGFiOmdoeXQ5ZTRmdQ==
Content-Length: 0
Content-Type: application/json
```
#### Response
```
HTTP/1.1 200
Cache-Control: max-age=0, private, must-revalidate
Content-Length: 67
Content-Type: application/json
{
"domains": [
"domain0.ee",
"domain1.ee"
],
"total_number_of_records": 2
}
```
## GET /repp/v1/domains
Returns an error with invalid parameters in domain index.
### Example
#### Request
```
GET /repp/v1/domains?limit=0 HTTP/1.1
Accept: application/json
Authorization: Basic Z2l0bGFiOmdoeXQ5ZTRmdQ==
Content-Length: 0
Content-Type: application/json
```
#### Response
```
HTTP/1.1 400
Cache-Control: no-cache
Content-Length: 45
Content-Type: application/json
{
"error": "limit does not have a valid value"
}
```

View file

@ -92,4 +92,5 @@ RSpec.configure do |config|
Autodoc.configuration.path = 'doc/repp/v1' Autodoc.configuration.path = 'doc/repp/v1'
Autodoc.configuration.suppressed_request_header = ['Host'] Autodoc.configuration.suppressed_request_header = ['Host']
Autodoc.configuration.suppressed_response_header = ['ETag', 'X-Request-Id', 'X-Runtime'] Autodoc.configuration.suppressed_response_header = ['ETag', 'X-Request-Id', 'X-Runtime']
Autodoc.configuration.template = File.read('spec/requests/repp_doc_template.md.erb')
end end

View file

@ -8,8 +8,8 @@ describe Repp::ContactV1 do
Fabricate.times(2, :contact) Fabricate.times(2, :contact)
end end
describe 'GET /repp/v1/contacts', autodoc: true do describe 'GET /repp/v1/contacts' do
it 'returns contacts of the current registrar' do it 'returns contacts of the current registrar', autodoc: true, route_info_doc: true do
get_with_auth '/repp/v1/contacts', { limit: 1, details: true }, @api_user get_with_auth '/repp/v1/contacts', { limit: 1, details: true }, @api_user
expect(response.status).to eq(200) expect(response.status).to eq(200)
@ -29,7 +29,7 @@ describe Repp::ContactV1 do
expect(log[:ip]).to eq('127.0.0.1') expect(log[:ip]).to eq('127.0.0.1')
end end
it 'returns contact names with offset' do it 'returns contact names with offset', autodoc: true do
get_with_auth '/repp/v1/contacts', { offset: 1 }, @api_user get_with_auth '/repp/v1/contacts', { offset: 1 }, @api_user
expect(response.status).to eq(200) expect(response.status).to eq(200)

View file

@ -8,9 +8,8 @@ describe Repp::DomainV1 do
Fabricate.times(2, :domain, registrar: @api_user.registrar) Fabricate.times(2, :domain, registrar: @api_user.registrar)
end end
describe 'GET /repp/v1/domains', autodoc: true do describe 'GET /repp/v1/domains' do
it 'returns domains of the current registrar' do it 'returns domains of the current registrar', autodoc: true, route_info_doc: true do
binding.pry
get_with_auth '/repp/v1/domains', { limit: 1, details: true }, @api_user get_with_auth '/repp/v1/domains', { limit: 1, details: true }, @api_user
response.status.should == 200 response.status.should == 200
@ -30,7 +29,7 @@ describe Repp::DomainV1 do
log[:ip].should == '127.0.0.1' log[:ip].should == '127.0.0.1'
end end
it 'returns domain names with offset' do it 'returns domain names with offset', autodoc: true do
get_with_auth '/repp/v1/domains', { offset: 1 }, @api_user get_with_auth '/repp/v1/domains', { offset: 1 }, @api_user
response.status.should == 200 response.status.should == 200

View file

@ -0,0 +1,20 @@
<%# coding: UTF-8 -%>
## <%= title %>
<%= description %>
<% rid = route_info_doc %>
<% if rid %>
#### Parameters
<%= rid %>
<% end %>
#### Request
```
<%= method %> <%= request.path %><%= request_query %> <%= request_http_version %>
<%= request_header %><%= request_body_section %>
```
#### Response
```
<%= response_http_version %> <%= response.status %>
<%= response_header %><%= response_body_section %>
```

View file

@ -29,26 +29,59 @@ module Request
) )
}) })
end end
def get_route_info(path)
route = Repp::API.routes.select do |x|
x.route_path.gsub('(.:format)', '').gsub(':version', x.route_version) == path
end.first
route_path = route.route_path.gsub('(.:format)', '').gsub(':version', route.route_version)
puts "#{route.route_method} #{route_path}"
puts " #{route.route_description}" if route.route_description
if route.route_params.is_a?(Hash)
params = route.route_params.map do |name, desc|
required = desc.is_a?(Hash) ? desc[:required] : false
description = desc.is_a?(Hash) ? desc[:description] : desc.to_s
[name, required, " * #{name}: #{description} #{required ? '(required)' : ''}"]
end end
puts " parameters:" module Autodoc
params.each { |p| puts p[2] } class Document
def route_info_doc
return unless example.metadata[:route_info_doc]
route = request.env["rack.routing_args"][:route_info]
return unless route.route_params.is_a?(Hash)
params_details = [
"| Field name | Required | Type | Allowed values |",
"| ---------- | -------- | ---- | -------------- |"
]
route.route_params.each do |name, desc|
details = []
details << "| #{name} "
details << "| #{desc[:required]} "
details << "| #{desc[:type]} "
details << "| #{desc[:values]} |"
params_details << details.join
# required = desc.is_a?(Hash) ? desc[:required] : false
# description = desc.is_a?(Hash) ? desc[:description] : desc.to_s
# [name, required, " * #{name}: #{description} #{required ? '(required)' : ''}"]
end
prettify_table(params_details).join("\n")
end
def prettify_table(rows)
# longest_in_col = 0
matrix_array = []
rows.each do |x|
matrix_array << x.split('|') + [''] # [''] is because split loses last |
end
new_arr = []
matrix_array.transpose.each do |col|
new_col = []
longest = col.max_by(&:size).size
col.each do |r|
new_col << r.center(longest)
end
new_arr << new_col
end
matrix_array = []
new_arr.transpose.each do |x|
matrix_array << x.join('|')
end
matrix_array
end end
end end
end end