pachube-stream 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pachube-stream/client.rb +15 -13
- data/lib/pachube-stream/version.rb +1 -1
- metadata +3 -3
@@ -17,18 +17,18 @@ module PachubeStream
|
|
17
17
|
# @todo refactor ugly as Sin
|
18
18
|
def process_data(response)
|
19
19
|
parsed_response = parse_response(response)
|
20
|
-
|
20
|
+
status_and_no_ok = parsed_response["status"] && parsed_response["status"] != 200
|
21
21
|
if request = @requests[parsed_response["token"]]
|
22
|
-
if
|
23
|
-
call_block_for_request(request, parsed_response)
|
24
|
-
else
|
22
|
+
if status_and_no_ok
|
25
23
|
call_error_for_request_block(request, parsed_response)
|
24
|
+
else
|
25
|
+
call_block_for_request(request, parsed_response)
|
26
26
|
end
|
27
27
|
else
|
28
|
-
if
|
29
|
-
@conn.on_response_block.call(parsed_response) if @conn.on_response_block
|
30
|
-
else
|
28
|
+
if status_and_no_ok
|
31
29
|
receive_error(parsed_response)
|
30
|
+
else
|
31
|
+
@conn.on_response_block.call(parsed_response) if @conn.on_response_block
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -62,13 +62,15 @@ module PachubeStream
|
|
62
62
|
# finds the correct callback based on the token which
|
63
63
|
# has the method call in its sig
|
64
64
|
def call_block_for_request(request, parsed_response)
|
65
|
-
|
66
|
-
when "subscribe" && !parsed_response["body"].nil?
|
67
|
-
request.on_datastream_block.call(parsed_response) if request.on_datastream_block
|
68
|
-
when "get" && !parsed_response["body"].nil?
|
69
|
-
request.on_get_block.call(parsed_response) if request.on_get_block
|
70
|
-
else
|
65
|
+
if parsed_response["body"].nil?
|
71
66
|
request.on_complete_block.call(parsed_response) if request.on_complete_block
|
67
|
+
else
|
68
|
+
case request.token.gsub(/:.*/, "")
|
69
|
+
when "subscribe"
|
70
|
+
request.on_datastream_block.call(parsed_response) if request.on_datastream_block
|
71
|
+
when "get"
|
72
|
+
request.on_get_block.call(parsed_response) if request.on_get_block
|
73
|
+
end
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Hookercookerman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-04-
|
17
|
+
date: 2011-04-24 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|