예제 #1
0
        public static void Authorize(this FlickrNet.Flickr flickr, OAuthAccessToken accessToken)
        {
            if (!IsComplete(accessToken)) throw new AuthorizationException();

            flickr.OAuthAccessToken = accessToken.Token;
            flickr.OAuthAccessTokenSecret = accessToken.TokenSecret;
        }
예제 #2
0
        public IEnumerable<Photo> GetItems(string setName, OAuthAccessToken accessToken)
        {
            if (accessToken == null) throw new ArgumentNullException("accessToken");

            _flickr.Authorize(accessToken);

            if (string.IsNullOrEmpty(setName))
            {
                var publicPhotos = _flickr.PeopleGetPublicPhotos(accessToken.UserId);

                return publicPhotos
                    .Select(Map);
            }

            var photoSets = _flickr.PhotosetsGetList();
            var photoSet = photoSets
                .SingleOrDefault(p => p.Title == setName);

            if (photoSet == null)
            {
                return new List<Photo>();
            }

            var photos = _flickr.PhotosetsGetPhotos(photoSet.PhotosetId);

            return photos
                .Select(Map);
        }
예제 #3
0
        public static OAuthAccessToken CreateSingle()
        {
            var entity = new OAuthAccessToken();

            entity.FullName = string.Format(CultureInfo.InvariantCulture, "FullName {0}", entity.Id);
            entity.Token = string.Format(CultureInfo.InvariantCulture, "Token {0}", entity.Id);
            entity.TokenSecret = string.Format(CultureInfo.InvariantCulture, "TokenSecret {0}", entity.Id);
            entity.UserId = string.Format(CultureInfo.InvariantCulture, "UserId {0}", entity.Id);
            entity.Username = string.Format(CultureInfo.InvariantCulture, "Username {0}", entity.Id);

            return entity;
        }
예제 #4
0
        public IEnumerable<AudioTrack> GetItems(string setName, OAuthAccessToken accessToken)
        {
            var soundCloud = new Api.SoundCloud(_apiKey, accessToken.Token);

            if (string.IsNullOrEmpty(setName))
            {
                return soundCloud.Me.Tracks.Get()
                    .Select(Map);
            }

            return soundCloud.Me.Playlists.Get()
                .Single(p => p.title == setName)
                .tracks
                .Select(Map);
        }
예제 #5
0
        public AudioTrack GetItem(int id, OAuthAccessToken accessToken)
        {
            var soundCloud = new Api.SoundCloud(_apiKey, accessToken.Token);

            return Map(soundCloud.Tracks[id].Get());
        }
예제 #6
0
        public string UploadItem(Stream data, string setName, string title, OAuthAccessToken accessToken)
        {
            var soundCloud = new Api.SoundCloud(_apiKey, accessToken.Token);

            byte[] buffer;
            using (var ms = new MemoryStream())
            {
                data.CopyTo(ms);
                buffer = ms.ToArray();
            }
            var track = new Track
                {
                    asset_data = buffer,
                    title = title
                };

            return soundCloud.Tracks.Post(track).stream_url;
        }
예제 #7
0
        public string UploadItem(Stream data, string setName, string fileName, OAuthAccessToken accessToken)
        {
            if (data == null) throw new ArgumentNullException("data");
            if (accessToken == null) throw new ArgumentNullException("accessToken");

            _flickr.Authorize(accessToken);

            var photoId = _flickr.UploadPicture(
                data,
                fileName,
                Path.GetFileNameWithoutExtension(fileName),
                description: "",
                tags: "music band",
                isPublic: true,
                isFamily: false,
                isFriend: false,
                contentType: FlickrNet.ContentType.Photo,
                safetyLevel: FlickrNet.SafetyLevel.Safe,
                hiddenFromSearch: FlickrNet.HiddenFromSearch.Visible);

            if (string.IsNullOrEmpty(setName)) return photoId;

            var photoSets = _flickr.PhotosetsGetList();
            var photoSet = photoSets
                .SingleOrDefault(p => p.Title == setName);

            if (photoSet == null)
            {
                _flickr.PhotosetsCreate(setName, photoId);
            }
            else
            {
                _flickr.PhotosetsAddPhoto(photoSet.PhotosetId, photoId);
            }

            return photoId;
        }
예제 #8
0
 public string UploadItem(Stream data, string setName, string title, OAuthAccessToken accessToken)
 {
     throw new NotImplementedException();
 }
예제 #9
0
 public IEnumerable<Video> GetItems(string setName, OAuthAccessToken accessToken, int page, int pageSize)
 {
     throw new NotImplementedException();
 }
예제 #10
0
 public Video GetItem(int id, OAuthAccessToken accessToken)
 {
     throw new NotImplementedException();
 }
예제 #11
0
 private static bool IsComplete(OAuthAccessToken accessToken)
 {
     return !(string.IsNullOrEmpty(accessToken.Token) ||
             string.IsNullOrEmpty(accessToken.TokenSecret) ||
             string.IsNullOrEmpty(accessToken.UserId));
 }