示例#1
0
        public void AddParameter_DuplicateParameterDifferentValue_ThrowsException()
        {
            var b = new UrlBuilder("http://www.example.com/");

            b.AddParameter("UserId", "1");
            b.AddParameter("UserId", "2");
        }
示例#2
0
        /// <summary>
        /// Gets the genre list.
        /// </summary>
        /// <param name="baseUrl">The base URL.</param>
        /// <returns>The genre list</returns>
        protected IEnumerable <GenreResult> GetGenreList(string baseUrl)
        {
            var urlBuilder = new UrlBuilder(baseUrl);

            urlBuilder.AddParameter("api_key", _configurationApi.GetApiKey());
            urlBuilder.AddParameter("language", "en-GB");

            var apiResponse = ApiHelper.MakeApiRequest(urlBuilder.BuildUrl());

            var genreListResult = JsonConvert.DeserializeObject <GenreListResult>(apiResponse);

            return(genreListResult.Genres);
        }
示例#3
0
        /// <summary>
        /// Gets the movie details.
        /// </summary>
        /// <param name="movieId">The movie identifier.</param>
        /// <returns>Movie details</returns>
        private ExtendedMovieResult GetMovieDetails(int movieId)
        {
            string baseUrl = string.Format(ApiUrls.Movie.Details, movieId);

            var urlBuilder = new UrlBuilder(baseUrl);

            urlBuilder.AddParameter("api_key", _configurationApi.GetApiKey());
            urlBuilder.AddParameter("language", "en-GB");

            var apiResponse = ApiHelper.MakeApiRequest(urlBuilder.BuildUrl());

            var movieDetails = JsonConvert.DeserializeObject <ExtendedMovieResult>(apiResponse);

            return(movieDetails);
        }
示例#4
0
        public void AddParameter_NewParameter_IsAddedToUrl()
        {
            var b = new UrlBuilder("http://www.example.com/");

            b.AddParameter("UserId", 1);

            Assert.AreEqual("http://www.example.com/?UserId=1", b.ToString());
        }
示例#5
0
        public void MergeParameter_AddAndMergeDifferentValues_LastParameterOverwrites()
        {
            var b = new UrlBuilder("http://www.example.com/");

            b.AddParameter("UserId", "1");
            b.MergeParameter("UserId", "2");

            Assert.AreEqual("http://www.example.com/?UserId=2", b.ToString());
        }
        public MessageBoxEventBatch GetEvents([NotNull] string authToken, [CanBeNull] string exclusiveEventPointer, int?count = null)
        {
            var url = new UrlBuilder(BaseUri, relativeUrl + "GetEvents");

            if (!string.IsNullOrWhiteSpace(exclusiveEventPointer))
            {
                url.AddParameter("exclusiveEventPointer", exclusiveEventPointer);
            }
            if (count.HasValue)
            {
                url.AddParameter("count", count.Value.ToString(CultureInfo.InvariantCulture));
            }
            var boxEventBatch = MakeGetRequest <MessageBoxEventBatch>(url.ToUri(), authToken);

            boxEventBatch.Events = boxEventBatch.Events ?? new MessageBoxEvent[0];
            foreach (var boxEvent in boxEventBatch.Events)
            {
                AdjustEventContent(boxEvent);
            }
            return(boxEventBatch);
        }
        public MessageBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] string boxId, DateTime fromDateTime, uint?count = null)
        {
            var url = new UrlBuilder(BaseUri, relativeUrl + "GetEventsFrom")
                      .AddParameter(boxIdUrlParameterName, boxId)
                      .AddParameter("fromDateTime", DateTimeUtils.ToString(fromDateTime));

            if (count.HasValue)
            {
                url.AddParameter("count", count.Value.ToString(CultureInfo.InvariantCulture));
            }
            return(GetEvents(authToken, url));
        }
        public MessageBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] string boxId, string exclusiveEventId, uint?count = null)
        {
            var url = new UrlBuilder(BaseUri, relativeUrl + "GetEvents")
                      .AddParameter(boxIdUrlParameterName, boxId)
                      .AddParameter("exclusiveEventId", exclusiveEventId);

            if (count.HasValue)
            {
                url.AddParameter("count", count.Value.ToString(CultureInfo.InvariantCulture));
            }
            return(GetEvents(authToken, url));
        }
        /// <summary>
        /// Gets the configuration from API.
        /// </summary>
        /// <param name="apiKey">The API key.</param>
        /// <returns>The API response</returns>
        protected string GetConfigurationFromApi(string apiKey)
        {
            var baseUrl = ApiUrls.Configuration.Details;

            var urlBuilder = new UrlBuilder(baseUrl);

            urlBuilder.AddParameter("api_key", apiKey);

            var apiResponse = ApiHelper.MakeApiRequest(urlBuilder.BuildUrl());

            return(apiResponse);
        }
示例#10
0
        /// <summary>
        /// Returns an object URL with the given selector.
        /// </summary>
        public UrlBuilder GetPathUrl(string repositoryId, string path, string selector)
        {
            UrlBuilder result = GetPathUrl(repositoryId, path);

            if (result == null)
            {
                return(null);
            }

            result.AddParameter(Selector, selector);

            return(result);
        }
示例#11
0
        /// <summary>
        /// Searches the movies.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="page">The page number.</param>
        /// <returns>Search results</returns>
        public MovieSearchResult SearchMovies(string query, int page)
        {
            if (string.IsNullOrWhiteSpace(query))
            {
                return(new MovieSearchResult());
            }

            string baseUrl = ApiUrls.Movie.Search;

            var urlBuilder = new UrlBuilder(baseUrl);

            urlBuilder.AddParameter("api_key", _configurationApi.GetApiKey());
            urlBuilder.AddParameter("query", query);
            urlBuilder.AddParameter("page", page);
            urlBuilder.AddParameter("language", "en-GB");

            var apiResponse = ApiHelper.MakeApiRequest(urlBuilder.BuildUrl());

            var movieSearchResult = JsonConvert.DeserializeObject <MovieSearchResult>(apiResponse);

            return(movieSearchResult);
        }
示例#12
0
        /// <summary>
        /// Returns an object URL with the given selector.
        /// </summary>
        public UrlBuilder GetObjectUrl(string repositoryId, string objectId, string selector)
        {
            UrlBuilder result = GetObjectUrl(repositoryId, objectId);

            if (result == null)
            {
                return(null);
            }

            result.AddParameter(Selector, selector);

            return(result);
        }
        /// <summary>
        /// Gets the person credits.
        /// </summary>
        /// <param name="personId">The person identifier.</param>
        /// <returns>Person credits</returns>
        private PersonCreditCollection GetPersonCredits(int personId)
        {
            string baseUrl = string.Format(ApiUrls.Person.Credits, personId);

            var urlBuilder = new UrlBuilder(baseUrl);

            urlBuilder.AddParameter("api_key", _configurationApi.GetApiKey());

            var apiResponse = ApiHelper.MakeApiRequest(urlBuilder.BuildUrl());

            var credits = JsonConvert.DeserializeObject <PersonCreditCollection>(apiResponse);

            return(credits);
        }
示例#14
0
        /// <summary>
        /// Gets the collection details.
        /// </summary>
        /// <param name="collectionId">The collection identifier.</param>
        /// <returns>The collection details</returns>
        private ExtendedCollectionResult GetCollectionDetails(int collectionId)
        {
            string baseUrl = string.Format(ApiUrls.Collection.Details, collectionId);

            var urlBuilder = new UrlBuilder(baseUrl);

            urlBuilder.AddParameter("api_key", _configurationApi.GetApiKey());

            var apiResponse = ApiHelper.MakeApiRequest(urlBuilder.BuildUrl());

            var collectionDetails = JsonConvert.DeserializeObject <ExtendedCollectionResult>(apiResponse);

            return(collectionDetails);
        }
示例#15
0
        /// <summary>
        /// Gets the movie credits.
        /// </summary>
        /// <param name="movieId">The movie identifier.</param>
        /// <returns>Movie credits</returns>
        private MovieCreditResult GetMovieCredits(int movieId)
        {
            string baseUrl = string.Format(ApiUrls.Movie.Credits, movieId);

            var urlBuilder = new UrlBuilder(baseUrl);

            urlBuilder.AddParameter("api_key", _configurationApi.GetApiKey());

            var apiResponse = ApiHelper.MakeApiRequest(urlBuilder.BuildUrl());

            var credits = JsonConvert.DeserializeObject <MovieCreditResult>(apiResponse);

            return(credits);
        }
示例#16
0
        /// <summary>
        /// Returns an object URL with the given selector.
        /// </summary>
        public UrlBuilder GetObjectUrl(string repositoryId, string objectId)
        {
            String url = GetRootUrl(repositoryId);

            if (url == null)
            {
                return(null);
            }

            UrlBuilder result = new UrlBuilder(url);

            result.AddParameter(ObjectId, objectId);

            return(result);
        }
示例#17
0
        public string Execute(string textToExecute)
        {
            textToExecute = textToExecute.Trim(' ', '\r', '\n', '\t');

            var splittedText = textToExecute.Trim(' ', '\r', '\n').Split(new[] { " ", "\r\n", "\t" },
                                                                         StringSplitOptions.RemoveEmptyEntries);
            string action = splittedText[0];
            string path   = splittedText[1];

            path = UrlBuilder.AddParameter(path, "pretty", "true");

            int    endOfFirstLine = textToExecute.IndexOf("\r\n");
            string body           = "";

            if (endOfFirstLine > 0)
            {
                body = textToExecute.Remove(0, endOfFirstLine + 2);
            }

            switch (action.ToUpper())
            {
            case "GET":
                if (string.IsNullOrWhiteSpace(body))
                {
                    return(Connection.Get(path));
                }
                return(Connection.Post(path, body));

            case "POST":
                return(Connection.Post(path, body));

            case "PUT":
                return(Connection.Put(path, body));

            case "DELETE":
                return(Connection.Delete(path, body));

            default:
                throw new ArgumentException("Invalid Action {0} detected".F(action), "textToExecute");
            }
        }