Module: Ikachan
- Defined in:
- lib/ikachan.rb,
lib/ikachan/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
- .join ⇒ Object
- .logger ⇒ Object
- .notice(message) ⇒ Object
- .request(path, params) ⇒ Object
- .uri_for(path = nil) ⇒ Object
Class Method Details
.join ⇒ Object
12 13 14 |
# File 'lib/ikachan.rb', line 12 def join request('/join', { 'channel' => @@channel }) end |
.logger ⇒ Object
43 44 45 |
# File 'lib/ikachan.rb', line 43 def logger @@_logger ||= Rails.logger end |
.notice(message) ⇒ Object
16 17 18 19 |
# File 'lib/ikachan.rb', line 16 def notice() join request('/notice', { 'channel' => @@channel, 'message' => }) end |
.request(path, params) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ikachan.rb', line 27 def request(path, params) begin uri = uri_for(path) http = Net::HTTP.new(uri.host, uri.port) http.open_timeout = http.read_timeout = 10 req = Net::HTTP::Post.new(uri.path) req.form_data = params http.request(req) rescue StandardError, TimeoutError => e logger.warn("#{e.class} #{e.}") end end |
.uri_for(path = nil) ⇒ Object
21 22 23 24 25 |
# File 'lib/ikachan.rb', line 21 def uri_for(path = nil) uri = URI.parse("#{@@url}/#{path}") uri.path = Pathname.new(uri.path).cleanpath.to_s uri end |