Exemple #1
0
        public Listing CreateListing(Listing listing, PermanentToken authToken)
        {
            listing.State = "draft";
            if (!authToken.IsValidEtsyToken())
            {
                throw new EtsyWrapperException("Auth token is not valid!  Please authenticate before calling the CreateListing method.");
            }
            RestRequest request = _restServiceWrapper.GetRestRequest("listings", Method.POST);

            _restClient.Authenticator = _restServiceWrapper.GetAuthenticatorForProtectedResource(authToken);

            request.AddHeader("Accept", "application/json");
            request.AddParameter("application/json", JsonConvert.SerializeObject(listing), ParameterType.RequestBody);

            var etsyResponse = _restClient.Execute(request);

            if (etsyResponse.StatusCode != HttpStatusCode.Created)
            {
                throw new EtsyWrapperException(
                          $"Create Listing failed.  Please check your parameters and try again. Error: {etsyResponse.Content}");
            }
            var listingResponse = JsonConvert.DeserializeObject <ListingResponse>(etsyResponse.Content);

            listing.ID = listingResponse.Listing[0].ID;
            return(listing);
        }
        public TemporaryToken GetTemporaryCredentials(string apiKey, string sharedSecret, string[] permissions)
        {
            _restClient.Authenticator = _restServiceWrapper.GetAuthenticatorForRequestToken(apiKey, sharedSecret);

            RestRequest restRequest = _restServiceWrapper.GetRestRequest("oauth/request_token", Method.POST);

            restRequest.AddParameter("scope", string.Join(" ", permissions));

            IRestResponse response = _restClient.Execute(restRequest);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                return(null);
            }
            var args = ParseQueryString(response.Content);

            return(new TemporaryToken
            {
                LoginURL = Uri.UnescapeDataString(args.First(x => x.Key == "login_url").Value),
                OAuthToken = args.First(x => x.Key == "oauth_token").Value,
                OAuthTokenSecret = args.First(x => x.Key == "oauth_token_secret").Value
            });
        }