error_msg)) throw new Exception($rval->error_msg, $http_status); else throw new Exception("Unknown error: ".$result, $http_status); } return $rval; } /* * getFeedList */ $parameters = array( 'action' => 'getFeedList', ); try { $rval = apiRequest($parameters); printf("Feed Groups\n"); $i = 0; foreach ($rval->feed_groups as $feed_group) { printf(" %2d: %s\n", $i++, $feed_group); } printf("Feeds\n"); $i = 0; foreach ($rval->feed_list as $feed) { printf(" %2d: ID: %d, %s: %s\n", $i++, $feed->feed_id, $feed->feed_group, $feed->feed_name); } } catch (Exception $e) { printf("%s: failed: HTTP status: %d: %s\n", $parameters['action'], $e->getCode(), $e->getMessage()); } /* * searchFeedList */ $parameters = array( 'action' => 'searchFeedList', 'query_string' => 'internet of things', ); printf("\nSearch for Feeds related to: '%s'\n", $parameters['query_string']); try { $rval = apiRequest($parameters); $i = 0; foreach ($rval->matching_feeds as $feed) { printf(" %2d: ID: %d, %s: %s\n", $i++, $feed->feed_id, $feed->feed_group, $feed->feed_name); } } catch (Exception $e) { printf("%s: failed: HTTP status: %d: %s\n", $parameters['action'], $e->getCode(), $e->getMessage()); } function printArticles($articles) { $i = 0; foreach ($articles as $article) { printf(" %2d: ID: %d\n", $i++, $article->id); printf(" Link: %s\n", $article->link); printf(" Title: %s\n", $article->title); printf(" Description: %s\n", $article->description); if (isset($article->feed_id)) printf(" Feed ID: %s\n", $article->feed_id); if (isset($article->feed_group)) printf(" Feed Group: %s\n", $article->feed_group); if (isset($article->feed_name)) printf(" Feed Name: %s\n", $article->feed_name); echo PHP_EOL; } } /* * searchArticles */ $parameters = array( 'action' => 'searchArticles', 'query_string' => 'Electric Vehicles', 'count' => 2, ); printf("\nSearch for 2 most recent articles related to: '%s'\n", $parameters['query_string']); try { $rval = apiRequest($parameters); printArticles($rval->matching_articles); } catch (Exception $e) { printf("%s: failed: HTTP status: %d: %s\n", $parameters['action'], $e->getCode(), $e->getMessage()); } printf("Get the next 2 most recent articles\n"); $parameters['offset'] = 2; try { $rval = apiRequest($parameters); printArticles($rval->matching_articles); } catch (Exception $e) { printf("%s: failed: HTTP status: %d: %s\n", $parameters['action'], $e->getCode(), $e->getMessage()); } /* * getFeedID */ $parameters = array( 'action' => 'getFeedID', 'feed_group' => 'Automotive', 'feed_name' => 'Electric Vehicles', ); printf("\nGet the FeedID for the %s / %s Feed\n", $parameters['feed_group'], $parameters['feed_name']); try { $rval = apiRequest($parameters); $feedID = $rval->feed_id; printf(" %s / %s feed has feedID %d\n", $parameters['feed_group'], $parameters['feed_name'], $feedID); } catch (Exception $e) { printf("%s: failed: HTTP status: %d: %s\n", $parameters['action'], $e->getCode(), $e->getMessage()); } /* * getArticles */ $parameters = array( 'action' => 'getArticles', 'feed_id' => $feedID, 'count' => 2, ); printf("\nGet the for 2 most recent articles for feed: %d\n", $parameters['feed_id']); try { $rval = apiRequest($parameters); printArticles($rval->articles); $pagingCursor = $rval->paging_cursor; } catch (Exception $e) { printf("%s: failed: HTTP status: %d: %s\n", $parameters['action'], $e->getCode(), $e->getMessage()); } printf("Get the next 2 most recent articles\n"); $parameters['paging_cursor'] = $pagingCursor; try { $rval = apiRequest($parameters); printArticles($rval->articles); } catch (Exception $e) { printf("%s: failed: HTTP status: %d: %s\n", $parameters['action'], $e->getCode(), $e->getMessage()); }