Sha256: d2077a462d04291bd37f8ebeaa6286eee141a23fceccf451beb49ca1f916afc9
Contents?: true
Size: 970 Bytes
Versions: 2
Compression:
Stored size: 970 Bytes
Contents
require 'httparty' module Messenger class Web def self.valid_url?(url) !!URI.parse(url) rescue URI::InvalidURIError false end # URL format: # http://example.com # https://user:pass@example.com # # The body of the message is posted as the body of the request, not the query. def self.send(url, body, options={}) raise URLError, "The URL provided is invalid" unless self.valid_url?(url) response = HTTParty.post(url, options.merge(:body => body)) Result.new(success?(response), response) end def self.obfuscate(url) raise URLError, "The URL provided is invalid" unless self.valid_url?(url) path = URI.parse(url) if path.password url.sub(/#{path.password}/, 'xxxx') else url end end private def self.success?(response) case response.code when 200, 201: true else false end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
messenger-0.2.0 | lib/messenger/web.rb |
messenger-0.1.1 | lib/messenger/web.rb |