mudbug 0.5.0.1 → 0.5.1.3

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.
Files changed (5) hide show
  1. checksums.yaml +15 -0
  2. data/VERSION +1 -1
  3. data/bin/mb +175 -0
  4. data/mudbug.gemspec +2 -0
  5. metadata +18 -28
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDg5MjE2ZjY2M2ZjNDg0YTYxNGI3MzA3YWVhY2M5ZjMyYzk3OTVhZA==
5
+ data.tar.gz: !binary |-
6
+ ZDhiNWRkYzlmZTBlNTc0NzEyMWY2ZmM3ODFiZjRiZThjZjUwYjgwMw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ N2M1ZTFhNjUxOGEwZDNhODBkMDA5ZmY4ZGVmMGIzMTkyMDBlNDZiMDlhYzhj
10
+ NTYxMDk0ZGFjY2VjODc0ZmYwNWMxMTZmYWVkNDc0ODYyNjg2MzgzMWU3MzZk
11
+ MDA2NGQxMDk3MThkNzNhMWYyYjZlMzY5ZjAyZDdjOGQ5MWFmMjk=
12
+ data.tar.gz: !binary |-
13
+ YTA1YjE4Y2I0ODQ0YWY1YmM3YTJlYmQ1ZGQ0ZGMzNWJmZTRkMmE1ZTg2ZjEz
14
+ NWRmZjQyOTFhNjRkNjY3MjlhMzkyNDk0ZDU1MTRiOGQ5MWI1YWFhMTVjMjcz
15
+ NmU2ODgyN2Q2N2QzM2QwNWFjNDc2MDcxMTY5ZmY0NDUyYTY1MzE=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0.1
1
+ 0.5.1.3
data/bin/mb ADDED
@@ -0,0 +1,175 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ def usage(msg = nil)
4
+ puts "ERROR: #{msg}" if msg
5
+ puts <<USAGE
6
+ USAGE:
7
+ mb host|method|path|payload [VAL] - Set or display the current config item
8
+ mb accept [ACC1] [ACC2] [etc] - Set or display the accept config item
9
+ mb config - Display the current config
10
+ mb [get|delete] [PATH] - GET or DELETE PATH
11
+ mb [post|put] [PATH] [PAYLOAD] - POST or PUT PAYLOAD to PATH
12
+
13
+ * A host must be configured for mb to operate
14
+ * method, path, and payload, if configured, can be omitted as CLI arguments
15
+ * accept is optional; valid values include json, html, text
16
+ USAGE
17
+ puts
18
+ puts "CONFIG: #{Mudbug.load.inspect}" if Mudbug.fresh?
19
+
20
+ exit 1
21
+ end
22
+
23
+ def conclude(msg)
24
+ puts msg
25
+ exit 0
26
+ end
27
+
28
+ require 'mudbug'
29
+
30
+ CFG_FILE = File.expand_path '~/.mudbug'
31
+ FILE_EXPIRY = 3600 # seconds
32
+
33
+ class Mudbug
34
+ def self.save config
35
+ raise "unable to write to #{CFG_FILE}" unless File.writable? CFG_FILE
36
+ File.open(CFG_FILE, 'w') { |f| f.write config.to_json }
37
+ end
38
+
39
+ def self.load
40
+ if self.fresh?
41
+ File.open(CFG_FILE, 'r') { |f| JSON.parse(f.read) rescue nil }
42
+ end
43
+ end
44
+
45
+ def self.fresh?
46
+ File.exists?(CFG_FILE) and File.readable?(CFG_FILE) and
47
+ Time.now - File.mtime(CFG_FILE) < FILE_EXPIRY
48
+ end
49
+ end
50
+
51
+ CFG = Mudbug.load || {}
52
+
53
+ #
54
+ # Stage 1: handle commands that manipulate CFG / CFG_FILE
55
+ #
56
+
57
+ # don't consume ARGV here
58
+ cfg_cmd = ARGV.first
59
+
60
+ if cfg_cmd
61
+ cfg_cmd = cfg_cmd.downcase
62
+
63
+ case cfg_cmd
64
+ when 'host', 'method', 'path', 'payload'
65
+ ARGV.shift # confirmed cfg_cmd, go ahead and shift
66
+ val = ARGV.shift
67
+ if val and !val.empty?
68
+ if val.downcase == 'nil'
69
+ CFG.delete cfg_cmd
70
+ Mudbug.save CFG
71
+ conclude "removed config for #{cfg_cmd}"
72
+ else
73
+ CFG[cfg_cmd] = val
74
+ Mudbug.save CFG
75
+ end
76
+ else
77
+ val = CFG[cfg_cmd] or conclude "no #{cfg_cmd} is set"
78
+ end
79
+ conclude "Using #{cfg_cmd}: #{val}"
80
+
81
+ when 'accept'
82
+ ARGV.shift # confirmed cfg_cmd, go ahead and shift
83
+ accepts = []
84
+ until ARGV.empty?
85
+ accepts << ARGV.shift
86
+ end
87
+
88
+ case accepts.length
89
+ when 0
90
+ if CFG['accept']
91
+ conclude "Using accept: #{CFG['accept'].join(' ')}"
92
+ else
93
+ conclude "no accept is set"
94
+ end
95
+ when 1
96
+ # did they provide a quoted or CSV list? or pseudo-symbols with colons?
97
+ accepts = accepts.first.split(/[ ,:]+/).map { |s|
98
+ s.empty? ? nil : s
99
+ }.compact
100
+ else
101
+ accepts.map! { |s| s.gsub %r{[ ,:]+}, '' }
102
+ end
103
+ CFG['accept'] = accepts
104
+ Mudbug.save CFG
105
+ conclude "using accept: #{CFG['accept']}"
106
+
107
+ when 'config'
108
+ conclude Mudbug.load.inspect
109
+ end
110
+ end
111
+
112
+ #
113
+ # Done with manipulating CFG and CFG_FILE
114
+ #
115
+
116
+ #
117
+ # Stage 2: create Mudbug based on CFG and command line options
118
+ #
119
+
120
+ # set the host, always from CFG
121
+ conclude "no host is set" unless CFG['host']
122
+ mb = Mudbug.new CFG['host']
123
+
124
+ mb.accept CFG['accept'].map(&:to_sym) if CFG['accept']
125
+
126
+ # set the method, possibly from CLI args
127
+ meth_cmd = ARGV.first
128
+ case meth_cmd
129
+ when 'get', 'post', 'put', 'delete', 'del'
130
+ ARGV.shift # confirmed meth_cmd, go ahead and shift
131
+ method = meth_cmd
132
+ else
133
+ method = CFG['method'] or usage "no method provided"
134
+ end
135
+
136
+ # set the path, possibly from CLI args
137
+ path_cmd = ARGV.first
138
+ case path_cmd
139
+ when %r{^\/} # starts with a slash
140
+ ARGV.shift # confirmed path_cmd, go ahead and shift
141
+ path = path_cmd
142
+ else
143
+ path = CFG['path'] or usage "no path provided"
144
+ end
145
+
146
+ case method
147
+ when 'get'
148
+ data = mb.get path
149
+ conclude JSON.pretty_generate data
150
+ when 'del', 'delete'
151
+ data = mb.delete path
152
+ conclude JSON.pretty_generate data
153
+ when 'post', 'put', 'patch'
154
+ # do nothing for now
155
+ else
156
+ usage "Bad HTTP method #{method}"
157
+ end
158
+
159
+ # to get here, we must be doing POST, PUT, or PATCH
160
+ # we need a payload
161
+
162
+ payload = ARGV.first
163
+ case payload
164
+ when nil
165
+ payload = CFG['payload'] or usage "no payload provided"
166
+ else
167
+ begin
168
+ JSON.parse payload
169
+ rescue
170
+ usage "could not parse payload:\n#{payload.inspect}"
171
+ end
172
+ end
173
+
174
+ data = mb.send(method, path, payload)
175
+ conclude JSON.pretty_generate data
data/mudbug.gemspec CHANGED
@@ -7,6 +7,8 @@ Gem::Specification.new do |s|
7
7
  s.has_rdoc = true
8
8
  s.description = "GET, POST, PUT, and DELETE JSON payloads. Easy Accept headers. Fine-grained response handling using Mudbug#resource."
9
9
 
10
+ s.executables << 'mb'
11
+
10
12
  s.add_runtime_dependency "rest-client", ["~> 1"]
11
13
  s.add_runtime_dependency "json", ["~> 1"]
12
14
  s.add_runtime_dependency "lager", [">= 0.2"]
metadata CHANGED
@@ -1,100 +1,90 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mudbug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.1
5
- prerelease:
4
+ version: 0.5.1.3
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-09 00:00:00.000000000 Z
11
+ date: 2013-07-11 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
21
19
  version: '1'
22
- type: :runtime
23
- prerelease: false
24
20
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
21
  requirements:
27
22
  - - ~>
28
23
  - !ruby/object:Gem::Version
29
24
  version: '1'
25
+ type: :runtime
26
+ prerelease: false
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
37
33
  version: '1'
38
- type: :runtime
39
- prerelease: false
40
34
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
35
  requirements:
43
36
  - - ~>
44
37
  - !ruby/object:Gem::Version
45
38
  version: '1'
39
+ type: :runtime
40
+ prerelease: false
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
53
47
  version: '0.2'
54
- type: :runtime
55
- prerelease: false
56
48
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
49
  requirements:
59
50
  - - ! '>='
60
51
  - !ruby/object:Gem::Version
61
52
  version: '0.2'
53
+ type: :runtime
54
+ prerelease: false
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: minitest
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
- type: :development
71
- prerelease: false
72
62
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
63
  requirements:
75
64
  - - ! '>='
76
65
  - !ruby/object:Gem::Version
77
66
  version: '0'
67
+ type: :development
68
+ prerelease: false
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: buildar
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
85
75
  version: '1.4'
86
- type: :development
87
- prerelease: false
88
76
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
77
  requirements:
91
78
  - - ~>
92
79
  - !ruby/object:Gem::Version
93
80
  version: '1.4'
81
+ type: :development
82
+ prerelease: false
94
83
  description: GET, POST, PUT, and DELETE JSON payloads. Easy Accept headers. Fine-grained
95
84
  response handling using Mudbug#resource.
96
85
  email:
97
- executables: []
86
+ executables:
87
+ - mb
98
88
  extensions: []
99
89
  extra_rdoc_files: []
100
90
  files:
@@ -107,29 +97,29 @@ files:
107
97
  - lib/mudbug.rb
108
98
  - test/mudbug.rb
109
99
  - examples/accepts_and_methods.rb
100
+ - bin/mb
110
101
  homepage: http://github.com/rickhull/mudbug
111
102
  licenses:
112
103
  - LGPL
104
+ metadata: {}
113
105
  post_install_message:
114
106
  rdoc_options: []
115
107
  require_paths:
116
108
  - lib
117
109
  required_ruby_version: !ruby/object:Gem::Requirement
118
- none: false
119
110
  requirements:
120
111
  - - ! '>='
121
112
  - !ruby/object:Gem::Version
122
113
  version: '0'
123
114
  required_rubygems_version: !ruby/object:Gem::Requirement
124
- none: false
125
115
  requirements:
126
116
  - - ! '>='
127
117
  - !ruby/object:Gem::Version
128
118
  version: '0'
129
119
  requirements: []
130
120
  rubyforge_project:
131
- rubygems_version: 1.8.23
121
+ rubygems_version: 2.0.3
132
122
  signing_key:
133
- specification_version: 3
123
+ specification_version: 4
134
124
  summary: This hardy creature consumes JSON / REST APIs
135
125
  test_files: []