Class: Infrataster::Resources::HttpResource
- Inherits:
-
BaseResource
- Object
- BaseResource
- Infrataster::Resources::HttpResource
- Defined in:
- lib/infrataster/resources/http_resource.rb
Constant Summary collapse
- Error =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #basic_auth ⇒ Object
- #body ⇒ Object
- #faraday_middlewares ⇒ Object
- #follow_redirects? ⇒ Boolean
- #headers ⇒ Object
- #host_mapping ⇒ Object
- #inflate_gzip? ⇒ Boolean
-
#initialize(url_str, options = {}) ⇒ HttpResource
constructor
A new instance of HttpResource.
- #method ⇒ Object
- #params ⇒ Object
- #ssl_option ⇒ Object
- #to_s ⇒ Object
Methods inherited from BaseResource
Constructor Details
#initialize(url_str, options = {}) ⇒ HttpResource
Returns a new instance of HttpResource.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/infrataster/resources/http_resource.rb', line 11 def initialize(url_str, = {}) @options = {params: {}, method: :get, headers: {}}.merge() @uri = URI.parse(url_str) if @uri.scheme unless %w!http https!.include?(@uri.scheme) raise Error, "The provided url, '#{@uri}', is not http or https." end else @uri = URI::HTTP.build([@uri.userinfo, @uri.host, @uri.port, @uri.path, @uri.query, @uri.fragment]) end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/infrataster/resources/http_resource.rb', line 9 def @options end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
9 10 11 |
# File 'lib/infrataster/resources/http_resource.rb', line 9 def uri @uri end |
Instance Method Details
#basic_auth ⇒ Object
52 53 54 |
# File 'lib/infrataster/resources/http_resource.rb', line 52 def basic_auth @options[:basic_auth] end |
#body ⇒ Object
44 45 46 |
# File 'lib/infrataster/resources/http_resource.rb', line 44 def body @options[:body] end |
#faraday_middlewares ⇒ Object
64 65 66 67 68 |
# File 'lib/infrataster/resources/http_resource.rb', line 64 def faraday_middlewares (@options[:faraday_middlewares] || []).map do |m| Array(m) end end |
#follow_redirects? ⇒ Boolean
60 61 62 |
# File 'lib/infrataster/resources/http_resource.rb', line 60 def follow_redirects? !!@options[:follow_redirects] end |
#headers ⇒ Object
40 41 42 |
# File 'lib/infrataster/resources/http_resource.rb', line 40 def headers @options[:headers] end |
#host_mapping ⇒ Object
70 71 72 |
# File 'lib/infrataster/resources/http_resource.rb', line 70 def host_mapping @options[:host_mapping] || {} end |
#inflate_gzip? ⇒ Boolean
56 57 58 |
# File 'lib/infrataster/resources/http_resource.rb', line 56 def inflate_gzip? !!@options[:inflate_gzip] end |
#method ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/infrataster/resources/http_resource.rb', line 31 def method valid_methods = [:get, :head, :delete, :post, :put, :patch] unless valid_methods.include?(@options[:method]) raise Error, "#{@options[:method]} is not supported HTTP method." end @options[:method] end |
#params ⇒ Object
27 28 29 |
# File 'lib/infrataster/resources/http_resource.rb', line 27 def params @options[:params] end |
#ssl_option ⇒ Object
48 49 50 |
# File 'lib/infrataster/resources/http_resource.rb', line 48 def ssl_option @options[:ssl] end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/infrataster/resources/http_resource.rb', line 23 def to_s "http '#{@uri}' with #{@options}" end |