mudbug 1.0.0.1 → 1.0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +48 -0
- data/VERSION +1 -1
- data/examples/accepts_and_methods.rb +0 -2
- data/lib/mudbug.rb +6 -2
- data/test/mudbug.rb +90 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d8281020004f1bf40dde65058ebff959bfd3aa6
|
4
|
+
data.tar.gz: 3331caa343c648ca1d28a135a225b6ff2f56085b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e305e5b3360335819a063fdd46d7182331d733807006a72c943fea63e0021213a9cee06d1b33c577250a2f7d8d0c6374185debdda25f31641b266a9c079aaca9
|
7
|
+
data.tar.gz: 90ad745244b7d8b29901dcfca3690f31c0d633df3359ea6c6cdbaf8209411739ccd5e49e654538e402cb22e56b821c5457d3d8c7620a07ede4d4f07148ac3b0f
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/rickhull/mudbug.svg?branch=master)](https://travis-ci.org/rickhull/
|
1
|
+
[![Build Status](https://travis-ci.org/rickhull/mudbug.svg?branch=master)](https://travis-ci.org/rickhull/mudbug)
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/mudbug.svg)](http://badge.fury.io/rb/mudbug)
|
3
3
|
[![Code Climate](https://codeclimate.com/github/rickhull/mudbug/badges/gpa.svg)](https://codeclimate.com/github/rickhull/mudbug)
|
4
4
|
[![Dependency Status](https://gemnasium.com/rickhull/mudbug.svg)](https://gemnasium.com/rickhull/mudbug)
|
data/Rakefile
CHANGED
@@ -2,10 +2,58 @@ require 'rake/testtask'
|
|
2
2
|
|
3
3
|
Rake::TestTask.new :test do |t|
|
4
4
|
t.pattern = 'test/*.rb'
|
5
|
+
t.warning = true
|
5
6
|
end
|
6
7
|
|
8
|
+
task default: :test
|
7
9
|
|
8
10
|
|
11
|
+
#
|
12
|
+
# METRICS
|
13
|
+
#
|
14
|
+
|
15
|
+
metrics_tasks = []
|
16
|
+
|
17
|
+
begin
|
18
|
+
require 'flog_task'
|
19
|
+
|
20
|
+
FlogTask.new do |t|
|
21
|
+
t.dirs = ['lib']
|
22
|
+
t.verbose = true
|
23
|
+
end
|
24
|
+
metrics_tasks << :flog
|
25
|
+
rescue LoadError
|
26
|
+
warn 'flog_task unavailable'
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'flay_task'
|
31
|
+
|
32
|
+
FlayTask.new do |t|
|
33
|
+
t.dirs = ['lib']
|
34
|
+
t.verbose = true
|
35
|
+
end
|
36
|
+
metrics_tasks << :flay
|
37
|
+
rescue LoadError
|
38
|
+
warn 'flay_task unavailable'
|
39
|
+
end
|
40
|
+
|
41
|
+
begin
|
42
|
+
require 'roodi_task'
|
43
|
+
RoodiTask.new patterns: ['lib/**/*.rb']
|
44
|
+
metrics_tasks << :roodi
|
45
|
+
rescue LoadError
|
46
|
+
warn 'roodi_task unavailable'
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Generate code metrics reports"
|
50
|
+
task :code_metrics => metrics_tasks
|
51
|
+
|
52
|
+
|
53
|
+
#
|
54
|
+
# GEM BUILD / PUBLISH
|
55
|
+
#
|
56
|
+
|
9
57
|
begin
|
10
58
|
require 'buildar'
|
11
59
|
Buildar.new do |b|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1.1
|
data/lib/mudbug.rb
CHANGED
@@ -83,12 +83,15 @@ class Mudbug
|
|
83
83
|
end
|
84
84
|
|
85
85
|
attr_reader :options
|
86
|
-
attr_accessor :host
|
86
|
+
attr_accessor :host, :protocol
|
87
87
|
|
88
88
|
def initialize(host = 'localhost', options = {})
|
89
89
|
@host = host
|
90
|
+
https = options.delete(:https)
|
91
|
+
@protocol = https ? 'https' : 'http'
|
90
92
|
@options = options
|
91
93
|
accept :json, :html, :text
|
94
|
+
yield self if block_given?
|
92
95
|
end
|
93
96
|
|
94
97
|
# Writes the Accept: header for you
|
@@ -113,10 +116,11 @@ class Mudbug
|
|
113
116
|
uri = URI.parse(path)
|
114
117
|
if uri.host # a full URL was passed in
|
115
118
|
@host = uri.host
|
119
|
+
@protocol = uri.scheme
|
116
120
|
url = uri.to_s
|
117
121
|
else
|
118
122
|
path = "/#{path}" unless path[0,1] == '/'
|
119
|
-
url = "
|
123
|
+
url = "#{@protocol}://#{@host}#{path}"
|
120
124
|
end
|
121
125
|
RestClient::Resource.new(url, @options)
|
122
126
|
end
|
data/test/mudbug.rb
CHANGED
@@ -2,6 +2,11 @@ require 'minitest/autorun'
|
|
2
2
|
require 'mudbug'
|
3
3
|
|
4
4
|
describe "Mudbug" do
|
5
|
+
|
6
|
+
#
|
7
|
+
# class methods
|
8
|
+
#
|
9
|
+
|
5
10
|
describe "accept_header" do
|
6
11
|
it "must generate valid headers" do
|
7
12
|
h = Mudbug.accept_header(:json, :xml, :html, :text, :foo)
|
@@ -81,5 +86,90 @@ describe "Mudbug" do
|
|
81
86
|
out.must_be_empty
|
82
87
|
err.wont_be_empty
|
83
88
|
end
|
89
|
+
|
90
|
+
it "must faithfully yield valid JSON" do
|
91
|
+
data = { "hi" => "mom" }
|
92
|
+
resp = rest_client_resp(data.to_json, content_type: 'application/json')
|
93
|
+
Mudbug.process(resp).must_equal data
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# instance methods
|
99
|
+
#
|
100
|
+
|
101
|
+
describe "initalize" do
|
102
|
+
it "must allow https" do
|
103
|
+
mb = Mudbug.new 'localhost', https: true
|
104
|
+
mb.protocol.must_equal 'https'
|
105
|
+
mb.options[:https].must_be_nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "resource" do
|
110
|
+
it "must handle various path formulations" do
|
111
|
+
paths = %w[/path/to/res path/to/res http://localhost/path/to/res]
|
112
|
+
mb = Mudbug.new 'localhost'
|
113
|
+
paths.each { |p|
|
114
|
+
res = mb.resource(p)
|
115
|
+
res.wont_be_nil
|
116
|
+
res.url.must_equal 'http://localhost/path/to/res'
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
it "must update the host when provided" do
|
121
|
+
mb = Mudbug.new
|
122
|
+
mb.host.must_equal 'localhost'
|
123
|
+
res = mb.resource('http://localghost/path/to/res')
|
124
|
+
res.url.must_equal 'http://localghost/path/to/res'
|
125
|
+
mb.host.must_equal 'localghost'
|
126
|
+
end
|
127
|
+
|
128
|
+
it "must respect https" do
|
129
|
+
mb = Mudbug.new
|
130
|
+
mb.protocol.wont_equal 'https'
|
131
|
+
res = mb.resource('https://localhost/')
|
132
|
+
mb.protocol.must_equal 'https'
|
133
|
+
res.url.must_equal 'https://localhost/'
|
134
|
+
res = mb.resource('/foo')
|
135
|
+
res.url.must_equal 'https://localhost/foo'
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "accept" do
|
140
|
+
before do
|
141
|
+
@mb = Mudbug.new
|
142
|
+
end
|
143
|
+
|
144
|
+
it "must accept nil to remove accept headers" do
|
145
|
+
@mb.options[:headers][:accept].wont_be_nil
|
146
|
+
@mb.accept nil
|
147
|
+
@mb.options[:headers][:accept].must_be_nil
|
148
|
+
end
|
149
|
+
|
150
|
+
it "must accept some known symbols" do
|
151
|
+
[:json, :html, :text].each { |sym|
|
152
|
+
@mb.accept sym
|
153
|
+
@mb.options[:headers][:accept].must_equal Mudbug.accept_header(sym)
|
154
|
+
}
|
155
|
+
end
|
156
|
+
|
157
|
+
it "must accept an array" do
|
158
|
+
ary = [:json, :html, :text]
|
159
|
+
@mb.accept ary
|
160
|
+
ah = @mb.options[:headers][:accept]
|
161
|
+
ah.must_be_kind_of String
|
162
|
+
ah.split(', ').length.must_equal ary.length
|
163
|
+
end
|
164
|
+
|
165
|
+
it "must accept unknown symbols and strings" do
|
166
|
+
[:foo, 'foo'].each { |unk|
|
167
|
+
@mb.accept unk
|
168
|
+
ah = @mb.options[:headers][:accept]
|
169
|
+
ah.must_be_kind_of String
|
170
|
+
ah.must_equal Mudbug.accept_header unk
|
171
|
+
ah.must_equal "application/#{unk}"
|
172
|
+
}
|
173
|
+
end
|
84
174
|
end
|
85
175
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mudbug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Hull
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|