Class: Stockboy::Providers::HTTP
- Inherits:
-
Stockboy::Provider
- Object
- Stockboy::Provider
- Stockboy::Providers::HTTP
- Defined in:
- lib/stockboy/providers/http.rb
Overview
Fetches data from an HTTP endpoint
Job template DSL
provider :http do
get "http://example.com/api/things"
end
Options collapse
-
#body ⇒ String
HTTP request body.
-
#get ⇒ String
Shorthand for
:method
and:uri
using HTTP GET. -
#headers ⇒ String
HTTP request headers.
-
#method ⇒ Symbol
HTTP method:
:get
or:post
. -
#password ⇒ String
Password for basic auth connection credentials.
-
#post ⇒ String
Shorthand for
:method
and:uri
using HTTP POST. -
#query ⇒ Hash
Hash of query options.
-
#uri ⇒ String
HTTP host and path to the data resource.
-
#username ⇒ String
User name for basic auth connection credentials.
Attributes inherited from Stockboy::Provider
#data, #data_size, #data_time, #errors, #logger
Instance Method Summary collapse
- #client ⇒ Object
-
#initialize(opts = {}, &block) ⇒ HTTP
constructor
Initialize an HTTP provider.
Methods inherited from Stockboy::Provider
#clear, #data?, #inspect, #reload, #valid?
Constructor Details
#initialize(opts = {}, &block) ⇒ HTTP
Initialize an HTTP provider
127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/stockboy/providers/http.rb', line 127 def initialize(opts={}, &block) super(opts, &block) self.uri = opts[:uri] self.method = opts[:method] || :get self.query = opts[:query] || Hash.new self.headers = opts[:headers] || Hash.new self.body = opts[:body] self.username = opts[:username] self.password = opts[:password] DSL.new(self).instance_eval(&block) if block_given? end |
Instance Attribute Details
#body ⇒ String
HTTP request body
61 |
# File 'lib/stockboy/providers/http.rb', line 61 dsl_attr :body |
#get ⇒ String
Shorthand for :method
and :uri
using HTTP GET
25 |
# File 'lib/stockboy/providers/http.rb', line 25 dsl_attr :get, attr_writer: false |
#headers ⇒ String
HTTP request headers
52 |
# File 'lib/stockboy/providers/http.rb', line 52 dsl_attr :headers |
#method ⇒ Symbol
HTTP method: :get
or :post
43 |
# File 'lib/stockboy/providers/http.rb', line 43 dsl_attr :method, attr_writer: false |
#password ⇒ String
Password for basic auth connection credentials
79 |
# File 'lib/stockboy/providers/http.rb', line 79 dsl_attr :password |
#post ⇒ String
Shorthand for :method
and :uri
using HTTP POST
34 |
# File 'lib/stockboy/providers/http.rb', line 34 dsl_attr :post, attr_writer: false |
#query ⇒ Hash
Hash of query options
106 |
# File 'lib/stockboy/providers/http.rb', line 106 dsl_attr :query |
#uri ⇒ String
HTTP host and path to the data resource
97 98 99 100 |
# File 'lib/stockboy/providers/http.rb', line 97 def uri return nil if @uri.nil? || @uri.to_s.empty? URI(@uri).tap { |u| u.query = URI.encode_www_form(@query) if @query } end |
#username ⇒ String
User name for basic auth connection credentials
70 |
# File 'lib/stockboy/providers/http.rb', line 70 dsl_attr :username |
Instance Method Details
#client ⇒ Object
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/stockboy/providers/http.rb', line 139 def client orig_logger, HTTPI.logger = HTTPI.logger, logger req = HTTPI::Request.new.tap { |c| c.url = uri } req.auth.basic(username, password) if username && password req.headers = headers req.body = body block_given? ? yield(req) : req ensure HTTPI.logger = orig_logger end |