swd 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +6 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +8 -5
- data/VERSION +1 -1
- data/lib/swd/resource.rb +9 -1
- data/lib/swd.rb +35 -1
- data/spec/swd/resource_spec.rb +14 -4
- data/spec/swd_spec.rb +26 -0
- metadata +51 -2
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
swd (0.0.
|
4
|
+
swd (0.0.4)
|
5
5
|
activesupport (>= 3)
|
6
6
|
attr_required (>= 0.0.3)
|
7
7
|
httpclient (>= 2.2.1)
|
@@ -11,14 +11,16 @@ PATH
|
|
11
11
|
GEM
|
12
12
|
remote: http://rubygems.org/
|
13
13
|
specs:
|
14
|
-
activesupport (3.0
|
14
|
+
activesupport (3.1.0)
|
15
|
+
multi_json (~> 1.0)
|
15
16
|
addressable (2.2.6)
|
16
17
|
attr_required (0.0.3)
|
17
18
|
crack (0.1.8)
|
18
|
-
diff-lcs (1.1.
|
19
|
+
diff-lcs (1.1.3)
|
19
20
|
httpclient (2.2.1)
|
20
21
|
i18n (0.6.0)
|
21
|
-
json (1.5.
|
22
|
+
json (1.5.4)
|
23
|
+
multi_json (1.0.3)
|
22
24
|
rake (0.9.2)
|
23
25
|
rcov (0.9.10)
|
24
26
|
rspec (2.6.0)
|
@@ -29,7 +31,7 @@ GEM
|
|
29
31
|
rspec-expectations (2.6.0)
|
30
32
|
diff-lcs (~> 1.1.2)
|
31
33
|
rspec-mocks (2.6.0)
|
32
|
-
webmock (1.7.
|
34
|
+
webmock (1.7.5)
|
33
35
|
addressable (> 2.2.5, ~> 2.2)
|
34
36
|
crack (>= 0.1.7)
|
35
37
|
|
@@ -37,6 +39,7 @@ PLATFORMS
|
|
37
39
|
ruby
|
38
40
|
|
39
41
|
DEPENDENCIES
|
42
|
+
jruby-openssl (>= 0.7)
|
40
43
|
rake (>= 0.8)
|
41
44
|
rcov (>= 0.9)
|
42
45
|
rspec (>= 2)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/lib/swd/resource.rb
CHANGED
@@ -22,7 +22,7 @@ module SWD
|
|
22
22
|
def discover!(cache_options = {})
|
23
23
|
SWD.cache.fetch(cache_key, cache_options) do
|
24
24
|
handle_response do
|
25
|
-
|
25
|
+
http_client.get_content endpoint.to_s
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -38,6 +38,14 @@ module SWD
|
|
38
38
|
|
39
39
|
private
|
40
40
|
|
41
|
+
def http_client
|
42
|
+
_http_client_ = HTTPClient.new(
|
43
|
+
:agent_name => "SWD (#{VERSION})"
|
44
|
+
)
|
45
|
+
_http_client_.request_filter << Debugger::RequestFilter.new if SWD.debugging?
|
46
|
+
_http_client_
|
47
|
+
end
|
48
|
+
|
41
49
|
def handle_response
|
42
50
|
res = JSON.parse(yield).with_indifferent_access
|
43
51
|
if redirect = res[:SWD_service_redirect]
|
data/lib/swd.rb
CHANGED
@@ -1,19 +1,53 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
1
3
|
module SWD
|
4
|
+
VERSION = ::File.read(
|
5
|
+
::File.join(::File.dirname(__FILE__), '../VERSION')
|
6
|
+
)
|
7
|
+
|
2
8
|
def self.cache=(cache)
|
3
9
|
@@cache = cache
|
4
10
|
end
|
5
11
|
def self.cache
|
6
12
|
@@cache
|
7
13
|
end
|
14
|
+
|
8
15
|
def self.discover!(attributes = {})
|
9
16
|
Resource.new(attributes).discover!(attributes[:cache])
|
10
17
|
end
|
18
|
+
|
19
|
+
def self.logger
|
20
|
+
@@logger
|
21
|
+
end
|
22
|
+
def self.logger=(logger)
|
23
|
+
@@logger = logger
|
24
|
+
end
|
25
|
+
self.logger = ::Logger.new(STDOUT)
|
26
|
+
self.logger.progname = 'SWD'
|
27
|
+
|
28
|
+
def self.debugging?
|
29
|
+
@@debugging
|
30
|
+
end
|
31
|
+
def self.debugging=(boolean)
|
32
|
+
@@debugging = boolean
|
33
|
+
end
|
34
|
+
def self.debug!
|
35
|
+
self.debugging = true
|
36
|
+
end
|
37
|
+
def self.debug(&block)
|
38
|
+
original = self.debugging?
|
39
|
+
self.debugging = true
|
40
|
+
yield
|
41
|
+
ensure
|
42
|
+
self.debugging = original
|
43
|
+
end
|
44
|
+
self.debugging = false
|
11
45
|
end
|
12
46
|
|
13
47
|
require 'swd/cache'
|
14
48
|
require 'swd/exception'
|
15
49
|
require 'swd/resource'
|
16
50
|
require 'swd/response'
|
51
|
+
require 'swd/debugger'
|
17
52
|
|
18
|
-
# NOTE: Default Cache doesn't cache anything.
|
19
53
|
SWD.cache = SWD::Cache.new
|
data/spec/swd/resource_spec.rb
CHANGED
@@ -70,31 +70,41 @@ describe SWD::Resource do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
describe 'error handling' do
|
73
|
+
let(:http_client) { resource.send(:http_client) }
|
74
|
+
before do
|
75
|
+
module SWD
|
76
|
+
class Resource
|
77
|
+
def http_client
|
78
|
+
@http_client ||= HTTPClient.new
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
73
83
|
|
74
84
|
context 'when invalid SSL cert' do
|
75
85
|
it do
|
76
|
-
|
86
|
+
http_client.should_receive(:get_content).and_raise(OpenSSL::SSL::SSLError)
|
77
87
|
expect { res = resource.discover! }.should raise_error SWD::Exception
|
78
88
|
end
|
79
89
|
end
|
80
90
|
|
81
91
|
context 'when invalid JSON' do
|
82
92
|
it do
|
83
|
-
|
93
|
+
http_client.should_receive(:get_content).and_raise(JSON::ParserError)
|
84
94
|
expect { res = resource.discover! }.should raise_error SWD::Exception
|
85
95
|
end
|
86
96
|
end
|
87
97
|
|
88
98
|
context 'when SocketError' do
|
89
99
|
it do
|
90
|
-
|
100
|
+
http_client.should_receive(:get_content).and_raise(SocketError)
|
91
101
|
expect { res = resource.discover! }.should raise_error SWD::Exception
|
92
102
|
end
|
93
103
|
end
|
94
104
|
|
95
105
|
context 'when BadResponseError without response' do
|
96
106
|
it do
|
97
|
-
|
107
|
+
http_client.should_receive(:get_content).and_raise(HTTPClient::BadResponseError.new(''))
|
98
108
|
expect { res = resource.discover! }.should raise_error SWD::Exception
|
99
109
|
end
|
100
110
|
end
|
data/spec/swd_spec.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SWD do
|
4
|
+
after { SWD.debugging = false }
|
5
|
+
|
6
|
+
its(:logger) { should be_a Logger }
|
7
|
+
its(:debugging?) { should be_false }
|
4
8
|
its(:cache) { should be_a SWD::Cache }
|
5
9
|
|
6
10
|
describe '#discover!' do
|
@@ -17,4 +21,26 @@ describe SWD do
|
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
24
|
+
|
25
|
+
describe '.debug!' do
|
26
|
+
before { SWD.debug! }
|
27
|
+
its(:debugging?) { should be_true }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '.debug' do
|
31
|
+
it 'should enable debugging within given block' do
|
32
|
+
SWD.debug do
|
33
|
+
SWD.debugging?.should be_true
|
34
|
+
end
|
35
|
+
SWD.debugging?.should be_false
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should not force disable debugging' do
|
39
|
+
SWD.debug!
|
40
|
+
SWD.debug do
|
41
|
+
SWD.debugging?.should be_true
|
42
|
+
end
|
43
|
+
SWD.debugging?.should be_true
|
44
|
+
end
|
45
|
+
end
|
20
46
|
end
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- nov matake
|
@@ -10,7 +15,7 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-
|
18
|
+
date: 2011-09-10 00:00:00 Z
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: json
|
@@ -20,6 +25,11 @@ dependencies:
|
|
20
25
|
requirements:
|
21
26
|
- - ">="
|
22
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 1
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 4
|
32
|
+
- 3
|
23
33
|
version: 1.4.3
|
24
34
|
type: :runtime
|
25
35
|
version_requirements: *id001
|
@@ -31,6 +41,11 @@ dependencies:
|
|
31
41
|
requirements:
|
32
42
|
- - ">="
|
33
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 5
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 2
|
48
|
+
- 1
|
34
49
|
version: 2.2.1
|
35
50
|
type: :runtime
|
36
51
|
version_requirements: *id002
|
@@ -42,6 +57,9 @@ dependencies:
|
|
42
57
|
requirements:
|
43
58
|
- - ">="
|
44
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 5
|
61
|
+
segments:
|
62
|
+
- 3
|
45
63
|
version: "3"
|
46
64
|
type: :runtime
|
47
65
|
version_requirements: *id003
|
@@ -53,6 +71,9 @@ dependencies:
|
|
53
71
|
requirements:
|
54
72
|
- - ">="
|
55
73
|
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
56
77
|
version: "0"
|
57
78
|
type: :runtime
|
58
79
|
version_requirements: *id004
|
@@ -64,6 +85,11 @@ dependencies:
|
|
64
85
|
requirements:
|
65
86
|
- - ">="
|
66
87
|
- !ruby/object:Gem::Version
|
88
|
+
hash: 25
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
- 0
|
92
|
+
- 3
|
67
93
|
version: 0.0.3
|
68
94
|
type: :runtime
|
69
95
|
version_requirements: *id005
|
@@ -75,6 +101,10 @@ dependencies:
|
|
75
101
|
requirements:
|
76
102
|
- - ">="
|
77
103
|
- !ruby/object:Gem::Version
|
104
|
+
hash: 27
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
- 8
|
78
108
|
version: "0.8"
|
79
109
|
type: :development
|
80
110
|
version_requirements: *id006
|
@@ -86,6 +116,10 @@ dependencies:
|
|
86
116
|
requirements:
|
87
117
|
- - ">="
|
88
118
|
- !ruby/object:Gem::Version
|
119
|
+
hash: 25
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
- 9
|
89
123
|
version: "0.9"
|
90
124
|
type: :development
|
91
125
|
version_requirements: *id007
|
@@ -97,6 +131,9 @@ dependencies:
|
|
97
131
|
requirements:
|
98
132
|
- - ">="
|
99
133
|
- !ruby/object:Gem::Version
|
134
|
+
hash: 7
|
135
|
+
segments:
|
136
|
+
- 2
|
100
137
|
version: "2"
|
101
138
|
type: :development
|
102
139
|
version_requirements: *id008
|
@@ -108,6 +145,11 @@ dependencies:
|
|
108
145
|
requirements:
|
109
146
|
- - ">="
|
110
147
|
- !ruby/object:Gem::Version
|
148
|
+
hash: 11
|
149
|
+
segments:
|
150
|
+
- 1
|
151
|
+
- 6
|
152
|
+
- 2
|
111
153
|
version: 1.6.2
|
112
154
|
type: :development
|
113
155
|
version_requirements: *id009
|
@@ -123,6 +165,7 @@ extra_rdoc_files: []
|
|
123
165
|
files:
|
124
166
|
- .gitignore
|
125
167
|
- .rspec
|
168
|
+
- .travis.yml
|
126
169
|
- Gemfile
|
127
170
|
- Gemfile.lock
|
128
171
|
- LICENSE
|
@@ -157,12 +200,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
200
|
requirements:
|
158
201
|
- - ">="
|
159
202
|
- !ruby/object:Gem::Version
|
203
|
+
hash: 3
|
204
|
+
segments:
|
205
|
+
- 0
|
160
206
|
version: "0"
|
161
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
208
|
none: false
|
163
209
|
requirements:
|
164
210
|
- - ">="
|
165
211
|
- !ruby/object:Gem::Version
|
212
|
+
hash: 3
|
213
|
+
segments:
|
214
|
+
- 0
|
166
215
|
version: "0"
|
167
216
|
requirements: []
|
168
217
|
|