Class: Lhj::ConnectAPI
- Inherits:
-
Object
- Object
- Lhj::ConnectAPI
- Defined in:
- lib/lhj/helper/apple/apple_connect_api.rb
Class Method Summary collapse
Class Method Details
.get(url) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/lhj/helper/apple/apple_connect_api.rb', line 20 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 |
.post(url, data = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lhj/helper/apple/apple_connect_api.rb', line 33 def self.post(url, data = {}) uri = URI(url) https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true request = Net::HTTP::Post.new(uri) jwt_token = token request['authorization'] = "Bearer #{jwt_token}" request['Content-Type'] = 'application/json' request.body = JSON.dump(data) https.request(request) end |
.token ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lhj/helper/apple/apple_connect_api.rb', line 7 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 |