herdic 1.0.2 → 1.0.3

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: e293ef971ac5b07472c541fa6b6348183cdaf105
4
- data.tar.gz: 2f0904dcdc7ecf20317d44e41434615ad8a856fb
3
+ metadata.gz: 76bb219a1e205279d9c5fe7ea6387d028e6f7d61
4
+ data.tar.gz: 26bfb9573646e1fef72de5d946fff6d118fa3746
5
5
  SHA512:
6
- metadata.gz: e7a737516853ed8aca699b0b5ccdf4a86235c67aa4c7eb7f0d5d80911bd23df7f246ae4d4c0edd52338296001f1c10363d17197d6d6a8dbe6b0f5bbd75a47aad
7
- data.tar.gz: 68317f866a290521f3b8a5075aaf3712069a19ab2f9e63bd53f9f737a4b997ee505beb18ff10402fd42b132206c03de98b7c6d38dd129a5ab2495851e3d4cbe0
6
+ metadata.gz: 954aa0df95280a8232b542a714895a453a9d2a0919a2637692e1b0df668561ec7809bfeec58d8c85f88cbc8c0e20996a8f5c920c8ee69c7cc6516699c12af942
7
+ data.tar.gz: 0d969818ec0da955b19b4086d3aded6dfb691eb081bbaa868e71f060b99d83e8edd6fbaa6995fc3e015b3c880a8d058dfe860e5de2d1ac5325379bacb916e1f5
data/lib/herdic.rb CHANGED
@@ -16,7 +16,8 @@ module Herdic
16
16
  :herdic_path,
17
17
  :store_path,
18
18
  :edit_request_file,
19
- :config_filename
19
+ :config_filename,
20
+ :editor
20
21
 
21
22
  def initialize
22
23
  @pwd = File.expand_path '.'
@@ -24,6 +25,7 @@ module Herdic
24
25
  @store_path = File.join @herdic_path, 'store'
25
26
  @edit_request_file = File.join @herdic_path, 'edit_request.yaml'
26
27
  @config_filename = 'herdic.yaml'
28
+ @editor = '/usr/bin/env vim'
27
29
  end
28
30
 
29
31
  end
data/lib/herdic/client.rb CHANGED
@@ -42,7 +42,7 @@ module Herdic
42
42
  def run_all
43
43
  if @options['e']
44
44
  FileUtils.cp @file, Herdic.edit_request_file
45
- system "$EDITOR '%s'" % Herdic.edit_request_file
45
+ system "%s '%s'" % [Herdic.editor, Herdic.edit_request_file]
46
46
 
47
47
  @specs = Loader.new Herdic.edit_request_file, @file
48
48
  else
@@ -64,11 +64,27 @@ module Herdic
64
64
  private def run(spec)
65
65
  setup_spec spec
66
66
 
67
+ @printer.title @meta
68
+ @printer.request @header, @body
69
+
70
+ response = get_response
71
+
72
+ body = response.body
73
+
74
+ if 'application/json' == response.content_type
75
+ body = JSON.parse body
76
+ register response, body
77
+ end
78
+
79
+ @printer.response response, body
80
+ end
81
+
82
+ private def get_response
67
83
  uri = URI.parse @meta['endpoint']
68
84
  http = Net::HTTP.new uri.host, uri.port
69
85
  http.use_ssl = @options['use-ssl']
70
86
 
71
- response = http.start do
87
+ http.start do
72
88
  case @meta['method']
73
89
  when 'GET', 'POST', 'PATCH', 'PUT', 'DELETE'
74
90
  http.send_request @meta['method'], uri.request_uri, @body.to_query, @header
@@ -76,15 +92,6 @@ module Herdic
76
92
  raise "Unsupported method: #{@meta['method']}"
77
93
  end
78
94
  end
79
-
80
- body = response.body
81
- body = JSON.parse body if 'application/json' == response.content_type
82
-
83
- @printer.title @meta
84
- @printer.request @header, @body
85
- @printer.response response, body
86
-
87
- register response, body
88
95
  end
89
96
 
90
97
  private def setup_spec(spec)
@@ -98,8 +105,6 @@ module Herdic
98
105
  end
99
106
 
100
107
  private def register(response, body)
101
- return unless 'application/json' == response.content_type
102
-
103
108
  @register.each do |name, path|
104
109
  next if path.empty?
105
110
 
@@ -58,7 +58,7 @@ module Herdic
58
58
 
59
59
  hr
60
60
 
61
- if body.empty?
61
+ if !body || body.empty?
62
62
  puts Util.color('no body', :white)
63
63
  elsif 'application/json' == response.content_type
64
64
  print_json body
@@ -2,7 +2,7 @@ module Herdic
2
2
 
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- REVISION = 2
5
+ REVISION = 3
6
6
 
7
7
  VERSION = [MAJOR, MINOR, REVISION].compact.join '.'
8
8
 
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.2
4
+ version: 1.0.3
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-19 00:00:00.000000000 Z
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport