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
-
#get ⇒ String
Shorthand for
:methodand:uriusing HTTP GET. -
#method ⇒ Symbol
HTTP method:
:getor:post. -
#post ⇒ String
Shorthand for
:methodand:uriusing HTTP POST. -
#query ⇒ Hash
Hash of query options.
-
#uri ⇒ String
HTTP host and path to the data resource.
Attributes inherited from Stockboy::Provider
#data, #data_time, #errors, #logger
Instance Method Summary collapse
- #client {|HTTPI| ... } ⇒ Object
-
#initialize(opts = {}, &block) ⇒ HTTP
constructor
Initialize an HTTP provider.
Methods inherited from Stockboy::Provider
#clear, #inspect, logger, #reload, #valid?
Constructor Details
#initialize(opts = {}, &block) ⇒ HTTP
Initialize an HTTP provider
91 92 93 94 95 96 97 |
# File 'lib/stockboy/providers/http.rb', line 91 def initialize(opts={}, &block) super(opts, &block) self.uri = opts[:uri] self.method = opts[:method] || :get self.query = opts[:query] || Hash.new DSL.new(self).instance_eval(&block) if block_given? end |
Instance Attribute Details
#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 |
#method ⇒ Symbol
HTTP method: :get or :post
43 |
# File 'lib/stockboy/providers/http.rb', line 43 dsl_attr :method, attr_writer: false |
#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
70 |
# File 'lib/stockboy/providers/http.rb', line 70 dsl_attr :query |
#uri ⇒ String
HTTP host and path to the data resource
61 62 63 64 |
# File 'lib/stockboy/providers/http.rb', line 61 def uri return nil if @uri.nil? || @uri.empty? URI(@uri).tap { |u| u.query = URI.encode_www_form(@query) } end |
Instance Method Details
#client {|HTTPI| ... } ⇒ Object
99 100 101 102 |
# File 'lib/stockboy/providers/http.rb', line 99 def client return HTTPI unless block_given? yield HTTPI end |