herdic 1.0.0 → 1.0.1

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: db085b78a8df105d3eb982a5b834d7304c1a8260
4
- data.tar.gz: 5c30a1b5ec2a9f5eaa5d40f011fd84276942392a
3
+ metadata.gz: ef268be629514bf377f23553f43f248b81b4be1d
4
+ data.tar.gz: 5650ca841a9f2755592bd60175970edf92bd7ace
5
5
  SHA512:
6
- metadata.gz: 2ddd65a6cbc49daa112c8cb94afd8be6b94aefd1d6b3788f3e8ea4615a9eea5f409f9a094751a5e964e52a8758410e9f077050332bf14f41099639e44f913f32
7
- data.tar.gz: 5d2cfe473cbef993e072f529a14bd00cfcf39569a7bf3e4f2de55bea794adb219ad5095806c56cdd9a1c01f6ea6f4a02d33a2b113f7b542e82c4b19fbc4fdc38
6
+ metadata.gz: f43967abd1f488067ab213c43401b1e5bd2e66fd85f53c87965c6359e19133632780a52588f71af2fb37c945b2a8efc767ec4334e2ad3660afcdf04f1cb90ed8
7
+ data.tar.gz: fe1f500659727cb2fb901720673c467eb8dc82aa3c956af6212315e4d4f2ee3b5c3d8396f5a8ba500ef42175cc6cb1abb7ac7018a76bc8b9dede286d09cd1329
data/herdic.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'activesupport', '~> 4.1', '>= 3.2'
22
- spec.add_dependency 'awesome_print', '~> 1.2'
22
+ spec.add_dependency "pygments.rb"
23
23
 
24
24
  spec.add_development_dependency 'bundler', '~> 1.6'
25
25
  spec.add_development_dependency 'rake', '~> 10.3'
data/lib/herdic.rb CHANGED
@@ -1,9 +1,9 @@
1
- require 'herdic/version'
2
- require 'herdic/util'
3
- require 'herdic/store'
4
- require 'herdic/loader'
5
- require 'herdic/printer'
6
- require 'herdic/client'
1
+ require_relative 'herdic/version'
2
+ require_relative 'herdic/util'
3
+ require_relative 'herdic/store'
4
+ require_relative 'herdic/loader'
5
+ require_relative 'herdic/printer'
6
+ require_relative 'herdic/client'
7
7
 
8
8
  require 'fileutils'
9
9
 
@@ -23,7 +23,7 @@ module Herdic
23
23
  @herdic_path = File.expand_path '~/.herdic'
24
24
  @store_path = File.join @herdic_path, 'store'
25
25
  @edit_request_file = File.join @herdic_path, 'edit_request.yml'
26
- @config_filename = 'api_config.yml'
26
+ @config_filename = 'herdic.yml'
27
27
  end
28
28
 
29
29
  end
data/lib/herdic/client.rb CHANGED
@@ -78,15 +78,8 @@ module Herdic
78
78
 
79
79
  response = http.start do
80
80
  case @meta['method']
81
- when 'GET'
82
- uri.query = @body.to_query
83
- http.get uri.request_uri, @header
84
- when 'POST'
85
- http.post uri.request_uri, @body.to_query, @header
86
- when 'PATCH'
87
- http.patch uri.request_uri, @body.to_query, @header
88
- when 'DELETE'
89
- http.delete uri.request_uri, @header
81
+ when 'GET', 'POST', 'PATCH', 'PUT', 'DELETE'
82
+ http.send_request @meta['method'], uri.request_uri, @body.to_query, @header
90
83
  else
91
84
  raise "Unsupported method: #{@meta['method']}"
92
85
  end
@@ -105,7 +98,7 @@ module Herdic
105
98
  private def setup_spec(spec)
106
99
  @meta = spec.slice 'title', 'method', 'endpoint'
107
100
  @register = spec['register'] || {}
108
- @header = spec['header'] || {}
101
+ @header = spec['header'] || {}
109
102
  @body = spec['body'] || {}
110
103
 
111
104
  @meta['method'].upcase!
@@ -0,0 +1 @@
1
+ class Her
@@ -1,4 +1,5 @@
1
- require 'ap'
1
+ require 'json'
2
+ require 'pygments'
2
3
 
3
4
 
4
5
  module Herdic
@@ -16,11 +17,11 @@ module Herdic
16
17
  puts "\n\n"
17
18
  hr rule: '=', color: :green
18
19
 
19
- puts [meta['method'].green, meta['endpoint']].join(' ')
20
+ puts [Util.color(meta['method'], :green), meta['endpoint']].join(' ')
20
21
 
21
22
  if meta['title']
22
23
  indent = ' ' * meta['method'].size
23
- puts [indent, meta['title'].white].join(' ')
24
+ puts [indent, Util.color(meta['title'], :white)].join(' ')
24
25
  end
25
26
 
26
27
  hr rule: '=', color: :green
@@ -28,22 +29,22 @@ module Herdic
28
29
 
29
30
  def subtitle(text)
30
31
  puts
31
- puts "==> #{text}".blue
32
- puts
32
+ puts Util.color(text, :green)
33
+ hr color: :green
33
34
  end
34
35
 
35
36
  def request(header, body)
36
37
  subtitle 'Request'
37
38
 
38
39
  if header.empty?
39
- puts 'no header'.white
40
+ puts Util.color('no header', :white)
40
41
  else
41
42
  print_header header
42
43
  end
43
44
 
44
45
  hr
45
46
 
46
- ap body
47
+ print_json body
47
48
  end
48
49
 
49
50
  def response(response, body)
@@ -54,25 +55,36 @@ module Herdic
54
55
  hr
55
56
 
56
57
  if body.empty?
57
- puts 'no body'.white
58
+ puts Util.color('no body', :white)
58
59
  elsif 'application/json' == response.content_type
59
- ap body
60
- elsif @options['html']
61
- puts body
60
+ print_json body
62
61
  else
63
- puts 'N/A'.white
62
+ puts body
64
63
  end
65
64
  end
66
65
 
67
66
  private def print_header(header)
68
67
  max_cols = header.keys.map(&:size).max
69
68
  header.each do |k, v|
70
- puts [("%#{max_cols}s" % k).white, v].join ' '
69
+ puts [Util.color("%#{max_cols}s" % k, :white), v].join ' '
71
70
  end
72
71
  end
73
72
 
73
+ private def print_json(json)
74
+ if json.empty?
75
+ puts '{}'
76
+ return
77
+ end
78
+
79
+ puts Pygments.highlight(JSON.pretty_generate(json), {
80
+ formatter: 'terminal',
81
+ lexer: 'json',
82
+ options: { encoding: 'utf-8' },
83
+ })
84
+ end
85
+
74
86
  private def hr(rule: '-', color: :black)
75
- puts (rule * terminal_cols).send(color)
87
+ puts Util.color(rule * terminal_cols, color)
76
88
  end
77
89
 
78
90
  private def terminal_cols
data/lib/herdic/util.rb CHANGED
@@ -1,24 +1,45 @@
1
+ require 'cgi'
2
+
3
+
1
4
  module Herdic
2
5
  module Util
6
+ class << self
7
+
8
+ def find_files_upward(filename, base, count = 0)
9
+ found = []
10
+ found_count = 0
11
+
12
+ while count == 0 || found_count <= count
13
+ file = File.join base, filename
3
14
 
4
- def self.find_files_upward(filename, base, count = 0)
5
- found = []
15
+ if File.exists? file
16
+ found << file
17
+ found_count += 1
18
+ end
6
19
 
7
- while count >= 1 || count < 0
8
- file = File.join base, filename
20
+ break if '.' == base || '/' == base
9
21
 
10
- if File.exists? file
11
- found << file
12
- count -= 1
22
+ base = File.dirname base
13
23
  end
14
24
 
15
- break if '.' == base
25
+ found
26
+ end
27
+
28
+ COLORS = {
29
+ black: 0,
30
+ red: 1,
31
+ green: 2,
32
+ yellow: 3,
33
+ blue: 4,
34
+ magenta: 5,
35
+ cyan: 6,
36
+ white: 7,
37
+ }
16
38
 
17
- base = File.dirname base
39
+ def color(str, c)
40
+ "\e[1;#{30+COLORS[c]}m#{str}\e[0m"
18
41
  end
19
42
 
20
- found
21
43
  end
22
-
23
44
  end
24
45
  end
@@ -2,7 +2,7 @@ module Herdic
2
2
 
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- REVISION = 0
5
+ REVISION = 1
6
6
 
7
7
  VERSION = [MAJOR, MINOR, REVISION].compact.join '.'
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: herdic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Iwanaga
@@ -31,19 +31,19 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: '3.2'
33
33
  - !ruby/object:Gem::Dependency
34
- name: awesome_print
34
+ name: pygments.rb
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '1.2'
39
+ version: '0'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - "~>"
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: '1.2'
46
+ version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -91,6 +91,7 @@ files:
91
91
  - herdic.gemspec
92
92
  - lib/herdic.rb
93
93
  - lib/herdic/client.rb
94
+ - lib/herdic/color.rb
94
95
  - lib/herdic/loader.rb
95
96
  - lib/herdic/printer.rb
96
97
  - lib/herdic/store.rb