Skip to content
Browse files

Add search and getSearch methods to Flickr.Client.

  • Loading branch information...
1 parent 723e471 commit b2b30891095843cb1a1dd163bad86c987423f84d @beastaugh beastaugh committed Jun 29, 2011
Showing with 69 additions and 17 deletions.
  1. +5 −0 CHANGELOG
  2. +11 −0 README.md
  3. +34 −1 source/flickr.js
  4. +0 −1 source/photo.js
  5. +19 −15 test/index.html
View
5 CHANGELOG
@@ -1,3 +1,8 @@
+Version 1.3.0, 2011.06.29
+
+* Added search and getSearch methods to the Flickr.Client class, wrapping the
+ search method of Flickr's API.
+
Version 1.2.0, 2010.09.03
* Extended the Flickr.Client class API with findByUsername, getUserId,
View
11 README.md
@@ -56,6 +56,17 @@ convenient API (detailed below).
* `photosOf` is the unwrapped version of `getPhotosOf`.
* `findByUsername` is the unwrapped version of `getUserId`.
+#### Search methods
+
+The search methods deviate slightly from the interface described above. Instead
+of an `id` value, they accept a `text` string which is the search query to be
+run. The `search` method also takes a `params` object before the `callback`
+parameter, which allows further search options to be set.
+
+* `search` calls the callback with a list of photos from the search.
+* `getSearch` is the wrapped version of `search`, and does not accept a
+ `params` object, just a search string, callback and optional scope argument.
+
### `Flickr.Photo` class
Instances of the `Flickr.Photo` class have the following methods available.
View
35 source/flickr.js
@@ -57,6 +57,40 @@ Flickr = {
},
/**
+ * Flickr.Client#search(text, callback, scope) -> undefined
+ * - text (String)
+ * - params (Object)
+ * - callback (Function)
+ * - scope (Object)
+ *
+ * Searches Flickr for photos matching the given string. The search can be
+ * customised by passing in additional parameters via the `params` object;
+ * for documentation of allowed parameters please refer to the Flickr API:
+ * http://www.flickr.com/services/api/flickr.photos.search.html
+ **/
+ search: function(text, params, callback, scope) {
+ params = params || {};
+ params.text = text;
+ this.call('photos.search', params, callback, scope);
+ },
+
+ /**
+ * Flickr.Client#getSearch(text, callback, scope) -> undefined
+ * - text (String)
+ * - callback (Function)
+ * - scope (Object)
+ *
+ * Searches Flickr for photos matching the given string. Result items are
+ * wrapped as `Flickr.Photo` objects.
+ **/
+ getSearch: function(text, callback, scope) {
+ var wrap = this._wrapPhotos;
+ this.search(text, {}, function(data) {
+ callback.call(scope, wrap(data.photos, 'photo'));
+ });
+ },
+
+ /**
* Flickr.Client#findByUsername(username, callback, scope) -> undefined
* - username (String)
* - callback (Function)
@@ -229,4 +263,3 @@ Flickr = {
REST_ENDPOINT: 'http://api.flickr.com/services/rest/',
FEED_ENDPOINT: 'http://api.flickr.com/services/feeds/'
};
-
View
1 source/photo.js
@@ -99,4 +99,3 @@ Flickr.Photo = new JS.Class({
});
})(key, map[key]);
})();
-
View
34 test/index.html
@@ -1,38 +1,38 @@
<!DOCTYPE html>
<html><head>
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+ <meta charset="utf-8">
<title>Flickr Tests</title>
<style type="text/css">
body {
- margin:0;
- padding:20px;
+ margin: 0;
+ padding: 20px;
}
#gallery {
- margin:0;
- padding:0;
+ margin: 0;
+ padding: 0;
}
#gallery li {
- list-style:none;
- margin:0 10px 10px 0;
- padding:0;
- float:left;
- height:240px;
- overflow:hidden;
+ list-style: none;
+ margin: 0 10px 10px 0;
+ padding: 0;
+ float: left;
+ height: 240px;
+ overflow: hidden;
}
#gallery img {
- display:block;
- border:none;
+ display: block;
+ border: none;
}
</style>
<script src="http://js.othermedia.com/helium.js" type="text/javascript"></script>
<script type="text/javascript">
Helium.use('yui', '2.8.0r4');
- Helium.use('ojay', '0.4.2');
+ Helium.use('ojay', '0.5.0');
</script>
<script src="./packages.js" type="text/javascript"></script>
</head><body>
@@ -61,8 +61,12 @@
Client = new Flickr.Client('63bb4efae64c3c04510c484dcdaef263');
+ Client.getSearch('Mycenae', function(photos) {
+ addPhotosToList(photos.slice(0, 20));
+ });
+
Client.getGroupPhotos('52240328087@N01', function(photos) {
- addPhotosToList(photos);
+ addPhotosToList(photos.slice(0, 20));
if (photos.length > 0) {
Client.getPublicPhotos(photos[0].getAuthorId(), function(photos) {

0 comments on commit b2b3089

Please sign in to comment.
Something went wrong with that request. Please try again.