fanforce 0.5.9 → 0.5.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fanforce/errors.rb +3 -3
- data/lib/fanforce/main.rb +8 -8
- data/lib/fanforce/response.rb +7 -7
- data/lib/fanforce/version.rb +1 -1
- metadata +1 -1
data/lib/fanforce/errors.rb
CHANGED
@@ -4,7 +4,7 @@ class Fanforce
|
|
4
4
|
class Error < StandardError
|
5
5
|
attr_accessor :path, :query_params, :request, :response, :request_url, :http_status
|
6
6
|
|
7
|
-
def initialize(
|
7
|
+
def initialize(response, request, path, query_params)
|
8
8
|
@query_params = query_params
|
9
9
|
@path = path
|
10
10
|
@request = request
|
@@ -47,9 +47,9 @@ class Fanforce
|
|
47
47
|
|
48
48
|
class UnknownError < Error
|
49
49
|
def code; @http_status ||= 500; 500 end
|
50
|
-
def initialize(
|
50
|
+
def initialize(response, request, path, query_params)
|
51
51
|
@http_status = response.code
|
52
|
-
super(
|
52
|
+
super(response, request, path, query_params)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
data/lib/fanforce/main.rb
CHANGED
@@ -25,8 +25,8 @@ class Fanforce
|
|
25
25
|
|
26
26
|
def get(path, req_params={})
|
27
27
|
req_params = apply_auth(req_params)
|
28
|
-
RestClient.get(url(path, req_params), :accept => :json) do |
|
29
|
-
Fanforce::Response.new(
|
28
|
+
RestClient.get(url(path, req_params), :accept => :json) do |response, request, result, &block|
|
29
|
+
Fanforce::Response.new(response, request, complete_url(path), req_params)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -43,24 +43,24 @@ class Fanforce
|
|
43
43
|
def post(path, req_params={})
|
44
44
|
url = complete_url(path)
|
45
45
|
req_params = apply_auth(req_params)
|
46
|
-
RestClient.post(url, req_params.to_json, :content_type => :json, :accept => :json) do |
|
47
|
-
Fanforce::Response.new(
|
46
|
+
RestClient.post(url, req_params.to_json, :content_type => :json, :accept => :json) do |response, request, result, &block|
|
47
|
+
Fanforce::Response.new(response, request, url, req_params)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
def put(path, req_params={})
|
52
52
|
url = complete_url(path)
|
53
53
|
req_params = apply_auth(req_params)
|
54
|
-
RestClient.put(url, req_params.to_json, :content_type => :json, :accept => :json) do |
|
55
|
-
Fanforce::Response.new(
|
54
|
+
RestClient.put(url, req_params.to_json, :content_type => :json, :accept => :json) do |response, request, result, &block|
|
55
|
+
Fanforce::Response.new(response, request, url, req_params)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
def delete(path, req_params={})
|
60
60
|
url = complete_url(path)
|
61
61
|
req_params = apply_auth(req_params)
|
62
|
-
RestClient.delete(url, {:params => to_query_string(req_params), :accept => :json}) do |
|
63
|
-
Fanforce::Response.new(
|
62
|
+
RestClient.delete(url, {:params => to_query_string(req_params), :accept => :json}) do |response, request, result, &block|
|
63
|
+
Fanforce::Response.new(response, request, url, req_params)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
data/lib/fanforce/response.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class Fanforce::Response
|
2
2
|
attr_reader :curl_command, :request_url, :response_body, :response_json
|
3
3
|
|
4
|
-
def initialize(
|
4
|
+
def initialize(response, request, url, req_params)
|
5
5
|
case response.code
|
6
6
|
when 200, 201
|
7
7
|
begin
|
@@ -30,17 +30,17 @@ class Fanforce::Response
|
|
30
30
|
raise
|
31
31
|
end
|
32
32
|
when 400
|
33
|
-
raise Fanforce::BadRequestError.new(
|
33
|
+
raise Fanforce::BadRequestError.new(response, request, url, req_params)
|
34
34
|
when 401
|
35
|
-
raise Fanforce::Unauthorized.new(
|
35
|
+
raise Fanforce::Unauthorized.new(response, request, url, req_params)
|
36
36
|
when 403
|
37
|
-
raise Fanforce::ForbiddenError.new(
|
37
|
+
raise Fanforce::ForbiddenError.new(response, request, url, req_params)
|
38
38
|
when 404
|
39
|
-
raise Fanforce::NotFoundError.new(
|
39
|
+
raise Fanforce::NotFoundError.new(response, request, url, req_params)
|
40
40
|
when 422
|
41
|
-
raise Fanforce::UnprocessableEntityError.new(
|
41
|
+
raise Fanforce::UnprocessableEntityError.new(response, request, url, req_params)
|
42
42
|
else
|
43
|
-
raise Fanforce::UnknownError.new(
|
43
|
+
raise Fanforce::UnknownError.new(response, request, url, req_params)
|
44
44
|
end
|
45
45
|
response
|
46
46
|
end
|
data/lib/fanforce/version.rb
CHANGED