Beispiel #1
0
 public function testReset()
 {
     $consumer = new Consumer();
     $testParams = array('k' => 'ultra+marathon', 'v' => 'json', 'l' => 'Florida');
     $consumer->setUrl('http://uws.net');
     $consumer->setParams($testParams);
     $consumer->setOptions($testParams);
     $consumer->setCallType('post');
     $consumer->setResponseType('xml');
     $this->assertEquals($consumer->getUrl(), 'http://uws.net');
     $this->assertEquals($consumer->getParams(), $testParams);
     $this->assertEquals($consumer->getOptions(), $testParams);
     $this->assertEquals($consumer->getCallType(), 'post');
     $this->assertEquals($consumer->getResponseType(), 'xml');
     $consumer->reset();
     $this->assertNull($consumer->getUrl());
     $this->assertEmpty($consumer->getParams());
     $this->assertEmpty($consumer->getOptions());
     $this->assertNull($consumer->getCallType());
     $this->assertNull($consumer->getResponseType());
 }
 /**
  * Send a mail message
  *
  * @param \Zend\Mail\Message $message
  * @return array
  */
 public function send(Mail\Message $message)
 {
     $consumer = new Consumer();
     $consumer->setUrl($this->config['url']);
     $params = array('to' => urlencode($this->config['to']), 'subject' => urlencode($message->getSubject()), 'from' => urlencode($message->getFrom()->current()->getEmail()), 'fromname' => urlencode($message->getFrom()->current()->getName()), 'text' => urlencode($message->getBodyText()), 'api_user' => urlencode($this->config['user']), 'api_key' => urlencode($this->config['key']));
     $bcc = $message->getBcc()->current();
     if ($bcc) {
         $params['bcc'] = $bcc->getEmail();
     }
     $consumer->setParams($params);
     $consumer->setResponseType('json');
     $consumer->setCallType('get');
     return $consumer->doApiCall();
 }
Beispiel #3
0
<?php

require_once 'src/ApiConsumer/Consumer.php';
//require_once 'vendor/autoload.php'; // if using Composer autoloader and psr-0
use ApiConsumer\Consumer;
/**
 * The example below uses the API at Active.com to query "Running" activities in
 * Florida with a start date within the next month that meet the query string of
 * "ultra marathon". It will return a result set of 25 records as set.
 * 
 * @author Adam Culp http://www.geekyboy.com
 */
$apiConsumer = new Consumer();
$url = 'http://api.amp.active.com/search?';
$meta = 'meta:channel=Running+meta:startDate:daterange:today..' . date('Y-m-d', strtotime('next month'));
$params = array('k' => 'ultra+marathon', 'v' => 'json', 'l' => 'Florida', 'r' => '25', 's' => 'date_asc', 'api_key' => '{Add API Key Here}', 'm' => $meta);
$options = array(CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_PORT => 8080);
$apiConsumer->setParams($params);
$apiConsumer->setOptions($options);
$apiConsumer->setResponseType('json');
$apiConsumer->setCallType('get');
$apiConsumer->setUrl($url);
$result = $apiConsumer->doApiCall();
print_r($result);
?>
<!DOCTYPE html>
<html>
<head>
    <title>API Consumer Example</title>
</head>
<body>