soundcloud 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/soundcloud.rb +71 -5
- data/lib/soundcloud/version.rb +1 -1
- metadata +2 -2
data/lib/soundcloud.rb
CHANGED
@@ -4,13 +4,77 @@ require 'uri'
|
|
4
4
|
|
5
5
|
class Soundcloud
|
6
6
|
class ResponseError < HTTParty::ResponseError
|
7
|
-
def
|
7
|
+
def message
|
8
8
|
error = response.parsed_response['error'] || response.parsed_response['errors']['error']
|
9
|
-
"HTTP status: #{response.code}
|
9
|
+
"HTTP status: #{StatusCodes.interpret_status(response.code)} Error: #{error}"
|
10
10
|
rescue
|
11
|
-
"HTTP status: #{response.code}"
|
11
|
+
"HTTP status: #{StatusCodes.interpret_status(response.code)}"
|
12
|
+
end
|
13
|
+
|
14
|
+
module StatusCodes
|
15
|
+
STATUS_CODES = {
|
16
|
+
100 => "Continue",
|
17
|
+
101 => "Switching Protocols",
|
18
|
+
102 => "Processing",
|
19
|
+
|
20
|
+
200 => "OK",
|
21
|
+
201 => "Created",
|
22
|
+
202 => "Accepted",
|
23
|
+
203 => "Non-Authoritative Information",
|
24
|
+
204 => "No Content",
|
25
|
+
205 => "Reset Content",
|
26
|
+
206 => "Partial Content",
|
27
|
+
207 => "Multi-Status",
|
28
|
+
226 => "IM Used",
|
29
|
+
|
30
|
+
300 => "Multiple Choices",
|
31
|
+
301 => "Moved Permanently",
|
32
|
+
302 => "Found",
|
33
|
+
303 => "See Other",
|
34
|
+
304 => "Not Modified",
|
35
|
+
305 => "Use Proxy",
|
36
|
+
307 => "Temporary Redirect",
|
37
|
+
|
38
|
+
400 => "Bad Request",
|
39
|
+
401 => "Unauthorized",
|
40
|
+
402 => "Payment Required",
|
41
|
+
403 => "Forbidden",
|
42
|
+
404 => "Not Found",
|
43
|
+
405 => "Method Not Allowed",
|
44
|
+
406 => "Not Acceptable",
|
45
|
+
407 => "Proxy Authentication Required",
|
46
|
+
408 => "Request Timeout",
|
47
|
+
409 => "Conflict",
|
48
|
+
410 => "Gone",
|
49
|
+
411 => "Length Required",
|
50
|
+
412 => "Precondition Failed",
|
51
|
+
413 => "Request Entity Too Large",
|
52
|
+
414 => "Request-URI Too Long",
|
53
|
+
415 => "Unsupported Media Type",
|
54
|
+
416 => "Requested Range Not Satisfiable",
|
55
|
+
417 => "Expectation Failed",
|
56
|
+
422 => "Unprocessable Entity",
|
57
|
+
423 => "Locked",
|
58
|
+
424 => "Failed Dependency",
|
59
|
+
426 => "Upgrade Required",
|
60
|
+
|
61
|
+
500 => "Internal Server Error",
|
62
|
+
501 => "Not Implemented",
|
63
|
+
502 => "Bad Gateway",
|
64
|
+
503 => "Service Unavailable",
|
65
|
+
504 => "Gateway Timeout",
|
66
|
+
505 => "HTTP Version Not Supported",
|
67
|
+
507 => "Insufficient Storage",
|
68
|
+
510 => "Not Extended"
|
69
|
+
}
|
70
|
+
|
71
|
+
def self.interpret_status(status)
|
72
|
+
"#{status} #{STATUS_CODES[status.to_i]}".strip
|
73
|
+
end
|
12
74
|
end
|
13
75
|
end
|
76
|
+
|
77
|
+
class UnauthorizedResponseError < ResponseError; end
|
14
78
|
|
15
79
|
include HTTMultiParty
|
16
80
|
|
@@ -101,12 +165,14 @@ private
|
|
101
165
|
def handle_response(refreshing_enabled=true, &block)
|
102
166
|
response = block.call
|
103
167
|
if response && !response.success?
|
104
|
-
if response.code == 401 && refreshing_enabled
|
168
|
+
if response.code == 401 && refreshing_enabled && options_for_refresh_flow_present?
|
105
169
|
exchange_token
|
106
170
|
# TODO it should return the original
|
107
171
|
handle_response(false, &block)
|
108
172
|
else
|
109
|
-
raise ResponseError.new(response), ResponseError.message(response)
|
173
|
+
#raise ResponseError.new(response), ResponseError.message(response)
|
174
|
+
raise ResponseError.new(response)
|
175
|
+
#raise ResponseError.from(response)
|
110
176
|
end
|
111
177
|
elsif response.is_a? Hash
|
112
178
|
HashResponseWrapper.new(response)
|
data/lib/soundcloud/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: soundcloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Johannes Wagener
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-08-08 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|