mudbug 0.7.1.1 → 0.7.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +15 -0
  2. data/VERSION +1 -1
  3. data/bin/mb +99 -59
  4. data/lib/mudbug.rb +1 -1
  5. metadata +5 -19
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzczZGM4MGZkMWIxMjI3NDg5Y2ZiYzVjM2UyNmRlM2FhM2E5OTQxYw==
5
+ data.tar.gz: !binary |-
6
+ MGVjNzE3MTBiMmU3MzA3YTJmOWRkNjJiYTkxYmEwNWE0OTMyMGVkMg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ N2M2OTBjMDVjODE1OTIwMmQ3ZjcwOGM1YmUxYzlmYzBjOTRhY2I1MWIwZTQ5
10
+ MzI5MWY3YWI1ZjRiOTBiNTJmMGE4MDM0NDNhMmRlMjc1MjMzZDMyMzg1ZmM5
11
+ MjUyZDIxMzQ2NTk5ZGFmYTkxZjQ3MWU2N2IwOTk0ZDU1YzA3NDU=
12
+ data.tar.gz: !binary |-
13
+ YjcxOWU0OWIyZjZjNzEwN2JiNjhiMDdhZTQ2NThkN2ViOTFlOWIzMjY4ODlj
14
+ YzQ0MmU2Yjg1NGYwZDRiNWIwZDQ3NTdmMmQ1M2QzMzNiZWFjMmZkZmYwNmNk
15
+ ZjBjYTY5YTRmMjQ0ZDg2YjNiOTc0MmM5MjI4ODIyZjFhYzBmNGM=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.1.1
1
+ 0.7.3.1
data/bin/mb CHANGED
@@ -1,26 +1,53 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ bef_require = Time.now
4
+
3
5
  require 'dotcfg'
4
6
  require 'mudbug'
5
7
 
8
+ $VERBOSE = ARGV.delete '--verbose'
9
+ Mudbug.log_level = :info if $VERBOSE
10
+ if ARGV.delete '--debug'
11
+ Mudbug.log_level = :debug
12
+ $VERBOSE = true
13
+ end
14
+
15
+ puts "Required in #{Time.now - bef_require} seconds" if $VERBOSE
16
+ bef_config = Time.now
17
+
6
18
  CONFIG = DotCfg.new '~/.mudbug', :json
19
+ RESET_ARG = '--reset'
20
+
21
+ puts "Loaded in #{Time.now - bef_config} seconds" if $VERBOSE
22
+
23
+ START = Time.now
7
24
 
8
25
  def usage(msg = nil)
9
26
  print "ERROR: #{msg}\n\n" if msg
10
27
  puts <<EOF
11
28
  USAGE:
12
- mb [get|delete] [PATH] - GET or DELETE PATH
13
- mb [post|put] [PATH] - - POST or PUT payload (STDIN) to PATH
14
-
15
- mb host|method|path [VAL] - Set or display current config item
16
- mb accept [ACC1] [ACC2] [etc] - Set or display accept types
17
- mb payload [-] - Set (from STDIN) or display payload config
18
- mb config - Display current config
19
-
20
- * A `host` must be configured for mb to operate
21
- * `method`, `path`, and `payload`, if configured, are not required arguments
22
- * Set a config item to nil in order to remove it
23
- * `accept` is optional; valid values include json, html, text
29
+ mb [get|delete] [$path] - GET or DELETE $path
30
+ mb [post|put] [$path] [-|"$json"] - POST or PUT payload to $path
31
+
32
+ * method, path, and payload, if configured, are not required arguments
33
+ * valid methods: get, post, put, patch, delete
34
+ * path may be a path like /foo or a full URL like http://foo.com/bar
35
+ * payload must be valid JSON
36
+ * payload should be provided via STDIN or a properly escaped quoted arg
37
+
38
+ CONFIGURATION:
39
+ mb config [--reset] - Display or reset the overall config
40
+ mb config $CONFIG_ITEM [--reset] - Display or reset $CONFIG_ITEM
41
+ mb config host|method|path $val - set host to $val
42
+ mb config accept $val1 [$val2] - set accept to multiple values
43
+ mb config payload -|"$json" - set payload from STDIN or $json
44
+
45
+ * CONFIG_ITEMS: host, accept, method, path, payload
46
+ * valid accepts: json, html, text
47
+
48
+ OPTIONS:
49
+ --verbose - log level INFO and extra output
50
+ --debug - log level DEBUG
24
51
  EOF
25
52
  puts
26
53
  puts "CONFIG: #{CONFIG.pretty}"
@@ -30,87 +57,98 @@ end
30
57
 
31
58
  def conclude(msg)
32
59
  puts msg
60
+ puts "Completed in #{Time.now - START} seconds" if $VERBOSE
33
61
  exit 0
34
62
  end
35
63
 
36
64
  #
37
65
  # Config section: handle commands that manipulate CONFIG
38
- # Should exit in all cases with conclude()
66
+ # Should exit in all recognized cases with conclude()
39
67
  #
40
68
 
41
69
  # don't consume ARGV here
42
70
  cfg_cmd = ARGV.first
43
71
 
44
- if cfg_cmd
45
- cfg_cmd = cfg_cmd.downcase
72
+ if cfg_cmd and cfg_cmd.downcase == 'config'
73
+ ARGV.shift
74
+
75
+ cfg_key = ARGV.shift
76
+ conclude "CONFIG: #{CONFIG.pretty}" unless cfg_key
77
+
78
+ cfg_key = cfg_key.downcase
79
+ case cfg_key
80
+ when RESET_ARG
81
+ CONFIG.reset
82
+ puts "CONFIG was reset"
46
83
 
47
- case cfg_cmd
48
84
  when 'host', 'method', 'path'
49
- ARGV.shift # confirmed cfg_cmd, go ahead and shift
50
85
  val = ARGV.shift
51
86
  if val and !val.empty?
52
- if val.downcase == 'nil'
53
- CONFIG.delete cfg_cmd
87
+ if val.downcase == RESET_ARG
88
+ CONFIG.delete cfg_key
54
89
  CONFIG.save
55
- conclude "removed config for #{cfg_cmd}"
90
+ puts "#{cfg_key} was reset"
56
91
  else
57
- CONFIG[cfg_cmd] = val
92
+ CONFIG[cfg_key] = val
58
93
  CONFIG.save
59
94
  end
60
95
  else
61
- val = CONFIG[cfg_cmd] or conclude "no #{cfg_cmd} is set"
96
+ val = CONFIG[cfg_key]
97
+ puts (val ? "#{cfg_key}: #{val}" : "#{cfg_key} is not set")
62
98
  end
63
- conclude "Using #{cfg_cmd}: #{val}"
64
-
65
- when 'reset'
66
- CONFIG.reset
67
- conclude "config was reset"
68
99
 
69
100
  when 'payload'
70
- ARGV.shift # confirmed
71
101
  val = ARGV.shift
72
102
  if val and !val.empty?
73
103
  case val.downcase
74
- when '-'
75
- CONFIG['payload'] = JSON.parse $stdin.read
76
- CONFIG.save
77
- when 'nil'
104
+ when RESET_ARG
78
105
  CONFIG.delete 'payload'
79
106
  CONFIG.save
80
- conclude "removed config for payload"
107
+ puts 'payload was reset'
108
+ when '-'
109
+ begin
110
+ CONFIG['payload'] = JSON.parse $stdin.read
111
+ CONFIG.save
112
+ rescue JSON::ParserError => e
113
+ puts "#{e.class} - #{e}"
114
+ end
115
+ else
116
+ begin
117
+ CONFIG['payload'] = JSON.parse val
118
+ CONFIG.save
119
+ rescue JSON::ParserError => e
120
+ puts "#{e.class} - #{e}"
121
+ end
81
122
  end
82
123
  else
83
- CONFIG['payload'] or conclude "no payload is set"
124
+ val = CONFIG['payload'] && JSON.pretty_generate(CONFIG['payload'])
125
+ puts (val ? "payload: #{val}" : "payload is not set")
84
126
  end
85
- conclude "Using payload:\n#{JSON.pretty_generate CONFIG['payload']}"
86
127
 
87
128
  when 'accept'
88
- ARGV.shift # confirmed cfg_cmd, go ahead and shift
89
129
  accepts = []
90
- until ARGV.empty?
91
- accepts << ARGV.shift
92
- end
130
+ accepts << ARGV.shift until ARGV.empty?
93
131
 
94
- case accepts.length
95
- when 0
96
- if CONFIG['accept']
97
- conclude "Using accept: #{CONFIG['accept'].join(' ')}"
132
+ if accepts.length == 1
133
+ if accepts.first == RESET_ARG
134
+ accepts.shift
135
+ CONFIG.delete 'accept'
136
+ CONFIG.save
137
+ puts 'accept was reset'
98
138
  else
99
- conclude "no accept is set"
139
+ # did they provide a quoted or CSV list? or pseudo-symbols with colons?
140
+ accepts = accepts.first.split(/[ ,:]+/).select { |s| !s.empty? }
100
141
  end
101
- when 1
102
- # did they provide a quoted or CSV list? or pseudo-symbols with colons?
103
- accepts = accepts.first.split(/[ ,:]+/).select { |s| !s.empty? }
142
+ end
143
+ if accepts.length > 0
144
+ CONFIG['accept'] = accepts.map { |s| s.gsub /[ ,:]+/, '' }
145
+ CONFIG.save
104
146
  else
105
- accepts.map! { |s| s.gsub %r{[ ,:]+}, '' }
147
+ val = CONFIG['accept']
148
+ puts (val ? "accept: " + val.join(' ') : "accept is not set")
106
149
  end
107
- CONFIG['accept'] = accepts
108
- CONFIG.save
109
- conclude "using accept: #{CONFIG['accept']}"
110
-
111
- when 'config'
112
- conclude CONFIG.pretty
113
150
  end
151
+ conclude "CONFIG: #{CONFIG.pretty}"
114
152
  end
115
153
 
116
154
  #
@@ -118,11 +156,11 @@ end
118
156
  # Create Mudbug, determine method and path - from CONFIG and cmd line args
119
157
  #
120
158
 
121
- # set the host, always from CONFIG
122
- #
123
- usage "no host is set" unless CONFIG['host']
124
- mb = Mudbug.new CONFIG['host']
159
+ mb = Mudbug.new
125
160
 
161
+ # set the host and Accept if configured
162
+ #
163
+ mb.host = CONFIG['host'] if CONFIG['host']
126
164
  mb.accept CONFIG['accept'].map(&:to_sym) if CONFIG['accept']
127
165
 
128
166
  # set the method, possibly from CLI args
@@ -137,7 +175,7 @@ end
137
175
  # set the path, possibly from CLI args
138
176
  #
139
177
  case ARGV.first
140
- when %r{^\/} # starts with a slash
178
+ when %r{^\/|http} # starts with a slash or http
141
179
  path = ARGV.shift
142
180
  else
143
181
  path = CONFIG['path'] or usage "no path provided"
@@ -171,6 +209,8 @@ end
171
209
  # finally!
172
210
  #
173
211
 
212
+ puts "Configured in #{Time.now - START} seconds" if $VERBOSE
213
+
174
214
  begin
175
215
  data = mb.send(*args)
176
216
  rescue RuntimeError => e
data/lib/mudbug.rb CHANGED
@@ -83,7 +83,7 @@ class Mudbug
83
83
  attr_reader :options
84
84
  attr_accessor :host
85
85
 
86
- def initialize(host, options = {})
86
+ def initialize(host = 'localhost', options = {})
87
87
  @host = host
88
88
  @options = options
89
89
  accept :json, :html, :text
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mudbug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1.1
5
- prerelease:
4
+ version: 0.7.3.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Rick Hull
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-20 00:00:00.000000000 Z
11
+ date: 2013-08-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rest-client
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: json
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: lager
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: dotcfg
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: minitest
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: buildar
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ~>
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ~>
108
95
  - !ruby/object:Gem::Version
@@ -128,26 +115,25 @@ files:
128
115
  homepage: http://github.com/rickhull/mudbug
129
116
  licenses:
130
117
  - LGPL
118
+ metadata: {}
131
119
  post_install_message:
132
120
  rdoc_options: []
133
121
  require_paths:
134
122
  - lib
135
123
  required_ruby_version: !ruby/object:Gem::Requirement
136
- none: false
137
124
  requirements:
138
125
  - - ! '>='
139
126
  - !ruby/object:Gem::Version
140
127
  version: '0'
141
128
  required_rubygems_version: !ruby/object:Gem::Requirement
142
- none: false
143
129
  requirements:
144
130
  - - ! '>='
145
131
  - !ruby/object:Gem::Version
146
132
  version: '0'
147
133
  requirements: []
148
134
  rubyforge_project:
149
- rubygems_version: 1.8.23
135
+ rubygems_version: 2.0.6
150
136
  signing_key:
151
- specification_version: 3
137
+ specification_version: 4
152
138
  summary: This hardy creature consumes JSON / REST APIs
153
139
  test_files: []