Commits

elem...@60038091-bd4c-0410-8356-ef1767570a53  committed f330e34

Added user search to Search Object for simplicity.

  • Participants
  • Parent commits d9547df

Comments (0)

Files changed (1)

File src/com/photobucket/webapi/objects/Search.as

  
 package com.photobucket.webapi.objects
 {
+	import com.photobucket.webapi.interfaces.IMedia;
 	import com.photobucket.webapi.oauth.OAuthRequest;
 	import com.photobucket.webapi.oauth.urlEncode;
+	import com.photobucket.webapi.oauth.OAuthRequestMethod;
 	import com.photobucket.webapi.service.PhotobucketService;
-	import com.photobucket.webapi.interfaces.IMedia;
+	import flash.events.Event;
+	
+	
 	import mx.collections.ArrayCollection;
 	
 	/**
 			return media;
 		}
 
+		public function user(username:String, type:String = "image", page:int = 1):ArrayCollection {
+			var request:OAuthRequest = new OAuthRequest();
+			request.method = OAuthRequestMethod.GET;
+			if (type != "all") {
+				request.addParameter("type", type);
+			}
+			if (page != 1) {
+				request.addParameter("page", page.toString());
+			}
+			if (numberOfResults != 20) {
+				request.addParameter("perpage", numberOfResults.toString());
+			}
+			var mediaList:ArrayCollection = new ArrayCollection();
+			request.url = PhotobucketService.API_ROOT + '/user/' + urlEncode(username) + "/search";
+			request.result = function (value:Object):void {
+				var results:XML = value as XML;
+				for each (var mediaXML:XML in results..media) {
+					var media:IMedia = pbservice.mediaFactory(null, mediaXML);
+					mediaList.addItem(media);
+				}
+				mediaList.dispatchEvent(new Event(Event.COMPLETE));
+			}
+			request.fault = function (value:Object):void {
+				mediaList.dispatchEvent(new Event(Event.COMPLETE));
+			}
+			pbservice.makeRequest(request);		
+			return mediaList;			
+		}
+
 	}
 }