Example #1
0
 function testValidReturn()
 {
     if ($this->cash_test_url) {
         $return = json_decode(CASHSystem::getURLContents(CASH_API_URL . 'verbose/element/getmarkup/100/status_uid/whatever', false, true));
         // test valid JSON:
         $this->assertNotNull($return);
         // make sure all the bits and pieces are in place
         $this->assertTrue(isset($return->status_code));
         $this->assertTrue(isset($return->status_uid));
         $this->assertTrue(isset($return->status_message));
         $this->assertTrue(isset($return->contextual_message));
         $this->assertTrue(isset($return->request_type));
         $this->assertTrue(isset($return->action));
         $this->assertTrue(isset($return->payload));
         $this->assertTrue(isset($return->api_version));
         $this->assertTrue(isset($return->timestamp));
         // test types for the standardized bits, ignore the variable pieces
         $this->assertTrue(is_int($return->status_code));
         $this->assertTrue(is_string($return->status_uid));
         $this->assertTrue(is_string($return->status_message));
         $this->assertTrue(is_string($return->contextual_message));
         $this->assertTrue(is_string($return->request_type));
         $this->assertTrue(is_string($return->action));
         $this->assertTrue(is_int($return->api_version));
         $this->assertTrue(is_int($return->timestamp));
     }
 }
Example #2
0
 function testURLsAndContent()
 {
     if ($this->s3_key) {
         $s3 = new S3Seed($this->cash_user_id, $this->s3_connection_id);
         // check for the timestamp in the public link for the public test file
         $test_content = CASHSystem::getURLContents('http://' . $this->s3_bucket . '.s3.amazonaws.com/' . 'test' . $this->timestamp);
         $this->assertPattern('/' . $this->timestamp . '/', $test_content);
         // and in the private link generated for the private test file
         $test_content = CASHSystem::getURLContents($s3->getExpiryURL('test_private' . $this->timestamp, 20));
         $this->assertPattern('/' . $this->timestamp . '/', $test_content);
         // now test headers -- relies on fopen wrappers
         if (ini_get('allow_url_fopen')) {
             // first defaults, both present:
             file_get_contents($s3->getExpiryURL('test_private' . $this->timestamp, 20));
             $this->assertTrue(array_search('Content-Disposition: attachment', $http_response_header));
             $this->assertTrue(array_search('Cache-Control: no-cache', $http_response_header));
             // no-cache only:
             file_get_contents($s3->getExpiryURL('test_private' . $this->timestamp, 20, false, true));
             $this->assertFalse(array_search('Content-Disposition: attachment', $http_response_header));
             $this->assertTrue(array_search('Cache-Control: no-cache', $http_response_header));
             // attachment only:
             file_get_contents($s3->getExpiryURL('test_private' . $this->timestamp, 20, true, false));
             $this->assertTrue(array_search('Content-Disposition: attachment', $http_response_header));
             $this->assertFalse(array_search('Cache-Control: no-cache', $http_response_header));
         }
     }
 }
Example #3
0
 public function getUser($username, $extended_detail = false)
 {
     $username = str_replace('@', '', $username);
     $endoint_url = 'https://api.twitter.com/1/users/show.json?screen_name=' . $username;
     $user_data = json_decode(CASHSystem::getURLContents($endoint_url), true);
     if ($user_data && !$extended_detail) {
         // let's trim out some of the things we don't need
         unset($user_data['status']);
         unset($user_data['follow_request_sent']);
         unset($user_data['profile_background_color']);
         unset($user_data['profile_background_tile']);
         unset($user_data['profile_sidebar_fill_color']);
         unset($user_data['notifications']);
         unset($user_data['default_profile_image']);
         unset($user_data['show_all_inline_media']);
         unset($user_data['profile_sidebar_border_color']);
         unset($user_data['following']);
         unset($user_data['is_translator']);
         unset($user_data['profile_use_background_image']);
         unset($user_data['profile_text_color']);
         unset($user_data['profile_background_image_url']);
         unset($user_data['profile_link_color']);
     }
     return $user_data;
 }
Example #4
0
 protected function postToPaypal($method_name, $nvp_parameters)
 {
     // Set the API operation, version, and API signature in the request.
     $request_parameters = array('METHOD' => $method_name, 'VERSION' => $this->api_version, 'PWD' => $this->api_password, 'USER' => $this->api_username, 'SIGNATURE' => $this->api_signature);
     $request_parameters = array_merge($request_parameters, $nvp_parameters);
     // Get response from the server.
     $http_response = CASHSystem::getURLContents($this->api_endpoint, $request_parameters, true);
     if ($http_response) {
         // Extract the response details.
         $http_response = explode("&", $http_response);
         $parsed_response = array();
         foreach ($http_response as $i => $value) {
             $tmpAr = explode("=", $value);
             if (sizeof($tmpAr) > 1) {
                 $parsed_response[$tmpAr[0]] = urldecode($tmpAr[1]);
             }
         }
         if (0 == sizeof($parsed_response) || !array_key_exists('ACK', $parsed_response)) {
             $this->setErrorMessage("Invalid HTTP Response for POST (" . $nvpreq . ") to " . $this->api_endpoint);
             return false;
         }
         if ("SUCCESS" == strtoupper($parsed_response["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($parsed_response["ACK"])) {
             return $parsed_response;
         } else {
             $this->setErrorMessage(print_r($parsed_response, true));
             return false;
         }
     } else {
         $this->setErrorMessage('could not reach Paypal servers');
         return false;
     }
 }
Example #5
0
 function test_getURLContents()
 {
     if (getTestEnv('CASHMUSIC_TEST_URL') == 'http://dev.cashmusic.org:8080' && !strpos(CASH_API_URL, 'localhost')) {
         // Test URL set to remote, so skip the local test
         echo "Testing getURLContents with cashmusic.org because of remote test URL.\n";
         $return = CASHSystem::getURLContents('http://cashmusic.org/');
         $this->assertPattern('/cash/', $return);
         // use google
     } else {
         $return = CASHSystem::getURLContents(CASH_API_URL);
         $this->assertPattern('/"greeting":"hi."/', $return);
         // using local API URL as firewalls could mess with an external test
     }
 }
Example #6
0
 /**
  * Returns the (best guess at) APE URL
  * fix that typo. I refuse. It's too funny.
  *
  * @return array
  */
 public static function getAPIDetails()
 {
     if (!defined('STDIN')) {
         // check for command line
         $api_url = 'http' . (empty($_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] != 443 ? '' : 's') . '://' . $_SERVER['HTTP_HOST'] . str_replace('/admin', '/api', ADMIN_WWW_BASE_PATH);
         $api_response = json_decode(CASHSystem::getURLContents($api_url));
         if ($api_response->greeting == 'hi.') {
             return array('api_url' => $api_url, 'api_version' => $api_response->api_version);
         } else {
             return false;
         }
         return $api_url;
     } else {
         return false;
     }
 }
Example #7
0
 /**
  * Takes a cache name, data name, and URL — first looks for viable cache data, 
  * then 
  *
  * @return int (remaining time in seconds) or false
  */
 protected function getCachedURL($cache_name, $data_name, $data_url, $format = 'json', $decode = true)
 {
     $url_contents = $this->getCacheData($cache_name, $data_name, false, $decode);
     if (!$url_contents) {
         $url_contents = CASHSystem::getURLContents($data_url);
         if (!$url_contents) {
             $url_contents = $this->getCacheData($cache_name, $data_name, true, $decode);
         } else {
             if ($format == 'json') {
                 $url_contents = json_decode($url_contents);
             }
             $this->setCacheData($cache_name, $data_name, $url_contents);
         }
     }
     return $url_contents;
 }
Example #8
0
 function testProcessWebhooks()
 {
     $time = time();
     // only run if key / list have been set properly
     if ($this->api_key && $this->api_list_id) {
         $data_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'getapicredentials', 'user_id' => $this->cash_user_id));
         $api_credentials = $data_request->response['payload'];
         // valid API url, but likely localhost
         $webhook_api_url = CASH_API_URL . '/verbose/people/processwebhook/origin/com.mailchimp/list_id/' . $this->test_list_id . '/api_key/' . $api_credentials['api_key'];
         // make sure we're rejecting bad keys
         $bad_webhook_api_url = CASH_API_URL . '/verbose/people/processwebhook/origin/com.mailchimp/list_id/' . $this->test_list_id . '/api_key/incorrect';
         $response = json_decode(CASHSystem::getURLContents($bad_webhook_api_url, array('sample' => 'data'), true));
         // TODO: this is currently returning 400, we need to get that to 403, but we'll test for not-200
         //       which at least proves we're not accepting bad keys
         $this->assertNotEqual($response->status_code, 200);
         $test_address = 'dev+shouldnotsubscribe' . $time . '@cashmusic.org';
         $add_post_data = array("type" => "subscribe", "fired_at" => "2009-03-26 21:35:57", "data" => array("id" => "8a25ff1d98", "list_id" => "a6b5da1054", "email" => $test_address, "email_type" => "html", "merges" => null, "ip_opt" => "10.20.10.30", "ip_signup" => "10.20.10.30"));
         CASHSystem::getURLContents($webhook_api_url, $add_post_data, true);
         $list_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'getaddresslistinfo', 'list_id' => $this->test_list_id, 'address' => $test_address));
         // make sure that the address has been added to the local list
         $this->assertTrue($list_request->response['payload']);
         $remove_post_data = array("type" => "unsubscribe", "fired_at" => "2009-03-26 21:36:52", "data" => array("id" => "8a25ff1d98", "action" => "unsub", "reason" => "manual", "list_id" => "a6b5da1054", "email" => $test_address, "email_type" => "html", "merges" => null, "ip_opt" => "10.20.10.30", "ip_signup" => "10.20.10.30"));
         CASHSystem::getURLContents($webhook_api_url, $remove_post_data, true);
         $list_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'getaddresslistinfo', 'list_id' => $this->test_list_id, 'address' => $test_address));
         // now make sure that the address has been removed
         $this->assertEqual($list_request->response['payload']['active'], 0);
     }
 }
Example #9
0
 public function getUserOrPage($id)
 {
     $endoint_url = 'https://graph.facebook.com/' . $id;
     $user_data = json_decode(CASHSystem::getURLContents($endoint_url), true);
     return $user_data;
 }
Example #10
0
 public static function getBrowserIdStatus($assertion, $return_details = false)
 {
     if (!$assertion) {
         return false;
     } else {
         $post_data = array('assertion' => $assertion, 'audience' => CASHSystem::getCurrentURL(true));
         $status = json_decode(CASHSystem::getURLContents('https://browserid.org/verify', $post_data, true), true);
         if ($return_details || !$status) {
             return $status;
         } else {
             if ($status['status'] == 'okay') {
                 return $status['email'];
             } else {
                 return false;
             }
         }
     }
 }
Example #11
0
 function testProcessWebhooks()
 {
     $time = time();
     if ($this->api_key) {
         $data_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'getapicredentials', 'user_id' => $this->cash_user_id));
         $api_credentials = $data_request->response['payload'];
         // valid API url, but likely localhost
         $webhook_api_url = CASH_API_URL . 'verbose/people/processwebhook/origin/com.mailchimp/list_id/' . $this->test_list_id . '/api_key/' . $api_credentials['api_key'];
         $test_address = 'dev+shouldnotsubscribe' . $time . '@cashmusic.org';
         $add_post_data = array("type" => "subscribe", "fired_at" => "2009-03-26 21:35:57", "data" => array("id" => "8a25ff1d98", "list_id" => "a6b5da1054", "email" => $test_address, "email_type" => "html", "merges" => null, "ip_opt" => "10.20.10.30", "ip_signup" => "10.20.10.30"));
         CASHSystem::getURLContents($webhook_api_url, $add_post_data, true);
         $list_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'getaddresslistinfo', 'list_id' => $this->test_list_id, 'address' => $test_address));
         // make sure that the address has been added to the local list
         $this->assertTrue($list_request->response['payload']);
         $remove_post_data = array("type" => "unsubscribe", "fired_at" => "2009-03-26 21:36:52", "data" => array("id" => "8a25ff1d98", "action" => "unsub", "reason" => "manual", "list_id" => "a6b5da1054", "email" => $test_address, "email_type" => "html", "merges" => null, "ip_opt" => "10.20.10.30", "ip_signup" => "10.20.10.30"));
         CASHSystem::getURLContents($webhook_api_url, $remove_post_data, true);
         $list_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'getaddresslistinfo', 'list_id' => $this->test_list_id, 'address' => $test_address));
         // now make sure that the address has been removed
         $this->assertEqual($list_request->response['payload']['active'], 0);
     } else {
         fwrite(STDERR, "Mailchimp api key not found, skipping mailchimp tests\n");
         return;
     }
 }
Example #12
0
<?php

if (isset($_POST['doupgrade'])) {
    $upgrade_file_contents = CASHSystem::getURLContents('https://raw.github.com/cashmusic/platform/latest_stable/installers/php/update/update.php');
    if ($upgrade_file_contents) {
        $success = file_put_contents(ADMIN_BASE_PATH . '/../update.php', $upgrade_file_contents);
        if ($success) {
            AdminHelper::controllerRedirect('/../update.php');
        } else {
            $cash_admin->page_data['error_message'] = 'Trouble copying update tool. Please make sure you have write permissions and try again.';
        }
    } else {
        $cash_admin->page_data['error_message'] = 'Failed to get the update tool. Please try again.';
    }
}
$cash_admin->page_data['platform_version'] = CASHRequest::$version;
$cash_admin->page_data['upgrade_available'] = false;
$current_profile_url = 'https://raw.github.com/cashmusic/platform/latest_stable/installers/php/update/releaseprofiles/release_' . $cash_admin->page_data['platform_version'] . '.json';
if (CASHSystem::getURLContents($current_profile_url)) {
    // found stable upgrade path...neat! let's check for a proper upgrade script:
    $upgrade_script_url = 'https://raw.github.com/cashmusic/platform/latest_stable/installers/php/update/updatescripts/' . $cash_admin->page_data['platform_version'] . '.php';
    $upgrade_script_contents = CASHSystem::getURLContents($upgrade_script_url);
    if ($upgrade_script_contents) {
        // okay rad, got an upgrade script too.
        $cash_admin->page_data['upgrade_available'] = true;
    }
} else {
    $cash_admin->page_data['is_edge'] = true;
}
$cash_admin->setPageContentTemplate('settings_update');
Example #13
0
 function test_getURLContents()
 {
     $return = CASHSystem::getURLContents(CASH_API_URL);
     $this->assertPattern('/"greeting":"hi."/', $return);
     // using local API URL as firewalls could mess with an external test
 }