Raised This Month: $52 Target: $400
 13% 

REST in Pawn - Communicate with JSON REST APIs


Post New Thread Reply   
 
Thread Tools Display Modes
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Old 08-28-2018 , 05:00   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #51

New release:
  • Possible fix for the crashes (thanks Peace-Maker)
  • Added ConnectTimeout, FollowLocation and Timeout properties to HTTPClient (thanks CrazyHackGUT)
  • Added error message to HTTPRequestCallback
Download

Please let me know if you're still experiencing crashes, as I haven't been able to reproduce them myself.
__________________
DJ Tsunami is offline
CrazyHackGUT
AlliedModders Donor
Join Date: Feb 2016
Location: Izhevsk, Russia
Old 08-28-2018 , 15:10   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #52

Well, i'm pleased to that you are back to working out on extension. This is really nice extension.
I'm also glad that part of the functionality was taken from my fork.

Good job!
__________________
My english is very bad. I am live in Russia. Learning english language - very hard task for me...
CrazyHackGUT is offline
Send a message via ICQ to CrazyHackGUT Send a message via Skype™ to CrazyHackGUT
Mitchell
~lick~
Join Date: Mar 2010
Old 10-25-2018 , 18:45   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #53

i'm not sure why but now every site I try returns 404 status after the tf2 update today. Was working fine before the update.
Guess express was returning 404 for missing a slight slash '/'
__________________

Last edited by Mitchell; 10-25-2018 at 19:47.
Mitchell is offline
slekenda
Junior Member
Join Date: Aug 2017
Old 11-21-2018 , 03:31   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #54

Hello!

I'm trying to load JSON from a file, but I'm getting an error. Anyone any help?

PHP Code:

    char path
[PLATFORM_MAX_PATH 1];
    
BuildPath(Path_SMpathsizeof(path), "data/match.json");
    
PrintToServer("FileExists %d"FileExists(path));

    
JSONObject data JSONObject.FromFile(path); 
Error:
PHP Code:
"[RIPEXT] Invalid JSON in line -1, column -1: unable to 
open addons/sourcemod/data/match.json: No such file or directory" 
PrintToServer("FileExists %d", FileExists(path)); <- This prints "FileExists: 1"

File:
PHP Code:
{
    
"map""de_dust2",
    
"uuid""awawras4aw4as4sa"

EDIT: Apparently when I add the absolute path of the JSON file to "JSONObject data = JSONObject.FromFile(path);" it works but not with the Path_SM

Last edited by slekenda; 11-21-2018 at 05:42.
slekenda is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Old 11-22-2018 , 12:00   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #55

Thanks slekenda, this should be fixed in 1.0.6.
__________________
DJ Tsunami is offline
Nerus
Senior Member
Join Date: Aug 2010
Location: Poland
Old 12-09-2018 , 18:41   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #56

How to get nested array from json?

I need to get value of total_time_played

Result
PHP Code:
public void OnTodoReceived(HTTPResponse responseany value)
{
    if (
response.Status != HTTPStatus_OK)
    {
        
ThrowError("Failed to retrieve data from web!");
        return;
    }

    if (
response.Data == null
    {
        
ThrowError("Invalid JSON response!");
        return;
    }

    
// Indicate that the response is a JSON array
    
JSONObject json view_as<JSONObject>(response.Data);
    
JSONObject playerstats view_as<JSONObject>(json.Get("playerstats"));

    
delete json;

    
JSONArray stats view_as<JSONArray>(playerstats.Get("stats"));

    
delete playerstats;

    
JSONObject total_time_played view_as<JSONObject>(stats.Get(2));

    
delete stats;

    
char name[32];
    
total_time_played.GetString("name"name32);

    
int time = -1;

    if(!
StrEqual(name"total_time_played"false))
    {
        
delete total_time_played;

        
ThrowError("Invalid element '%s'"name);

        return;
    }

    
time total_time_played.GetInt("value");
    
    
delete total_time_played;

    if(
time 0)
    {
        
ThrowError("Time was not parsed from JSON file correctly!");

        return;
    }

    
PrintToServer("total_time_played = %d"time);

BTW, @DJ Tsunami can you add something like default value on get.
Attached Files
File Type: txt example.txt (13.6 KB, 61 views)

Last edited by Nerus; 12-10-2018 at 17:43. Reason: [SOLVED]
Nerus is offline
Matix8981
Junior Member
Join Date: Jun 2016
Old 03-24-2019 , 10:09   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #57

I created simple debugging script in PHP for check if rest in pawn sending POST data to target HTTP but can't see any POST data in apache logs i see request from my csgo server.

Debugging script:
PHP Code:
<?php
    file_put_contents
("file.json"json_encode([$_REQUEST$_GET$_POST]));
?>
Output JSON file:
Code:
[[],[],[]]
Plugin:
PHP Code:
void RequestChecker()
{
    
HTTPClient client = new HTTPClient("PAGE");
    
JSONObject post = new JSONObject();
    
post.SetString("type""csgo");
    
post.SetString("param1""string_first");
    
post.SetString("param2""string_second");
    
    
client.Post("index.php"postRequestCheckerCallback);
    
    
delete post;
}

void RequestCheckerCallback(HTTPResponse responseany value)
{
    if (
response.Status != HTTPStatus_Created)
    {
        
PrintToServer("Error 01");
        return;
    }
    if (
response.Data == null)
    {
        
PrintToServer("Error 02");
        return;
    }
    
    
JSONObject post view_as<JSONObject>(response.Data);
    
char param1[128];
    
post.GetString("param1"param1sizeof(param1));
    
    
PrintToServer("Param one %d"param1);

Matix8981 is offline
lugui
Senior Member
Join Date: Feb 2016
Location: Brasil
Old 09-19-2019 , 17:22   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #58

Hey. I'm trying to read a json object that has a unknown number of values with the function GetString(). As the .inc file says it is suposed to return false on invalid index but it is causing a exception intead.
__________________

Last edited by lugui; 09-19-2019 at 17:22.
lugui is offline
Min2liz
AlliedModders Donor
Join Date: Feb 2008
Location: Street
Old 10-29-2019 , 03:18   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #59

Maybe someone can compile this extension with github request included. Extension really great, but missing HasKey method.
Min2liz is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:08.


Powered by vBulletin®
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Theme made by Freecode