mudbug 0.4.7.3 → 0.5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/examples/accepts_and_methods.rb +5 -1
- data/lib/mudbug.rb +12 -8
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0.1
|
data/lib/mudbug.rb
CHANGED
@@ -3,15 +3,16 @@ require 'json'
|
|
3
3
|
require 'lager'
|
4
4
|
|
5
5
|
class Mudbug
|
6
|
-
extend Lager
|
7
|
-
log_to $stderr, :warn
|
8
|
-
|
9
6
|
def self.version
|
10
|
-
|
11
|
-
File.read(
|
7
|
+
file = File.expand_path('../../VERSION', __FILE__)
|
8
|
+
File.read(file).chomp
|
12
9
|
end
|
13
10
|
|
11
|
+
extend Lager
|
12
|
+
log_to $stderr, :warn
|
13
|
+
|
14
14
|
class StatusCodeError < RuntimeError; end
|
15
|
+
class ContentTypeError < RuntimeError; end
|
15
16
|
|
16
17
|
# this structure declares what we support in the request Accept: header
|
17
18
|
# and defines automatic processing of the response based on the
|
@@ -45,6 +46,7 @@ class Mudbug
|
|
45
46
|
end
|
46
47
|
|
47
48
|
# do stuff based on response's Content-type
|
49
|
+
# accept is e.g. [:json, :html]
|
48
50
|
#
|
49
51
|
def self.process(resp, accept = nil)
|
50
52
|
@lager.debug { "response code: #{resp.code}" }
|
@@ -57,14 +59,16 @@ class Mudbug
|
|
57
59
|
# do you even Content-type, bro?
|
58
60
|
ct = resp.headers[:content_type]
|
59
61
|
unless ct
|
60
|
-
@lager.warn { "
|
62
|
+
@lager.warn { "abandon processing -- no response Content-type" }
|
61
63
|
return resp.body
|
62
64
|
end
|
63
65
|
|
64
|
-
#
|
66
|
+
# get the content-type
|
65
67
|
ct, charset = ct.split(';').map { |s| s.strip }
|
68
|
+
|
69
|
+
# raise if we got Content-type we didn't ask for
|
66
70
|
if accept and !accept.include?(ct)
|
67
|
-
|
71
|
+
raise ContentTypeError, "Asked for #{accept} but got #{ct}"
|
68
72
|
end
|
69
73
|
|
70
74
|
# process the response for known content types
|
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.
|
4
|
+
version: 0.5.0.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-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|