Client API

Mobile Applications API - no SDK required!

below the (ruby) code to be used by clients and their mobile applications in order to trigger advertising campaigns


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
@post_ws = "/api/v1/thunder"


def do_post
          req = Net::HTTP::Post.new(@post_ws, initheader = {'Content-Type' =>'application/json',"Accept" => "application/json"})
          req.basic_auth @user, @pass
          req.body = @payload
          response = Net::HTTP.new(@host, @port).start {|http| http.request(req) }
          puts "Response #{response.code} #{response.message}: "
          p "#{response.body}"
end

def get_dob
  t = Date.today
  t = t - rand(5400..12000)
  p ">>>>>: " + t.to_s
  t
end


######
#INFO - MINIMUM POSTING RULES
######
#'app' has be filled minimum with these keys:
#appid == the id of the app
#appsec == app secret
#device has to carry at least ONE key
#keys has to carry at least ONE appkey
######
#optional:
#mode = live|test # if ommitted, then live is assumed. spedicfy 'test' if desired

p "------------------------------------------------------------------------A1 - Location: Northvale, NJ 07647, USA"
#######EX1 - simple post
lat = 41.0008 
lng = -73.9506
devicedetails = { 'screenw' => 111+rand(0..150), 'screenh'=>222+rand(200..400) ,'model'=>"iphone#{rand(1..6)}"}
hscore = rand(1000..15000)
#p "hscore: #{hscore}"
@payload ={
    "device" => devicedetails,
    "keys" => {'level'=>rand(0..10), 'highscore'=>hscore, 'windpseed'=>3},
    "event" => {'lat'=>lat, 'lng'=>lng, 'dob'=>get_dob},
    "app" => {'appid'=> '1002' , 'appsec'=>'d455467196b84a71bfa118efa6f22695', 'appgid'=>999, 'mode'=>'test','channel'=>'email','email'=>"john_doe@gmail.com"}
}.to_json
#do_post
p "------------------------------------------------------------------------A2 END"


below the (html/js) code to be used by clients and their mobile applications in order to trigger advertising campaigns

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
<!DOCTYPE html>
            
<html>
<head>
    <meta name="viewport" content="width=device-width" />
        <script type="text/javascript" 
            src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js">
    </script>


        <script type="text/javascript">
        $(document).ready(function () {
                        
                var SendInfo= {name: "amit", id:1 }; 

                $('#ajaxBtn').click(function(){

                  var devicedetails  = { 'screenw': 111, 'screenh': 222  }; 
                  var keydetails  = { 'key1' : 999  }; 
                  var eventdetails  = { 'lat': 41.0008 , 'lng': -73.9506  }; 
     var appdetails  = {'appid': '1020' , 'appsec':'a14fe020665e4ccc837bfdb228e9c2311', 'appgid':999, 'mode':'test','channel':'email','email':"john_doe@gmail.com"};


                  var param = { 'device': devicedetails, 'keys' : keydetails, 'event' :eventdetails, 'app' : appdetails};

                  jQuery.ajax({
                    url: 'http://10.0.1.16:3002/api/v1/thunder',
                    contentType: "application/json; charset=utf-8",

                    type: "POST",
                    data: JSON.stringify(param),
                    dataType: "json",
                    beforeSend: function(x) {
                           // alert('sending now...');
                    },
                          error: function(xhr, textStatus, error){
                              console.log(xhr.statusText);
                              console.log(xhr.responseText);
                              var errors = $.parseJSON(xhr.responseText).thundermessage;
                              console.log(errors);
                              console.log(textStatus);
                              console.log(error);
                          },
                  success: function(result) {
                              alert(JSON.parse(result));
                  }
                        }); 


                });
    });
    </script>
</head>
<body>
        <h1> jQuery post() method demo 
        </h1>
        <input type="button" id="ajaxBtn" value="Send POST request" />
        <p>
        </p>
</body>
</html>