001 002package com.commercetools.api.client; 003 004import java.net.URI; 005import java.nio.charset.StandardCharsets; 006import java.time.Duration; 007import java.util.ArrayList; 008import java.util.List; 009import java.util.concurrent.CompletableFuture; 010 011import io.vrap.rmf.base.client.*; 012import io.vrap.rmf.base.client.utils.Generated; 013 014import org.apache.commons.lang3.builder.EqualsBuilder; 015import org.apache.commons.lang3.builder.HashCodeBuilder; 016 017/** 018 * <p>When using the endpoint, the Store specified in the path and the Stores specified in the payload's <code>stores</code> field are added to the CartDiscount.</p> 019 * 020 * <hr> 021 * <div class=code-example> 022 * <pre><code class='java'>{@code 023 * CompletableFuture<ApiHttpResponse<com.commercetools.api.models.cart_discount.CartDiscount>> result = apiRoot 024 * .withProjectKey("{projectKey}") 025 * .inStoreKeyWithStoreKeyValue("{storeKey}") 026 * .cartDiscounts() 027 * .post("") 028 * .execute() 029 * }</code></pre> 030 * </div> 031 */ 032@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 033public class ByProjectKeyInStoreKeyByStoreKeyCartDiscountsPostString extends 034 StringBodyApiMethod<ByProjectKeyInStoreKeyByStoreKeyCartDiscountsPostString, com.commercetools.api.models.cart_discount.CartDiscount> { 035 036 private String projectKey; 037 private String storeKey; 038 039 private String cartDiscountDraft; 040 041 public ByProjectKeyInStoreKeyByStoreKeyCartDiscountsPostString(final ApiHttpClient apiHttpClient, String projectKey, 042 String storeKey, String cartDiscountDraft) { 043 super(apiHttpClient); 044 this.projectKey = projectKey; 045 this.storeKey = storeKey; 046 this.cartDiscountDraft = cartDiscountDraft; 047 } 048 049 public ByProjectKeyInStoreKeyByStoreKeyCartDiscountsPostString( 050 ByProjectKeyInStoreKeyByStoreKeyCartDiscountsPostString t) { 051 super(t); 052 this.projectKey = t.projectKey; 053 this.storeKey = t.storeKey; 054 this.cartDiscountDraft = t.cartDiscountDraft; 055 } 056 057 @Override 058 protected ApiHttpRequest buildHttpRequest() { 059 List<String> params = new ArrayList<>(getQueryParamUriStrings()); 060 String httpRequestPath = String.format("%s/in-store/key=%s/cart-discounts", this.projectKey, this.storeKey); 061 if (!params.isEmpty()) { 062 httpRequestPath += "?" + String.join("&", params); 063 } 064 return new ApiHttpRequest(ApiHttpMethod.POST, URI.create(httpRequestPath), getHeaders(), 065 cartDiscountDraft.getBytes(StandardCharsets.UTF_8)); 066 067 } 068 069 @Override 070 public ApiHttpResponse<com.commercetools.api.models.cart_discount.CartDiscount> executeBlocking( 071 final ApiHttpClient client, final Duration timeout) { 072 return executeBlocking(client, timeout, com.commercetools.api.models.cart_discount.CartDiscount.class); 073 } 074 075 @Override 076 public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.cart_discount.CartDiscount>> execute( 077 final ApiHttpClient client) { 078 return execute(client, com.commercetools.api.models.cart_discount.CartDiscount.class); 079 } 080 081 public String getProjectKey() { 082 return this.projectKey; 083 } 084 085 public String getStoreKey() { 086 return this.storeKey; 087 } 088 089 public void setProjectKey(final String projectKey) { 090 this.projectKey = projectKey; 091 } 092 093 public void setStoreKey(final String storeKey) { 094 this.storeKey = storeKey; 095 } 096 097 public String getBody() { 098 return cartDiscountDraft; 099 } 100 101 public ByProjectKeyInStoreKeyByStoreKeyCartDiscountsPostString withBody(String cartDiscountDraft) { 102 ByProjectKeyInStoreKeyByStoreKeyCartDiscountsPostString t = copy(); 103 t.cartDiscountDraft = cartDiscountDraft; 104 return t; 105 } 106 107 @Override 108 public boolean equals(Object o) { 109 if (this == o) 110 return true; 111 112 if (o == null || getClass() != o.getClass()) 113 return false; 114 115 ByProjectKeyInStoreKeyByStoreKeyCartDiscountsPostString that = (ByProjectKeyInStoreKeyByStoreKeyCartDiscountsPostString) o; 116 117 return new EqualsBuilder().append(projectKey, that.projectKey) 118 .append(storeKey, that.storeKey) 119 .append(cartDiscountDraft, that.cartDiscountDraft) 120 .isEquals(); 121 } 122 123 @Override 124 public int hashCode() { 125 return new HashCodeBuilder(17, 37).append(projectKey).append(storeKey).append(cartDiscountDraft).toHashCode(); 126 } 127 128 @Override 129 protected ByProjectKeyInStoreKeyByStoreKeyCartDiscountsPostString copy() { 130 return new ByProjectKeyInStoreKeyByStoreKeyCartDiscountsPostString(this); 131 } 132}