require 'jwt' require 'openssl' module Lhj class ConnectAPI def self.token key_file = File.binread(Lhj::AppleJWTConfig.private_key_file) key = OpenSSL::PKey::EC.new(key_file) expiration = Time.now + 500 header = { kid: Lhj::AppleJWTConfig.key_id } payload = { iss: Lhj::AppleJWTConfig.issuer_id, exp: expiration.to_i, aud: 'appstoreconnect-v1' } JWT.encode(payload, key, 'ES256', header) end def self.get(url) uri = URI(url) https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true request = Net::HTTP::Get.new(uri) jwt_token = token request['authorization'] = "Bearer #{jwt_token}" https.request(request) end end end