swd 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,21 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ swd (0.0.1)
5
+ activesupport (>= 3)
6
+ attr_required (>= 0.0.3)
7
+ httpclient (>= 2.2.1)
8
+ i18n
9
+ json (>= 1.4.3)
10
+
11
+ GEM
12
+ remote: http://rubygems.org/
13
+ specs:
14
+ activesupport (3.0.10)
15
+ addressable (2.2.6)
16
+ attr_required (0.0.3)
17
+ crack (0.1.8)
18
+ diff-lcs (1.1.2)
19
+ httpclient (2.2.1)
20
+ i18n (0.6.0)
21
+ json (1.5.3)
22
+ rake (0.9.2)
23
+ rcov (0.9.10)
24
+ rspec (2.6.0)
25
+ rspec-core (~> 2.6.0)
26
+ rspec-expectations (~> 2.6.0)
27
+ rspec-mocks (~> 2.6.0)
28
+ rspec-core (2.6.4)
29
+ rspec-expectations (2.6.0)
30
+ diff-lcs (~> 1.1.2)
31
+ rspec-mocks (2.6.0)
32
+ webmock (1.7.4)
33
+ addressable (> 2.2.5, ~> 2.2)
34
+ crack (>= 0.1.7)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ rake (>= 0.8)
41
+ rcov (>= 0.9)
42
+ rspec (>= 2)
43
+ swd!
44
+ webmock (>= 1.6.2)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -9,7 +9,7 @@ module SWD
9
9
  include AttrRequired
10
10
  attr_required :principal, :service, :host, :path
11
11
 
12
- class ContentExpired < Exception; end
12
+ class Expired < Exception; end
13
13
 
14
14
  def initialize(attributes = {})
15
15
  required_attributes.each do |key|
@@ -23,7 +23,7 @@ module SWD
23
23
  def discover!
24
24
  SWD.cache.fetch(cache_key, @cache_options) do
25
25
  handle_response do
26
- HTTPClient.get endpoint.to_s
26
+ HTTPClient.get_content endpoint.to_s
27
27
  end
28
28
  end
29
29
  end
@@ -33,37 +33,42 @@ module SWD
33
33
  :principal => principal,
34
34
  :service => service
35
35
  }.to_query, nil]
36
+ rescue URI::Error => e
37
+ raise Exception.new(e.message)
36
38
  end
37
39
 
38
40
  private
39
41
 
40
42
  def handle_response
41
- res = yield
42
- case res.status
43
- when 200
44
- res = JSON.parse(res.body).with_indifferent_access
45
- if redirect = res[:SWD_service_redirect]
46
- redirect_to redirect[:location], redirect[:expires]
47
- else
48
- Response.new res
49
- end
43
+ res = JSON.parse(yield).with_indifferent_access
44
+ if redirect = res[:SWD_service_redirect]
45
+ redirect_to redirect[:location], redirect[:expires]
46
+ else
47
+ Response.new res
48
+ end
49
+ rescue HTTPClient::BadResponseError => e
50
+ case e.res.try(:status)
51
+ when nil
52
+ raise Exception.new(e.message)
50
53
  when 400
51
- raise BadRequest.new(res)
54
+ raise BadRequest.new('Bad Request', res)
52
55
  when 401
53
- raise Unauthorized.new(res)
56
+ raise Unauthorized.new('Unauthorized', res)
54
57
  when 403
55
- raise Forbidden.new(res)
58
+ raise Forbidden.new('Forbidden', res)
56
59
  when 404
57
- raise NotFound.new(res)
60
+ raise NotFound.new('Not Found', res)
58
61
  else
59
- raise HttpError.new(res.code, res)
62
+ raise HttpError.new(e.res.status, e.res.reason, res)
60
63
  end
64
+ rescue JSON::ParserError, OpenSSL::SSL::SSLError, SocketError => e
65
+ raise Exception.new(e.message)
61
66
  end
62
67
 
63
68
  def redirect_to(location, expires)
64
69
  uri = URI.parse(location)
65
70
  @host, @path = uri.host, uri.path
66
- raise ContentExpired if expires && expires.to_i < Time.now.utc.to_i
71
+ raise Expired if expires && expires.to_i < Time.now.utc.to_i
67
72
  discover!
68
73
  end
69
74
 
@@ -49,7 +49,7 @@ describe SWD::Resource do
49
49
  context 'when expired' do
50
50
  it 'should return SWD::Response' do
51
51
  mock_json resource.endpoint, 'redirect_expired' do
52
- expect { res = resource.discover! }.should raise_error SWD::Resource::ContentExpired
52
+ expect { res = resource.discover! }.should raise_error SWD::Resource::Expired
53
53
  end
54
54
  end
55
55
  end
@@ -69,42 +69,73 @@ describe SWD::Resource do
69
69
  end
70
70
  end
71
71
 
72
- context 'when bad request' do
73
- it 'should raise SWD::BadRequest' do
74
- mock_json resource.endpoint, 'blank', :status => 400 do
75
- expect { res = resource.discover! }.should raise_error SWD::BadRequest
72
+ describe 'error handling' do
73
+
74
+ context 'when invalid SSL cert' do
75
+ it do
76
+ HTTPClient.should_receive(:get_content).and_raise(OpenSSL::SSL::SSLError)
77
+ expect { res = resource.discover! }.should raise_error SWD::Exception
76
78
  end
77
79
  end
78
- end
79
80
 
80
- context 'when unauthorized' do
81
- it 'should raise SWD::Unauthorized' do
82
- mock_json resource.endpoint, 'blank', :status => 401 do
83
- expect { res = resource.discover! }.should raise_error SWD::Unauthorized
81
+ context 'when invalid JSON' do
82
+ it do
83
+ HTTPClient.should_receive(:get_content).and_raise(JSON::ParserError)
84
+ expect { res = resource.discover! }.should raise_error SWD::Exception
84
85
  end
85
86
  end
86
- end
87
87
 
88
- context 'when forbidden' do
89
- it 'should raise SWD::Forbidden' do
90
- mock_json resource.endpoint, 'blank', :status => 403 do
91
- expect { res = resource.discover! }.should raise_error SWD::Forbidden
88
+ context 'when SocketError' do
89
+ it do
90
+ HTTPClient.should_receive(:get_content).and_raise(SocketError)
91
+ expect { res = resource.discover! }.should raise_error SWD::Exception
92
92
  end
93
93
  end
94
- end
95
94
 
96
- context 'when not found' do
97
- it 'should raise SWD::NotFound' do
98
- mock_json resource.endpoint, 'blank', :status => 404 do
99
- expect { res = resource.discover! }.should raise_error SWD::NotFound
95
+ context 'when BadResponseError without response' do
96
+ it do
97
+ HTTPClient.should_receive(:get_content).and_raise(HTTPClient::BadResponseError.new(''))
98
+ expect { res = resource.discover! }.should raise_error SWD::Exception
99
+ end
100
+ end
101
+
102
+ context 'when bad request' do
103
+ it 'should raise SWD::BadRequest' do
104
+ mock_json resource.endpoint, 'blank', :status => 400 do
105
+ expect { res = resource.discover! }.should raise_error SWD::BadRequest
106
+ end
107
+ end
108
+ end
109
+
110
+ context 'when unauthorized' do
111
+ it 'should raise SWD::Unauthorized' do
112
+ mock_json resource.endpoint, 'blank', :status => 401 do
113
+ expect { res = resource.discover! }.should raise_error SWD::Unauthorized
114
+ end
115
+ end
116
+ end
117
+
118
+ context 'when forbidden' do
119
+ it 'should raise SWD::Forbidden' do
120
+ mock_json resource.endpoint, 'blank', :status => 403 do
121
+ expect { res = resource.discover! }.should raise_error SWD::Forbidden
122
+ end
100
123
  end
101
124
  end
102
- end
103
125
 
104
- context 'when other error happened' do
105
- it 'should raise SWD::HttpError' do
106
- mock_json resource.endpoint, 'blank', :status => 500 do
107
- expect { res = resource.discover! }.should raise_error SWD::HttpError
126
+ context 'when not found' do
127
+ it 'should raise SWD::NotFound' do
128
+ mock_json resource.endpoint, 'blank', :status => 404 do
129
+ expect { res = resource.discover! }.should raise_error SWD::NotFound
130
+ end
131
+ end
132
+ end
133
+
134
+ context 'when other error happened' do
135
+ it 'should raise SWD::HttpError' do
136
+ mock_json resource.endpoint, 'blank', :status => 500 do
137
+ expect { res = resource.discover! }.should raise_error SWD::HttpError
138
+ end
108
139
  end
109
140
  end
110
141
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swd
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 0
10
- version: 0.0.0
5
+ version: 0.0.1
11
6
  platform: ruby
12
7
  authors:
13
8
  - nov matake
@@ -25,11 +20,6 @@ dependencies:
25
20
  requirements:
26
21
  - - ">="
27
22
  - !ruby/object:Gem::Version
28
- hash: 1
29
- segments:
30
- - 1
31
- - 4
32
- - 3
33
23
  version: 1.4.3
34
24
  type: :runtime
35
25
  version_requirements: *id001
@@ -41,11 +31,6 @@ dependencies:
41
31
  requirements:
42
32
  - - ">="
43
33
  - !ruby/object:Gem::Version
44
- hash: 5
45
- segments:
46
- - 2
47
- - 2
48
- - 1
49
34
  version: 2.2.1
50
35
  type: :runtime
51
36
  version_requirements: *id002
@@ -57,9 +42,6 @@ dependencies:
57
42
  requirements:
58
43
  - - ">="
59
44
  - !ruby/object:Gem::Version
60
- hash: 5
61
- segments:
62
- - 3
63
45
  version: "3"
64
46
  type: :runtime
65
47
  version_requirements: *id003
@@ -71,9 +53,6 @@ dependencies:
71
53
  requirements:
72
54
  - - ">="
73
55
  - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
56
  version: "0"
78
57
  type: :runtime
79
58
  version_requirements: *id004
@@ -85,11 +64,6 @@ dependencies:
85
64
  requirements:
86
65
  - - ">="
87
66
  - !ruby/object:Gem::Version
88
- hash: 25
89
- segments:
90
- - 0
91
- - 0
92
- - 3
93
67
  version: 0.0.3
94
68
  type: :runtime
95
69
  version_requirements: *id005
@@ -101,10 +75,6 @@ dependencies:
101
75
  requirements:
102
76
  - - ">="
103
77
  - !ruby/object:Gem::Version
104
- hash: 27
105
- segments:
106
- - 0
107
- - 8
108
78
  version: "0.8"
109
79
  type: :development
110
80
  version_requirements: *id006
@@ -116,10 +86,6 @@ dependencies:
116
86
  requirements:
117
87
  - - ">="
118
88
  - !ruby/object:Gem::Version
119
- hash: 25
120
- segments:
121
- - 0
122
- - 9
123
89
  version: "0.9"
124
90
  type: :development
125
91
  version_requirements: *id007
@@ -131,9 +97,6 @@ dependencies:
131
97
  requirements:
132
98
  - - ">="
133
99
  - !ruby/object:Gem::Version
134
- hash: 7
135
- segments:
136
- - 2
137
100
  version: "2"
138
101
  type: :development
139
102
  version_requirements: *id008
@@ -145,11 +108,6 @@ dependencies:
145
108
  requirements:
146
109
  - - ">="
147
110
  - !ruby/object:Gem::Version
148
- hash: 11
149
- segments:
150
- - 1
151
- - 6
152
- - 2
153
111
  version: 1.6.2
154
112
  type: :development
155
113
  version_requirements: *id009
@@ -165,19 +123,9 @@ extra_rdoc_files: []
165
123
  files:
166
124
  - .gitignore
167
125
  - Gemfile
126
+ - Gemfile.lock
168
127
  - Rakefile
169
128
  - VERSION
170
- - coverage/index.html
171
- - coverage/jquery-1.3.2.min.js
172
- - coverage/jquery.tablesorter.min.js
173
- - coverage/lib-swd-cache_rb.html
174
- - coverage/lib-swd-exception_rb.html
175
- - coverage/lib-swd-resource_rb.html
176
- - coverage/lib-swd-response_rb.html
177
- - coverage/lib-swd_rb.html
178
- - coverage/print.css
179
- - coverage/rcov.js
180
- - coverage/screen.css
181
129
  - lib/swd.rb
182
130
  - lib/swd/cache.rb
183
131
  - lib/swd/exception.rb
@@ -206,18 +154,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
154
  requirements:
207
155
  - - ">="
208
156
  - !ruby/object:Gem::Version
209
- hash: 3
210
- segments:
211
- - 0
212
157
  version: "0"
213
158
  required_rubygems_version: !ruby/object:Gem::Requirement
214
159
  none: false
215
160
  requirements:
216
161
  - - ">="
217
162
  - !ruby/object:Gem::Version
218
- hash: 3
219
- segments:
220
- - 0
221
163
  version: "0"
222
164
  requirements: []
223
165
 
@@ -1,170 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
- <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
3
- <head>
4
- <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
5
- <title>Swd C0 Coverage Information - RCov</title>
6
- <link href="screen.css" media="all" rel="stylesheet" type="text/css" />
7
- <link href="print.css" media="print" rel="stylesheet" type="text/css" />
8
-
9
- <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
10
- <script type="text/javascript" src="jquery.tablesorter.min.js"></script>
11
- <script type="text/javascript" src="rcov.js"></script>
12
- </head>
13
- <body>
14
- <h1>Swd C0 Coverage Information - RCov</h1>
15
-
16
-
17
- <noscript><style type="text/css">.if_js { display:none; }</style></noscript>
18
-
19
- <div class="filters if_js">
20
- <fieldset>
21
- <label>File Filter:</label>
22
- <select id="file_filter" class="filter">
23
- <option value="all_files">Show All</option>
24
- <option value="lib">lib/</option><option value="swd">swd/</option>
25
- </select>
26
- </fieldset>
27
- <fieldset>
28
- <label>Code Coverage Threshold:</label>
29
- <select id="coverage_filter" class="filter">
30
- <option value="all_coverage">Show All</option>
31
- <option value="10">&lt; 10% Coverage</option><option value="20">&lt; 20% Coverage</option><option value="30">&lt; 30% Coverage</option><option value="40">&lt; 40% Coverage</option><option value="50">&lt; 50% Coverage</option><option value="60">&lt; 60% Coverage</option><option value="70">&lt; 70% Coverage</option><option value="80">&lt; 80% Coverage</option><option value="90">&lt; 90% Coverage</option><option value="100">&lt; 100% Coverage</option>
32
- <option value="110">= 100% Coverage</option>
33
- </select>
34
- </fieldset>
35
- </div>
36
-
37
- <div class="report_table_wrapper">
38
- <table class='report' id='report_table'>
39
- <thead>
40
- <tr>
41
- <th class="left_align">Name</th>
42
- <th class="right_align">Total Lines</th>
43
- <th class="right_align">Lines of Code</th>
44
- <th class="left_align">Total Coverage</th>
45
- <th class="left_align">Code Coverage</th>
46
- </tr>
47
- </thead>
48
- <tfoot>
49
- <tr>
50
- <td class="left_align">TOTAL</td>
51
- <td class='right_align'><tt>150</tt></td>
52
- <td class='right_align'><tt>134</tt></td>
53
- <td class="left_align"><div class="percent_graph_legend"><tt class=''>99.33%</tt></div>
54
- <div class="percent_graph">
55
- <div class="covered" style="width:99px"></div>
56
- <div class="uncovered" style="width:1px"></div>
57
- </div></td>
58
- <td class="left_align"><div class="percent_graph_legend"><tt class='coverage_total'>99.25%</tt></div>
59
- <div class="percent_graph">
60
- <div class="covered" style="width:99px"></div>
61
- <div class="uncovered" style="width:1px"></div>
62
- </div></td>
63
- </tr>
64
- </tfoot>
65
- <tbody>
66
-
67
- <tr class="all_files all_coverage 110 lib even">
68
- <td class="left_align"><a href="lib-swd_rb.html">lib/swd.rb</a></td>
69
- <td class='right_align'><tt>16</tt></td>
70
- <td class='right_align'><tt>15</tt></td>
71
- <td class="left_align"><div class="percent_graph_legend"><tt class=''>100.00%</tt></div>
72
- <div class="percent_graph">
73
- <div class="covered" style="width:100px"></div>
74
- <div class="uncovered" style="width:0px"></div>
75
- </div></td>
76
- <td class="left_align"><div class="percent_graph_legend"><tt class=''>100.00%</tt></div>
77
- <div class="percent_graph">
78
- <div class="covered" style="width:100px"></div>
79
- <div class="uncovered" style="width:0px"></div>
80
- </div></td>
81
- </tr>
82
-
83
- <tr class="all_files all_coverage 110 lib swd odd">
84
- <td class="left_align"><a href="lib-swd-cache_rb.html">lib/swd/cache.rb</a></td>
85
- <td class='right_align'><tt>8</tt></td>
86
- <td class='right_align'><tt>8</tt></td>
87
- <td class="left_align"><div class="percent_graph_legend"><tt class=''>100.00%</tt></div>
88
- <div class="percent_graph">
89
- <div class="covered" style="width:100px"></div>
90
- <div class="uncovered" style="width:0px"></div>
91
- </div></td>
92
- <td class="left_align"><div class="percent_graph_legend"><tt class=''>100.00%</tt></div>
93
- <div class="percent_graph">
94
- <div class="covered" style="width:100px"></div>
95
- <div class="uncovered" style="width:0px"></div>
96
- </div></td>
97
- </tr>
98
-
99
- <tr class="all_files all_coverage 110 lib swd even">
100
- <td class="left_align"><a href="lib-swd-exception_rb.html">lib/swd/exception.rb</a></td>
101
- <td class='right_align'><tt>36</tt></td>
102
- <td class='right_align'><tt>31</tt></td>
103
- <td class="left_align"><div class="percent_graph_legend"><tt class=''>100.00%</tt></div>
104
- <div class="percent_graph">
105
- <div class="covered" style="width:100px"></div>
106
- <div class="uncovered" style="width:0px"></div>
107
- </div></td>
108
- <td class="left_align"><div class="percent_graph_legend"><tt class=''>100.00%</tt></div>
109
- <div class="percent_graph">
110
- <div class="covered" style="width:100px"></div>
111
- <div class="uncovered" style="width:0px"></div>
112
- </div></td>
113
- </tr>
114
-
115
- <tr class="all_files all_coverage 100 lib swd odd">
116
- <td class="left_align"><a href="lib-swd-resource_rb.html">lib/swd/resource.rb</a></td>
117
- <td class='right_align'><tt>79</tt></td>
118
- <td class='right_align'><tt>70</tt></td>
119
- <td class="left_align"><div class="percent_graph_legend"><tt class=''>98.73%</tt></div>
120
- <div class="percent_graph">
121
- <div class="covered" style="width:99px"></div>
122
- <div class="uncovered" style="width:1px"></div>
123
- </div></td>
124
- <td class="left_align"><div class="percent_graph_legend"><tt class=''>98.57%</tt></div>
125
- <div class="percent_graph">
126
- <div class="covered" style="width:99px"></div>
127
- <div class="uncovered" style="width:1px"></div>
128
- </div></td>
129
- </tr>
130
-
131
- <tr class="all_files all_coverage 110 lib swd even">
132
- <td class="left_align"><a href="lib-swd-response_rb.html">lib/swd/response.rb</a></td>
133
- <td class='right_align'><tt>11</tt></td>
134
- <td class='right_align'><tt>10</tt></td>
135
- <td class="left_align"><div class="percent_graph_legend"><tt class=''>100.00%</tt></div>
136
- <div class="percent_graph">
137
- <div class="covered" style="width:100px"></div>
138
- <div class="uncovered" style="width:0px"></div>
139
- </div></td>
140
- <td class="left_align"><div class="percent_graph_legend"><tt class=''>100.00%</tt></div>
141
- <div class="percent_graph">
142
- <div class="covered" style="width:100px"></div>
143
- <div class="uncovered" style="width:0px"></div>
144
- </div></td>
145
- </tr>
146
-
147
- </tbody>
148
- </table>
149
- </div>
150
-
151
- <p>Generated on Fri Aug 19 16:24:16 +0900 2011 with <a href="http://github.com/relevance/rcov">rcov 0.9.10</a></p>
152
-
153
- <script type="text/javascript">
154
- $(document).ready(function(){$("#report_table").tablesorter({widgets: ['zebra'], textExtraction: 'complex'});});
155
- $('.filter').change(function(){
156
- ff = $('#file_filter').val();
157
- cf = $('#coverage_filter').val();
158
- $('table#report_table tbody tr').each(function(i){
159
- if ((this.className.split(" ").indexOf(ff) > -1) && (this.className.split(" ").indexOf(cf) > -1)) {
160
- this.style.display = "";
161
- } else {
162
- this.style.display = "none";
163
- };
164
- restripe();
165
- })
166
- })
167
- </script>
168
-
169
- </body>
170
- </html>