Post() public method

It serializes the toSend object into xml and sends the post message specified in the "to" string using an authorized connection. It returns the response from the server as an XDocument.

REQUIRES AUTHENTICATION.
public Post ( object toSend, string to ) : System.Xml.Linq.XDocument
toSend object The object that will be serialized into xml and sent.
to string The url the post message will be sent to.
return System.Xml.Linq.XDocument
Ejemplo n.º 1
0
        /// <summary>
        /// <para>
        /// Performs the Photo Method:
        /// Upload a photo.
        /// </para><para>
        /// Serializes the given PhotoUploadRequest into xml and sends the message.
        /// Loads the file and converts it to the appropriate data format for the request - it does not require the "PhotoData" field of the PhotoUploadRequest object to have anything in it.
        ///  </para>
        /// </summary>
        /// <param name="up">The object that will be serialized into xml and then sent in a POST message.</param>
        /// <returns>XDocument.</returns>
        public XDocument UploadPhotoFormat(PhotoUploadRequest up)
        {
            var fileName = up.FileName;

            var fs   = File.OpenRead(fileName);
            var data = new byte[fs.Length];

            // read in the file to a byte array
            using (Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                var offset    = 0;
                var remaining = data.Length;
                while (remaining > 0)
                {
                    var read = stream.Read(data, offset, remaining);
                    if (read <= 0)
                    {
                        throw new EndOfStreamException(String.Format(Constants.Culture, "End of stream reached with {0} bytes left to read", remaining));
                    }

                    remaining -= read;
                    offset    += read;
                }
            }

            // The data in the request is a base64 encoded string of the binary data in the photo.
            var endData = Convert.ToBase64String(data);

            // put the data in the object that will be converted to xml and posted
            up.PhotoData = endData;

            // send the post method
            return(_connection.Post(up, "Photos.xml"));
        }
Ejemplo n.º 2
0
        // Favourite methods:

        /// <summary>
        /// <para>Performs the Favourites method:
        /// Save Search. POST
        /// </para>
        /// <para>Serializes the given SaveSearchRequest into xml.</para>
        /// REQUIRES AUTHENTICATION.
        /// </summary>
        /// <param name="saveSearch">The object that will be serialized into xml and then sent in a POST message.</param>
        /// <returns>XDocument.</returns>
        public XDocument SaveSearch(SaveSearchRequest saveSearch)
        {
            const string query = Constants.FAVOURITES + "/" + Constants.SEARCH + Constants.XML;

            return(_connection.Post(saveSearch, query));
        }
        // Selling Methods:

        /// <summary>
        /// <para>Starts a new auction or classified.
        /// </para><para>
        /// There are several endpoints that should be used to get information needed to list an item.
        /// Check Category information, Legal Notice information, attributes, fees and listing duration options.
        /// </para>
        /// REQUIRES AUTHENTICATION.
        /// </summary>
        /// <param name="request">The object that will be serialized into xml and then sent in a POST message.</param>
        /// <returns>XDocument: ListingResponse</returns>
        public XDocument ListItem(ListingRequest request)
        {
            var query = String.Format(Constants.Culture, "{0}{1}", Constants.SELLING, Constants.XML);

            return(_connection.Post(request, query));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// <para>Performs the My Trade Me Method:
        /// Adds a listing to the authenticated user’s watchlist
        /// with the option to control when and if an email is sent to the member warning that the auction is closing soon. POST
        /// </para>
        /// REQUIRES AUTHENTICATION.
        /// </summary>
        /// <param name="request">SaveToWatchlistRequest.</param>
        /// <returns>XDocument: WatchListResponse.</returns>
        public XDocument SaveListingToWatchlist(SaveToWatchlistRequest request)
        {
            var query = String.Format(Constants.Culture, "{0}/{1}{2}", Constants.MY_TRADEME, Constants.WATCHLIST, Constants.XML);

            return(_connection.Post(request, query));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// <para>Performs the Fixed Price Offer Method:
        /// Accepts or rejects a fixed price offer. POST
        /// </para>
        /// REQUIRES AUTHENTICATION.
        /// </summary>
        /// <param name="request">The object that will be serialized into xml and then sent in a POST message.</param>
        /// <returns>XDocument: FixedPriceOfferResponse</returns>
        public XDocument RespondToFixedPriceOffer(FixedPriceOfferRequest request)
        {
            var query = String.Format(Constants.Culture, "{0}/{1}/Respond{2}", Constants.MY_TRADEME, Constants.FIXEDPRICEOFFER, Constants.XML);

            return(_connection.Post(request, query));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// <para>Performs the Listing Method:
        /// Provide an answer for a specific question. POST
        /// </para><para>
        /// Serializes the given ListingAnswerQuestion into xml.
        /// Creates a query string using the parameters provided.
        /// </para><para>
        /// All the parameters are required.
        /// </para>
        /// REQUIRES AUTHENTICATION.
        /// </summary>
        /// <param name="answerQuestion">The object that will be serialized into xml and then sent in a POST message.</param>
        /// <param name="listingId">The id of the listing that has the question being answered.</param>
        /// <param name="questionId">The id of the question being answered.</param>
        /// <returns>XDocument.</returns>
        public XDocument AnswerSpecificQuestion(ListingAnswerQuestion answerQuestion, string listingId, string questionId)
        {
            var query = String.Format(Constants.Culture, "{0}/{1}/{2}/{3}/answerquestion{4}", Constants.LISTINGS, listingId, Constants.QUESTIONS, questionId, Constants.XML);

            return(_connection.Post(answerQuestion, query));
        }
        /// <summary>
        /// <para>Performs the Bidding Method:
        /// Place a bid request. POST
        /// </para><para>
        /// Serializes the given BidRequest into xml and sends the message.
        /// </para>
        /// REQUIRES AUTHENTICATION.
        /// </summary>
        /// <param name="request">The object that will be serialized into xml and then sent in a POST message.</param>
        /// <returns>XDocument: AuctionBidResponse</returns>
        public XDocument BidRequest(BidRequest request)
        {
            var query = String.Format(Constants.Culture, "{0}/Bid{1}", Constants.BIDDING, Constants.XML);

            return(_connection.Post(request, query));
        }