lapiz 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lapiz/version.rb +1 -1
- data/lib/lapiz.rb +35 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df794cb2e0809ed82604aab62e686c2fef7a76a3
|
4
|
+
data.tar.gz: 6e687df08e82ab48483855f36c45d4e1da7cf501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c34a733d6c6d4bd76e92e1e86e67df3951920d46f59561fb022ecf14e2c08654a34d6ebf59565b7a200e22125644c4061b226cb290dc73180f2f69f75639772
|
7
|
+
data.tar.gz: 1a1f9e089081adcfed2ebc16f6ad50cc996925c93a4023cd2d6a319a031ed1f90a49872f0d6cca0e776525ae8353aaa79e02f89a26f7ad4d47d5bb5bbbe0d7df
|
data/lib/lapiz/version.rb
CHANGED
data/lib/lapiz.rb
CHANGED
@@ -82,14 +82,17 @@ module Lapiz
|
|
82
82
|
http_call(:delete, path, params, &block)
|
83
83
|
end
|
84
84
|
|
85
|
-
def http_call(method,
|
85
|
+
def http_call(method, path_pattern, params, &block)
|
86
|
+
path = path_pattern.gsub(/{([^{}]*)}/) { $1.split("=").last } # path_pattern contains {field=default_value}. gsub it with default value
|
87
|
+
pattern = path_pattern.gsub(/{([^{}]*)}/) { "{#{$1.split("=").first}}" } # same as above, but gsub it with field
|
88
|
+
|
86
89
|
if block.nil?
|
87
90
|
config = YAML.load(IO.read("config.yml"))
|
88
91
|
base_uri = config["server"]["base_uri"]
|
89
92
|
return HTTParty.send(method, base_uri + path, params)
|
90
93
|
end
|
91
94
|
|
92
|
-
it "tests action '#{
|
95
|
+
it "tests action '#{pattern}'", self do |group|
|
93
96
|
expect {
|
94
97
|
@response = HTTParty.send(method, group.metadata[:base_uri] + path, params)
|
95
98
|
}.to_not raise_error
|
@@ -111,22 +114,48 @@ module Lapiz
|
|
111
114
|
|
112
115
|
group_name = group.metadata[:group_name]
|
113
116
|
File.open("api_docs/#{group_name.gsub(/[^a-zA-Z_]+/,'_').underscore}.txt", "a+") do |fp|
|
114
|
-
fp.puts "## #{method.to_s.upcase} #{
|
117
|
+
fp.puts "## #{method.to_s.upcase} #{pattern}"
|
115
118
|
fp.puts
|
116
119
|
|
117
|
-
if
|
120
|
+
if @response.request.options[:description]
|
121
|
+
fp.puts @response.request.options[:description].lstrip
|
122
|
+
end
|
123
|
+
|
124
|
+
if request_type || (path != pattern) # path != pattern when there is a url pattern # TODO: Use better checks
|
118
125
|
if request_type == "application/json"
|
119
126
|
fp.puts "+ Request (#{request_type})"
|
120
|
-
elsif request_type == "x-www-form-urlencoded"
|
127
|
+
elsif request_type == "x-www-form-urlencoded" || (path != pattern)
|
121
128
|
fp.puts "+ Parameters"
|
122
129
|
|
130
|
+
flattened_params = {}
|
123
131
|
if @response.request.options[:body]
|
124
132
|
flattened_params = @response.request.options[:body] ? @response.request.options[:body].flatten : {}
|
125
133
|
flattened_params.each_pair do |k,v|
|
126
|
-
|
134
|
+
description = nil
|
135
|
+
if @response.request.options[:parameter_descriptions]
|
136
|
+
description = @response.request.options[:parameter_descriptions][k.to_s] || @response.request.options[:parameter_descriptions][k.to_sym]
|
137
|
+
end
|
138
|
+
fp.puts " + #{CGI.escape(k)}: (#{v.class.name})#{description ? " - #{description}" : ""}"
|
127
139
|
end
|
128
140
|
end
|
141
|
+
|
142
|
+
# This converts param_desc hash to an array ([[k1,v1],[k2,v2]]), removes any which are already in the body (and hence documented), and then convers back to hash
|
143
|
+
@response.request.options[:parameter_descriptions].to_a.map{|e| [e[0].to_s, e[1]]}.reject{|e| flattened_params.keys.include?(e[0])}.to_h.each_pair do |k,v|
|
144
|
+
fp.puts " + #{CGI.escape(k)}: (String) - #{v}"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
if @response.request.options[:headers]
|
150
|
+
fp.puts
|
151
|
+
fp.puts "+ Request"
|
152
|
+
fp.puts
|
153
|
+
fp.puts " + Headers"
|
154
|
+
fp.puts
|
155
|
+
@response.request.options[:headers].each_pair do |k,v|
|
156
|
+
fp.puts " #{k}: #{v}"
|
129
157
|
end
|
158
|
+
fp.puts
|
130
159
|
end
|
131
160
|
|
132
161
|
if @response.body && (@response.code / 100 == 2)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lapiz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ajith Hussain
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|