class Ereignishorizont::Client
Constants
- VERSION
Attributes
api_token[R]
url[R]
Public Class Methods
configure() { |self| ... }
click to toggle source
# File lib/ereignishorizont/client.rb, line 56 def self.configure yield self if block_given? end
new(url = nil, api_token = nil)
click to toggle source
# File lib/ereignishorizont/client.rb, line 18 def initialize(url = nil, api_token = nil) @url = (url || self.class.url) @api_token = (api_token || self.class.api_token).to_s raise ArgumentError.new('No url provided.') unless @url end
Public Instance Methods
send!(title, content = nil)
click to toggle source
POSTs a string to the event_girl server.
# File lib/ereignishorizont/client.rb, line 30 def send!(title, content = nil) uri = URI.parse(url) # Auto-correct missing trailing slash path = uri.path == '' ? '/' : uri.path # This is all the post request stuff. req = Net::HTTP::Post.new(path) # The request format and content type is json req['Accept'] = "application/json" req['Content-Type'] = "application/json" # This takes the entered api token and title. This is what is sent. It is a HASH! req.body = '{"api_token":"' + api_token + '","incoming_event":{"title":"' + title.to_s + '","content":"' + content.to_s + '"}}' # The request is sent via HTTP to the host and port. You also get a response # ex: 201 (it worked) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = ssl? http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.request(req) end
send_event(*args)
click to toggle source
@deprecated Use {#send!} instead.
# File lib/ereignishorizont/client.rb, line 25 def send_event(*args) send!(*args) end
Private Instance Methods
ssl?()
click to toggle source
# File lib/ereignishorizont/client.rb, line 72 def ssl? !!/^https:/.match(url) end