I need to =connect to a server and post some data and receive a response. I have a =php template (below) as a guideline. Is this something I can replicate =with [tcpconnect] and [tcpsend]?
Any pointers =(not sure what the curl stuff does)?
Thanks,
Will
Here is the =php version:
<?php
class =LimeLM{
private static =$api_key;
private static =$request;
public static function =SetAPIKey($api_key)
{
=self::$api_key =3D $api_key;
=//NOTE: If you're using the self-hosted version of LimeLM (that =is,
=// LimeLM running on your own servers), =then replace the URL with your own.
// =Almost all users should leave this line =unchanged.
=self::$request =3D =curl_init('https://wyday.com/limelm/api/rest/');
=}
public static function =CleanUp()
{
// =close curl object
=curl_close(self::$request);
}
public =static function AddFeature($version_id, $name, $required, $type =3D =null)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.feature.add',
&=nbsp; 'version_id' =3D> =$version_id,
&=nbsp; 'name' =3D> $name,
&=nbsp; 'required' =3D> $required ? 'true' : ='false'
=);
if =($type)
&=nbsp; $post_data['type'] =3D =$type;
=return self::PostRequest($post_data);
=}
public static function =DeleteFeature($feature_id)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.feature.delete',
&=nbsp; 'feature_id' =3D> =$feature_id
=);
=return self::PostRequest($post_data);
=}
public static function =EditFeature($feature_id, $name =3D null, $required =3D =null)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.feature.edit',
&=nbsp; 'feature_id' =3D> =$feature_id
=);
if =($name)
&=nbsp; $post_data['name'] =3D =$name;
if =($required !=3D=3D null)
&=nbsp; $post_data['required'] =3D $required ? 'true' : ='false';
=return self::PostRequest($post_data);
=}
public static function =FindPKey($version_id, $email)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.pkey.find',
&=nbsp; 'version_id' =3D> =$version_id,
&=nbsp; 'email' =3D> $email
=);
=return self::PostRequest($post_data);
=}
public static function =GeneratePKeys($version_id, $num_keys =3D 1, $num_acts =3D 1, $email =3D =null, $feature_names =3D null, $feature_values =3D =null)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.pkey.generate',
&=nbsp; 'version_id' =3D> =$version_id,
&=nbsp; 'num_keys' =3D> =$num_keys,
&=nbsp; 'num_acts' =3D> =$num_acts
=);
if =($email)
&=nbsp; $post_data['email'] =3D =$email;
if =($feature_names)
={
&=nbsp; $post_data['feature_name'] =3D =$feature_names;
= $post_data['feature_value'] =3D =$feature_values;
=}
=return self::PostRequest($post_data);
=}
public static function =GetPKeyDetails($pkey_id)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.pkey.getDetails',
&=nbsp; 'pkey_id' =3D> =$pkey_id
=);
=return self::PostRequest($post_data);
=}
public static function =GetPKeyID($version_id, $pkey)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.pkey.getID',
&=nbsp; 'version_id' =3D> =$version_id,
&=nbsp; 'pkey' =3D> $pkey
=);
=return self::PostRequest($post_data);
=}
public static function =ManualActivation($xml_act_request)
={
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.pkey.manualActivation',
&=nbsp; 'act_req_xml' =3D> =$xml_act_request
=);
=return self::PostRequest($post_data);
=}
public static function =SetPKeyDetails($pkey_id, $num_acts =3D null, $email =3D null, =$feature_names =3D null, $feature_values =3D =null)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.pkey.setDetails',
&=nbsp; 'pkey_id' =3D> =$pkey_id
=);
if =($num_acts !=3D=3D null)
&=nbsp; $post_data['num_acts'] =3D =$num_acts;
if =($email !=3D=3D null)
&=nbsp; $post_data['email'] =3D =$email;
if =($feature_names !=3D=3D null)
={
&=nbsp; $post_data['feature_name'] =3D =$feature_names;
&=nbsp; $post_data['feature_value'] =3D =$feature_values;
=}
=return self::PostRequest($post_data);
=}
public static function =GenerateTrialExtension($version_id, $is_online, $length, $expires, =$customer_id =3D null, $max_uses =3D null)
={
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.trialExtension.generate',
&=nbsp; 'version_id' =3D> =$version_id,
&=nbsp; 'is_online' =3D> $is_online ? 'true' : ='false',
&=nbsp; 'length' =3D> =$length,
&=nbsp; 'expires' =3D> =$expires
=);
if =($is_online)
&=nbsp; $post_data['max_uses'] =3D =$max_uses;
if =($customer_id !=3D=3D null)
&=nbsp; $post_data['customer_id'] =3D =$customer_id;
=return self::PostRequest($post_data);
=}
public static function =TestEcho($params)
{
=$params['method'] =3D 'limelm.test.echo';
=return self::PostRequest($params);
=}
private static function =PostRequest($post_data)
{
if =(!self::$api_key)
&=nbsp; throw new Exception('You must specify your =LimeLM API key and set it using SetAPIKey().');
=$post_data['api_key'] =3D self::$api_key;
// =This section takes the input fields and converts them to the proper =format
// =for an http post. For example: ="method=3Dlimelm.pkey.find&version_id=3D100"
=$post_string =3D '';
=foreach ($post_data as $key =3D> $value)
={
&=nbsp; if (is_array($value))
&=nbsp; {
&=nbsp; foreach ($value as =$sub_value)
&=nbsp; ={
&=nbsp; &n=bsp; $post_string .=3D =$key.'[]=3D'.urlencode($sub_value).'&';
&=nbsp; =}
&=nbsp; }
&=nbsp; else
&=nbsp; $post_string .=3D =$key.'=3D'.urlencode($value).'&';
=}
=$post_string =3D rtrim($post_string, '& ');
=curl_setopt(self::$request, CURLOPT_HEADER, 0); // eliminate header info =from response
=curl_setopt(self::$request, CURLOPT_ENCODING, ""); // support =gzip & deflate responses if available
=curl_setopt(self::$request, CURLOPT_RETURNTRANSFER, 1); // Returns =response data instead of TRUE(1)
=curl_setopt(self::$request, CURLOPT_POSTFIELDS, $post_string); // use =HTTP POST to send form data
=curl_setopt(self::$request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment =this line if you get no gateway response.
=return curl_exec(self::$request); // execute curl post and store results =in $post_response
}
}
?>
--
William J. =Starck, DDS
Big Ideas Software, =LLC
1850 Keller Parkway Suite =102
Keller, TX 76248
817-431-9566
http://www.bigideasoft.com
|
I need to =connect to a server and post some data and receive a response. I have a =php template (below) as a guideline. Is this something I can replicate =with [tcpconnect] and [tcpsend]?
Any pointers =(not sure what the curl stuff does)?
Thanks,
Will
Here is the =php version:
<?php
class =LimeLM{
private static =$api_key;
private static =$request;
public static function =SetAPIKey($api_key)
{
=self::$api_key =3D $api_key;
=//NOTE: If you're using the self-hosted version of LimeLM (that =is,
=// LimeLM running on your own servers), =then replace the URL with your own.
// =Almost all users should leave this line =unchanged.
=self::$request =3D =curl_init('https://wyday.com/limelm/api/rest/');
=}
public static function =CleanUp()
{
// =close curl object
=curl_close(self::$request);
}
public =static function AddFeature($version_id, $name, $required, $type =3D =null)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.feature.add',
&=nbsp; 'version_id' =3D> =$version_id,
&=nbsp; 'name' =3D> $name,
&=nbsp; 'required' =3D> $required ? 'true' : ='false'
=);
if =($type)
&=nbsp; $post_data['type'] =3D =$type;
=return self::PostRequest($post_data);
=}
public static function =DeleteFeature($feature_id)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.feature.delete',
&=nbsp; 'feature_id' =3D> =$feature_id
=);
=return self::PostRequest($post_data);
=}
public static function =EditFeature($feature_id, $name =3D null, $required =3D =null)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.feature.edit',
&=nbsp; 'feature_id' =3D> =$feature_id
=);
if =($name)
&=nbsp; $post_data['name'] =3D =$name;
if =($required !=3D=3D null)
&=nbsp; $post_data['required'] =3D $required ? 'true' : ='false';
=return self::PostRequest($post_data);
=}
public static function =FindPKey($version_id, $email)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.pkey.find',
&=nbsp; 'version_id' =3D> =$version_id,
&=nbsp; 'email' =3D> $email
=);
=return self::PostRequest($post_data);
=}
public static function =GeneratePKeys($version_id, $num_keys =3D 1, $num_acts =3D 1, $email =3D =null, $feature_names =3D null, $feature_values =3D =null)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.pkey.generate',
&=nbsp; 'version_id' =3D> =$version_id,
&=nbsp; 'num_keys' =3D> =$num_keys,
&=nbsp; 'num_acts' =3D> =$num_acts
=);
if =($email)
&=nbsp; $post_data['email'] =3D =$email;
if =($feature_names)
={
&=nbsp; $post_data['feature_name'] =3D =$feature_names;
= $post_data['feature_value'] =3D =$feature_values;
=}
=return self::PostRequest($post_data);
=}
public static function =GetPKeyDetails($pkey_id)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.pkey.getDetails',
&=nbsp; 'pkey_id' =3D> =$pkey_id
=);
=return self::PostRequest($post_data);
=}
public static function =GetPKeyID($version_id, $pkey)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.pkey.getID',
&=nbsp; 'version_id' =3D> =$version_id,
&=nbsp; 'pkey' =3D> $pkey
=);
=return self::PostRequest($post_data);
=}
public static function =ManualActivation($xml_act_request)
={
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.pkey.manualActivation',
&=nbsp; 'act_req_xml' =3D> =$xml_act_request
=);
=return self::PostRequest($post_data);
=}
public static function =SetPKeyDetails($pkey_id, $num_acts =3D null, $email =3D null, =$feature_names =3D null, $feature_values =3D =null)
{
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.pkey.setDetails',
&=nbsp; 'pkey_id' =3D> =$pkey_id
=);
if =($num_acts !=3D=3D null)
&=nbsp; $post_data['num_acts'] =3D =$num_acts;
if =($email !=3D=3D null)
&=nbsp; $post_data['email'] =3D =$email;
if =($feature_names !=3D=3D null)
={
&=nbsp; $post_data['feature_name'] =3D =$feature_names;
&=nbsp; $post_data['feature_value'] =3D =$feature_values;
=}
=return self::PostRequest($post_data);
=}
public static function =GenerateTrialExtension($version_id, $is_online, $length, $expires, =$customer_id =3D null, $max_uses =3D null)
={
=$post_data =3D array(
&=nbsp; 'method' =3D> ='limelm.trialExtension.generate',
&=nbsp; 'version_id' =3D> =$version_id,
&=nbsp; 'is_online' =3D> $is_online ? 'true' : ='false',
&=nbsp; 'length' =3D> =$length,
&=nbsp; 'expires' =3D> =$expires
=);
if =($is_online)
&=nbsp; $post_data['max_uses'] =3D =$max_uses;
if =($customer_id !=3D=3D null)
&=nbsp; $post_data['customer_id'] =3D =$customer_id;
=return self::PostRequest($post_data);
=}
public static function =TestEcho($params)
{
=$params['method'] =3D 'limelm.test.echo';
=return self::PostRequest($params);
=}
private static function =PostRequest($post_data)
{
if =(!self::$api_key)
&=nbsp; throw new Exception('You must specify your =LimeLM API key and set it using SetAPIKey().');
=$post_data['api_key'] =3D self::$api_key;
// =This section takes the input fields and converts them to the proper =format
// =for an http post. For example: ="method=3Dlimelm.pkey.find&version_id=3D100"
=$post_string =3D '';
=foreach ($post_data as $key =3D> $value)
={
&=nbsp; if (is_array($value))
&=nbsp; {
&=nbsp; foreach ($value as =$sub_value)
&=nbsp; ={
&=nbsp; &n=bsp; $post_string .=3D =$key.'[]=3D'.urlencode($sub_value).'&';
&=nbsp; =}
&=nbsp; }
&=nbsp; else
&=nbsp; $post_string .=3D =$key.'=3D'.urlencode($value).'&';
=}
=$post_string =3D rtrim($post_string, '& ');
=curl_setopt(self::$request, CURLOPT_HEADER, 0); // eliminate header info =from response
=curl_setopt(self::$request, CURLOPT_ENCODING, ""); // support =gzip & deflate responses if available
=curl_setopt(self::$request, CURLOPT_RETURNTRANSFER, 1); // Returns =response data instead of TRUE(1)
=curl_setopt(self::$request, CURLOPT_POSTFIELDS, $post_string); // use =HTTP POST to send form data
=curl_setopt(self::$request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment =this line if you get no gateway response.
=return curl_exec(self::$request); // execute curl post and store results =in $post_response
}
}
?>
--
William J. =Starck, DDS
Big Ideas Software, =LLC
1850 Keller Parkway Suite =102
Keller, TX 76248
817-431-9566
http://www.bigideasoft.com
DOWNLOAD WEBDNA NOW!
The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...