Class: Krakow::Producer::Http
- Inherits:
-
Object
- Object
- Krakow::Producer::Http
- Extended by:
- Utils::Lazy::ClassMethods
- Includes:
- Utils::Lazy, Utils::Lazy::InstanceMethods
- Defined in:
- lib/krakow/producer/http.rb
Overview
HTTP based producer
Defined Under Namespace
Classes: Response
Instance Attribute Summary (collapse)
-
- (Hash) arguments
included
from Utils::Lazy::InstanceMethods
readonly
Argument hash.
-
- (Object) uri
readonly
Returns the value of attribute uri.
Attributes (collapse)
-
- (Hash) config
The config attribute.
-
- (TrueClass, FalseClass) config?
Truthiness of the config attribute.
-
- (String) endpoint
The endpoint attribute.
-
- (TrueClass, FalseClass) endpoint?
Truthiness of the endpoint attribute.
-
- (Hash) ssl_context
The ssl_context attribute.
-
- (TrueClass, FalseClass) ssl_context?
Truthiness of the ssl_context attribute.
-
- (String) topic
The topic attribute.
-
- (TrueClass, FalseClass) topic?
Truthiness of the topic attribute.
Class Method Summary (collapse)
-
+ (nil) attribute(name, type, options = {})
extended
from Utils::Lazy::ClassMethods
Add new attributes to class.
-
+ (Array<Hash>) attributes(*args)
extended
from Utils::Lazy::ClassMethods
Return attributes.
-
+ (TrueClass) set_attributes(attrs)
extended
from Utils::Lazy::ClassMethods
Directly set attribute hash.
Instance Method Summary (collapse)
-
- (OpenSSL::SSL::SSLContext) build_ssl_context
Create a new SSL context.
-
- (Response) create_channel(chan)
Create channel on topic.
-
- (Response) create_topic
Create the topic.
-
- (Response) delete_channel(chan)
Delete channel on topic.
-
- (Response) delete_topic
Delete the topic.
-
- (Response) empty_channel(chan)
Remove all messages from given channel on topic.
-
- (Response) empty_topic
Remove all messages from topic.
-
- (Response) info
Server information.
-
- (Http) initialize(args = {})
constructor
A new instance of Http.
- - (String) inspect included from Utils::Lazy::InstanceMethods
-
- (Logger?) log(*args)
included
from Utils::Logging
Log message.
-
- (Response) pause_channel(chan)
Pause messages on given channel.
-
- (Response) ping
Ping the server.
-
- (Response) send_message(method, path, args = {})
Send a message via HTTP.
-
- (Response) stats(format = 'json')
Server stats.
- - (String) to_s included from Utils::Lazy::InstanceMethods
-
- (Response) unpause_channel(chan)
Resume messages on a given channel.
-
- (Response) write(*payload)
Send messages.
Constructor Details
- (Http) initialize(args = {})
Returns a new instance of Http
45 46 47 48 49 |
# File 'lib/krakow/producer/http.rb', line 45 def initialize(args={}) super build_ssl_context if ssl_context @uri = URI.parse(endpoint) end |
Instance Attribute Details
- (Hash) arguments (readonly) Originally defined in module Utils::Lazy::InstanceMethods
Returns argument hash
- (Object) uri (readonly)
Returns the value of attribute uri
29 30 31 |
# File 'lib/krakow/producer/http.rb', line 29 def uri @uri end |
Class Method Details
+ (nil) attribute(name, type, options = {}) Originally defined in module Utils::Lazy::ClassMethods
Add new attributes to class
+ (Array<Hash>) attributes(*args) Originally defined in module Utils::Lazy::ClassMethods
Return attributes
+ (TrueClass) set_attributes(attrs) Originally defined in module Utils::Lazy::ClassMethods
need deep dup here
Directly set attribute hash
Instance Method Details
- (OpenSSL::SSL::SSLContext) build_ssl_context
Create a new SSL context
54 55 56 57 58 59 60 |
# File 'lib/krakow/producer/http.rb', line 54 def build_ssl_context require 'openssl' context = OpenSSL::SSL::SSLContext.new context.cert = OpenSSL::X509::Certificate.new(File.open(ssl_context[:certificate])) context.key = OpenSSL::PKey::RSA.new(File.open(ssl_context[:key])) config[:ssl_context] = context end |
- (Hash) config
Returns the config attribute
40 |
# File 'lib/krakow/producer/http.rb', line 40 attribute :config, Hash, :default => ->{ Hash.new } |
- (TrueClass, FalseClass) config?
Returns truthiness of the config attribute
40 |
# File 'lib/krakow/producer/http.rb', line 40 attribute :config, Hash, :default => ->{ Hash.new } |
- (Response) create_channel(chan)
Create channel on topic
121 122 123 124 125 126 127 128 |
# File 'lib/krakow/producer/http.rb', line 121 def create_channel(chan) (:post, :create_channel, :params => { :topic => topic, :channel => chan } ) end |
- (Response) create_topic
Create the topic
102 103 104 105 106 |
# File 'lib/krakow/producer/http.rb', line 102 def create_topic (:post, :create_topic, :params => {:topic => topic} ) end |
- (Response) delete_channel(chan)
Delete channel on topic
134 135 136 137 138 139 140 141 |
# File 'lib/krakow/producer/http.rb', line 134 def delete_channel(chan) (:post, :delete_channel, :params => { :topic => topic, :channel => chan } ) end |
- (Response) delete_topic
Delete the topic
111 112 113 114 115 |
# File 'lib/krakow/producer/http.rb', line 111 def delete_topic (:post, :delete_topic, :params => {:topic => topic} ) end |
- (Response) empty_channel(chan)
Remove all messages from given channel on topic
156 157 158 159 160 161 162 163 |
# File 'lib/krakow/producer/http.rb', line 156 def empty_channel(chan) (:post, :empty_channel, :params => { :topic => topic, :channel => chan } ) end |
- (Response) empty_topic
Remove all messages from topic
146 147 148 149 150 |
# File 'lib/krakow/producer/http.rb', line 146 def empty_topic (:post, :empty_topic, :params => {:topic => topic} ) end |
- (String) endpoint
Returns the endpoint attribute
38 |
# File 'lib/krakow/producer/http.rb', line 38 attribute :endpoint, String, :required => true |
- (TrueClass, FalseClass) endpoint?
Returns truthiness of the endpoint attribute
38 |
# File 'lib/krakow/producer/http.rb', line 38 attribute :endpoint, String, :required => true |
- (Response) info
Server information
213 214 215 |
# File 'lib/krakow/producer/http.rb', line 213 def info (:get, :info) end |
- (String) inspect Originally defined in module Utils::Lazy::InstanceMethods
- (Logger?) log(*args) Originally defined in module Utils::Logging
Log message
- (Response) pause_channel(chan)
Pause messages on given channel
169 170 171 172 173 174 175 176 |
# File 'lib/krakow/producer/http.rb', line 169 def pause_channel(chan) (:post, :pause_channel, :params => { :topic => topic, :channel => chan } ) end |
- (Response) ping
Ping the server
206 207 208 |
# File 'lib/krakow/producer/http.rb', line 206 def ping (:get, :ping) end |
- (Response) send_message(method, path, args = {})
Send a message via HTTP
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/krakow/producer/http.rb', line 68 def (method, path, args={}) build = uri.dup build.path = "/#{path}" response = HTTP.send(method, build.to_s, args.merge(config)) begin response = MultiJson.load(response.body.to_s) rescue MultiJson::LoadError response = {'status_code' => response.code, 'status_txt' => response.body.to_s, 'data' => nil} end Response.new(response) end |
- (Hash) ssl_context
Returns the ssl_context attribute
41 |
# File 'lib/krakow/producer/http.rb', line 41 attribute :ssl_context, Hash |
- (TrueClass, FalseClass) ssl_context?
Returns truthiness of the ssl_context attribute
41 |
# File 'lib/krakow/producer/http.rb', line 41 attribute :ssl_context, Hash |
- (Response) stats(format = 'json')
Server stats
195 196 197 198 199 200 201 |
# File 'lib/krakow/producer/http.rb', line 195 def stats(format='json') (:get, :stats, :params => { :format => format } ) end |
- (String) to_s Originally defined in module Utils::Lazy::InstanceMethods
- (String) topic
Returns the topic attribute
39 |
# File 'lib/krakow/producer/http.rb', line 39 attribute :topic, String, :required => true |
- (TrueClass, FalseClass) topic?
Returns truthiness of the topic attribute
39 |
# File 'lib/krakow/producer/http.rb', line 39 attribute :topic, String, :required => true |
- (Response) unpause_channel(chan)
Resume messages on a given channel
182 183 184 185 186 187 188 189 |
# File 'lib/krakow/producer/http.rb', line 182 def unpause_channel(chan) (:post, :unpause_channel, :params => { :topic => topic, :channel => chan } ) end |
- (Response) write(*payload)
Send messages
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/krakow/producer/http.rb', line 84 def write(*payload) if(payload.size == 1) payload = payload.first (:post, :pub, :body => payload, :params => {:topic => topic} ) else (:post, :mpub, :body => payload.join("\n"), :params => {:topic => topic} ) end end |