Class: IAPServer::StoreRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/iap/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(use_post: false, sandbox: false) ⇒ StoreRequest

Returns a new instance of StoreRequest.



6
7
8
9
# File 'lib/iap/request.rb', line 6

def initialize(use_post: false, sandbox: false)
	@use_post = use_post
	@sandbox = sandbox
end

Instance Method Details

#request(path, token, params = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/iap/request.rb', line 11

def request(path, token, params={})
	http = Net::HTTP.new('api.storekit.itunes.apple.com', 443)
       if @sandbox
           http = Net::HTTP.new('api.storekit-sandbox.itunes.apple.com', 443)
       end
	http.use_ssl = true

	headers = {   ##定义http请求头信息
	  'Authorization' => "Bearer #{token}",
	  'Content-Type' => 'application/json'
	}
	if @use_post
		resp = http.post(path, params.to_json, headers)
	else
		resp = http.get(path, headers)
	end
	resp
end