From d1cace4e74d4b81ca3c85e492deac39f11be2cc9 Mon Sep 17 00:00:00 2001 From: Jill Earles Date: Thu, 3 Apr 2014 16:23:43 -0700 Subject: [PATCH 1/6] Updated to work with the Ning v2 API, for Ning 3.0 Networks --- LICENSE | 2 +- README.md | 14 +-- src/NingApi.php | 162 ++++++++++++++++++++------- src/NingObject.php | 17 +-- src/NingUpload.php | 44 ++++++++ src/NingUploadBinary.php | 42 +++++++ src/NingUploadFile.php | 19 ++++ src/objects/NingActivityItem.php | 42 ------- src/objects/NingBlogPost.php | 69 ++++-------- src/objects/NingBroadcastMessage.php | 22 ---- src/objects/NingBundle.php | 25 +++++ src/objects/NingComment.php | 34 ++---- src/objects/NingDiscussion.php | 21 ++++ src/objects/NingFriend.php | 31 ----- src/objects/NingGroup.php | 34 ++++++ src/objects/NingMemberCategory.php | 25 +++++ src/objects/NingMessage.php | 26 +++++ src/objects/NingNetwork.php | 19 ++-- src/objects/NingPhoto.php | 67 +++-------- src/objects/NingSitePage.php | 22 ++++ src/objects/NingTag.php | 41 ------- src/objects/NingUser.php | 74 +++++------- src/objects/NingVideo.php | 42 ------- test/BlogPostTest.php | 124 ++++++++++++++++++++ test/BundleTest.php | 63 +++++++++++ test/CommentTest.php | 118 +++++++++++++++++++ test/DiscussionTest.php | 125 +++++++++++++++++++++ test/GroupTest.php | 105 +++++++++++++++++ test/MemberCategoryTest.php | 36 ++++++ test/MessageTest.php | 106 ++++++++++++++++++ test/NetworkTest.php | 34 ++++++ test/NingActivityItemTest.php | 45 -------- test/NingBlogPostTest.php | 153 ------------------------- test/NingBroadcastMessageTest.php | 24 ---- test/NingCommentTest.php | 52 --------- test/NingFriendTest.php | 25 ----- test/NingNetworkTest.php | 40 ------- test/NingPhotoTest.php | 158 -------------------------- test/NingTagTest.php | 36 ------ test/NingTestHelper.php | 9 -- test/NingUserTest.php | 78 ------------- test/NingVideoTest.php | 36 ------ test/PhotoTest.php | 125 +++++++++++++++++++++ test/SitePageTest.php | 51 +++++++++ test/TestConfig.php | 12 ++ test/TokenTest.php | 30 +++++ test/UserTest.php | 94 ++++++++++++++++ 47 files changed, 1505 insertions(+), 1068 deletions(-) create mode 100644 src/NingUpload.php create mode 100644 src/NingUploadBinary.php create mode 100644 src/NingUploadFile.php delete mode 100644 src/objects/NingActivityItem.php delete mode 100644 src/objects/NingBroadcastMessage.php create mode 100644 src/objects/NingBundle.php create mode 100644 src/objects/NingDiscussion.php delete mode 100644 src/objects/NingFriend.php create mode 100644 src/objects/NingGroup.php create mode 100644 src/objects/NingMemberCategory.php create mode 100644 src/objects/NingMessage.php create mode 100644 src/objects/NingSitePage.php delete mode 100644 src/objects/NingTag.php delete mode 100644 src/objects/NingVideo.php create mode 100644 test/BlogPostTest.php create mode 100644 test/BundleTest.php create mode 100644 test/CommentTest.php create mode 100644 test/DiscussionTest.php create mode 100644 test/GroupTest.php create mode 100644 test/MemberCategoryTest.php create mode 100644 test/MessageTest.php create mode 100644 test/NetworkTest.php delete mode 100644 test/NingActivityItemTest.php delete mode 100644 test/NingBlogPostTest.php delete mode 100644 test/NingBroadcastMessageTest.php delete mode 100644 test/NingCommentTest.php delete mode 100644 test/NingFriendTest.php delete mode 100644 test/NingNetworkTest.php delete mode 100644 test/NingPhotoTest.php delete mode 100644 test/NingTagTest.php delete mode 100644 test/NingTestHelper.php delete mode 100644 test/NingUserTest.php delete mode 100644 test/NingVideoTest.php create mode 100644 test/PhotoTest.php create mode 100644 test/SitePageTest.php create mode 100644 test/TestConfig.php create mode 100644 test/TokenTest.php create mode 100644 test/UserTest.php diff --git a/LICENSE b/LICENSE index abe9162..e8d4869 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2010 Ning, Inc. +Copyright 2014 Ning, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of diff --git a/README.md b/README.md index 281f2b8..f466d55 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,15 @@ Overview [ning-api-php][1] is a PHP client for accessing the [Ning][2] API. The Ning API is a RESTful API that allows developers to access the content on -their Ning Networks. The [Ning API Documentation][3] contains a complete API -reference and tutorials. +their Ning Networks. The [Ning 3.0 API Documentation][3] contains a complete API +reference. Support ======= -If you need help with using this library, you can find us on the [Ning Build -Network][4]. If you find an issue with this library, please file a bug on our -[issues page][5]. +If you find an issue with this library, please file a bug on our +[issues page][4]. Example Usage @@ -24,6 +23,5 @@ See the `/test` directory for examples of how to use this library. [1]: https://github.com/ning/ning-api-php [2]: http://www.ning.com/ -[3]: http://developer.ning.com/ -[4]: http://build.ning.com/ -[5]: https://github.com/ning/ning-api-php/issues +[3]: http://www.ning.com/ning3help/ning-v2-api-documentation/ +[4]: https://github.com/ning/ning-api-php/issues \ No newline at end of file diff --git a/src/NingApi.php b/src/NingApi.php index 91152b9..2ab5d94 100644 --- a/src/NingApi.php +++ b/src/NingApi.php @@ -6,16 +6,20 @@ require_once('OAuth.php'); require_once('NingException.php'); require_once('NingObject.php'); +require_once('NingUpload.php'); +require_once('NingUploadFile.php'); +require_once('NingUploadBinary.php'); + class NingApi { const SECURE_PROTOCOL = 'https://'; const INSECURE_PROTOCOL = 'http://'; - const BASE_URL = 'external.ningapis.com/xn/rest'; - const API_VERSION = '1.0'; + protected static $BASE_URL = 'external.ningapis.com/xn/rest'; + protected static $API_VERSION = '2.0'; // The maximum number of seconds to allow cURL to execute - const CURL_TIMEOUT = 10; - // Ning network subdomain (ie. 'apiexample' in apiexample.ning.com) + protected static $CURL_TIMEOUT = 100; + public $subdomain = ''; // Ning user email address protected $email = ''; @@ -25,9 +29,12 @@ class NingApi { protected $consumerKey = ''; // Consumer secret found at [subdomain].ning.com/main/extend/keys protected $consumerSecret = ''; + protected $requestToken = null; private static $_instance = null; + protected $verifySslCertificates = true; + public static function instance() { if (is_null(self::$_instance)) { self::$_instance = new NingApi(); @@ -35,7 +42,7 @@ public static function instance() { return self::$_instance; } - public function __construct($subdomain=null, $consumerKey=null, $consumerSecret=null, $email=null, $password=null) { + public function __construct($subdomain=null, $consumerKey=null, $consumerSecret=null, $emailOrRequestKey=null, $passwordOrRequestSecret=null) { if ($subdomain) { $this->subdomain = $subdomain; } @@ -45,19 +52,26 @@ public function __construct($subdomain=null, $consumerKey=null, $consumerSecret= if ($consumerSecret) { $this->consumerSecret = $consumerSecret; } - if ($email) { - $this->email = $email; - } - if ($password) { - $this->password = $password; - } if ($this->consumerKey && $this->consumerSecret) { $this->_initAuthTokens($this->consumerKey, $this->consumerSecret); } - if ($this->email && $this->password) { - $this->login($this->email, $this->password); + if (preg_match('/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/', $emailOrRequestKey) && preg_match('/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/', $passwordOrRequestSecret)) { + $this->setRequestTokens($emailOrRequestKey, + $passwordOrRequestSecret); + } + else { + if ($emailOrRequestKey) { + $this->email = $emailOrRequestKey; + } + if ($passwordOrRequestSecret) { + $this->password = $passwordOrRequestSecret; + } + + if ($this->email && $this->password) { + $this->login($this->email, $this->password); + } } $this->_initNingObjects(); @@ -65,7 +79,36 @@ public function __construct($subdomain=null, $consumerKey=null, $consumerSecret= self::$_instance = $this; } - private function _requireUserSpecificData($required = array('subdomain', 'email', 'consumerKey', 'consumerSecret', 'password')) { + public function setVersion($version) { + self::$API_VERSION = $version; + } + + public function setBaseUrl($baseUrl) { + self::$BASE_URL = $baseUrl; + echo "set base url successfully"; + } + + /** + * + * Set maximum number of seconds to allow cURL to execute + * @param int $time + */ + public function setCurlTimeOut($time) { + self::$CURL_TIMEOUT = $time; + } + + public function setSslCertificateVerification($verify, $check = null) { + if ((! $verify) && ($check !== "I am only turning off SSL Certificate Verification because I am testing something and I promise I know what I am doing.")) { + NingException::generate(array('reason' => "Don't turn off SSL Certificate Verification unless you know what you are doing.", + 'status' => 401, + 'code' => 1, + 'subcode' => 4)); + } + $this->verifySslCertificates = (bool) $verify; + echo "set ssl verification to $verify"; + } + + private function _requireUserSpecificData($required = array('subdomain', 'consumerKey', 'consumerSecret', 'requestToken')) { foreach ($required as $val) { if (!$this->{$val}) { throw new NingException("Failed to find the value for '$val'"); @@ -80,16 +123,11 @@ private function _initAuthTokens($consumerKey, $consumerSecret) { } private function _initNingObjects() { - $this->activityItem = new NingActivityItem(); $this->blogPost = new NingBlogPost(); - $this->broadcastMessage = new NingBroadcastMessage(); $this->comment = new NingComment(); $this->network = new NingNetwork(); $this->photo = new NingPhoto(); $this->user = new NingUser(); - $this->video = new NingVideo(); - $this->friend = new NingFriend(); - $this->tag = new NingTag(); } public function setSubdomain($subdomain) { @@ -104,6 +142,12 @@ public function setConsumerTokens($consumerKey, $consumerSecret) { self::$_instance = $this; } + public function setRequestTokens($key, $secret) { + $this->oauthToken = $key; + $this->oauthTokenSecret = $secret; + $this->requestToken = new OAuthConsumer($this->oauthToken, $this->oauthTokenSecret); + } + public function login($email, $password) { try{ $this->_requireUserSpecificData(array('subdomain','consumerKey','consumerSecret')); @@ -117,20 +161,20 @@ public function login($email, $password) { $headers = array( 'Authorization: Basic ' . $credentials ); - $result = $this->post('Token', NULL, $headers, TRUE); - $this->oauthToken = $result['entry']['oauthToken']; - $this->oauthTokenSecret = $result['entry']['oauthTokenSecret']; - $this->requestToken = new OAuthConsumer($this->oauthToken, $this->oauthTokenSecret); + $result = $this->post('Token', NULL, $headers, true); + $this->setRequestTokens($result['entry']['oauthToken'], + $result['entry']['oauthTokenSecret']); self::$_instance = $this; + return $result; } /** * Create a Ning API request URL */ - public function buildUrl($path, $secure=FALSE) { + public function buildUrl($path, $secure=TRUE, $version='2.0') { $protocol = $secure ? self::SECURE_PROTOCOL : self::INSECURE_PROTOCOL; - $base = $protocol . self::BASE_URL; - $parts = array($base, $this->subdomain, self::API_VERSION, $path); + $base = $protocol . self::$BASE_URL; + $parts = array($base, $this->subdomain, $version, $path); $url = join('/', $parts); return $url; } @@ -138,25 +182,29 @@ public function buildUrl($path, $secure=FALSE) { /** * Call the Ning API */ - public function call($path, $method='GET', $body=NULL, $headers=NULL, $secure=FALSE) { - if($path != 'Token'){ + public function call($path, $method='GET', $body=NULL, $headers=NULL, $secure=TRUE) { + if($path == 'Token'){ + $version = '1.0'; + } else { //unless we're authenticating, we need all user data $this->_requireUserSpecificData(); + $version = self::$API_VERSION; } - $url = $this->buildUrl($path, $secure); + $url = $this->buildUrl($path, $secure, $version); $headers = $headers ? $headers : array(); $ch = curl_init(); - curl_setopt($ch, CURLOPT_TIMEOUT, self::CURL_TIMEOUT); + curl_setopt($ch, CURLOPT_TIMEOUT, self::$CURL_TIMEOUT); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_SSLVERSION,3); + + $isMultipart = $this->isMultipart($body); - if ($body && array_key_exists('file', $body)) { - $isMultipart = TRUE; + if ($isMultipart) { // Don't include the body params for multipart requests $oauth_req = OAuthRequest::from_consumer_and_token($this->consumerToken, $this->requestToken, $method, $url); } else { - $isMultipart = FALSE; $oauth_req = OAuthRequest::from_consumer_and_token($this->consumerToken, $this->requestToken, $method, $url, $body); } @@ -169,7 +217,7 @@ public function call($path, $method='GET', $body=NULL, $headers=NULL, $secure=FA if ($isMultipart) { // Send as multipart/form-data $headers[] = $oauth_req->to_header(); - curl_setopt($ch, CURLOPT_POSTFIELDS, $body); + curl_setopt($ch, CURLOPT_POSTFIELDS, $this->transformMultipartBody($body)); } else { // Send as application/x-www-form-urlencoded curl_setopt($ch, CURLOPT_POSTFIELDS, @@ -194,6 +242,11 @@ public function call($path, $method='GET', $body=NULL, $headers=NULL, $secure=FA curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } + if (false === $this->verifySslCertificates) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); + } + $json = null; try { $json = curl_exec($ch); @@ -203,7 +256,7 @@ public function call($path, $method='GET', $body=NULL, $headers=NULL, $secure=FA if (curl_errno($ch)) { - throw new NingException('cURL error: ' . curl_error($ch)); + throw new NingException('cURL error: ' . curl_error($ch) . " accessing $method $path"); } curl_close($ch); @@ -217,20 +270,51 @@ public function call($path, $method='GET', $body=NULL, $headers=NULL, $secure=FA return $result; } - public function post($path, $body=NULL, $headers=NULL, $secure=false) { + public function post($path, $body=NULL, $headers=NULL, $secure=true) { return $this->call($path, 'POST', $body, $headers, $secure); } - public function put($path, $body=NULL, $headers=NULL, $secure=false) { + public function put($path, $body=NULL, $headers=NULL, $secure=true) { return $this->call($path, 'PUT', $body, $headers, $secure); } - public function delete($path, $body=NULL, $headers=NULL, $secure=false) { + public function delete($path, $body=NULL, $headers=NULL, $secure=true) { return $this->call($path, 'DELETE', $body, $headers, $secure); } - public function get($path, $body=NULL, $headers=NULL, $secure=false) { + public function get($path, $body=NULL, $headers=NULL, $secure=true) { return $this->call($path, 'GET', $body, $headers, $secure); } + /** + * Does the provided array of request body elements contain any + * upload items so that the request should be treated as a multipart + * request? + * + * @param $body array key=>value pairs of request body items + * @return boolean + */ + protected function isMultipart($body){ + if (is_array($body)) { + foreach ($body as $name => $value){ + if ($value instanceof NingUpload) { + return true; + } + } + } + return false; + } + + /** + * Transform the provided request body elements into the proper + * key=>value pairs that curl expects + */ + protected function transformMultipartBody($body) { + foreach ($body as $name => $value) { + if ($value instanceof NingUpload) { + $body[$name] = (string) $value; + } + } + return $body; + } } diff --git a/src/NingObject.php b/src/NingObject.php index 9eb313b..1db2721 100644 --- a/src/NingObject.php +++ b/src/NingObject.php @@ -1,21 +1,22 @@ data = $data; + $this->type = $type; + } + + /** + * Append a ;type or ;filename parameter as + * necessary to a parameter being provided to cURL + * + * @param $s string Parameter before modification + * @param $name string Property name of param to append + * @return string + */ + protected function appendParam($s, $name) { + if (! is_null($this->$name)) { + return $s . ";$name=" . $this->$name; + } else { + return $s; + } + } +} diff --git a/src/NingUploadBinary.php b/src/NingUploadBinary.php new file mode 100644 index 0000000..fcc79f4 --- /dev/null +++ b/src/NingUploadBinary.php @@ -0,0 +1,42 @@ +filename = null; + } + + /** + * Write the binary data to a temp file and then produce the + * right value for cURL to upload that temp file + * @return string + */ + public function __toString() { + $tempFile = tempnam(sys_get_temp_dir(), "binaryupload"); + file_put_contents($tempFile, $this->data); + /* Make sure the temp file gets deleted when we're done */ + register_shutdown_function('unlink',$tempFile); + $s = '@' . $tempFile; + $s = $this->appendParam($s, 'type'); + $s = $this->appendParam($s, 'filename'); + return $s; + } +} \ No newline at end of file diff --git a/src/NingUploadFile.php b/src/NingUploadFile.php new file mode 100644 index 0000000..7453fee --- /dev/null +++ b/src/NingUploadFile.php @@ -0,0 +1,19 @@ +data; + $s = $this->appendParam($s, 'type'); + return $s; + } +} diff --git a/src/objects/NingActivityItem.php b/src/objects/NingActivityItem.php deleted file mode 100644 index e2988b3..0000000 --- a/src/objects/NingActivityItem.php +++ /dev/null @@ -1,42 +0,0 @@ -create($args); - } - -} \ No newline at end of file diff --git a/src/objects/NingBundle.php b/src/objects/NingBundle.php new file mode 100644 index 0000000..2fc90b1 --- /dev/null +++ b/src/objects/NingBundle.php @@ -0,0 +1,25 @@ +ningApi = $ningApi; + + $this->ningApi->login(TestConfig::EMAIL, TestConfig::PASSWORD); + } + + private function create() { + $bundleId = $this->getBundleId(); + $parts = array( + 'bundleId' => $bundleId, + 'title' => 'BlogPost Title', + 'description' => 'BlogPost Description' + ); + + $result = $this->ningApi->post('BlogPost', $parts); + $this->assertTrue($result['success']); + + return $result; + } + + private function getBundleId() { + $bundleId = 'none'; + $count = 1; + $fields = 'id'; + $entryContentType = 'BlogPost'; + $path = sprintf('Bundle/recent?count=%s&fields=%s&entryContentType=%s', $count, + $fields, $entryContentType); + + $result = $this->ningApi->get($path); + if (isset($result['entry'][0]['id'])) { + $bundleId = $result['entry'][0]['id']; + } + + return $bundleId; + } + + public function testGet() { + $result = $this->create(); + $fields = 'author,title,description'; + $path = sprintf('BlogPost/?id=%s&fields=%s', $result['id'], $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testRecent() { + $count = 3; + $fields = 'title,author.url'; + $bundleId = $this->getBundleId(); + $path = sprintf('BlogPost/recent?count=%s&fields=%s&bundleId=%s', $count, + $fields, $bundleId); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testFeatured() { + $count = 3; + $fields = 'title,author.url'; + $bundleId = $this->getBundleId(); + $path = sprintf('BlogPost/featured?count=%s&fields=%s&bundleId=%s', $count, + $fields, $bundleId); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testCreate() { + $result = $this->create(); + $this->assertTrue($result['success']); + } + + public function testUpdate() { + $result = $this->create(); + + $parts = array( + 'title' => 'Updated BlogPost Title', + 'description' => 'Updated BlogPost Description', + 'id' => $result['id'] + ); + + $result = $this->ningApi->put('BlogPost', $parts); + $this->assertTrue($result['success']); + } + + public function testDelete() { + $result = $this->create(); + + $path = sprintf('BlogPost?id=%s', $result['id']); + + $result = $this->ningApi->delete($path); + $this->assertTrue($result['success']); + } + + public function testCount() { + date_default_timezone_set('UTC'); + $date = date('Y-m-d\TH:i:s\Z', strtotime('-2 days')); + $bundleId = $this->getBundleId(); + + $path = sprintf('BlogPost/count?createdAfter=%s&bundleId=%s', $date, $bundleId); + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + protected function tearDown() { + $this->ningApi = NULL; + } +} diff --git a/test/BundleTest.php b/test/BundleTest.php new file mode 100644 index 0000000..1a910dc --- /dev/null +++ b/test/BundleTest.php @@ -0,0 +1,63 @@ +ningApi = $ningApi; + + $this->ningApi->login(TestConfig::EMAIL, TestConfig::PASSWORD); + } + + private function getBundleId() { + $bundleId = 'none'; + $count = 1; + $fields = 'id'; + $entryContentType = 'BlogPost'; + $path = sprintf('Bundle/recent?count=%s&fields=%s&entryContentType=%s', $count, + $fields, $entryContentType); + + $result = $this->ningApi->get($path); + if (isset($result['entry'][0]['id'])) { + $bundleId = $result['entry'][0]['id']; + } + + return $bundleId; + } + + public function testGet() { + $bundleId = $this->getBundleId(); + $fields = 'createdDate,author,entryContentType,categoryNames'; + $path = sprintf('Bundle/?id=%s&fields=%s', $bundleId, $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testRecent() { + $count = 12; + $fields = 'id,entryContentType,categoryNames'; + $path = sprintf('Bundle/recent?count=%s&fields=%s', $count, + $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + + return $result['entry'][0]['id']; + } + + protected function tearDown() { + $this->ningApi = NULL; + } +} \ No newline at end of file diff --git a/test/CommentTest.php b/test/CommentTest.php new file mode 100644 index 0000000..b0e51e6 --- /dev/null +++ b/test/CommentTest.php @@ -0,0 +1,118 @@ +ningApi = $ningApi; + + $this->ningApi->login(TestConfig::EMAIL, TestConfig::PASSWORD); + } + + private function create() { + $attachedTo = $this->getEntryId(); + $parts = array( + 'description' => 'Comment Description', + 'attachedTo' => $attachedTo + ); + + $result = $this->ningApi->post('Comment', $parts); + $this->assertTrue($result['success']); + + return $result; + } + + private function getEntryId() { + $entryId = null; + $count = 1; + $fields = 'id'; + $entryContentType = 'BlogPost'; + $path = sprintf('Bundle/recent?count=%s&fields=%s&entryContentType=%s', $count, + $fields, $entryContentType); + + $result = $this->ningApi->get($path); + if (isset($result['entry'][0]['id'])) { + $bundleId = $result['entry'][0]['id']; + $path = sprintf('BlogPost/recent?bundleId=%s&count=%s&fields=%s', $bundleId, + $count, $fields); + $entries = $this->ningApi->get($path); + if (isset($entries['entry'][0]['id'])) { + $entryId = $entries['entry'][0]['id']; + } + } + + return $entryId; + } + + public function testGet() { + $result = $this->create(); + $fields = 'author,description'; + $path = sprintf('Comment/?id=%s&fields=%s', $result['id'], $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testRecent() { + $count = 3; + $fields = 'title,author.url'; + $attachedTo = $this->getEntryId(); + $path = sprintf('Comment/recent?count=%s&fields=%s&attachedTo=%s', $count, + $fields, $attachedTo); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testFeatured() { + $count = 3; + $fields = 'title, author.url'; + $attachedTo = $this->getEntryId(); + $path = sprintf('Comment/featured?count=%s&fields=%s&attachedTo=%s', $count, + $fields, $attachedTo); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testCreate() { + $result = $this->create(); + $this->assertTrue($result['success']); + } + + public function testUpdate() { + $result = $this->create(); + + $parts = array( + 'description' => 'Updated Comment Description', + 'id' => $result['id'] + ); + + $result = $this->ningApi->put('Comment', $parts); + $this->assertTrue($result['success']); + } + + public function testDelete() { + $result = $this->create(); + + $path = sprintf('Comment?id=%s', $result['id']); + + $result = $this->ningApi->delete($path); + $this->assertTrue($result['success']); + } + + protected function tearDown() { + $this->ningApi = NULL; + } +} diff --git a/test/DiscussionTest.php b/test/DiscussionTest.php new file mode 100644 index 0000000..5037935 --- /dev/null +++ b/test/DiscussionTest.php @@ -0,0 +1,125 @@ +ningApi = $ningApi; + + $this->ningApi->login(TestConfig::EMAIL, TestConfig::PASSWORD); + } + + private function create() { + $bundleId = $this->getBundleId(); + $parts = array( + 'bundleId' => $bundleId, + 'title' => 'Discussion Title', + 'description' => 'Discussion Description', + 'tagNames' => 'test, api' + ); + + $result = $this->ningApi->post('Discussion', $parts); + $this->assertTrue($result['success']); + + return $result; + } + + private function getBundleId() { + $bundleId = 'none'; + $count = 1; + $fields = 'id'; + $entryContentType = 'Discussion'; + $path = sprintf('Bundle/recent?count=%s&fields=%s&entryContentType=%s', $count, + $fields, $entryContentType); + + $result = $this->ningApi->get($path); + if (isset($result['entry'][0]['id'])) { + $bundleId = $result['entry'][0]['id']; + } + + return $bundleId; + } + + public function testGet() { + $result = $this->create(); + $fields = 'author,title,description'; + $path = sprintf('Discussion/?id=%s&fields=%s', $result['id'], $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testRecent() { + $count = 3; + $fields = 'title, author.url'; + $bundleId = $this->getBundleId(); + $path = sprintf('Discussion/recent?count=%s&fields=%s&bundleId=%s', $count, + $fields, $bundleId); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testFeatured() { + $count = 3; + $fields = 'title, author.url'; + $bundleId = $this->getBundleId(); + $path = sprintf('Discussion/featured?count=%s&fields=%s&bundleId=%s', $count, + $fields, $bundleId); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testCreate() { + $result = $this->create(); + $this->assertTrue($result['success']); + } + + public function testUpdate() { + $result = $this->create(); + + $parts = array( + 'title' => 'Updated Discussion Title', + 'description' => 'Updated Discussion Description', + 'id' => $result['id'] + ); + + $result = $this->ningApi->put('Discussion', $parts); + $this->assertTrue($result['success']); + } + + public function testDelete() { + $result = $this->create(); + + $path = sprintf('Discussion?id=%s', $result['id']); + + $result = $this->ningApi->delete($path); + $this->assertTrue($result['success']); + } + + public function testCount() { + date_default_timezone_set('UTC'); + $date = date('Y-m-d\TH:i:s\Z', strtotime('-2 days')); + $bundleId = $this->getBundleId(); + + $path = sprintf('Discussion/count?createdAfter=%s&bundleId=%s', $date, $bundleId); + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + protected function tearDown() { + $this->ningApi = NULL; + } +} diff --git a/test/GroupTest.php b/test/GroupTest.php new file mode 100644 index 0000000..7144092 --- /dev/null +++ b/test/GroupTest.php @@ -0,0 +1,105 @@ +ningApi = $ningApi; + + $this->ningApi->login(TestConfig::EMAIL, TestConfig::PASSWORD); + } + + private function create() { + $parts = array( + 'title' => 'Group Title', + 'description' => 'Group Description', + 'joinSetting' => 'invitation' + ); + + $result = $this->ningApi->post('Group', $parts); + $this->assertTrue($result['success']); + + return $result; + } + + public function testGet() { + $result = $this->create(); + $fields = 'title,description,joinSetting'; + $path = sprintf('Group/?id=%s&fields=%s', $result['id'], $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testRecent() { + $count = 3; + $fields = 'title,description,joinSetting'; + $path = sprintf('Group/recent?count=%s&fields=%s', $count, + $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testFeatured() { + $count = 3; + $fields = 'title,description,joinSetting'; + $path = sprintf('Group/featured?count=%s&fields=%s', $count, + $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testCreate() { + $result = $this->create(); + $this->assertTrue($result['success']); + } + + public function testUpdate() { + $result = $this->create(); + + $parts = array( + 'title' => 'Updated Group Title', + 'description' => 'Updated Group Description', + 'joinSetting' => 'anyone', + 'id' => $result['id'] + ); + + $result = $this->ningApi->put('Group', $parts); + $this->assertTrue($result['success']); + } + + public function testDelete() { + $result = $this->create(); + + $path = sprintf('Group?id=%s', $result['id']); + + $result = $this->ningApi->delete($path); + $this->assertTrue($result['success']); + } + + public function testCount() { + date_default_timezone_set('UTC'); + $date = date('Y-m-d\TH:i:s\Z', strtotime('-2 days')); + + $path = sprintf('Group/count?createdAfter=%s&', $date); + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + protected function tearDown() { + $this->ningApi = NULL; + } +} diff --git a/test/MemberCategoryTest.php b/test/MemberCategoryTest.php new file mode 100644 index 0000000..66ad892 --- /dev/null +++ b/test/MemberCategoryTest.php @@ -0,0 +1,36 @@ +ningApi = $ningApi; + + $this->ningApi->login(TestConfig::EMAIL, TestConfig::PASSWORD); + } + + public function testRecent() { + $count = 9; + $fields = 'title,imageUrl'; + $path = sprintf('MemberCategory/recent?count=%s&fields=%s', $count, + $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + protected function tearDown() { + $this->ningApi = NULL; + } +} \ No newline at end of file diff --git a/test/MessageTest.php b/test/MessageTest.php new file mode 100644 index 0000000..d26dfd1 --- /dev/null +++ b/test/MessageTest.php @@ -0,0 +1,106 @@ +ningApi = $ningApi; + + $this->ningApi->login(TestConfig::EMAIL, TestConfig::PASSWORD); + } + + private function create() { + $recipients = $this->getRecipients(); + $parts = array( + 'recipients' => $recipients, + 'subject' => 'Message Subject', + 'body' => 'Message body: the content of the message.', + 'email' => 'true' + ); + + $result = $this->ningApi->post('Message', $parts); + $this->assertTrue($result['success']); + + return $result; + } + + private function getRecipients() { + $count = 3; + $fields = 'title'; + $path = sprintf('User/recent?count=%s&fields=%s', $count, + $fields); + + $result = $this->ningApi->get($path); + $recipients = array(); + foreach ($result['entry'] as $user) { + $recipients[] = $user['title']; + } + return json_encode($recipients); + } + + public function testInbox() { + $fields = 'id,createdDate,sender,subject'; + $path = sprintf('Message/inbox?fields=%s', $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + + return $result; + } + + public function testSent() { + $count = 3; + $fields = 'id,createdDate,subject,recipients'; + $path = sprintf('Message/sent?count=%s&fields=%s', $count, + $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + + return $result; + } + + public function testArchive() { + $count = 3; + $fields = 'createdDate,sender,subject'; + $path = sprintf('Message/archive?count=%s&fields=%s', $count, + $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testCreate() { + $result = $this->create(); + $this->assertTrue($result['success']); + } + + public function testUpdate() { + $this->create(); + $result = $this->testSent(); + $id = $result['entry'][0]['id']; + + $parts = array( + 'read' => 'true', + 'id' => $id + ); + + $result = $this->ningApi->put('Message', $parts); + $this->assertTrue($result['success']); + } + + protected function tearDown() { + $this->ningApi = NULL; + } +} diff --git a/test/NetworkTest.php b/test/NetworkTest.php new file mode 100644 index 0000000..e81882e --- /dev/null +++ b/test/NetworkTest.php @@ -0,0 +1,34 @@ +ningApi = $ningApi; + + $this->ningApi->login(TestConfig::EMAIL, TestConfig::PASSWORD); + } + + public function testGet() { + $fields = 'subdomain, author, profileQuestions'; + $path = sprintf('Network/?fields=%s', $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + protected function tearDown() { + $this->ningApi = NULL; + } +} \ No newline at end of file diff --git a/test/NingActivityItemTest.php b/test/NingActivityItemTest.php deleted file mode 100644 index bafe076..0000000 --- a/test/NingActivityItemTest.php +++ /dev/null @@ -1,45 +0,0 @@ -activityItem->fetchRecent(); - $this->assertTrue($result['success']); - } - - /** - * @group delete - */ - public function testDelete() { - $item = NingApi::instance()->activityItem->fetchRecent(); - $result = NingApi::instance()->activityItem->delete($item['entry'][0]); - $this->assertTrue($result['success']); - } - - public function testRecent_old() { - $count = 3; - $fields = "title"; - $path = sprintf("Activity/recent?count=%s&fields=%s", $count, - $fields); - - $result = NingApi::instance()->get($path); - $this->assertTrue($result['success']); - } - - public function testCount_old() { - date_default_timezone_set("UTC"); - $date = date("Y-m-d\TH:i:s\Z", strtotime("-2 days")); - - $path = sprintf("Activity/count?createdAfter=%s", $date); - $result = NingApi::instance()->get($path); - $this->assertTrue($result['success']); - } - -} - -?> diff --git a/test/NingBlogPostTest.php b/test/NingBlogPostTest.php deleted file mode 100644 index 8ceed17..0000000 --- a/test/NingBlogPostTest.php +++ /dev/null @@ -1,153 +0,0 @@ -blogPost->create($args); - } - - /** - * @group create - */ - public function testCreate() { - $result = $this->createNewBlogPost(); - $this->assertTrue($result['success']); - } - - /** - * @group delete - */ - public function testDelete() { - $newBlogPost = $this->createNewBlogPost(); - $args = array('id' => $newBlogPost['id']); - $result = NingApi::instance()->blogPost->delete($args); - $this->assertTrue($result['success']); - } - - /** - * @group update - */ - public function testUpdate() { - $newBlogPost = $this->createNewBlogPost(); - $args = array('id' => $newBlogPost['id']); - $result = NingApi::instance()->blogPost->update($args); - $this->assertTrue($result['success']); - } - - public function testFetch() { - $newBlogPost = $this->createNewBlogPost(); - $args = array('id' => $newBlogPost['id']); - $result = NingApi::instance()->blogPost->fetch($args); - $this->assertTrue($result['success']); - } - - /** - * @group count - */ - public function testGetCount() { - $args = array('createdAfter' => gmdate('c',@strtotime("-2 days"))); - $result = NingApi::instance()->blogPost->getCount($args); - $this->assertTrue($result['success']); - } - - /** - * @group count - */ - public function testGetCountCreatedAfter() { - $result = NingApi::instance()->blogPost->getCountCreatedAfter(gmdate('c',@strtotime("-2 days"))); - $this->assertTrue($result['success']); - } - - /** - * @group count - */ - public function testGetCountCreatedInLastNDays() { - $result = NingApi::instance()->blogPost->getCountCreatedInLastNDays(3); - $this->assertTrue($result['success']); - } - - public function testFetchRecent() { - $result = NingApi::instance()->blogPost->fetchRecent(); - $this->assertTrue($result['success']); - } - - public function testFetchNRecent() { - $result = NingApi::instance()->blogPost->fetchNRecent(3); - $this->assertTrue($result['success']); - } - - public function testFetchRecentNextPage() { - $result = NingApi::instance()->blogPost->fetchRecentNextPage(); - $this->assertTrue($result['success']); - } - - private function create() { - $parts = array( - "title" => "BlogPost Title", - "description" => "BlogPost Description", - "tag" => "tests" - ); - - $result = NingApi::instance()->post("BlogPost", $parts); - $this->assertTrue($result['success']); - - return $result; - } - - public function testRecent_old() { - $count = 3; - $fields = "title,author.url"; - $path = sprintf("BlogPost/recent?count=%s&fields=%s", $count, - $fields); - - $result = NingApi::instance()->get($path); - $this->assertTrue($result['success']); - } - - public function testCreate_old() { - $result = $this->create(); - } - - public function testUpdate_old() { - $result = $result = $this->create(); - - $parts = array( - "title" => "Updated BlogPost Title", - "description" => "Updated BlogPost Description", - "id" => $result['id'] - ); - - $result = NingApi::instance()->put("BlogPost", $parts); - $this->assertTrue($result['success']); - } - - public function testDelete_old() { - $result = $result = $this->create(); - - $path = sprintf("BlogPost?id=%s", $result['id']); - - $result = NingApi::instance()->delete($path); - $this->assertTrue($result['success']); - } - - public function testCount_old() { - date_default_timezone_set("UTC"); - $date = date("Y-m-d\TH:i:s\Z", strtotime("-2 days")); - - $path = sprintf("BlogPost/count?createdAfter=%s", $date); - $result = NingApi::instance()->get($path); - $this->assertTrue($result['success']); - } - -} - -?> diff --git a/test/NingBroadcastMessageTest.php b/test/NingBroadcastMessageTest.php deleted file mode 100644 index 740efd8..0000000 --- a/test/NingBroadcastMessageTest.php +++ /dev/null @@ -1,24 +0,0 @@ -broadcastMessage->createMessage($subject, $body); - $this->assertTrue($result['success']); - } - -} - -?> diff --git a/test/NingCommentTest.php b/test/NingCommentTest.php deleted file mode 100644 index 2fb7232..0000000 --- a/test/NingCommentTest.php +++ /dev/null @@ -1,52 +0,0 @@ -blogPost->fetchNRecent(); - $args['attachedTo'] = $blogPosts['entry'][0]['id']; - $result = NingApi::instance()->comment->create($args); - $this->assertTrue($result['success']); - } - - public function testFetchNRecent() { - $blogPosts = NingApi::instance()->blogPost->fetchNRecent(); - $args = array('attachedTo' => $blogPosts['entry'][0]['id']); - $result = NingApi::instance()->comment->fetchNRecent(1, $args); - $this->assertTrue($result['success']); - } - - public function testFetchRecent() { - $blogPosts = NingApi::instance()->blogPost->fetchNRecent(); - $args = array('attachedTo' => $blogPosts['entry'][0]['id']); - $result = NingApi::instance()->comment->fetchRecent($args); - $this->assertTrue($result['success']); - } - - /** - * @group delete - */ - public function testDelete() { - $args = array(); - $blogPosts = NingApi::instance()->blogPost->fetchNRecent(); - $args['attachedTo'] = $blogPosts['entry'][0]['id']; - $args['description'] = "This is a test comment."; - $newComment = NingApi::instance()->comment->create($args); - $args = array('id' => $newComment['id']); - $result = NingApi::instance()->comment->delete($args); - $this->assertTrue($result['success']); - } - -} - -?> diff --git a/test/NingFriendTest.php b/test/NingFriendTest.php deleted file mode 100644 index 22af7fd..0000000 --- a/test/NingFriendTest.php +++ /dev/null @@ -1,25 +0,0 @@ -friend->fetchRecent(); - $this->assertTrue($result['success']); - } - - public function testFetchNRecent() { - $result = NingApi::instance()->friend->fetchNRecent(3); - $this->assertTrue($result['success']); - } - - public function testFetchRecentNextPage() { - $result = NingApi::instance()->friend->fetchRecentNextPage(); - $this->assertTrue($result['success']); - } - -} diff --git a/test/NingNetworkTest.php b/test/NingNetworkTest.php deleted file mode 100644 index eacc62b..0000000 --- a/test/NingNetworkTest.php +++ /dev/null @@ -1,40 +0,0 @@ -network->fetch(); - $this->assertTrue($result['success']); - } - - public function testFetchAlphabetical() { - $result = NingApi::instance()->network->fetchAlphabetical(); - $this->assertTrue($result['success']); - } - - public function testGet_old() { - $fields = "name"; - $path = sprintf("Network/alpha?fields=%s", $fields); - - $result = NingApi::instance()->get($path); - $this->assertTrue($result['success']); - } - - public function testAlpha_old() { - $count = 3; - $fields = "name"; - $path = sprintf("Network/alpha?count=%s&fields=%s", $count, - $fields); - - $result = NingApi::instance()->get($path); - $this->assertTrue($result['success']); - } - -} - -?> diff --git a/test/NingPhotoTest.php b/test/NingPhotoTest.php deleted file mode 100644 index dff7517..0000000 --- a/test/NingPhotoTest.php +++ /dev/null @@ -1,158 +0,0 @@ - "Photo Title", - "description" => "Photo Description", - "tag" => "tests", - "file" => "@" . __DIR__ . "/files/sample.jpg" - ); - return $parts; - } - - /** - * @group create - */ - public function testCreate() { - $result = NingApi::instance()->photo->create(self::photoData()); - $this->assertTrue($result['success']); - } - - /** - * @group update - */ - public function testUpdate() { - $newPhoto = NingApi::instance()->photo->create(self::photoData()); - $result = NingApi::instance()->photo->update($newPhoto); - $this->assertTrue($result['success']); - } - - /** - * @group update - */ - public function testUpdateById() { - $newPhoto = NingApi::instance()->photo->create(self::photoData()); - $args = array('id' => $newPhoto['id']); - $result = NingApi::instance()->photo->updateById($args); - $this->assertTrue($result['success']); - } - - public function testFetch() { - $newPhoto = NingApi::instance()->photo->create(self::photoData()); - $args = array('id' => $newPhoto['id']); - $result = NingApi::instance()->photo->fetch($args); - $this->assertTrue($result['success']); - } - - public function testFetchNRecent() { - $result = NingApi::instance()->photo->fetchNRecent(); - $this->assertTrue($result['success']); - } - - public function testFetchRecent() { - $result = NingApi::instance()->photo->fetchRecent(); - $this->assertTrue($result['success']); - } - - /** - * @group delete - */ - public function testDelete() { - $newPhoto = NingApi::instance()->photo->create(self::photoData()); - $result = NingApi::instance()->photo->delete($newPhoto); - $this->assertTrue($result['success']); - } - - /** - * @group count - */ - public function testGetCount() { - $args = array('createdAfter' => gmdate('c')); - $result = NingApi::instance()->photo->getCount($args); - $this->assertTrue($result['success']); - } - - /** - * @group count - */ - public function testGetCountCreatedAfter() { - $result = NingApi::instance()->photo->getCountCreatedAfter(gmdate('c')); - $this->assertTrue($result['success']); - } - - /** - * @group count - */ - public function testGetCountCreatedInLastNDays() { - $result = NingApi::instance()->photo->getCountCreatedInLastNDays(3); - $this->assertTrue($result['success']); - } - - private function create() { - $parts = array( - "title" => "Photo Title", - "description" => "Photo Description", - "file" => "@" . __DIR__ . "/files/sample.jpg" - ); - - $result = NingApi::instance()->post("Photo", $parts); - $this->assertTrue($result['success']); - - return $result; - } - - public function testRecent_old() { - $count = 3; - $fields = "title,author.url"; - $path = sprintf("Photo/recent?count=%s&fields=%s", $count, - $fields); - - $result = NingApi::instance()->get($path); - $this->assertTrue($result['success']); - } - - public function testCreate_old() { - $result = $this->create(); - } - - public function testUpdate_old() { - $result = $result = $this->create(); - - $parts = array( - "title" => "Updated Photo Title", - "description" => "Updated Photo Description", - "id" => $result['id'] - ); - - $result = NingApi::instance()->put("Photo", $parts); - $this->assertTrue($result['success']); - } - - public function testDelete_old() { - $result = $result = $this->create(); - - $path = sprintf("Photo?id=%s", $result['id']); - - $result = NingApi::instance()->delete($path); - $this->assertTrue($result['success']); - } - - public function testCount_old() { - date_default_timezone_set("UTC"); - $date = date("Y-m-d\TH:i:s\Z", strtotime("-2 days")); - - $path = sprintf("Photo/count?createdAfter=%s", $date); - $result = NingApi::instance()->get($path); - $this->assertTrue($result['success']); - } - -} - -?> diff --git a/test/NingTagTest.php b/test/NingTagTest.php deleted file mode 100644 index bc816d8..0000000 --- a/test/NingTagTest.php +++ /dev/null @@ -1,36 +0,0 @@ -tag->fetchUnordered($contentId); - $this->assertTrue($result['success']); - } - - public function testFetchNUnordered() { - $contentId = self::getContentId(); - $result = NingApi::instance()->tag->fetchNUnordered($contentId, self::FETCH_COUNT); - $this->assertTrue($result['success']); - } - - public function testFetchUnorderedNextPage() { - $contentId = self::getContentId(); - $result = NingApi::instance()->tag->fetchUnorderedNextPage($contentId); - $this->assertTrue($result['success']); - } - - private function getContentId() { - $client = NingApi::instance(); - $result = $client->blogPost->fetchNRecent(self::FETCH_COUNT); - return $result['entry'][0]['id']; - } - -} diff --git a/test/NingTestHelper.php b/test/NingTestHelper.php deleted file mode 100644 index fffbdc7..0000000 --- a/test/NingTestHelper.php +++ /dev/null @@ -1,9 +0,0 @@ - diff --git a/test/NingUserTest.php b/test/NingUserTest.php deleted file mode 100644 index 2a9aed4..0000000 --- a/test/NingUserTest.php +++ /dev/null @@ -1,78 +0,0 @@ -user->fetchRecent(); - $args = array('id' => $recent['entry'][0]['id']); - $result = NingApi::instance()->user->fetch($args); - $this->assertTrue($result['success']); - } - - /** - * @group nc - */ - public function testFetchRecent() { - $result = NingApi::instance()->user->fetchRecent(); - $this->assertTrue($result['success']); - } - - /** - * @group nc - */ - public function testFetchNRecent() { - $result = NingApi::instance()->user->fetchNRecent(5); - $this->assertTrue($result['success']); - } - - /** - * @group update - */ - public function testUpdateStatusMessage() { - $recent = NingApi::instance()->user->fetch(array()); - $userId = $recent['entry']['id']; - $message = "Hey guys just statusing up some messages."; - $result = NingApi::instance()->user->addStatusMessage($userId, $message); - $this->assertTrue($result['success']); - } - - public function testRecent_old() { - $count = 3; - $fields = "fullName"; - $path = sprintf("User/recent?count=%s&fields=%s", $count, - $fields); - - $result = NingApi::instance()->get($path); - $this->assertTrue($result['success']); - } - - public function testAlpha_old() { - $count = 3; - $fields = "fullName"; - $path = sprintf("User/alpha?count=%s&fields=%s", $count, - $fields); - - $result = NingApi::instance()->get($path); - $this->assertTrue($result['success']); - } - - public function testCount_old() { - date_default_timezone_set("UTC"); - $date = date("Y-m-d\TH:i:s\Z", strtotime("-2 days")); - - $path = sprintf("User/count?createdAfter=%s", $date); - $result = NingApi::instance()->get($path); - $this->assertTrue($result['success']); - } - -} - -?> \ No newline at end of file diff --git a/test/NingVideoTest.php b/test/NingVideoTest.php deleted file mode 100644 index 9377ca9..0000000 --- a/test/NingVideoTest.php +++ /dev/null @@ -1,36 +0,0 @@ -video->fetchRecent(); - $this->assertTrue($result['success']); - } - - public function testRecent_old() { - $count = 3; - $fields = "title,author.url"; - $path = sprintf("Video/recent?count=%s&fields=%s", $count, - $fields); - - $result = NingApi::instance()->get($path); - $this->assertTrue($result['success']); - } - - public function testCount_old() { - date_default_timezone_set("UTC"); - $date = date("Y-m-d\TH:i:s\Z", strtotime("-2 days")); - - $path = sprintf("Video/count?createdAfter=%s", $date); - $result = NingApi::instance()->get($path); - $this->assertTrue($result['success']); - } - -} - -?> diff --git a/test/PhotoTest.php b/test/PhotoTest.php new file mode 100644 index 0000000..0a59215 --- /dev/null +++ b/test/PhotoTest.php @@ -0,0 +1,125 @@ +ningApi = $ningApi; + + $this->ningApi->login(TestConfig::EMAIL, TestConfig::PASSWORD); + } + + private function create() { + $bundleId = $this->getBundleId(); + $parts = array( + 'bundleId' => $bundleId, + 'title' => 'Photo Title', + 'description' => 'Photo Description', + 'photo' => '@' . __DIR__ . '/files/sample.jpg' + ); + + $result = $this->ningApi->post('Photo', $parts); + $this->assertTrue($result['success']); + + return $result; + } + + private function getBundleId() { + $bundleId = 'none'; + $count = 1; + $fields = 'id'; + $entryContentType = 'Photo'; + $path = sprintf('Bundle/recent?count=%s&fields=%s&entryContentType=%s', $count, + $fields, $entryContentType); + + $result = $this->ningApi->get($path); + if (isset($result['entry'][0]['id'])) { + $bundleId = $result['entry'][0]['id']; + } + + return $bundleId; + } + + public function testGet() { + $result = $this->create(); + $fields = 'author,title'; + $path = sprintf('Photo/?id=%s&fields=%s', $result['id'], $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testRecent() { + $count = 3; + $fields = 'title,author.url'; + $bundleId = $this->getBundleId(); + $path = sprintf('Photo/recent?count=%s&fields=%s&bundleId=%s', $count, + $fields, $bundleId); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testFeatured() { + $count = 3; + $fields = 'title, author.url'; + $bundleId = $this->getBundleId(); + $path = sprintf('Photo/featured?count=%s&fields=%s&bundleId=%s', $count, + $fields, $bundleId); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testCreate() { + $result = $this->create(); + $this->assertTrue($result['success']); + } + + public function testUpdate() { + $result = $this->create(); + + $parts = array( + 'title' => 'Updated Photo Title', + 'description' => 'Updated Photo Description', + 'id' => $result['id'] + ); + + $result = $this->ningApi->put('Photo', $parts); + $this->assertTrue($result['success']); + } + + public function testDelete() { + $result = $this->create(); + + $path = sprintf('Photo?id=%s', $result['id']); + + $result = $this->ningApi->delete($path); + $this->assertTrue($result['success']); + } + + public function testCount() { + date_default_timezone_set('UTC'); + $date = date('Y-m-d\TH:i:s\Z', strtotime('-2 days')); + $bundleId = $this->getBundleId(); + + $path = sprintf('Photo/count?createdAfter=%s&bundleId=%s', $date, $bundleId); + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + protected function tearDown() { + $this->ningApi = NULL; + } +} diff --git a/test/SitePageTest.php b/test/SitePageTest.php new file mode 100644 index 0000000..de7a819 --- /dev/null +++ b/test/SitePageTest.php @@ -0,0 +1,51 @@ +ningApi = $ningApi; + + $this->ningApi->login(TestConfig::EMAIL, TestConfig::PASSWORD); + } + + private function create($customPath) { + $parts = array( + 'targetType' => 'customPage', + 'customPath' => $customPath, + 'viewerType' => 'member', + 'contributorType' => 'admin' + ); + + $result = $this->ningApi->post('SitePage', $parts); + $this->assertTrue($result['success']); + + return $result; + } + + public function testCreate() { + $result = $this->create('sitePageTestCreate'); + $this->assertTrue($result['success']); + } + + public function testGet() { + $result = $this->create('sitePageTestGet'); + $fields = 'targetType,published'; + $path = sprintf('SitePage/?id=%s&fields=%s', $result['id'], $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + +} \ No newline at end of file diff --git a/test/TestConfig.php b/test/TestConfig.php new file mode 100644 index 0000000..06cc297 --- /dev/null +++ b/test/TestConfig.php @@ -0,0 +1,12 @@ +ningApi = $ningApi; + } + + public function testLogin() { + $result = $this->ningApi->login(TestConfig::EMAIL, + TestConfig::PASSWORD); + $this->assertTrue($result['success']); + } + + protected function tearDown() { + $this->ningApi = NULL; + } +} \ No newline at end of file diff --git a/test/UserTest.php b/test/UserTest.php new file mode 100644 index 0000000..e25eb56 --- /dev/null +++ b/test/UserTest.php @@ -0,0 +1,94 @@ +ningApi = $ningApi; + + $this->ningApi->login(TestConfig::EMAIL, TestConfig::PASSWORD); + } + + public function create($n) { + $parts = array( + 'email' => 'testUser'.$n.'@ning.com', + 'password' => 'Test1234', + 'fullName' => 'User Create Test' + ); + + $result = $this->ningApi->post('User', $parts); + $this->assertTrue($result['success']); + $this->userId = $result['id']; + return $result; + } + + public function testCreate() { + $result = $this->create(1); + $this->assertTrue($result['success']); + } + + public function testUpdate() { + $result = $this->create(2); + $parts = array( + 'id' => $result['id'], + 'fullName' => 'User Update Test' + ); + + $result = $this->ningApi->put('User', $parts); + $this->assertTrue($result['success']); + } + + public function testGet() { + $result = $this->create(3); + $fields = 'email,fullName'; + $path = sprintf('User/?id=%s&fields=%s', $result['id'], $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testRecent() { + $count = 3; + $fields = 'fullName,createdDate'; + $path = sprintf('User/recent?count=%s&fields=%s', $count, + $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testFeatured() { + $count = 3; + $fields = 'fullName,featuredDate'; + $path = sprintf('User/featured?count=%s&fields=%s', $count, + $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + public function testPending() { + $count = 3; + $fields = 'fullName,createdDate'; + $path = sprintf('User/pending?count=%s&fields=%s', $count, + $fields); + + $result = $this->ningApi->get($path); + $this->assertTrue($result['success']); + } + + protected function tearDown() { + $this->ningApi = NULL; + } +} From c45dfc6fa0c8213d6483f5d81eadccc6a6a49624 Mon Sep 17 00:00:00 2001 From: Jill Earles Date: Thu, 3 Apr 2014 16:28:26 -0700 Subject: [PATCH 2/6] Added note regarding branch to use for Ning 2 client --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f466d55..406dc7c 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,14 @@ The Ning API is a RESTful API that allows developers to access the content on their Ning Networks. The [Ning 3.0 API Documentation][3] contains a complete API reference. +For the Ning 2.0 version of this client, use branch [ning2-apiv1-master][4]. + Support ======= If you find an issue with this library, please file a bug on our -[issues page][4]. +[issues page][5]. Example Usage @@ -24,4 +26,5 @@ See the `/test` directory for examples of how to use this library. [1]: https://github.com/ning/ning-api-php [2]: http://www.ning.com/ [3]: http://www.ning.com/ning3help/ning-v2-api-documentation/ -[4]: https://github.com/ning/ning-api-php/issues \ No newline at end of file +[4]: https://github.com/ning/ning-api-php/tree/ning2-apiv1-master +[5]: https://github.com/ning/ning-api-php/issues \ No newline at end of file From e53e0a97c330c7538d5aa0f58267be8964726a12 Mon Sep 17 00:00:00 2001 From: Jonathan Aquino Date: Fri, 31 Jul 2015 11:51:30 -0700 Subject: [PATCH 3/6] Clarify when to use the Ning 2.0 API vs the current API. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 406dc7c..63faabd 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ their Ning Networks. The [Ning 3.0 API Documentation][3] contains a complete API reference. For the Ning 2.0 version of this client, use branch [ning2-apiv1-master][4]. +Please use the Ning 2.0 version if your Ning Network was created before March +13, 2013. Support From 4731db80fb759dc983625285812142c5dac338ed Mon Sep 17 00:00:00 2001 From: Jonathan Aquino Date: Fri, 9 Oct 2015 15:44:17 -0700 Subject: [PATCH 4/6] Doc tweaks. --- README.md | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 63faabd..fe97243 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,14 @@ Overview [ning-api-php][1] is a PHP client for accessing the [Ning][2] API. The Ning API is a RESTful API that allows developers to access the content on -their Ning Networks. The [Ning 3.0 API Documentation][3] contains a complete API -reference. +their Ning Networks. + +For examples, see the [test directory][6]. + +The [Ning 3.0 API Documentation][3] contains a complete API reference. For the Ning 2.0 version of this client, use branch [ning2-apiv1-master][4]. -Please use the Ning 2.0 version if your Ning Network was created before March +Please use this version if your Ning Network was created before March 13, 2013. @@ -18,15 +21,9 @@ Support If you find an issue with this library, please file a bug on our [issues page][5]. - -Example Usage -============= - -See the `/test` directory for examples of how to use this library. - - [1]: https://github.com/ning/ning-api-php [2]: http://www.ning.com/ [3]: http://www.ning.com/ning3help/ning-v2-api-documentation/ [4]: https://github.com/ning/ning-api-php/tree/ning2-apiv1-master -[5]: https://github.com/ning/ning-api-php/issues \ No newline at end of file +[5]: https://github.com/ning/ning-api-php/issues +[6]: https://github.com/ning/ning-api-php/tree/master/test \ No newline at end of file From d4cb9e297a3baa729f7cc754a912aa3eb42413b4 Mon Sep 17 00:00:00 2001 From: Jonathan Aquino Date: Fri, 9 Oct 2015 15:45:22 -0700 Subject: [PATCH 5/6] More doc tweaks. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fe97243..cacfc96 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ Overview ======== -[ning-api-php][1] is a PHP client for accessing the [Ning][2] API. +[ning-api-php][1] is a PHP client for accessing the [Ning][2] API for Ning Networks +created after March 13, 2013. The Ning API is a RESTful API that allows developers to access the content on their Ning Networks. From cbefe0169e1c18796483412205acc2cbbddf16d9 Mon Sep 17 00:00:00 2001 From: Jonathan Aquino Date: Fri, 9 Oct 2015 15:46:37 -0700 Subject: [PATCH 6/6] Yet more doc tweaks. --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cacfc96..c1634e8 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,15 @@ Overview ======== [ning-api-php][1] is a PHP client for accessing the [Ning][2] API for Ning Networks -created after March 13, 2013. - -The Ning API is a RESTful API that allows developers to access the content on -their Ning Networks. +created after March 13, 2013. This is a RESTful API that allows developers to +access the content on their Ning Networks. For examples, see the [test directory][6]. The [Ning 3.0 API Documentation][3] contains a complete API reference. For the Ning 2.0 version of this client, use branch [ning2-apiv1-master][4]. -Please use this version if your Ning Network was created before March +Please use that version if your Ning Network was created before March 13, 2013.