From 03b3ce7d5441e36830645cb16cbccdafc3893edf Mon Sep 17 00:00:00 2001 From: Sammy Herring Date: Sat, 2 Apr 2016 22:09:59 +0100 Subject: [PATCH] Bug Fix for Class API There was an issue with the namespace function on my version of Wordpress, I have repositioned it to the start of the file which has removed any errors in my case. Others may be having the same issue - hope this helps. --- includes/class-apple-news.php | 190 +++++++++++++++++++++++++++++++--- 1 file changed, 174 insertions(+), 16 deletions(-) diff --git a/includes/class-apple-news.php b/includes/class-apple-news.php index 9fb441cb8..9c4d4cc3f 100644 --- a/includes/class-apple-news.php +++ b/includes/class-apple-news.php @@ -1,35 +1,193 @@ +endpoint = $endpoint; + $this->request = new Request( $credentials, $debug ); + } + + /** + * Sends a new article to a given channel. * - * @var string - * @access protected + * @param string $article The JSON string representing the article + * @param array $bundles An array of file paths for the article attachments + * + * @since 0.2.0 + * @param string $article + * @param string $channel_uuid + * @param array $bundles + * @return object + * @access public + */ + public function post_article_to_channel( $article, $channel_uuid, $bundles = array() ) { + $url = $this->endpoint . '/channels/' . $channel_uuid . '/articles'; + return $this->send_post_request( $url, $article, $bundles ); + } + + /** + * Updates an existing article to a given channel. + * + * @param string $article The JSON string representing the article + * @param array $bundles An array of file paths for the article attachments + * + * @since 0.2.0 + * @param string $uid + * @param string $article + * @param string $channel_uuid + * @param array $bundles + * @return object + * @access public + */ + public function update_article( $uid, $revision, $article, $bundles = array() ) { + $url = $this->endpoint . '/articles/' . $uid; + return $this->send_post_request( $url, $article, $bundles, array( + 'data' => array( 'revision' => $revision ), + ) ); + } + + /** + * Gets channel information. + * + * @since 0.2.0 + * @param string $channel_uuid + * @return object + * @access public + */ + public function get_channel( $channel_uuid ) { + $url = $this->endpoint . '/channels/' . $channel_uuid; + return $this->send_get_request( $url ); + } + + /** + * Gets article information. + * + * @since 0.2.0 + * @param int $article_id + * @return object + * @access public + */ + public function get_article( $article_id ) { + $url = $this->endpoint . '/articles/' . $article_id; + return $this->send_get_request( $url ); + } + + /** + * Deletes an article using a DELETE request. + * + * @since 0.4.0 + * @param int $article_id + * @return object + * @access public + */ + public function delete_article( $article_id ) { + $url = $this->endpoint . '/articles/' . $article_id; + return $this->send_delete_request( $url ); + } + + /** + * Gets all sections in the given channel. + * + * @since 0.2.0 + * @param string $channel_uuid + * @return object + * @access public + */ + public function get_sections( $channel_uuid ) { + $url = $this->endpoint . '/channels/' . $channel_uuid . '/sections'; + return $this->send_get_request( $url ); + } + + /** + * Gets information for a section. + * + * @since 0.2.0 + * @param string $section_id + * @return object + * @access public + */ + public function get_section( $section_id ) { + $url = $this->endpoint . '/sections/' . $section_id; + return $this->send_get_request( $url ); + } + + // Isolate request dependency. + // ------------------------------------------------------------------------- + + + /** + * Send a get request. + * + * @since 0.2.0 + * @param string $url + * @return object + * @access private + */ + private function send_get_request( $url ) { + return $this->request->get( $url ); + } + + /** + * Send a delete request. + * + * @since 0.2.0 + * @param string $url + * @return object + * @access private + */ + private function send_delete_request( $url ) { + return $this->request->delete( $url ); + } + + /** + * Send a post request. + * + * @since 0.2.0 + * @param string $url + * @param string $article + * @param array $bundles + * @param array $meta + * @return object + * @access private */ - protected $version = '0.9.0'; + private function send_post_request( $url, $article, $bundles, $meta = null ) { + return $this->request->post( $url, $article, $bundles, $meta ); + } }