Translate from PHP to Xojo

Hi everybody,

I am trying to use a sms web service provided by Aruba, but as I have some difficulties, I opened a ticket, asking for explanations on the use of the service (I use HTTPSocket and API REST).
I was given, by way of explanation, this example of code in php: since I don’t know php, I have some difficulty in understanding the explanation. Is there any good soul that translates it into Xojo for me?

Here is the code:

$client = new http\Client;

$request = new http\Client\Request;
$request->setRequestUrl(‘https://adminsms.aruba/API/v1.0/REST/sms’);
$request->setRequestMethod(‘POST’);
$body = new http\Message\Body;
$body->append(’{
“returnCredits”: true,
“order_id”: “123456789bis”,
“recipient”: [
“+393290044092”
],
“message”: “Hello world!”,
“message_type”: “GP”,
“sender”: “Prova”,
“max_fragments”:“2”,
“truncate”: “true”
}’);
$request->setBody($body);
$request->setOptions(array());
$request->setHeaders(array(
‘user_key’ => ‘50007121’,
‘Session_key’ => ‘A2469E015F2714FF02DXXXXXXXXXXXX04605FB1631DD6E50232513408B8B7B9E66454CF’,
‘Content-Type’ => ‘application/json’
)
);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();

Thank you.

Nedi

As an experiment in a text editor, this should at least be close to getting you started. It may not work if you copy and paste blindly, tweak as necessary.

var tjsRecipient as new JSONItem
tjsRecipient.Add("+393290044092")

var tjsBody as new JSONItem
tjsBody.Value("returnCredits") = true
tjsBody.Value("order_id") = "123456789bis"
tjsBody.Value("recipient") = tjsRecipient
tjsBody.Value("message") = "Hello world!"
tjsBody.Value("message_type") = "GP"
tjsBody.Value("sender") = "Prova"
tjsBody.Value("max_fragments") = "2"
tjsBody.Value("truncate") = "true"

var toSocket as new URLConnection
toSocket.RequestHeader("user_key") = "50007121"
toSocket.RequestHeader("Session_key") = "A2469E015F2714FF02DXXXXXXXXXXXX04605FB1631DD6E50232513408B8B7B9E66454CF"

toSocket.SetRequestContent(tjsBody.ToString, "application/json")

var tsResponse as String
tsResponse = toSocket.SendSync("POST", "https://adminsms.aruba/API/v1.0/REST/sms", 5)

break
2 Likes

Thank you so much, Tim!
I forgot to say that I’m using Xojo 2019r1.1, but a few correction and the code is compiled.
I will try it as soon as possible.

Yeaaahh! Tim!! It works!!
Thank you so much!!!

1 Like

Hi Tim, I have another question for you.
In your example tjsRecipient is an array and when you add it to tjsBody you see it enclosed in square brackets [ ]
I have to do the same thing (a dozen of elements) that must be seen as an object.
In other words I have this situation:

Dim tjsDatiAlias As New JSONItem
tjsDatiAlias.Append(“alias=TamburHello”)
tjsDatiAlias.Append(“company-name=TamburHello”)
tjsDatiAlias.Append(“contact-name=Michele”)


Then I write

Dim tjsBody As New JSONItem
tjsBody.Value(“alias”) = tjsDatiAlias

but this means that tjsDatiAlias is an array, and I want it as object, enclose in curly brackets { }
How can I do this?

Thanks again.

Check out the difference between JSONItem as an Array and JSONItem as an Object in the documentation https://documentation.xojo.com/api/text/json/jsonitem.html

The key difference is how you interact with the item.

Thank you, Tim: I found it!

@Tim_Parnell My web app (CGI) is deployed to a shared Linux server, and I have found out that the URLConnection class on Linux requires Libsoup 2.4

Since I can’t install anything on Linux server, I need the .so file(s) to copy into my app Libs folder.

Can you help me?

Thanks a lot!

I normally deploy standalone to a Linux server I’m in control of. There I can just yum install libsoup. I’m not sure about bundling it into the Libs folder, but we can try.

What flavor Linux is your shared hosting? We can try to include a libsoup.so for your flavor and see what happens :man_shrugging:

If anyone’s done this, feel free to chime in :slight_smile:

My shared server Linux is CentOS 7 with Apache 2.4
When I wrote my first web app I had to copy the libunwind libraries to Libs folder by the copyfile build step and it worked. I hope that even this time it will be the same. But I can’t find the .so files, so I hope somebody can send it by mail (fregugliadotnediatgmaildotcom) or in any other way.