/// <summary> /// Get a Customer from Tictail API /// </summary> /// <param name="customerId">ID of the Customer</param> /// <returns>A specific Customer</returns> public Customer Get(string customerId) { if (string.IsNullOrEmpty(customerId)) { throw new Exception("You must provide a valid customer Id"); } if (string.IsNullOrEmpty(StoreId)) { throw new Exception("You must provide a valid store Id"); } var request = new RestRequest("v1/stores/{storeId}/customers/{customerId}", Method.GET); request.AddUrlSegment("storeId", StoreId); request.AddUrlSegment("customerId", customerId); try { // GET /v1/stores/<store_id>/customers/<customer_id> string content = _client.ExecuteRequest(request, HttpStatusCode.OK).Content; return(DeserializeGet(content)); } catch (KeyNotFoundException) { throw new Exception("No Customer found with ID : " + customerId + ", at store : " + StoreId); } }
/// <summary> /// Add a new follower of this store /// </summary> /// <param name="follower">The new follower (only email is need)</param> /// <returns>Location - The url of the created follower</returns> public string Post(Follower follower) { // https://tictail.com/developers/documentation/api-reference/#Follower if (string.IsNullOrEmpty(StoreId)) { throw new Exception("You must provide a valid store Id"); } //POST /v1/stores/<store_id>/followers var request = new RestRequest("v1/stores/{storeId}/followers", Method.POST); request.AddUrlSegment("storeId", StoreId); request.AddJsonBody(follower); try { var response = _client.ExecuteRequest(request, HttpStatusCode.Created); var locationHeader = response.Headers.FirstOrDefault(f => f.Name == "Location"); if (locationHeader == null) { return(string.Empty); } return((string)locationHeader.Value); } catch (KeyNotFoundException) { throw new Exception("No Store found with ID : " + StoreId); } }
/// <summary> /// Get Store from Tictail API /// </summary> /// <param name="storeId">ID of store to retrive</param> /// <returns>A Store</returns> public Store Get(string storeId) { if (string.IsNullOrEmpty(storeId)) { throw new Exception("You can't specify an empty storeId"); } var request = new RestRequest("v1/stores/{storeId}", Method.GET); request.AddUrlSegment("storeId", storeId); Store store; try { store = DeserializeGet(_client.ExecuteRequest(request, HttpStatusCode.OK).Content); } catch (KeyNotFoundException) { throw new Exception("No Store found with ID : " + storeId); } store.Products = new ProductResource(_client, storeId); store.Theme = new ThemeResource(_client, storeId); store.Categories = new CategoryResource(_client, storeId); store.Customers = new CustomerResource(_client, storeId); store.Followers = new FollowerResource(_client, storeId); store.Orders = new OrderResource(_client, storeId); store.Cards = new CardResource(_client, storeId); return(store); }
/// <summary> /// Get a Product from Tictail API /// </summary> /// <param name="productId">ID of the product</param> /// <returns>A specific product</returns> public Product Get(string productId) { if (string.IsNullOrEmpty(productId)) { throw new Exception("You must provide a valid product Id"); } if (string.IsNullOrEmpty(StoreId)) { throw new Exception("You must provide a valid store Id"); } var request = new RestRequest("v1/stores/{storeId}/products/{productId}", Method.GET); request.AddUrlSegment("storeId", StoreId); request.AddUrlSegment("productId", productId); try { var content = _client.ExecuteRequest(request, HttpStatusCode.OK).Content; return(DeserializeGet(content)); } catch (KeyNotFoundException) { throw new Exception("No Product found with ID : " + productId + ", at store : " + StoreId); } }
/// <summary> /// Post token request back to Tictail /// </summary> /// <param name="oauth">Oauth object</param> /// <returns>A token</returns> public Token Post(Oauth oauth) { var request = new RestRequest("oauth/token", Method.POST); request.AddParameter("application/x-www-form-urlencoded", oauth.GenerateBody(), ParameterType.RequestBody); string content = _client.ExecuteRequest(request, HttpStatusCode.OK).Content; return(DeserializeGet(content)); }
/// <summary> /// Get Me from Tictail API /// </summary> /// <returns>A Me, describing the current store</returns> public Me Get() { var request = new RestRequest("v1/me", Method.GET); try { return(DeserializeGet(_client.ExecuteRequest(request, HttpStatusCode.OK).Content)); } catch (KeyNotFoundException) { throw new Exception("No Me found"); } }
/// <summary> /// Get all Orders /// </summary> /// <returns>An enumerator of orders</returns> public IEnumerator <Order> GetRange() { if (string.IsNullOrEmpty(StoreId)) { throw new Exception("You must provide a valid store Id"); } //GET /v1/stores/<store_id>/orders var request = new RestRequest("v1/stores/{storeId}/orders", Method.GET); request.AddUrlSegment("storeId", StoreId); try { string content = _client.ExecuteRequest(request, HttpStatusCode.OK).Content; return(DeserializeRangeGet(content)); } catch (KeyNotFoundException) { throw new Exception("No Store found with ID : " + StoreId); } }
/// <summary> /// Get Theme from Tictail API /// </summary> /// <returns>A Theme</returns> public Theme Get() { if (string.IsNullOrEmpty(StoreId)) { throw new Exception("You must provide a valid product Id"); } var request = new RestRequest("v1/stores/{storeId}/theme", Method.GET); request.AddUrlSegment("storeId", StoreId); try { return(DeserializeGet(_client.ExecuteRequest(request, HttpStatusCode.OK).Content)); } catch (KeyNotFoundException) { throw new Exception("No Me found"); } }