class AccessWatch::Client
Constants
- CERTIFICATE_AUTHORITIES_PATH
- HTTPS
Attributes
api_endpoint[R]
api_key[R]
api_secret[R]
Public Class Methods
new(options)
click to toggle source
# File lib/access_watch.rb, line 10 def initialize(options) @api_secret = options[:api_secret] @api_key = options[:api_key] or raise "AccessWatch api_key is mandatory." @api_endpoint = options[:api_endpoint] || "https://access.watch/api/1.0/" end
Public Instance Methods
default_headers()
click to toggle source
# File lib/access_watch.rb, line 34 def default_headers { "Api-Key" => api_key, "Accept" => "application/json", "Content-Type" => "application/json", } end
post(path, data)
click to toggle source
# File lib/access_watch.rb, line 19 def post(path, data) uri = URI(api_endpoint + path) http = Net::HTTP.new(uri.host, uri.port) if uri.scheme == HTTPS http.verify_mode = OpenSSL::SSL::VERIFY_PEER http.ca_file = CERTIFICATE_AUTHORITIES_PATH http.use_ssl = true end post = Net::HTTP::Post.new(uri.path, default_headers) post.body = data.to_json http.request(post) end