Class: ApiSpec::Parameters
- Inherits:
-
Object
- Object
- ApiSpec::Parameters
show all
- Defined in:
- lib/api_spec/parameters.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(method, path, table = nil) ⇒ Parameters
Returns a new instance of Parameters.
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/api_spec/parameters.rb', line 5
def initialize(method, path, table = nil)
@method = method
@path = path
@path_params = {}
@query = {}
@form = {}
@json = {}
@cookie = {}
@header = {}
load_table(table) if table
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
32
33
34
|
# File 'lib/api_spec/parameters.rb', line 32
def method_missing(name)
State.get(name)
end
|
Instance Attribute Details
#query ⇒ Object
Returns the value of attribute query.
3
4
5
|
# File 'lib/api_spec/parameters.rb', line 3
def query
@query
end
|
Instance Method Details
#body ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/api_spec/parameters.rb', line 36
def body
if @json.any?
@json.to_json
elsif @form.any?
@form
else
""
end
end
|
60
61
62
63
64
65
66
67
|
# File 'lib/api_spec/parameters.rb', line 60
def
if @json.any?
{content_type: :json, "CONTENT_TYPE" => "application/json"}
else
{}
end
end
|
50
51
52
|
# File 'lib/api_spec/parameters.rb', line 50
def
{ "Cookie" => cookie_string, "HTTP_COOKIE" => cookie_string }
end
|
#cookie_string ⇒ Object
54
55
56
57
58
|
# File 'lib/api_spec/parameters.rb', line 54
def cookie_string
@cookie
.map { |key, value| "#{key}=#{value}" }
.join("; ")
end
|
46
47
48
|
# File 'lib/api_spec/parameters.rb', line 46
def
@header.merge().merge()
end
|
#url ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/api_spec/parameters.rb', line 19
def url
interpolated_path = @path.scan(/\{(.*?)\}/).reduce(@path) do |path, match|
key = match.first
value = @path_params[key]
raise StandardError.new("Missing #{key}") unless value
path.gsub /\{#{key}\}/, URI.encode(value)
end
"http://localhost:#{$port}#{interpolated_path}"
end
|