Sha256: cc1e1debba2418ad534a78fe895e643e28e72ecd6ed000752ae9cc92e09f971d
Contents?: true
Size: 981 Bytes
Versions: 1
Compression:
Stored size: 981 Bytes
Contents
module PirschApi class Token def initialize(client_id, client_secret) @client_id = client_id @client_secret = client_secret end def request_url "https://api.pirsch.io/api/v1/token" end def request_body { "client_id" => @client_id, "client_secret" => @client_secret }.to_json end def parse_response(body) JSON.parse(body)['access_token'] end def run uri = URI.parse request_url http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE header = { 'Content-Type': 'text/json' } request = Net::HTTP::Post.new(uri.request_uri, header) request.body = request_body response = http.request(request) raise PirschApi::Error.new "Token request failed. (#{response.body})" unless response.code == "200" parse_response(response.body) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pirsch_api-0.0.1 | lib/pirsch_api/token.rb |