View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFPROP:Proposal Zone Template}

{zone-data:component-name}
Zend_Service_Instagram
{zone-data}

{zone-data:proposer-list}
[Mauricio Cuenca|mailto:macuenca@gmail.com]
{zone-data}

{zone-data:liaison}
TBD
{zone-data}

{zone-data:revision}
1.0 - 06 March 2011: Initial Draft.
{zone-data}

{zone-data:overview}
Zend_Service_Instagram is a full implementation of the official Instagram API. It provides an object oriented interface to the API and returns data in JSON format or PHP data objects.
{zone-data}

{zone-data:references}
* [Instagram Developer|http://instagr.am/developer/]
* [Instagram PHP API implementation|https://github.com/macuenca/Instagram-PHP-API]
{zone-data}

{zone-data:requirements}
* This component *will* fully implement Instagram official API.
* This component should namespace the API methods as they are stated in Instagram's API documentation.
* This component *will not* support real-time photo updates.
{zone-data}

{zone-data:dependencies}
* Zend_Oauth
* Zend_Service_Exception
* Zend_Http_Client
* Zend_Http_Client_Adapter_Curl
* Zend_Http_Client_Exception
{zone-data}

{zone-data:operation}
Zend_Service_Instagram will allow a developer an easy interaction with the Instagram API in an object oriented manner, supporting such actions as getting users' information, browse through popular media, manage users' relationships, comments, likes, tags and locations. All data returned can be represented whether in JSON format or as PHP data objects. Zend_Service_Instagram creates a PHP client for the Instagram API.
{zone-data}

{zone-data:milestones}
* Milestone 1: Proposal, Community Review and Acceptance.
* Milestone 2: Unit tests exist, work, and are checked into versioning system.
* Milestone 4: Initial documentation exists.
{zone-data}

{zone-data:class-list}
* Zend_Instagram_Exception
* Zend_Instagram
{zone-data}

{zone-data:use-cases}
||UC-01 Users||



{composition-setup}

{deck:id=Users}
{card:label=Get Info}
Get basic information about a user.
{code:php}
$instagram = new Instagram($config);
$userInfo = $instagram->getUser(3847232);
{code}
{card}

{card:label=Get Feed}
See the authenticated user's feed.
{code:php}
$instagram = new Instagram($config);
$userFeed = $instagram->getUserFeed(100, 90);
{code}
{card}

{card:label=Get Recent Info}
Get the most recent media published by a user.
{code:php}
$instagram = new Instagram($config);
$recentInfo = $instagram->getUserRecent(3847232);
{code}
{card}

{card:label=Search Username}
Search for a user by name.
{code:php}
$instagram = new Instagram($config);
$searchResults = $instagram->searchUser('Mauricio');
{code}
{card}

{deck}


||UC-02 Relationships||

{deck:id=Relationships}
{card:label=User Follows}
Get the list of users this user follows.
{code:php}
$instagram = new Instagram($config); 
$userFollows = $instagram->getUserFollows(3847232); 
{code}
{card}

{card:label=User Followed By}
Get the list of users this user is followed by.
{code:php}
$instagram = new Instagram($config);
$followedBy = $instagram->getUserFollowedBy(3847232);
{code}
{card}

{card:label=Follow Requests}
List the users who have requested this user's permission to follow.
{code:php}
$instagram = new Instagram($config); 
$followRequests = $instagram->getUserRequestedBy();
{code}
{card}

{card:label=User Relationships}
Get information about the current user's relationship (follow/following/etc) to another user.
{code:php}
$instagram = new Instagram($config); 
$relationships = $instagram->getUserRelationship(3847232);
{code}
{card}

{deck}


||UC-03 Media||

{deck:id=Media}
{card:label=Media Object Info}
Get information about a media object.
{code:php}
$instagram = new Instagram($config); 
$media = $instagram->getMedia(87319873891);
{code}
{card}

{card:label=Search Media By Location}
Search for media in a given area.
{code:php}
$instagram = new Instagram($config); 
$nearbyMedia = $instagram->mediaSearch(3.3727468, -0.21312389);
{code}
{card}

{card:label=Popular Media}
Get a list of what media is most popular at the moment.
{code:php}
$instagram = new Instagram($config); 
$popular = $instagram->getPopularMedia();
{code}
{card}

{deck}


||UC-04 Comments||

{deck:id=Comments}
{card:label=Media Comments}
Get a full list of comments on a media.
{code:php}
$instagram = new Instagram($config); 
$comments = $instagram->getMediaComments(87319873891);
{code}
{card}

{card:label=Create Media Comment}
Create a comment on a media.
{code:php}
$instagram = new Instagram($config); 
$instagram->postMediaComment(87319873891, 'A beautiful landscape');
{code}
{card}

{card:label=Remove Media Comment}
Remove a comment either on the authenticated user's media or authored by the authenticated user.
{code:php}
$instagram = new Instagram($config); 
$instagram->deleteComment(87319873891, 2);
{code}
{card}

{deck}

||UC-05 Likes||

{deck:id=Likes}
{card:label=Get Likes}
Get a list of users who have liked this media.
{code:php}
$instagram = new Instagram($config); 
$likes = $instagram->getLikes(87319873891);
{code}
{card}

{card:label=Set Like}
Set a like on this media by the currently authenticated user.
{code:php}
$instagram = new Instagram($config);
$instagram->postLike(87319873891);
{code}
{card}

{card:label=Remove Like}
Remove a like on this media by the currently authenticated user.
{code:php}
$instagram = new Instagram($config); 
$instagram->removeLike(87319873891); 
{code}
{card}

{deck}

||UC-06 Tags||

{deck:id=Tags}
{card:label=Get Tags}
Get information about a tag object.
{code:php}
$instagram = new Instagram($config); 
$tags = $instagram->getTags('landscape'); 
{code}
{card}

{card:label=Get Recent Tags}
Get a list of recently tagged media.
{code:php}
$instagram = new Instagram($config); 
$recentTags = $instagram->getRecentTags('landscape');
{code}
{card}

{card:label=Search Tags}
Search for tags by name.
{code:php}
$instagram = new Instagram($config); 
$tags = $instagram->searchTags('new york');
{code}
{card}

{deck}

||UC-07 Locations||

{deck:id=Locations}
{card:label=Get Location Info}
Get information about a tag object.
{code:php}
$instagram = new Instagram($config); 
$locationInfo = $instagram->getLocation(1); 
{code}
{card}

{card:label=Get Recent Media At Location}
Get a list of recent media objects from a given location.
{code:php}
$instagram = new Instagram($config); 
$recentMedia = $instagram->getLocationRecentMedia(1); 
{code}
{card}

{card:label=Search Location}
Search for a location by name and geographic coordinate.
{code:php}
$instagram = new Instagram($config); 
$location = $instagram->searchLocation(3.3727468, -0.21312389); 
{code}
{card}

{deck}


{zone-data}

{zone-data:skeletons}
{code:php}
require_once 'Zend/Http/Client.php';

class Zend_Service_Instagram extends Zend_Service {

/**
* The name of the GET param that holds the authentication code
* @var string
*/
const RESPONSE_CODE_PARAM = 'code';

/**
* Format for endpoint URL requests
* @var string
*/
protected $_endpointUrls = array(
'user' => 'https://api.instagram.com/v1/users/%d/?access_token=%s',
'user_search' => 'https://api.instagram.com/v1/users/search?q=%s&access_token=%s',
'user_follows' => 'https://api.instagram.com/v1/users/%d/follows?access_token=%s',
'media' => 'https://api.instagram.com/v1/media/%d?access_token=%s',
'media_popular' => 'https://api.instagram.com/v1/media/popular?access_token=%s',
'media_comments' => 'https://api.instagram.com/v1/media/%d/comments?access_token=%s',
'post_like' => 'https://api.instagram.com/v1/media/%d/likes,',
'remove_like' => 'https://api.instagram.com/v1/media/%d/likes?access_token=%s',
'tags' => 'https://api.instagram.com/v1/tags/%s?access_token=%s',
'tags_search' => 'https://api.instagram.com/v1/tags/search?q=%s&access_token=%s',
'locations' => 'https://api.instagram.com/v1/locations/%d?access_token=%s',
);

/**
* Configuration parameter
*/
protected $_config = array();

/**
* Access token
* @var string
*/
protected $_accessToken = null;

/**
* Holds the HTTP client instance
* @param Zend_Http_Client $httpClient
*/
protected $_httpClient = null;

/**
* Constructor needs to receive the config as an array
* @param mixed $config
*/
public function __construct($config = null) {
$this->_config = $config;
if (empty($config)) {
throw new InstagramException('Configuration params are empty or not an array.');
}
}

/**
* The init method is triggered on every call to retrieve the
* access token in case is not in the current instance.
*/
protected function _init() {}

/**
* Gets the code param received during the authorization step
*/
public function getCode() {
return $_GET[self::RESPONSE_CODE_PARAM];
}

/**
* Retrieves the OAuth token to be used in every request
* @return string
*/
protected function _getOauthToken() {}

/**
* Get basic information about a user.
* @param $id
* @param $oauthToken
*/
public function getUser($id) {}

/**
* See the authenticated user's feed.
* @param integer $maxId. Return media after this maxId.
* @param integer $minId. Return media before this minId.
*/
public function getUserFeed($maxId = null, $minId = null) {}

/**
* Get the most recent media published by a user.
* @param $id. User id
* @param $maxId. Return media after this maxId
* @param $minId. Return media before this minId
* @param $maxTimestamp. Return media before this UNIX timestamp
* @param $minTimestamp. Return media after this UNIX timestamp
*/
public function getUserRecent($id, $maxId = '', $minId = '',
$maxTimestamp = '', $minTimestamp = '') {}

/**
* Search for a user by name.
* @param string $name. A query string
*/
public function searchUser($name) {
}

/**
* Get the list of users this user follows.
* @param integer $id. The user id
*/
public function getUserFollows($id) {}

/**
* Get the list of users this user is followed by.
* @param integer $id
*/
public function getUserFollowedBy($id) {}

/**
* List the users who have requested this user's permission to follow
*/
public function getUserRequestedBy() {}

/**
* Get information about the current user's relationship
* @param integer $id
*/
public function getUserRelationship($id) {}

/**
* Modify the relationship between the current user and the target user
* In order to perform this action the scope must be set to 'relationships'
* @param integer $id
* @param string $action. One of follow/unfollow/block/unblock/approve/deny
*/
public function modifyUserRelationship($id, $action) {}

/**
* Get information about a media object.
* @param integer $mediaId
*/
public function getMedia($id) {}

/**
* Search for media in a given area.
* @param float $lat
* @param float $lng
* @param integer $maxTimestamp
* @param integer $minTimestamp
* @param integer $distance
*/
public function mediaSearch($lat, $lng, $maxTimestamp = '',
$minTimestamp = '', $distance = '') {}

/**
* Get a list of what media is most popular at the moment.
*/
public function getPopularMedia() {}

/**
* Get a full list of comments on a media.
* @param integer $id
*/
public function getMediaComments($id) {}

/**
* Create a comment on a media.
* @param integer $id
* @param string $text
*/
public function postMediaComment($id, $text) {}

/**
* Remove a comment either on the authenticated user's media
* @param integer $mediaId
* @param integer $commentId
*/
public function deleteComment($mediaId, $commentId) {}

/**
* Get a list of users who have liked this media.
* @param integer $mediaId
*/
public function getLikes($mediaId) {}

/**
* Set a like on this media by the currently authenticated user.
* @param integer $mediaId
*/
public function postLike($mediaId) {}

/**
* Remove a like on this media by the currently authenticated user.
* @param integer $mediaId
*/
public function removeLike($mediaId) {}

/**
* Get information about a tag object.
* @param string $tagName
*/
public function getTags($tagName) {}

/**
* Get a list of recently tagged media.
* @param string $tagName
* @param integer $maxId
* @param integer $minId
*/
public function getRecentTags($tagName, $maxId = '', $minId = '') {}

/**
* Search for tags by name - results are ordered first as an exact match
* @param string $tagName
*/
public function searchTags($tagName) {}

/**
* Get information about a location.
* @param integer $id
*/
public function getLocation($id) {}

/**
* Get a list of recent media objects from a given location.
* @param integer $locationId
*/
public function getLocationRecentMedia($id, $maxId = '', $minId = '',
$maxTimestamp = '', $minTimestamp = '') {}

/**
* Search for a location by name and geographic coordinate.
* @see http://instagr.am/developer/endpoints/locations/#get_locations_search
* @param float $lat
* @param float $lng
* @param integer $foursquareId
* @param integer $distance
*/
public function searchLocation($lat, $lng, $foursquareId = '', $distance = '') {}
}
{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>