fanforce 0.3.12 → 0.3.13
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fanforce/main.rb +35 -35
- data/lib/fanforce/version.rb +1 -1
- metadata +1 -1
data/lib/fanforce/main.rb
CHANGED
@@ -8,7 +8,7 @@ class Fanforce
|
|
8
8
|
def initialize(arg={})
|
9
9
|
if arg.is_a?(Hash)
|
10
10
|
add_params(arg)
|
11
|
-
auth(params) if params.length > 0
|
11
|
+
auth(@params) if @params.length > 0
|
12
12
|
elsif arg.is_a?(String)
|
13
13
|
auth(arg)
|
14
14
|
end
|
@@ -18,76 +18,76 @@ class Fanforce
|
|
18
18
|
@params ||= {}
|
19
19
|
end
|
20
20
|
|
21
|
-
def add_params(
|
22
|
-
params.merge!(collect_known_params
|
21
|
+
def add_params(params_to_add)
|
22
|
+
params.merge!(collect_known_params params_to_add)
|
23
23
|
end
|
24
24
|
|
25
|
-
def get(path,
|
25
|
+
def get(path, req_params={})
|
26
26
|
url = complete_url(path)
|
27
|
-
|
28
|
-
RestClient.get(url, {:params =>
|
29
|
-
handle_response(response, request, url,
|
27
|
+
req_params = apply_auth(req_params)
|
28
|
+
RestClient.get(url, {:params => req_params, :accept => :json}) do |response, request, result, &block|
|
29
|
+
handle_response(response, request, url, req_params)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def get_url(path,
|
33
|
+
def get_url(path, req_params={})
|
34
34
|
url = complete_url(path)
|
35
|
-
|
36
|
-
"#{url}?#{to_query_string(
|
35
|
+
req_params = apply_auth(req_params)
|
36
|
+
"#{url}?#{to_query_string(req_params)}"
|
37
37
|
end
|
38
38
|
|
39
|
-
def post(path,
|
39
|
+
def post(path, req_params={})
|
40
40
|
url = complete_url(path)
|
41
|
-
|
42
|
-
RestClient.post(url,
|
43
|
-
handle_response(response, request, url,
|
41
|
+
req_params = apply_auth(req_params)
|
42
|
+
RestClient.post(url, req_params, {:accept => :json}) do |response, request, result, &block|
|
43
|
+
handle_response(response, request, url, req_params)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def put(path,
|
47
|
+
def put(path, req_params={})
|
48
48
|
url = complete_url(path)
|
49
|
-
|
50
|
-
RestClient.put(url,
|
51
|
-
handle_response(response, request, url,
|
49
|
+
req_params = apply_auth(req_params)
|
50
|
+
RestClient.put(url, req_params, {:accept => :json}) do |response, request, result, &block|
|
51
|
+
handle_response(response, request, url, req_params)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
def delete(path,
|
55
|
+
def delete(path, req_params={})
|
56
56
|
url = complete_url(path)
|
57
|
-
|
58
|
-
RestClient.delete(url, {:params =>
|
59
|
-
handle_response(response, request, url,
|
57
|
+
req_params = apply_auth(req_params)
|
58
|
+
RestClient.delete(url, {:params => req_params, :accept => :json}) do |response, request, result, &block|
|
59
|
+
handle_response(response, request, url, req_params)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
def identify(
|
64
|
-
post '/bie/identify',
|
63
|
+
def identify(req_params)
|
64
|
+
post '/bie/identify', req_params
|
65
65
|
{success: true}
|
66
66
|
end
|
67
67
|
|
68
|
-
def track(behavior_id,
|
69
|
-
post '/bie/track',
|
68
|
+
def track(behavior_id, req_params)
|
69
|
+
post '/bie/track', req_params.merge(behavior_id: behavior_id)
|
70
70
|
{success: true}
|
71
71
|
end
|
72
72
|
|
73
|
-
def handle_response(response, request, url,
|
73
|
+
def handle_response(response, request, url, req_params)
|
74
74
|
case response.code
|
75
75
|
when 200, 201
|
76
76
|
begin
|
77
77
|
response = decode_json(response)
|
78
78
|
rescue
|
79
|
-
raise UnknownError.new(response, request, url,
|
79
|
+
raise UnknownError.new(response, request, url, req_params)
|
80
80
|
end
|
81
81
|
when 400
|
82
|
-
raise BadRequestError.new(response, request, url,
|
82
|
+
raise BadRequestError.new(response, request, url, req_params)
|
83
83
|
when 403
|
84
|
-
raise ForbiddenError.new(response, request, url,
|
84
|
+
raise ForbiddenError.new(response, request, url, req_params)
|
85
85
|
when 404
|
86
|
-
raise NotFoundError.new(response, request, url,
|
86
|
+
raise NotFoundError.new(response, request, url, req_params)
|
87
87
|
when 422
|
88
|
-
raise UnprocessableEntityError.new(response, request, url,
|
88
|
+
raise UnprocessableEntityError.new(response, request, url, req_params)
|
89
89
|
else
|
90
|
-
raise UnknownError.new(response, request, url,
|
90
|
+
raise UnknownError.new(response, request, url, req_params)
|
91
91
|
end
|
92
92
|
response
|
93
93
|
end
|
@@ -105,8 +105,8 @@ class Fanforce
|
|
105
105
|
is_present?(@auth_hash) and is_present?(@auth_hash[:api_key]) and is_present?(@auth_hash[:fanforce_id])
|
106
106
|
end
|
107
107
|
|
108
|
-
def apply_auth(
|
109
|
-
|
108
|
+
def apply_auth(req_params)
|
109
|
+
req_params.merge(@auth_hash || {})
|
110
110
|
end
|
111
111
|
|
112
112
|
def complete_url(path)
|
data/lib/fanforce/version.rb
CHANGED