module Nagareboshi::Sender
Public Class Methods
publish(urls)
click to toggle source
# File lib/nagareboshi/sender.rb, line 5 def publish(urls) urls = [urls] if urls.is_a?(String) body = urls.map do |url| URI.encode_www_form({'hub.mode' => 'publish', 'hub.url' => url}) end.join('&') shooting_star(body) end
Private Class Methods
headers()
click to toggle source
# File lib/nagareboshi/sender.rb, line 29 def headers {"User-Agent" => "Nagareboshi Ruby Library v#{VERSION}", "Content-Type" => "application/x-www-form-urlencoded"} end
port()
click to toggle source
# File lib/nagareboshi/sender.rb, line 41 def port if port = Nagareboshi.configuration.port port else ssl? ? 443 : 80 end end
send?()
click to toggle source
# File lib/nagareboshi/sender.rb, line 33 def send? Nagareboshi.configuration.send == true end
shooting_star(body)
click to toggle source
# File lib/nagareboshi/sender.rb, line 14 def shooting_star(body) request = Net::HTTP::Post.new(URI(uri)) request.body = body headers.each { |k, v| request[k.to_s] = v.to_s} ☆(request) if send? end
ssl?()
click to toggle source
# File lib/nagareboshi/sender.rb, line 49 def ssl? Nagareboshi.configuration.use_ssl == true end
uri()
click to toggle source
# File lib/nagareboshi/sender.rb, line 37 def uri "#{ssl? ? 'https' : 'http'}://#{Nagareboshi.configuration.host}/#{Nagareboshi.configuration.path}" end
☆(request)
click to toggle source
# File lib/nagareboshi/sender.rb, line 21 def ☆(request) http = Net::HTTP.new(Nagareboshi.configuration.host, port) http.use_ssl = ssl? response = http.start do |http| http.request request end end