apitest 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4c952cd85e1b81d7f680d663d77b1d0525ede63
4
- data.tar.gz: 2ffbda569a158b43255fab59cd8216cd7eea9f8a
3
+ metadata.gz: b0633ebdeafbf793f850ec77c572c6e10687c1aa
4
+ data.tar.gz: c8a24eb02574bf285718e4b2a1ea651168e11193
5
5
  SHA512:
6
- metadata.gz: 838ae386e16075d421b9aca54a28702c670d966eedba3eaefcb8dc989fa25318ed946d7109f969e3c70c810b508123bb2580d2e13c713354a195fbcaebeebfe9
7
- data.tar.gz: 871dfc1d7b8cd81794b54296b75b5be9c9cf7a837a3d74c94858dcd6841785ce77990b8c5922e489fb128dda73665a6573d61a09247d1aa4b479d1e30e78585b
6
+ metadata.gz: 4f9234362ef3cb83cc44be3368aee0a21c8d6c82bbf1d1d2d5a67b28ffb010090372e4858aab9749071d7b719de690bfab6a3c36e7d60279200d386fc0a2f994
7
+ data.tar.gz: b96dc2f3036ffd72dec49ab2744cd491ffab60b8f92e059b361e268801c35e78588ba419248d1b71a197029fc75ba7d8b0f9235ecff95239070255642414ba5f
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # Apitest
2
- Short description and motivation.
2
+ - 通过在API controller里的常量,配置API文档
3
+ - 并附带一个测试界面,辅助API开发。
4
+ - 适用与API开发人员,客户端/前端开发人员交流验证文档。
5
+ - 目前无出参,需要提交后,得到无法完全替代API文档
3
6
 
4
7
  ## Version
5
- 0.1.8
8
+ 0.1.9
6
9
 
7
10
  ## Installation
8
11
  添加如下代码到 Gemfile:
@@ -45,25 +45,24 @@ $(document).on "turbolinks:load" , ->
45
45
  elm = $(e.target).parents('.api')
46
46
  result = elm.find('.result')
47
47
  result_pre = elm.find('.result_pre')
48
- path = elm.find('.path').val()
48
+ path = elm.find('.path').val().replace ':id' , elm.find('.params[name=":id"]').val()
49
49
  method = elm.find('.method').text()
50
50
  postData = {}
51
51
 
52
52
  elm.find('.params').each ->
53
- postData[$(this).attr('name')] = $(this).val()
53
+
54
+ postData[$(this).attr('name')] = $(this).val() unless $(this).attr('name').indexOf(':id') >= 0
54
55
 
55
56
  $.ajax
56
57
  url : path
57
58
  type : method
58
59
  data : postData
59
60
  success : (data) =>
60
- # result.val JSON.stringify(data , null , 4)
61
61
  result_pre.jsonViewer(data)
62
62
  error : (data) =>
63
63
  result.val data.responseText
64
64
 
65
65
  clear_result : (e) ->
66
- # $(e.target).parents('.api').find('.result').val('')
67
66
  $(e.target).parents('.api').find('.result_pre').html('')
68
67
 
69
68
  log_scroll : ->
@@ -42,17 +42,12 @@ module Apitest
42
42
  class_match = File.open(path).read.match(/class (.*) </)
43
43
  controller_class = class_match[1].constantize if class_match && class_match[1]
44
44
  if defined? controller_class::APIDOC
45
- token_need = {
46
- token: {
47
- text: 'token' ,
48
- required: true ,
49
- }
50
- }
51
45
  doc = controller_class::APIDOC
52
46
  doc[:sort] = 99 if doc[:sort].blank?
53
47
  doc[:apis].each do |k,v|
54
- doc[:apis][k][:params] = token_need.merge doc[:apis][k][:params] unless v[:token] == false
55
- # doc[:apis][k][:params] = general_need
48
+ d = doc[:apis][k]
49
+ d = public_required d unless Apitest::public_required.blank?
50
+ d[:params] = {':id' => { required: true }}.merge d[:params] if d[:path].include? ':id'
56
51
  end
57
52
 
58
53
  docs[doc[:type]] = [] if docs[doc[:type]].blank?
@@ -62,8 +57,11 @@ module Apitest
62
57
  end
63
58
  docs
64
59
  end
65
- def general_need(api_params)
66
-
60
+ def public_required(api)
61
+ Apitest::public_required.reverse.each do |need|
62
+ api[:params] = need.merge api[:params] if api[need.keys.first.to_sym] != false
63
+ end
64
+ api
67
65
  end
68
66
  end
69
67
  end
@@ -1,3 +1,3 @@
1
1
  module Apitest
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
data/lib/apitest.rb CHANGED
@@ -13,7 +13,7 @@ module Apitest
13
13
  @api_dir
14
14
  @theme
15
15
  @default_types
16
- @general_need
16
+ @public_required
17
17
  class << self
18
18
  def api_dir(dir = nil)
19
19
  @api_dir = dir if dir
@@ -34,13 +34,14 @@ module Apitest
34
34
  @default_types
35
35
  end
36
36
 
37
- def general_need(general_need = [])
38
- return @general_need if general_need.blank?
39
- @general_need = {}
40
- general_need.each do |need|
41
- @general_need[need] = { text: need.to_s , required: true }
37
+ def public_required(public_required = [])
38
+ return @public_required if public_required.blank?
39
+ @public_required = []
40
+ public_required.each do |need|
41
+ n = { need => {required: true }}
42
+ @public_required.push n
42
43
  end
43
- @general_need
44
+ @public_required
44
45
  end
45
46
 
46
47
  def start_server_log_listen
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apitest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyuubi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-26 00:00:00.000000000 Z
11
+ date: 2017-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails