mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-05 00:05:35 -04:00
add support for parallel json parsing
This commit is contained in:
parent
9b0d33fa85
commit
43884ec7d9
@ -23,9 +23,11 @@ experiments in a rest api lib
|
||||
resp = conn.get("/sake.json")
|
||||
resp.body # => %({"name":"Sake"})
|
||||
|
||||
# uses Typhoeus, performs requests in parallel
|
||||
# uses Typhoeus, Yajl parsing, performs requests in parallel
|
||||
conn = Faraday::Connection.new("http://sushi.com")
|
||||
conn.extend Faraday::Adapter::Typhoeus
|
||||
conn.response_class = Faraday::Response::DelayedYajlResponse
|
||||
resp1, resp2 = nil, nil
|
||||
conn.in_parallel do
|
||||
resp1 = conn.get("/sake.json")
|
||||
resp2 = conn.get("/unagi.json")
|
||||
@ -34,8 +36,8 @@ experiments in a rest api lib
|
||||
resp1.body # => nil
|
||||
resp2.body # => nil
|
||||
end
|
||||
resp1.body # => %({"name":"Sake"})
|
||||
resp2.body # => %({"name":"Unagi"})
|
||||
resp1.body # => {"name": "Sake"}
|
||||
resp2.body # => {"name": "Unagi"}
|
||||
|
||||
== Testing
|
||||
|
||||
|
10
lib/faraday/response/delayed_yajl_response.rb
Normal file
10
lib/faraday/response/delayed_yajl_response.rb
Normal file
@ -0,0 +1,10 @@
|
||||
require 'yajl'
|
||||
module Faraday
|
||||
class Response
|
||||
class DelayedYajlResponse < YajlResponse
|
||||
def content
|
||||
self
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -2,7 +2,8 @@ require 'yajl'
|
||||
module Faraday
|
||||
class Response
|
||||
class YajlResponse < Response
|
||||
attr_reader :content
|
||||
attr_reader :body
|
||||
alias content body
|
||||
|
||||
def initialize(headers = nil, body = nil)
|
||||
super
|
||||
@ -22,7 +23,7 @@ module Faraday
|
||||
end
|
||||
|
||||
def object_parsed(obj)
|
||||
@content = obj
|
||||
@body = obj
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user