mudbug 0.4.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +165 -0
- data/MANIFEST.txt +8 -0
- data/README.md +98 -0
- data/VERSION +1 -0
- data/examples/accepts_and_methods.rb +61 -0
- data/lib/mudbug.rb +127 -0
- data/rakefile.rb +122 -0
- data/test/mudbug.rb +10 -0
- metadata +129 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/MANIFEST.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
Mudbug
|
2
|
+
=======
|
3
|
+
Mudbug is a JSON-oriented, thin wrapper around [rest-client](https://github.com/rest-client/rest-client)'s [RestClient::Resource](https://github.com/rest-client/rest-client#usage-activeresource-style)
|
4
|
+
|
5
|
+
Features
|
6
|
+
--------
|
7
|
+
* *GET*, *POST*, *PUT*, or *DELETE* JSON payloads
|
8
|
+
* Convenience
|
9
|
+
* Do The Right Thing 80% of the time every time
|
10
|
+
* Easy *Accept:* headers
|
11
|
+
* Understand and fall back to basic Content-types if application/json is not provided
|
12
|
+
* Fine-grained response handling using Mudbug#resource
|
13
|
+
|
14
|
+
Quick Start
|
15
|
+
-----------
|
16
|
+
Initialize it with a host:
|
17
|
+
|
18
|
+
mb = Mudbug.new 'ip.jsontest.com'
|
19
|
+
|
20
|
+
The convenience methods *#get*, *#post*, *#put*, or *#delete* return the response body. If the response has a *Content-type:* **application/json** header, then JSON parsing will be automatically performed on the response body, with the resulting object returned.
|
21
|
+
|
22
|
+
response = mb.get '/'
|
23
|
+
# => {"ip"=>"12.34.56.78"}
|
24
|
+
|
25
|
+
response.class
|
26
|
+
# => Hash
|
27
|
+
|
28
|
+
Usage
|
29
|
+
-----
|
30
|
+
You can pass through persistent [options to rest-client](https://github.com/rest-client/rest-client/blob/master/lib/restclient/request.rb):
|
31
|
+
|
32
|
+
mb = Mudbug.new 'google.com', max_redirects: 3
|
33
|
+
|
34
|
+
Declare what you accept: (optional, default shown)
|
35
|
+
|
36
|
+
mb.accept :json, :html, :text
|
37
|
+
|
38
|
+
You can pass through per-request [options to rest-client](https://github.com/rest-client/rest-client/blob/master/lib/restclient/request.rb)
|
39
|
+
|
40
|
+
mb.get '/', max_redirects: 3
|
41
|
+
# => "<!doctype html><html ... <head><meta content=\"Search the world's information ... "
|
42
|
+
|
43
|
+
[RestClient exceptions](https://github.com/rest-client/rest-client/blob/master/lib/restclient/exceptions.rb) will be passed through. POST and PUT payloads will be sent as strings. Non-string payloads will be converted to JSON by calling #to_json.
|
44
|
+
|
45
|
+
mb = Mudbug.new 'plus.google.com'
|
46
|
+
mb.post '/', { 'hi' => 'mom' }, max_redirects: 3
|
47
|
+
|
48
|
+
/path/to/lib/restclient/abstract_response.rb:48:in `return!': 405 Method Not Allowed (RestClient::MethodNotAllowed)
|
49
|
+
|
50
|
+
# lawyer up
|
51
|
+
# hit gym
|
52
|
+
Mudbug.new('facebook.com').delete '/'
|
53
|
+
|
54
|
+
/path/to/lib/restclient/abstract_response.rb:39:in `return!': 301 Moved Permanently (RestClient::MovedPermanently)
|
55
|
+
|
56
|
+
Digging Deeper
|
57
|
+
--------------
|
58
|
+
Call Mudbug#resource directly for finer-grained response handling:
|
59
|
+
|
60
|
+
resp = Mudbug.new('google.com').resource('/').get
|
61
|
+
# check resp.code
|
62
|
+
# check resp.headers
|
63
|
+
# process resp.body
|
64
|
+
# etc.
|
65
|
+
|
66
|
+
Here is the heart of the Mudbug's [response processing](https://github.com/rickhull/mudbug/blob/master/lib/mudbug.rb#L37):
|
67
|
+
|
68
|
+
# this structure declares what we support in the request Accept: header
|
69
|
+
# and defines automatic processing of the response based on the
|
70
|
+
# response Content-type: header
|
71
|
+
#
|
72
|
+
CONTENT = {
|
73
|
+
json: {
|
74
|
+
type: 'application/json',
|
75
|
+
proc: proc { |text| JSON.parse(text, symobolize_names: true) },
|
76
|
+
},
|
77
|
+
html: {
|
78
|
+
type: 'text/html',
|
79
|
+
proc: proc { |text| text },
|
80
|
+
},
|
81
|
+
text: {
|
82
|
+
type: 'text/plain',
|
83
|
+
proc: proc { |text| text },
|
84
|
+
},
|
85
|
+
}
|
86
|
+
|
87
|
+
Funny, that
|
88
|
+
-----------
|
89
|
+
Mudbug works best with webservers that respect the *Accept:* request header and provide proper *Content-type:* response headers.
|
90
|
+
|
91
|
+
[RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)
|
92
|
+
|
93
|
+
> If no Accept header field is present, then it is assumed that the client accepts all media types. If an Accept header field is present, and if the server cannot send a response which is acceptable according to the combined Accept field value, then the server SHOULD send a 406 (not acceptable) response.
|
94
|
+
|
95
|
+
Examples
|
96
|
+
--------
|
97
|
+
* accepts_and_methods [sample script](https://github.com/rickhull/mudbug/blob/master/examples/accepts_and_methods.rb)
|
98
|
+
* accepts_and_methods [sample output](https://github.com/rickhull/mudbug/blob/master/examples/accepts_and_methods.txt)
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.4.5.1
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# normally, just require 'mudbug', but this will use your local version
|
2
|
+
# useful for development purposes
|
3
|
+
#
|
4
|
+
require_relative '../lib/mudbug'
|
5
|
+
|
6
|
+
sites = %w{google.com yahoo.com microsoft.com amazon.com ibm.com reddit.com}
|
7
|
+
accepts = [:json, :html, :text, :xml]
|
8
|
+
http_methods = [:get, :post, :put, :delete]
|
9
|
+
|
10
|
+
path = '/'
|
11
|
+
|
12
|
+
unless ARGV.shift == 'skip'
|
13
|
+
puts
|
14
|
+
puts "Checking Accepts across sites"
|
15
|
+
puts "============================="
|
16
|
+
sites.each { |site|
|
17
|
+
b = Mudbug.new(site)
|
18
|
+
url = "http://#{site}#{path}"
|
19
|
+
|
20
|
+
accepts.each { |acp|
|
21
|
+
b.accept(acp)
|
22
|
+
|
23
|
+
print "GET #{url} [#{acp}] "
|
24
|
+
b.get path
|
25
|
+
puts
|
26
|
+
}
|
27
|
+
puts
|
28
|
+
}
|
29
|
+
|
30
|
+
puts
|
31
|
+
puts
|
32
|
+
end
|
33
|
+
|
34
|
+
payload = { 'hi' => 'mom' }.to_json
|
35
|
+
|
36
|
+
unless ARGV.shift == 'skip'
|
37
|
+
puts "Checking HTTP methods across sites"
|
38
|
+
puts "=================================="
|
39
|
+
puts "POST/PUT payload = #{payload.to_json}"
|
40
|
+
puts
|
41
|
+
sites.each { |site|
|
42
|
+
b = Mudbug.new(site)
|
43
|
+
url = "http://#{site}#{path}"
|
44
|
+
|
45
|
+
http_methods.each { |meth|
|
46
|
+
args = [meth, path]
|
47
|
+
args << payload if [:post, :put].include?(meth)
|
48
|
+
|
49
|
+
print "#{meth.to_s.upcase} #{url} "
|
50
|
+
begin
|
51
|
+
b.send(*args)
|
52
|
+
puts
|
53
|
+
rescue RuntimeError => e
|
54
|
+
puts "#{e} (#{e.class})"
|
55
|
+
end
|
56
|
+
}
|
57
|
+
puts
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
puts "DONE"
|
data/lib/mudbug.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class Mudbug
|
5
|
+
def self.version
|
6
|
+
vpath = File.join(File.dirname(__FILE__), '..', 'VERSION')
|
7
|
+
File.read(vpath).chomp
|
8
|
+
end
|
9
|
+
|
10
|
+
class StatusCodeError < RuntimeError; end
|
11
|
+
|
12
|
+
# this structure declares what we support in the request Accept: header
|
13
|
+
# and defines automatic processing of the response based on the
|
14
|
+
# response Content-type: header
|
15
|
+
#
|
16
|
+
CONTENT = {
|
17
|
+
json: {
|
18
|
+
type: 'application/json',
|
19
|
+
proc: proc { |text| JSON.parse(text, symobolize_names: true) },
|
20
|
+
},
|
21
|
+
html: {
|
22
|
+
type: 'text/html',
|
23
|
+
proc: proc { |text| text },
|
24
|
+
},
|
25
|
+
text: {
|
26
|
+
type: 'text/plain',
|
27
|
+
proc: proc { |text| text },
|
28
|
+
},
|
29
|
+
}
|
30
|
+
|
31
|
+
# map our internal symbols to HTTP content types
|
32
|
+
# assign q scores based on the parameter order
|
33
|
+
# construct the right side of the Accept: header
|
34
|
+
#
|
35
|
+
def self.accept_header(*types)
|
36
|
+
types.map.with_index { |t, i|
|
37
|
+
type = CONTENT[t] ? CONTENT[t][:type] : "application/#{t.to_s.downcase}"
|
38
|
+
quality = "q=" << sprintf("%0.1f", 1.0 - i*0.1)
|
39
|
+
i == 0 ? type : [type, quality].join(';')
|
40
|
+
}.join(', ')
|
41
|
+
end
|
42
|
+
|
43
|
+
# do stuff based on response's Content-type
|
44
|
+
#
|
45
|
+
def self.process(resp, accept = nil)
|
46
|
+
case resp.code
|
47
|
+
when 200..299
|
48
|
+
# 2xx, OK
|
49
|
+
else
|
50
|
+
warn "proceeding with HTTP Status Code #{resp.code}"
|
51
|
+
end
|
52
|
+
|
53
|
+
# do you even Content-type, bro?
|
54
|
+
ct = resp.headers[:content_type]
|
55
|
+
unless ct
|
56
|
+
warn "process NOOP -- no response Content-type"
|
57
|
+
return resp.body
|
58
|
+
end
|
59
|
+
|
60
|
+
# warn if we got Content-type we didn't ask for
|
61
|
+
ct, charset = ct.split(';').map { |s| s.strip }
|
62
|
+
warn "Asked for #{accept} but got #{ct}" if accept and !accept.include?(ct)
|
63
|
+
|
64
|
+
# process the response for known content types
|
65
|
+
CONTENT.each { |sym, hsh|
|
66
|
+
return hsh[:proc].call(resp.body) if ct == hsh[:type]
|
67
|
+
}
|
68
|
+
|
69
|
+
warn "process NOOP -- unrecognized Content-type: #{ct}"
|
70
|
+
return response.body
|
71
|
+
end
|
72
|
+
|
73
|
+
attr_reader :options
|
74
|
+
attr_accessor :host
|
75
|
+
|
76
|
+
def initialize(host, options = nil)
|
77
|
+
@host = host
|
78
|
+
@options = options || {}
|
79
|
+
accept :json, :html, :text
|
80
|
+
end
|
81
|
+
|
82
|
+
# Writes the Accept: header for you
|
83
|
+
# e.g.
|
84
|
+
# accept :json, :html # Accept: application/json, text/html
|
85
|
+
# accept nil # remove Accept: header
|
86
|
+
# Now adds q-scores automatically based on order
|
87
|
+
# Note: the hard work is done by the class method
|
88
|
+
#
|
89
|
+
def accept(*types)
|
90
|
+
types = types.first if types.first.is_a?(Array)
|
91
|
+
@options[:headers] ||= {}
|
92
|
+
return @options[:headers].delete(:accept) if types.first.nil?
|
93
|
+
@options[:headers][:accept] = self.class.accept_header(*types)
|
94
|
+
end
|
95
|
+
|
96
|
+
# use this method directly if you want finer-grained request and response
|
97
|
+
# handling
|
98
|
+
#
|
99
|
+
def resource(path, options = {})
|
100
|
+
path = "/#{path}" unless path[0,1] == '/'
|
101
|
+
url = "http://#{@host}#{path}"
|
102
|
+
options = @options.merge(options)
|
103
|
+
|
104
|
+
RestClient::Resource.new(url, options)
|
105
|
+
end
|
106
|
+
|
107
|
+
# no payload
|
108
|
+
#
|
109
|
+
[:get, :delete].each { |meth|
|
110
|
+
define_method(meth) { |path, options = {}|
|
111
|
+
res = resource(path, options)
|
112
|
+
self.class.process(res.send(meth), res.headers[:accept])
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
# (JSON) payload required
|
117
|
+
# if payload is a String, then assume it's already JSON
|
118
|
+
# otherwise apply #to_json to payload automatically. Quack.
|
119
|
+
#
|
120
|
+
[:post, :put].each { |meth|
|
121
|
+
define_method(meth) { |path, payload, options={}|
|
122
|
+
payload = payload.to_json unless payload.is_a?(String)
|
123
|
+
res = resource(path, options)
|
124
|
+
self.class.process(res.send(meth, payload), res.heads[:accept])
|
125
|
+
}
|
126
|
+
}
|
127
|
+
end
|
data/rakefile.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'rubygems/package_task'
|
2
|
+
|
3
|
+
PROJECT_ROOT = File.dirname(__FILE__)
|
4
|
+
PROJECT_NAME = File.split(PROJECT_ROOT).last
|
5
|
+
VERSION_FILE = File.join(PROJECT_ROOT, 'VERSION')
|
6
|
+
MANIFEST_FILE = File.join(PROJECT_ROOT, 'MANIFEST.txt')
|
7
|
+
|
8
|
+
def version
|
9
|
+
File.read(VERSION_FILE).chomp
|
10
|
+
end
|
11
|
+
|
12
|
+
def manifest
|
13
|
+
File.readlines(MANIFEST_FILE).map { |line| line.chomp }
|
14
|
+
end
|
15
|
+
|
16
|
+
task :version do
|
17
|
+
puts "#{PROJECT_NAME} #{version}"
|
18
|
+
end
|
19
|
+
|
20
|
+
task :manifest do
|
21
|
+
puts manifest.join("\n")
|
22
|
+
end
|
23
|
+
|
24
|
+
task :build do
|
25
|
+
spec = Gem::Specification.new do |s|
|
26
|
+
# Static assignments
|
27
|
+
s.name = "mudbug"
|
28
|
+
s.summary = "A thin layer over rest-client that returns JSON objects"
|
29
|
+
s.description = <<EOF
|
30
|
+
* GET, POST, PUT, and DELETE JSON payloads
|
31
|
+
* Simple Accept headers with automatic q-score weighting
|
32
|
+
* Understand and fall back to basic Content-types if application/json is not available
|
33
|
+
* Fine-grained response handling using Mudbug#resource
|
34
|
+
* A winning combination of guts, salad, sea legs, and torpor will propel our fair spaceship beyond the pale shadow of any doubt that the inxorable result of our redoubled efforts will counfound any chance at snatching defeat from the jars of whiskey.
|
35
|
+
EOF
|
36
|
+
s.authors = ["Rick Hull"]
|
37
|
+
s.email = "rick@cloudscaling.com"
|
38
|
+
s.homepage = "http://github.com/rickhull/mudbug"
|
39
|
+
s.licenses = ['LGPL']
|
40
|
+
|
41
|
+
# Dynamic assignments
|
42
|
+
s.files = manifest
|
43
|
+
s.version = version
|
44
|
+
s.date = Time.now.strftime("%Y-%m-%d")
|
45
|
+
|
46
|
+
s.add_runtime_dependency "rest-client", ["~> 1"]
|
47
|
+
s.add_runtime_dependency "json", ["~> 1"]
|
48
|
+
s.add_development_dependency "minitest", [">= 0"]
|
49
|
+
s.add_development_dependency "rake", [">= 0"]
|
50
|
+
end
|
51
|
+
|
52
|
+
# we're definining the task at runtime, rather than requiretime
|
53
|
+
# so that the gemspec will reflect any version bumping since requiretime
|
54
|
+
#
|
55
|
+
Gem::PackageTask.new(spec).define
|
56
|
+
Rake::Task["package"].invoke
|
57
|
+
end
|
58
|
+
|
59
|
+
# e.g. bump(:minor, '1.2.3') #=> '1.3.0'
|
60
|
+
# only works for integers delimited by periods (dots)
|
61
|
+
#
|
62
|
+
def bump(position, version)
|
63
|
+
pos = [:major, :minor, :patch, :build].index(position) || position
|
64
|
+
places = version.split('.')
|
65
|
+
raise "bad position: #{pos} (for version #{version})" unless places[pos]
|
66
|
+
places.map.with_index { |place, i|
|
67
|
+
if i < pos
|
68
|
+
place
|
69
|
+
elsif i == pos
|
70
|
+
place.to_i + 1
|
71
|
+
else
|
72
|
+
0
|
73
|
+
end
|
74
|
+
}.join('.')
|
75
|
+
end
|
76
|
+
|
77
|
+
def write_version new_version
|
78
|
+
File.open(VERSION_FILE, 'w') { |f| f.write(new_version) }
|
79
|
+
end
|
80
|
+
|
81
|
+
[:major, :minor, :patch, :build].each { |v|
|
82
|
+
task "bump_#{v}" do
|
83
|
+
old_version = version
|
84
|
+
new_version = bump(v, old_version)
|
85
|
+
puts "bumping #{old_version} to #{new_version}"
|
86
|
+
write_version new_version
|
87
|
+
end
|
88
|
+
}
|
89
|
+
task :bump => [:bump_patch]
|
90
|
+
|
91
|
+
task :tag do
|
92
|
+
tagname = "v#{version}"
|
93
|
+
sh "git tag -a #{tagname} -m 'auto-tagged #{tagname} by Rake'"
|
94
|
+
end
|
95
|
+
|
96
|
+
task :release => [:bump_build, :tag, :publish]
|
97
|
+
task :release_patch => [:bump_patch, :tag, :publish]
|
98
|
+
task :release_minor => [:bump_minor, :tag, :publish]
|
99
|
+
task :release_major => [:bump_major, :tag, :publish]
|
100
|
+
|
101
|
+
task :verify_publish_credentials do
|
102
|
+
creds = '~/.gem/credentials'
|
103
|
+
fp = File.expand_path(creds)
|
104
|
+
raise "#{creds} does not exist" unless File.exists?(fp)
|
105
|
+
raise "can't read #{creds}" unless File.readable?(fp)
|
106
|
+
end
|
107
|
+
|
108
|
+
task :publish => [:verify_publish_credentials, :build] do
|
109
|
+
fragment = "-#{version}.gem"
|
110
|
+
pkg_dir = File.join(PROJECT_ROOT, 'pkg')
|
111
|
+
Dir.chdir(pkg_dir) {
|
112
|
+
candidates = Dir.glob "*#{fragment}"
|
113
|
+
case candidates.length
|
114
|
+
when 0
|
115
|
+
raise "could not find .gem matching #{fragment}"
|
116
|
+
when 1
|
117
|
+
sh "gem push #{candidates.first}"
|
118
|
+
else
|
119
|
+
raise "multiple candidates found matching #{fragment}"
|
120
|
+
end
|
121
|
+
}
|
122
|
+
end
|
data/test/mudbug.rb
ADDED
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mudbug
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.5.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rick Hull
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: minitest
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: ! '* GET, POST, PUT, and DELETE JSON payloads
|
79
|
+
|
80
|
+
* Simple Accept headers with automatic q-score weighting
|
81
|
+
|
82
|
+
* Understand and fall back to basic Content-types if application/json is not available
|
83
|
+
|
84
|
+
* Fine-grained response handling using Mudbug#resource
|
85
|
+
|
86
|
+
* A winning combination of guts, salad, sea legs, and torpor will propel our fair
|
87
|
+
spaceship beyond the pale shadow of any doubt that the inxorable result of our redoubled
|
88
|
+
efforts will counfound any chance at snatching defeat from the jars of whiskey.
|
89
|
+
|
90
|
+
'
|
91
|
+
email: rick@cloudscaling.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- README.md
|
97
|
+
- VERSION
|
98
|
+
- rakefile.rb
|
99
|
+
- MANIFEST.txt
|
100
|
+
- LICENSE.txt
|
101
|
+
- lib/mudbug.rb
|
102
|
+
- test/mudbug.rb
|
103
|
+
- examples/accepts_and_methods.rb
|
104
|
+
homepage: http://github.com/rickhull/mudbug
|
105
|
+
licenses:
|
106
|
+
- LGPL
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 1.8.23
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: A thin layer over rest-client that returns JSON objects
|
129
|
+
test_files: []
|