Class: Dataset::Adaptors::Iqvoc::HttpAdaptor
- Inherits:
-
Object
- Object
- Dataset::Adaptors::Iqvoc::HttpAdaptor
- Defined in:
- app/models/dataset/adaptors/iqvoc/http_adaptor.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_TIMEOUT =
5.freeze
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #http_get(path, redirect_count = 0) ⇒ Object
-
#initialize(url) ⇒ HttpAdaptor
constructor
A new instance of HttpAdaptor.
Constructor Details
#initialize(url) ⇒ HttpAdaptor
Returns a new instance of HttpAdaptor.
7 8 9 10 11 12 13 |
# File 'app/models/dataset/adaptors/iqvoc/http_adaptor.rb', line 7 def initialize(url) @url = url @conn = Faraday.new(url: url, request: { timeout: DEFAULT_TIMEOUT }) do |conn| #conn.use Faraday::Response::Logger if Rails.env.development? conn.adapter Faraday.default_adapter end end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'app/models/dataset/adaptors/iqvoc/http_adaptor.rb', line 5 def url @url end |
Instance Method Details
#http_get(path, redirect_count = 0) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/dataset/adaptors/iqvoc/http_adaptor.rb', line 15 def http_get(path, redirect_count = 0) begin response = @conn.get(path) rescue Faraday::ConnectionFailed, Faraday::ResourceNotFound => e return failed_request(path) end if response.status == 404 return failed_request(path) end if response.status == 302 && redirect_count < 3 response = http_get(response.headers['location'], redirect_count + 1) end response end |