Last active
May 26, 2016 21:44
-
-
Save JordiCorbilla/68f07883eb8d84dfc853c06b49af2e60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @Author: Jordi Corbilla | |
* (c) Copyright by Jordi Corbilla. | |
**/ | |
//Usage -> UpdateClient('1', 100, 100, 100, 100, '0.0'); | |
function UpdateClient(id: string; photos, views, likes, comments: integer; version: string): boolean; | |
var | |
IdHTTP: TIdHTTP; | |
IdIOHandler: TIdSSLIOHandlerSocketOpenSSL; | |
response : string; | |
JsonToSend: TStringStream; | |
begin | |
JsonToSend := TStringStream.Create('{"version":"'+version+'","Id":"'+id+'","photos":'+photos.ToString+',"views":'+views.ToString+',"likes":'+likes.ToString+',"comments":'+comments.ToString+'}'); | |
try | |
IdIOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil); | |
IdIOHandler.ReadTimeout := IdTimeoutInfinite; | |
IdIOHandler.ConnectTimeout := IdTimeoutInfinite; | |
IdHTTP := TIdHTTP.Create(nil); | |
try | |
IdHTTP.IOHandler := IdIOHandler; | |
IdHTTP.Request.Connection := 'Keep-Alive'; | |
IdIOHandler.SSLOptions.Method := sslvSSLv23; | |
IdHTTP.Request.CustomHeaders.Clear; | |
IdHTTP.Request.CustomHeaders.Values['X-Parse-Application-Id'] := 'thunderParse'; | |
IdHTTP.Request.ContentType := 'application/json'; | |
response := IdHTTP.Post('http://thunderParse.herokuapp.com/parse/classes/Instances', JsonToSend); | |
response := response.Replace(AnsiChar(#10), ''); | |
result := (response.Contains('createdAt')); | |
finally | |
IdHTTP.Free; | |
end; | |
finally | |
IdIOHandler.Free; | |
JsonToSend.Free; | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment