Class: PM::Network

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-byte-panglem-beta/net.rb

Overview

网络请求

Class Method Summary collapse

Class Method Details

.post(url, body) ⇒ Object

post请求



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cocoapods-byte-panglem-beta/net.rb', line 13

def Network.post (url,body)
    # puts "start net request:#{body}"
    uri = URI.parse(url)
    https = Net::HTTP.new(uri.host,uri.port)
    https.use_ssl = true ## 正式时请打开
    request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
    # request["Cookie"]="__union_admin_sess_cookie=232301_noduimkpdwrbyrkr1qih; _ssa_userphone=; _ssa_username=zhangtianhao.1230"
    request.body = body.to_json
    if PM::Recorder.instance.is_debug
        puts "[cocoapods-byte-panglem-beta][debug] 网络请求信息: #{body.to_json}, url:#{url}"
    end
    res = https.request(request)

    if res.code == "200"
        data = JSON.parse(res.body)
        if PM::Recorder.instance.is_debug
            puts "[cocoapods-byte-panglem-beta][debug] 网络返回信息: #{data}"
        end
        return data
    else
        ## 网络请求异常的提示
        puts "[cocoapods-byte-panglem-beta][error] response code = #{res.code}, message = #{res.message}"
    end
    nil
end

.request_adapter(body, is_debug = false) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cocoapods-byte-panglem-beta/net.rb', line 39

def Network.request_adapter(body, is_debug = false)
    if is_debug
        url = URI.parse('http://localhost:8080/index.html')
        http = Net::HTTP.new(url.host, url.port)
        request = Net::HTTP::Get.new(url.path, initheader = {'Content-Type' =>'application/json'})
        response = http.request(request)
        if PM::Recorder.instance.is_debug
            puts "[cocoapods-byte-panglem-beta][debug] 网络请求信息: #{body.to_json}, url:#{url}"
        end
        data = JSON.parse(response.body)
        if  PM::Recorder.instance.is_debug
            puts "[cocoapods-byte-panglem-beta][debug] 网络返回信息: #{data}"
        end

        data
    else
        data = post("https://open-api.pangleglobal.com/union/media/open_api/auto_upgrade/config",body)
    end
end

.request_track(body, version_code) ⇒ Object



59
60
61
62
63
64
# File 'lib/cocoapods-byte-panglem-beta/net.rb', line 59

def Network.request_track(body, version_code)
    ##     https://api16-access-sg.pangle.io/api/ad/union/sdk/stats/batch/
    url = "https://api16-access-sg.pangle.io/api/ad/union/sdk/stats/batch/"+"?aid=5000546&version_code=#{version_code}&device_platform=iphone"
    data = post(url,body)
    data
end