Class: ApiExplorer::Request

Inherits:
Node
  • Object
show all
Defined in:
lib/api_explorer/request.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #parent, #path

Instance Method Summary collapse

Methods inherited from Node

#full_path

Constructor Details

#initialize(method, path, params = [], headers = [], description = "", excluded_shared_headers = []) ⇒ Request

Returns a new instance of Request.



5
6
7
8
9
10
11
12
13
# File 'lib/api_explorer/request.rb', line 5

def initialize(method, path, params = [], headers = [], description = "", excluded_shared_headers = [])
  super nil, nil, path

  self.method                  = method.to_s
  self.params                  = Array(params)
  self.headers                 = Array(headers)
  self.description             = description
  self.excluded_shared_headers = Array(excluded_shared_headers)
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/api_explorer/request.rb', line 3

def description
  @description
end

#excluded_shared_headersObject

Returns the value of attribute excluded_shared_headers.



3
4
5
# File 'lib/api_explorer/request.rb', line 3

def excluded_shared_headers
  @excluded_shared_headers
end

#headersObject

Returns the value of attribute headers.



3
4
5
# File 'lib/api_explorer/request.rb', line 3

def headers
  @headers
end

#methodObject

Returns the value of attribute method.



3
4
5
# File 'lib/api_explorer/request.rb', line 3

def method
  @method
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'lib/api_explorer/request.rb', line 3

def params
  @params
end

Instance Method Details

#titleObject



33
34
35
# File 'lib/api_explorer/request.rb', line 33

def title
  "#{method.upcase} #{path}"
end

#urlObject



15
16
17
# File 'lib/api_explorer/request.rb', line 15

def url
  full_path
end

#url_paramsObject



19
20
21
# File 'lib/api_explorer/request.rb', line 19

def url_params
  path.scan(/:[a-zA-Z_\-]+/).map { |s| s[1..s.size] }
end

#url_segmentsObject



23
24
25
26
27
28
29
30
31
# File 'lib/api_explorer/request.rb', line 23

def url_segments
  path.scan(/(:[a-zA-Z_\-]+)|([^:]+)/).map do |param, normal|
    if param
      [:param, param[1..param.size]]
    else
      [:normal, normal]
    end
  end
end