forked from deniza/Ad-Mediator-for-Corona
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admediator_inneractive.lua
86 lines (64 loc) · 2.5 KB
/
admediator_inneractive.lua
1
2
3
4
5
6
7
8
9
10
11
12
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
------------------------------------------------------------
------------------------------------------------------------
-- Ad Mediator for Corona
--
-- Ad network mediation module for Ansca Corona
-- by Deniz Aydinoglu
--
-- he2apps.com
--
-- GitHub repository and documentation:
-- https://github.com/deniza/Ad-Mediator-for-Corona
------------------------------------------------------------
------------------------------------------------------------
local instance = {}
local adServerUrl = "http://m2m1.inner-active.com/simpleM2M/clientRequestAd"
local protocolVersion = "Sm2m-1.5.3"
local deviceId = "" --not used anymore
local userAgent = AdMediator.getUserAgentString()
local clientId = "0"
local clientKey = ""
local platformId
local metaTag = AdMediator.viewportMetaTagForPlatform()
local function adRequestListener(event)
local available = true
local i,f,statusOK, imageUrl, adUrl
if event.isError then
available = false
else
i,f,statusOK = string.find(event.response, '(<tns:Response Error="OK")')
clientId = event.response:match('<tns:Client Id="(.-)"')
if clientId == nil then
clientId = "0"
end
adUrl = event.response:match('<tns:URL>(.-)</tns:URL>')
imageUrl = event.response:match('<tns:Image>(.-)</tns:Image>')
if statusOK == nil or adUrl == nil or imageUrl == nil then
available = false
end
end
local htmlContent = ""
if available then
local banner = '<a href="'..adUrl..'"><img src="'..imageUrl..'"/></a>'
htmlContent = '<html><head>'..metaTag..'</head><body style="margin:0; padding:0;">' .. banner .. '</body></html>'
end
Runtime:dispatchEvent({name="adMediator_adResponse",available=available,htmlContent=htmlContent})
end
function instance:init(networkParams)
clientKey = networkParams.clientKey
if system.getInfo("platformName") == "Android" then
platformId = "559"
else
platformId = "642"
end
print("inneractive init:",clientKey)
end
function instance:requestAd()
local headers = {}
headers["User-Agent"] = userAgent
local params = {}
params.headers = headers
local uriParams = "aid=" .. clientKey .. "&v="..protocolVersion.."&po="..platformId.."&w=320&h=480&hid="..deviceId.."&cid=" .. clientId .. "&t=" .. os.time()
network.request(adServerUrl.."?"..uriParams,"GET",adRequestListener,params)
end
return instance