rename Fetcher to HttpClient
don't use the same classname twice
This commit is contained in:
parent
d83b6f14f5
commit
176425f881
6 changed files with 16 additions and 16 deletions
|
|
@ -5,7 +5,7 @@ require "diaspora_federation/properties_dsl"
|
|||
require "diaspora_federation/entity"
|
||||
require "diaspora_federation/validators"
|
||||
|
||||
require "diaspora_federation/fetcher"
|
||||
require "diaspora_federation/http_client"
|
||||
|
||||
require "diaspora_federation/entities"
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ module DiasporaFederation
|
|||
|
||||
def get(url, http_fallback=false)
|
||||
logger.info "Fetching #{url} for #{diaspora_id}"
|
||||
response = Fetcher.get(url)
|
||||
response = HttpClient.get(url)
|
||||
raise "Failed to fetch #{url}: #{response.status}" unless response.success?
|
||||
response.body
|
||||
rescue => e
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ module DiasporaFederation
|
|||
# @param [String] guid guid of the entity to fetch
|
||||
def self.fetch_public(author, entity_type, guid)
|
||||
url = DiasporaFederation.callbacks.trigger(:fetch_person_url_to, author, "/fetch/#{entity_type}/#{guid}")
|
||||
response = DiasporaFederation::Fetcher.get(url)
|
||||
response = HttpClient.get(url)
|
||||
raise "Failed to fetch #{url}: #{response.status}" unless response.success?
|
||||
|
||||
magic_env = Nokogiri::XML::Document.parse(response.body).root
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ require "faraday"
|
|||
require "faraday_middleware/response/follow_redirects"
|
||||
|
||||
module DiasporaFederation
|
||||
# A wrapper for {https://github.com/lostisland/faraday Faraday} used for
|
||||
# fetching
|
||||
# A wrapper for {https://github.com/lostisland/faraday Faraday}.
|
||||
#
|
||||
# @see Discovery::Discovery
|
||||
class Fetcher
|
||||
# @see Federation::Fetcher
|
||||
class HttpClient
|
||||
# Perform a GET request
|
||||
#
|
||||
# @param [String] uri the URI
|
||||
|
|
@ -59,7 +59,7 @@ module DiasporaFederation
|
|||
end
|
||||
|
||||
it "raises NotFetchable if connection refused" do
|
||||
expect(DiasporaFederation::Fetcher).to receive(:get).with(
|
||||
expect(HttpClient).to receive(:get).with(
|
||||
"https://example.org/fetch/post/#{post.guid}"
|
||||
).and_raise(Faraday::ConnectionFailed, "Couldn't connect to server")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
module DiasporaFederation
|
||||
describe Fetcher do
|
||||
describe HttpClient do
|
||||
describe ".get" do
|
||||
it "gets the url" do
|
||||
stub_request(:get, "http://www.example.com")
|
||||
.to_return(body: "foobar", status: 200)
|
||||
|
||||
response = Fetcher.get("http://www.example.com")
|
||||
response = HttpClient.get("http://www.example.com")
|
||||
expect(response.body).to eq("foobar")
|
||||
end
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ module DiasporaFederation
|
|||
stub_request(:get, "http://www.example.com/redirected")
|
||||
.to_return(body: "foobar", status: 200)
|
||||
|
||||
response = Fetcher.get("http://www.example.com")
|
||||
response = HttpClient.get("http://www.example.com")
|
||||
expect(response.body).to eq("foobar")
|
||||
end
|
||||
|
||||
|
|
@ -24,32 +24,32 @@ module DiasporaFederation
|
|||
.to_return(status: 302, headers: {"Location" => "http://www.example.com"}).times(4)
|
||||
.to_return(status: 200)
|
||||
|
||||
Fetcher.get("http://www.example.com")
|
||||
HttpClient.get("http://www.example.com")
|
||||
end
|
||||
|
||||
it "follows redirects not more than 4 times" do
|
||||
stub_request(:get, "http://www.example.com")
|
||||
.to_return(status: 302, headers: {"Location" => "http://www.example.com"})
|
||||
|
||||
expect { Fetcher.get("http://www.example.com") }.to raise_error FaradayMiddleware::RedirectLimitReached
|
||||
expect { HttpClient.get("http://www.example.com") }.to raise_error FaradayMiddleware::RedirectLimitReached
|
||||
end
|
||||
|
||||
it "uses the gem name as User-Agent" do
|
||||
stub_request(:get, "http://www.example.com")
|
||||
.with(headers: {"User-Agent" => "DiasporaFederation/#{DiasporaFederation::VERSION}"})
|
||||
|
||||
Fetcher.get("http://www.example.com")
|
||||
HttpClient.get("http://www.example.com")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".connection" do
|
||||
it "returns a new connection every time" do
|
||||
expect(Fetcher.connection).to be_a Faraday::Connection
|
||||
expect(HttpClient.connection).to be_a Faraday::Connection
|
||||
end
|
||||
|
||||
it "returns a new connection every time" do
|
||||
connection1 = Fetcher.connection
|
||||
expect(Fetcher.connection).to_not be(connection1)
|
||||
connection1 = HttpClient.connection
|
||||
expect(HttpClient.connection).to_not be(connection1)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue