lapiz 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/lapiz/version.rb +1 -1
  3. data/lib/lapiz.rb +35 -6
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0ab0b44e4874b9bdfc660a8a5aac8d713590293
4
- data.tar.gz: 9d06ae27e0b93082aabb4c5a7f38ce21a969b1c2
3
+ metadata.gz: df794cb2e0809ed82604aab62e686c2fef7a76a3
4
+ data.tar.gz: 6e687df08e82ab48483855f36c45d4e1da7cf501
5
5
  SHA512:
6
- metadata.gz: b4b1ec0a78f21c60d0b38280c8601e374b03fb72172b2063dc63f7d02edddb3464e514016c9d249da59393eee255119a817098e8649f80efca6b7155a64f1a93
7
- data.tar.gz: eb4b20fc26669e158fc1364461845e259f90810a5c8821bb3fecffeb4373faa6a7a4c237e6562b6ead964fca5107dd85309d0b8f79bae629da73794520751c78
6
+ metadata.gz: 8c34a733d6c6d4bd76e92e1e86e67df3951920d46f59561fb022ecf14e2c08654a34d6ebf59565b7a200e22125644c4061b226cb290dc73180f2f69f75639772
7
+ data.tar.gz: 1a1f9e089081adcfed2ebc16f6ad50cc996925c93a4023cd2d6a319a031ed1f90a49872f0d6cca0e776525ae8353aaa79e02f89a26f7ad4d47d5bb5bbbe0d7df
data/lib/lapiz/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lapiz
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
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, path, params, &block)
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 '#{path}'", self do |group|
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} #{path}"
117
+ fp.puts "## #{method.to_s.upcase} #{pattern}"
115
118
  fp.puts
116
119
 
117
- if request_type
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
- fp.puts " + #{CGI.escape(k)}: \"#{v.to_s}\" (#{v.class.name})"
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.1
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-06 00:00:00.000000000 Z
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler