herdic 1.0.1 → 1.0.2

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: ef268be629514bf377f23553f43f248b81b4be1d
4
- data.tar.gz: 5650ca841a9f2755592bd60175970edf92bd7ace
3
+ metadata.gz: e293ef971ac5b07472c541fa6b6348183cdaf105
4
+ data.tar.gz: 2f0904dcdc7ecf20317d44e41434615ad8a856fb
5
5
  SHA512:
6
- metadata.gz: f43967abd1f488067ab213c43401b1e5bd2e66fd85f53c87965c6359e19133632780a52588f71af2fb37c945b2a8efc767ec4334e2ad3660afcdf04f1cb90ed8
7
- data.tar.gz: fe1f500659727cb2fb901720673c467eb8dc82aa3c956af6212315e4d4f2ee3b5c3d8396f5a8ba500ef42175cc6cb1abb7ac7018a76bc8b9dede286d09cd1329
6
+ metadata.gz: e7a737516853ed8aca699b0b5ccdf4a86235c67aa4c7eb7f0d5d80911bd23df7f246ae4d4c0edd52338296001f1c10363d17197d6d6a8dbe6b0f5bbd75a47aad
7
+ data.tar.gz: 68317f866a290521f3b8a5075aaf3712069a19ab2f9e63bd53f9f737a4b997ee505beb18ff10402fd42b132206c03de98b7c6d38dd129a5ab2495851e3d4cbe0
data/README.md CHANGED
@@ -4,6 +4,88 @@ Herdic
4
4
  **Herdic is a command line HTTP client intended to create and test API documentation with ease.**
5
5
 
6
6
 
7
+ Installation
8
+ ------------
9
+
10
+ ```sh
11
+ $ gem install herdic
12
+ ```
13
+
14
+ Or add the gem to your Gemfile.
15
+
16
+ ```ruby
17
+ gem 'herdic'
18
+ ```
19
+
20
+
21
+ Synopsis
22
+ --------
23
+
24
+ ```
25
+ herdic [-e] [-c config.yaml] [--use-ssl] path/to/spec.yaml
26
+ ```
27
+
28
+ | Option | Description |
29
+ | ---------------- | --------------------------------------------- |
30
+ | `-e` | Edit request file in vim (default) before run |
31
+ | `-c config.yaml` | Specify absolute path of herdic.yaml |
32
+ | `--use-ssl` | Use `Net::HTTP` with flag `use_ssl = true` |
33
+
34
+
35
+ Sample
36
+ ------
37
+
38
+ ### Config
39
+
40
+ ```yaml
41
+ # herdic.yaml
42
+ api_base: http://localhost:3000/user_v1
43
+
44
+ user_account:
45
+ email: user+1@example.com
46
+ password: password
47
+ ```
48
+
49
+ ### Specs
50
+
51
+ ```yaml
52
+ # sessions/create.yaml
53
+
54
+ - title: Signin as user
55
+ method: post
56
+ endpoint: <%= config['api_base'] %>/user_account/session
57
+
58
+ body:
59
+ user_account:
60
+ email: <%= config['user_account']['email'] %>
61
+ password: <%= config['user_account']['password'] %>
62
+
63
+ register:
64
+ user_account_access_token: user_account.access_token
65
+ ```
66
+
67
+ ```yaml
68
+ # user_bases/show.yaml
69
+
70
+ - include: ../sessions/create.yaml
71
+
72
+ - title: Show user basis
73
+ method: get
74
+ endpoint: <%= config['api_base'] %>/user_basis
75
+
76
+ header:
77
+ X-Access-Token: <%= registry['user_account_access_token'] %>
78
+ ```
79
+
80
+ ### Run
81
+
82
+ ```sh
83
+ $ herdic user_bases/show.yaml
84
+ ```
85
+
86
+ ![](./preview.gif)
87
+
88
+
7
89
  License
8
90
  -------
9
91
 
data/bin/herdic CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'herdic'
4
4
 
5
5
 
6
- options = ARGV.getopts 'e', 'c:', 'use-ssl', 'html'
6
+ options = ARGV.getopts 'e', 'c:', 'use-ssl'
7
7
  file = ARGV[0]
8
8
 
9
9
  raise 'No file given' if !file || file.empty?
data/lib/herdic.rb CHANGED
@@ -22,8 +22,8 @@ module Herdic
22
22
  @pwd = File.expand_path '.'
23
23
  @herdic_path = File.expand_path '~/.herdic'
24
24
  @store_path = File.join @herdic_path, 'store'
25
- @edit_request_file = File.join @herdic_path, 'edit_request.yml'
26
- @config_filename = 'herdic.yml'
25
+ @edit_request_file = File.join @herdic_path, 'edit_request.yaml'
26
+ @config_filename = 'herdic.yaml'
27
27
  end
28
28
 
29
29
  end
data/lib/herdic/client.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'active_support/core_ext'
2
2
  require 'erb'
3
+ require 'fileutils'
3
4
  require 'json'
4
5
  require 'net/http'
5
6
  require 'open-uri'
@@ -16,16 +17,16 @@ module Herdic
16
17
  def initialize(file, options)
17
18
  @file, @options = file, options
18
19
 
19
- @config_file = @options['c'] || Util.find_files_upward(Herdic.config_filename, Herdic.pwd, 1)[0]
20
20
  @context = binding
21
21
 
22
- @store = Store.new @config_file
23
- @registry = @store.data
22
+ @config_file = @options['c'] || Util.find_files_upward(Herdic.config_filename, Herdic.pwd, 1)[0]
23
+ load_config @config_file if @config_file
24
24
 
25
25
  @printer = Printer.new @options
26
+ @printer.start_message @config_file
26
27
 
27
- load_config @config_file if @config_file
28
- load_yaml
28
+ @store = Store.new @config_file
29
+ @registry = @store.data
29
30
  end
30
31
 
31
32
  def load_config(file)
@@ -38,24 +39,15 @@ module Herdic
38
39
  @config = Psych.load @config
39
40
  end
40
41
 
41
- def load_yaml
42
- @specs = Loader.new(@file).specs
43
-
42
+ def run_all
44
43
  if @options['e']
45
- File.open(Herdic.edit_request_file, 'w+') do |f|
46
- f.write Psych.dump(@specs)
47
- end
48
-
44
+ FileUtils.cp @file, Herdic.edit_request_file
49
45
  system "$EDITOR '%s'" % Herdic.edit_request_file
50
46
 
51
- File.open(Herdic.edit_request_file, 'r') do |f|
52
- @specs = Psych.load f.read
53
- end
47
+ @specs = Loader.new Herdic.edit_request_file, @file
48
+ else
49
+ @specs = Loader.new @file
54
50
  end
55
- end
56
-
57
- def run_all
58
- @printer.start_message @specs
59
51
 
60
52
  @specs.each do |spec|
61
53
  # FIXME: figure out better way
data/lib/herdic/loader.rb CHANGED
@@ -4,34 +4,39 @@ require 'psych'
4
4
  module Herdic
5
5
  class Loader
6
6
 
7
- attr_accessor :specs
7
+ include Enumerable
8
8
 
9
- def initialize(file)
10
- @specs = []
11
-
12
- load file
9
+ def initialize(file, original = nil)
10
+ @file, @original = file, original
13
11
  end
14
12
 
15
- def load(file, included_from = nil)
13
+ def load(file, original, included_from = nil)
16
14
  file = File.expand_path file, included_from
17
15
 
16
+ specs = ''
17
+
18
18
  File.open(file, 'r') do |f|
19
- @_specs = f.read
19
+ specs = f.read
20
20
  end
21
21
 
22
- @_specs = Psych.load @_specs
22
+ specs = Psych.load specs
23
23
 
24
- @_specs.each do |spec|
25
- spec['file'] = file
24
+ specs.each do |spec|
25
+ spec['file'] = original || file
26
26
 
27
27
  if spec['include']
28
- load spec['include'], File.dirname(file)
28
+ load spec['include'], nil, File.dirname(spec['file'])
29
29
  else
30
- @specs << spec
30
+ @block.call spec
31
31
  end
32
32
  end
33
+ end
34
+
35
+ def each(&block)
36
+ return unless block
33
37
 
34
- @_specs = nil
38
+ @block = block
39
+ load @file, @original
35
40
  end
36
41
 
37
42
  end
@@ -9,8 +9,12 @@ module Herdic
9
9
  @options = options
10
10
  end
11
11
 
12
- def start_message(specs)
13
- puts 'Running %d spec(s)' % specs.size
12
+ def start_message(config_file = nil)
13
+ if config_file
14
+ puts "Starting Herdic (#{config_file})"
15
+ else
16
+ puts 'Starting Herdic'
17
+ end
14
18
  end
15
19
 
16
20
  def title(meta)
@@ -93,4 +97,3 @@ module Herdic
93
97
 
94
98
  end
95
99
  end
96
-
@@ -2,7 +2,7 @@ module Herdic
2
2
 
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- REVISION = 1
5
+ REVISION = 2
6
6
 
7
7
  VERSION = [MAJOR, MINOR, REVISION].compact.join '.'
8
8
 
data/preview.gif ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: herdic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Iwanaga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-18 00:00:00.000000000 Z
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -91,12 +91,12 @@ files:
91
91
  - herdic.gemspec
92
92
  - lib/herdic.rb
93
93
  - lib/herdic/client.rb
94
- - lib/herdic/color.rb
95
94
  - lib/herdic/loader.rb
96
95
  - lib/herdic/printer.rb
97
96
  - lib/herdic/store.rb
98
97
  - lib/herdic/util.rb
99
98
  - lib/herdic/version.rb
99
+ - preview.gif
100
100
  homepage: https://github.com/creasty/herdic
101
101
  licenses:
102
102
  - MIT
data/lib/herdic/color.rb DELETED
@@ -1 +0,0 @@
1
- class Her