Integrate MyAllocator SDK with zf2 - php

I have been looking for the help to configure SDK for my Allocator.
I have already followed the steps given in the documentation.
https://github.com/MyAllocator/myallocator-ota-php
From the above documentation I have installed myAllocator using composer and I can see MyAllocator directory inside vendor.
Moving further I tried to copy the code from MaReceiver.php to my controller but this does not work out.
I have also checked how to configure the facebook sdk but this also does not help me to get a good idea to work out with MyAllocator SDK.
Again now tried to created a separate module in zf2 but I did not get any success.
It would be really helpful if anyone can guide me of give me any reference for SDK configuration in zend framework 2.

Please find the code
$request = $this->getRequest();
if ($request->isPost()) {
$data = $request->getPost('id');
$propertyId = $request->getPost('pand_id');
$password = $data['pand_password'];
$guid = empty($data['guid'])? '' : $data['guid'];
$verb = empty($data['verb'])? 'SetupProperty' : $data['verb'];
$booking_id = empty($data['booking_id'])? '' : $data['booking_id'];
$myallocator_pid = empty($data['pid'])? '' : $data['pid'];
// Instantiate backend interface that implements MaInboundInterface
$interface = new MaInboundInterfaceStub();
$interface->mya_property_id = $myallocator_pid;
$interface->ota_property_id = $propertyId;
$interface->verb = $verb;
$interface->guid = $guid;
$interface->shared_secret = 'xxxx';
$interface->ota_regcode = $password;
$interface->booking_id = $booking_id;
$interface->mya_property_id = 'M not in else ';
$router = new \MyAllocator\phpsdkota\src\Api\Inbound\MaRouter($interface);
// Process request
$post_body = file_get_contents('php://input');
$post_body = json_encode($interface);
$response = $router->processRequest($post_body);
header('Content-Type: application/json');
echo json_encode($response);exit;
}
With the above code am successfully able to call the function and work perfectly fine with the value on interface object
But now the problem is that am not able to get the request parameter from MyAllocator

Related

Url Routing not working Rest Api codeigniter

I am creating rest api using codeigniter and want to use function but after hit "http://localhost/codeigniter-rest-api-master/api/testing" showing me error
"404 page not found".Where i am wrong ?
here is my "application/config/routes.php"
$route['api'] = 'api/users/';
//api/users
$route['api/users'] = 'api/testing/testing/';
$route['api/users/format/json'] = 'api/testing/testing/format/json';
$route['api/users/format/xml'] = 'api/testing/testing/format/xml';
$route['api/users/format/html'] = 'api/testing/testing/format/html';
$route['api/users/format/csv'] = 'api/testing/users/format/csv';
$route['api/users.json'] = 'api/testing/testing.json';
$route['api/users.xml'] = 'api/testing/testing.xml';
$route['api/users.html'] = 'api/testing/testing.html';
$route['api/users.csv'] = 'api/testing/testing.csv';
here is my "application/controller/api/Users.php"
public function testing()
{
echo "hello world";
}
You don't have a api/testing route. Use something like this
$route['api/testing'] = 'api/users/testing/';
The route is folder/controller_class/function. I think you should read the guide.
This Answer would be helpful too.

How to avoid getting page number as a string using slim framework?

I am using slim 2.x framework for developing a web service. When I use 'get' request method its working fine but all the parameters getting are string. I want 'page' parameter as a numeric value. How to change this in slim. Below is my code.
$app->get('/listings','getListings');
/* Run the application */
$app->run();
function getListings(){
global $api_obj;//api obj
$response = array();//array
$app = \Slim\Slim::getInstance();
$req = $app->request;
$page = $req->get('page');
$response = $api_obj->api_Listings($page); //return
echoResponse(200, $response);
}
You can use a simple cast to get the integer from it:
$page = (int)$req->get('page');
//or
$page = intval($req->get('page'));
Ex: https://3v4l.org/cUqVA

Using an existing API with codeigniter 2

I dont ask many questions as I like to research for myself but this has me stumped.
I have an existing Codeigniter2(CI) application and am trying to integrate an existing API for a payment system (MangoPay). I have added it as a library and also preloaded it in autoload.php, it is being included with no errors.
My question is about setting up the class structure and addressing the class from my application.
Now, if you were to get this working from a plain old PHP file, the code would look like this (and btw it works on my machine with no issue from a plain php file)
<?php
require_once('../vendor/autoload.php');
$mangoPayApi = new MangoPay\MangoPayApi();
$mangoPayApi->Config->ClientId = 'user_id';
$mangoPayApi->Config->ClientPassword = 'password_here';
$mangoPayApi->Config->TemporaryFolder = 'c:\\wamp\\tmp/';
$User = new MangoPay\UserNatural();
$User->Email = "test_natural#testmangopay.com";
$User->FirstName = "Bob";
$User->LastName = "Briant";
$User->Birthday = 121271;
$User->Nationality = "FR";
$User->CountryOfResidence = "ZA";
$result = $mangoPayApi->Users->Create($User);
var_dump($result);
?>
So, I have created a new class in the libraries folder and if i was to var_dump() the contents of mangoPayApi as below, it throws all kinds of stuff which proves that it is working (ie no PHP errors).
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once('/vendor/autoload.php');
class MangoPayService {
private $mangoPayApi;
private $user;
public function __construct()
{
$this->mangoPayApi = new MangoPay\MangoPayApi();
$this->mangoPayApi->Config->ClientId = 'user_id_here';
$this->mangoPayApi->Config->ClientPassword = 'password_here';
$this->mangoPayApi->Config->TemporaryFolder = 'c:\\wamp\\tmp/';
//var_dump($mangoPayApi);
}
I thought I could just write a method in the class like this
function add_user(){
//CREATE NATURAL USER
$this->user = new user();
$user->Email = 'test_natural#testmangopay.com';
$user->FirstName = "John";
$user->LastName = "Smith";
$user->Birthday = 121271;
$user->Nationality = "FR";
$user->CountryOfResidence = "ZA";
$add_userResult = $this->mangoPayApi->Users->Create($user);
var_dump($add_userResult);
}
and acces it in my application like
<?php echo $this->mangopayservice->add_user() ?>
But i get errors Fatal error: Class 'user' not found in C:\wamp\www\mpapp\application\libraries\MangoPayService.php on line 25 (which is this->user = new user(); this line)
Can anyone explain how to correctly set up this scenario and how to integrate correctly with the API.
if I can get something to create a user simply when a page is opened, I think I can work it from there using the solution as a roadmap.
I will be writing all the integration code once I understand how to make this work.
Thank in advance
MangoPay requires a NaturalUser class. You try to instantiate a user class.
Simply replace your first line of the add_user function with :
$user = new MangoPay\UserNatural();

PHP MetaWeblog API server

Is there any PHP class or resource for using Metaweblog api ?
I want to add this api to my own cms (like wp) so that other application could easily post (or ...) throw it
Implementation of the MetaWeblog API http://www.xmlrpc.com/metaWeblogApi in PHP.
I looked to this script I linked for inspiration to develop the implementation I'm currently using. Feel free to use the example code below as an example of implementing the metaweblog API - but please consider using a modern XMLRPC library. I've included a link to a modified version of the original "xmlrpc.php" file that the example code requires.
Here's the xmlrpc library the example code utilizes: XMLRPC library modified to work with PHP 5.4 - originally written by Keith Devens.
Doing a quick package search on packagist also provides many great options that are much more forward thinking in terms of PHP standards. ZendFramework2 even includes a component you can use in your project with minimal dependencies (10 packages - not the entire framework). I would strongly recommend that this example code, be used as such, and any new development be done with a modern XMLRPC library.
Adding the example code here in case the first link dies:
<?php
/**
* Skeleton file for MetaWeblog API http://www.xmlrpc.com/metaWeblogApi in PHP
* Requires Keith Devens' XML-RPC Library http://keithdevens.com/software/xmlrpc and store it as xmlrpc.php in the same folder
* Written by Daniel Lorch, based heavily on Keith Deven's examples on the Blogger API.
*/
require_once dirname(__FILE__) . '/xmlrpc.php';
function metaWeblog_newPost($params) {
list($blogid, $username, $password, $struct, $publish) = $params;
$title = $struct['title'];
$description = $struct['description'];
// YOUR CODE:
$post_id = 0; // id of the post you just created
XMLRPC_response(XMLRPC_prepare((string)$post_id), WEBLOG_XMLRPC_USERAGENT);
}
function metaWeblog_editPost($params) {
list($postid, $username, $password, $struct, $publish) = $params;
// YOUR CODE:
$result = false; // whether or not the action succeeded
XMLRPC_response(XMLRPC_prepare((boolean)$result), WEBLOG_XMLRPC_USERAGENT);
}
function metaWeblog_getPost($params) {
list($postid, $username, $password) = $params;
$post = array();
// YOUR CODE:
$post['userId'] = '1';
$post['dateCreated'] = XMLRPC_convert_timestamp_to_iso8601(time());
$post['title'] = 'Replace me';
$post['content'] = 'Replace me, too';
$post['postid'] = '1';
XMLRPC_response(XMLRPC_prepare($post), WEBLOG_XMLRPC_USERAGENT);
}
function XMLRPC_method_not_found($methodName) {
XMLRPC_error("2", "The method you requested, '$methodName', was not found.", WEBLOG_XMLRPC_USERAGENT);
}
$xmlrpc_methods = array(
'metaWeblog.newPost' => 'metaWeblog_newPost',
'metaWeblog.editPost' => 'metaWeblog_editPost',
'metaWeblog.getPost' => 'metaWeblog_getPost'
);
$xmlrpc_request = XMLRPC_parse($HTTP_RAW_POST_DATA);
$methodName = XMLRPC_getMethodName($xmlrpc_request);
$params = XMLRPC_getParams($xmlrpc_request);
if(!isset($xmlrpc_methods[$methodName])) {
XMLRPC_method_not_found($methodName);
} else {
$xmlrpc_methods[$methodName]($params);
}

How do i remove a file from Rackspace's Cloudfiles with their api?

I was wondering how do i remove a file from Rackspace's Cloudfiles using their API?
Im using php.
Devan
Use the delete_object method of CF_Container.
Here is my code in C#. Just guessing the api is similar for php.
UserCredentials userCredientials = new UserCredentials("xxxxxx", "99999999999999");
cloudConnection = new Connection(userCredientials);
cloudConnection.DeleteStorageItem(ContainerName, fileName);
Make sure you set the container and define any sudo folder you are using.
$my_container = $this->conn->get_container($cf_container);
//delete file
$my_container->delete_object($cf_folder.$file_name);
I thought I would post here since there isn't an answer marked as the correct one, although I would accept Matthew Flaschen answer as the correct one. This would be all the code you need to delete your file
<?php
require '/path/to/php-cloudfiles/cloudfiles.php';
$username = 'my_username';
$api_key = 'my_api_key';
$full_object_name = 'this/is/the/full/file/name/in/the/container.png';
$auth = new CF_Authentication($username, $api_key);
$auth->ssl_use_cabundle();
$auth->authenticate();
if ( $auth->authenticated() )
{
$this->connection = new CF_Connection($auth);
// Get the container we want to use
$container = $this->connection->get_container($name);
$object = $container->delete_object($full_object_name);
echo 'object deleted';
}
else
{
throw new AuthenticationException("Authentication failed") ;
}
Note that the "$full_object_name" includes the "path" to the file in the container and the file name with no initial '/'. This is because containers use a Pseudo-Hierarchical folders/directories and what end ups being the name of the file in the container is the path + filename. for more info see http://docs.rackspace.com/files/api/v1/cf-devguide/content/Pseudo-Hierarchical_Folders_Directories-d1e1580.html
Use the method called DeleteObject from class CF_Container.
The method DeleteObject of CF_Container require only one string argument object_name.
This arguments should be the filename to be deleted.
See the example C# code bellow:
string username = "your-username";
string apiKey = "your-api-key";
CF_Client client = new CF_Client();
UserCredentials creds = new UserCredentials(username, apiKey);
Connection conn = new CF_Connection(creds, client);
conn.Authenticate();
var containerObj = new CF_Container(conn, client, container);
string file = "filename-to-delete";
containerObj.DeleteObject(file);
Note DonĀ“t use the DeleteObject from class *CF_Client*

Categories