mudbug 0.7.0.1 → 0.7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MANIFEST.txt +0 -1
- data/README.md +9 -10
- data/VERSION +1 -1
- data/bin/mb +34 -31
- data/mudbug.gemspec +6 -5
- metadata +18 -3
- data/lib/mb_config.rb +0 -60
data/MANIFEST.txt
CHANGED
data/README.md
CHANGED
@@ -14,13 +14,13 @@ Features
|
|
14
14
|
Installation
|
15
15
|
------------
|
16
16
|
Install the gem:
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
Or, if using bundler, add to your Gemfile:
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
```
|
18
|
+
$ gem install mudbug # sudo as necessary
|
19
|
+
```
|
20
|
+
Or, if using [Bundler](http://bundler.io/), add to your Gemfile:
|
21
|
+
```ruby
|
22
|
+
gem 'mudbug', '~> 0.6'
|
23
|
+
```
|
24
24
|
Quick Start
|
25
25
|
-----------
|
26
26
|
Initialize it with a host:
|
@@ -89,7 +89,7 @@ resp = Mudbug.new('google.com').resource('/').get
|
|
89
89
|
# etc.
|
90
90
|
```
|
91
91
|
|
92
|
-
Here is the heart of Mudbug's [response processing](https://github.com/rickhull/mudbug/blob/master/lib/mudbug.rb#
|
92
|
+
Here is the heart of Mudbug's [response processing](https://github.com/rickhull/mudbug/blob/master/lib/mudbug.rb#L51):
|
93
93
|
|
94
94
|
```ruby
|
95
95
|
# this structure declares what we support in the request Accept: header
|
@@ -116,8 +116,7 @@ Careful with that axe, Eugene.
|
|
116
116
|
|
117
117
|
Examples
|
118
118
|
--------
|
119
|
-
* accepts_and_methods [sample
|
120
|
-
* accepts_and_methods [sample output](https://github.com/rickhull/mudbug/blob/master/examples/accepts_and_methods.txt)
|
119
|
+
* [accepts_and_methods](https://github.com/rickhull/mudbug/blob/master/examples/accepts_and_methods.rb) [(sample output)](https://github.com/rickhull/mudbug/blob/master/examples/accepts_and_methods.txt)
|
121
120
|
|
122
121
|
Funny, that
|
123
122
|
-----------
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.1.1
|
data/bin/mb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'dotcfg'
|
4
|
+
require 'mudbug'
|
5
|
+
|
6
|
+
CONFIG = DotCfg.new '~/.mudbug', :json
|
4
7
|
|
5
8
|
def usage(msg = nil)
|
6
|
-
|
9
|
+
print "ERROR: #{msg}\n\n" if msg
|
7
10
|
puts <<EOF
|
8
11
|
USAGE:
|
9
12
|
mb [get|delete] [PATH] - GET or DELETE PATH
|
@@ -20,7 +23,7 @@ USAGE:
|
|
20
23
|
* `accept` is optional; valid values include json, html, text
|
21
24
|
EOF
|
22
25
|
puts
|
23
|
-
puts "CONFIG: #{
|
26
|
+
puts "CONFIG: #{CONFIG.pretty}"
|
24
27
|
|
25
28
|
exit 1
|
26
29
|
end
|
@@ -31,7 +34,7 @@ def conclude(msg)
|
|
31
34
|
end
|
32
35
|
|
33
36
|
#
|
34
|
-
# Config section: handle commands that manipulate
|
37
|
+
# Config section: handle commands that manipulate CONFIG
|
35
38
|
# Should exit in all cases with conclude()
|
36
39
|
#
|
37
40
|
|
@@ -47,20 +50,20 @@ if cfg_cmd
|
|
47
50
|
val = ARGV.shift
|
48
51
|
if val and !val.empty?
|
49
52
|
if val.downcase == 'nil'
|
50
|
-
|
51
|
-
|
53
|
+
CONFIG.delete cfg_cmd
|
54
|
+
CONFIG.save
|
52
55
|
conclude "removed config for #{cfg_cmd}"
|
53
56
|
else
|
54
|
-
|
55
|
-
|
57
|
+
CONFIG[cfg_cmd] = val
|
58
|
+
CONFIG.save
|
56
59
|
end
|
57
60
|
else
|
58
|
-
val =
|
61
|
+
val = CONFIG[cfg_cmd] or conclude "no #{cfg_cmd} is set"
|
59
62
|
end
|
60
63
|
conclude "Using #{cfg_cmd}: #{val}"
|
61
64
|
|
62
65
|
when 'reset'
|
63
|
-
|
66
|
+
CONFIG.reset
|
64
67
|
conclude "config was reset"
|
65
68
|
|
66
69
|
when 'payload'
|
@@ -69,17 +72,17 @@ if cfg_cmd
|
|
69
72
|
if val and !val.empty?
|
70
73
|
case val.downcase
|
71
74
|
when '-'
|
72
|
-
|
73
|
-
|
75
|
+
CONFIG['payload'] = JSON.parse $stdin.read
|
76
|
+
CONFIG.save
|
74
77
|
when 'nil'
|
75
|
-
|
76
|
-
|
78
|
+
CONFIG.delete 'payload'
|
79
|
+
CONFIG.save
|
77
80
|
conclude "removed config for payload"
|
78
81
|
end
|
79
82
|
else
|
80
|
-
|
83
|
+
CONFIG['payload'] or conclude "no payload is set"
|
81
84
|
end
|
82
|
-
conclude "Using payload:\n#{JSON.pretty_generate
|
85
|
+
conclude "Using payload:\n#{JSON.pretty_generate CONFIG['payload']}"
|
83
86
|
|
84
87
|
when 'accept'
|
85
88
|
ARGV.shift # confirmed cfg_cmd, go ahead and shift
|
@@ -90,8 +93,8 @@ if cfg_cmd
|
|
90
93
|
|
91
94
|
case accepts.length
|
92
95
|
when 0
|
93
|
-
if
|
94
|
-
conclude "Using accept: #{
|
96
|
+
if CONFIG['accept']
|
97
|
+
conclude "Using accept: #{CONFIG['accept'].join(' ')}"
|
95
98
|
else
|
96
99
|
conclude "no accept is set"
|
97
100
|
end
|
@@ -101,26 +104,26 @@ if cfg_cmd
|
|
101
104
|
else
|
102
105
|
accepts.map! { |s| s.gsub %r{[ ,:]+}, '' }
|
103
106
|
end
|
104
|
-
|
105
|
-
|
106
|
-
conclude "using accept: #{
|
107
|
+
CONFIG['accept'] = accepts
|
108
|
+
CONFIG.save
|
109
|
+
conclude "using accept: #{CONFIG['accept']}"
|
107
110
|
|
108
111
|
when 'config'
|
109
|
-
conclude
|
112
|
+
conclude CONFIG.pretty
|
110
113
|
end
|
111
114
|
end
|
112
115
|
|
113
116
|
#
|
114
|
-
# OK, we're not manipulating
|
115
|
-
# Create Mudbug, determine method and path - from
|
117
|
+
# OK, we're not manipulating CONFIG
|
118
|
+
# Create Mudbug, determine method and path - from CONFIG and cmd line args
|
116
119
|
#
|
117
120
|
|
118
|
-
# set the host, always from
|
121
|
+
# set the host, always from CONFIG
|
119
122
|
#
|
120
|
-
usage "no host is set" unless
|
121
|
-
mb = Mudbug.new
|
123
|
+
usage "no host is set" unless CONFIG['host']
|
124
|
+
mb = Mudbug.new CONFIG['host']
|
122
125
|
|
123
|
-
mb.accept
|
126
|
+
mb.accept CONFIG['accept'].map(&:to_sym) if CONFIG['accept']
|
124
127
|
|
125
128
|
# set the method, possibly from CLI args
|
126
129
|
#
|
@@ -128,7 +131,7 @@ case ARGV.first
|
|
128
131
|
when 'get', 'post', 'put', 'delete'# , 'patch' # Soon(tm)
|
129
132
|
method = ARGV.shift
|
130
133
|
else
|
131
|
-
method =
|
134
|
+
method = CONFIG['method'] or usage "no method provided"
|
132
135
|
end
|
133
136
|
|
134
137
|
# set the path, possibly from CLI args
|
@@ -137,7 +140,7 @@ case ARGV.first
|
|
137
140
|
when %r{^\/} # starts with a slash
|
138
141
|
path = ARGV.shift
|
139
142
|
else
|
140
|
-
path =
|
143
|
+
path = CONFIG['path'] or usage "no path provided"
|
141
144
|
end
|
142
145
|
|
143
146
|
# determine method
|
@@ -151,7 +154,7 @@ when 'post', 'put', 'patch'
|
|
151
154
|
# get payload
|
152
155
|
case ARGV.first
|
153
156
|
when nil
|
154
|
-
payload =
|
157
|
+
payload = CONFIG['payload'] or usage "no payload provided"
|
155
158
|
when '-'
|
156
159
|
begin
|
157
160
|
payload = JSON.parse $stdin.read
|
data/mudbug.gemspec
CHANGED
@@ -9,11 +9,12 @@ Gem::Specification.new do |s|
|
|
9
9
|
|
10
10
|
s.executables << 'mb'
|
11
11
|
|
12
|
-
s.add_runtime_dependency "rest-client",
|
13
|
-
s.add_runtime_dependency "json",
|
14
|
-
s.add_runtime_dependency "lager",
|
15
|
-
s.
|
16
|
-
s.add_development_dependency
|
12
|
+
s.add_runtime_dependency "rest-client", "~> 1"
|
13
|
+
s.add_runtime_dependency "json", "~> 1"
|
14
|
+
s.add_runtime_dependency "lager", ">= 0.2"
|
15
|
+
s.add_runtime_dependency "dotcfg", "~> 0.2"
|
16
|
+
s.add_development_dependency "minitest", ">= 0"
|
17
|
+
s.add_development_dependency "buildar", "~> 1.4"
|
17
18
|
|
18
19
|
# dynamic setup
|
19
20
|
this_dir = File.expand_path('..', __FILE__)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mudbug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0.2'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: dotcfg
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.2'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.2'
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: minitest
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,7 +122,6 @@ files:
|
|
106
122
|
- LICENSE.txt
|
107
123
|
- rakefile.rb
|
108
124
|
- lib/mudbug.rb
|
109
|
-
- lib/mb_config.rb
|
110
125
|
- test/mudbug.rb
|
111
126
|
- examples/accepts_and_methods.rb
|
112
127
|
- bin/mb
|
data/lib/mb_config.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'mudbug'
|
2
|
-
|
3
|
-
module MbConfig
|
4
|
-
FILE = File.expand_path '~/.mudbug'
|
5
|
-
CFG = {}
|
6
|
-
|
7
|
-
def self.[] key
|
8
|
-
CFG[key]
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.[]= key, value
|
12
|
-
CFG[key] = value
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.delete key
|
16
|
-
CFG.delete key
|
17
|
-
end
|
18
|
-
|
19
|
-
# write CFG to FILE
|
20
|
-
#
|
21
|
-
def self.save
|
22
|
-
File.open(FILE, 'w') { |f| f.write CFG.to_json }
|
23
|
-
end
|
24
|
-
|
25
|
-
# call reset as necessary
|
26
|
-
#
|
27
|
-
def self.load
|
28
|
-
reset unless File.exists?(FILE)
|
29
|
-
rescues = 0
|
30
|
-
begin
|
31
|
-
File.open(FILE, 'r') { |f|
|
32
|
-
CFG.merge! JSON.parse f.read
|
33
|
-
}
|
34
|
-
rescue JSON::ParserError => e
|
35
|
-
rescues += 1
|
36
|
-
puts "#{e} (#{e.class})"
|
37
|
-
if rescues < 2
|
38
|
-
puts "Resetting #{FILE}"
|
39
|
-
reset
|
40
|
-
retry
|
41
|
-
end
|
42
|
-
Mudbug.lager.fatal { "MbConfig.load failed!" }
|
43
|
-
raise e
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# write an empty hash/object
|
48
|
-
#
|
49
|
-
def self.reset
|
50
|
-
File.open(FILE, 'w') { |f| f.write '{}' }
|
51
|
-
end
|
52
|
-
|
53
|
-
# dump the current CFG (may differ from FILE contents!)
|
54
|
-
#
|
55
|
-
def self.dump
|
56
|
-
JSON.pretty_generate CFG
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
MbConfig.load
|