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
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.
6 7 8 9 10 11 12 |
# File 'app/models/dataset/adaptors/iqvoc/http_adaptor.rb', line 6 def initialize(url) @url = url @conn = Faraday.new(url: url) 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.
4 5 6 |
# File 'app/models/dataset/adaptors/iqvoc/http_adaptor.rb', line 4 def url @url end |
Instance Method Details
#http_get(path, redirect_count = 0) ⇒ Object
14 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 14 def http_get(path, redirect_count = 0) begin response = @conn.get(path) rescue Faraday::Error::ConnectionFailed, Faraday::Error::ResourceNotFound, Faraday::Error::TimeoutError => 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 |