// Path: client/src/main/java/com/shopzilla/api/client/ProductClient.java
// public class ProductClient {
// 
//     private RestOperations restTemplate;
//     private ProductService productService;
// 
//     /**
//      * Wrapper for retrieveProductResponseList(), made for parsing sets of Products from searches
//      * for a particular keyword.
//      * 
//      * @param apiKey
//      * @param publisherId
//      * @param searchKeyword
//      * @param numResults
//      * 
//      * @return ProductResponse
//      */
//     public ProductResponse doProductSearch(String apiKey, String publisherId, String searchKeyword,
//             Integer numResults) {
// 
//         ProductSearchRequest request = new ProductSearchRequest();
//         request.setApiKey(apiKey);
//         request.setPublisherId(publisherId);
//         request.setKeyword(searchKeyword);
//         request.setNumResults(numResults);
// 
//         return retrieveProductResponseList(request);
// 
//     }
// 
//     /**
//      * Multi-purpose method for fetching + parsing ProductResponse XML from Shopzilla API
//      * 
//      * @param ProductSearchRequest
//      * 
//      * @return ProductResponse
//      */
//     private ProductResponse retrieveProductResponseList(ProductSearchRequest request) {
// 
//         return restTemplate.getForObject(ProductUrl.PRODUCT_URL,
//                                          ProductResponse.class,
//                                          ProductUrl.makeParameterMap(request));
//     }
// 
//     public void setRestTemplate(RestOperations restTemplate) {
//         this.restTemplate = restTemplate;
//     }
// 
//     public void setProductService(ProductService productService) {
//         this.productService = productService;
//     }
// 
// }
// 
// Path: client/src/main/java/com/shopzilla/api/client/helper/CredentialFactory.java
// public class CredentialFactory {
//     private String publisherId;
//     private String publisherApiKey;
// 
//     public CredentialFactory() {
//         String id = StringUtils.isNotBlank(System.getenv("PUBLISHER_ID")) ? System.getenv("PUBLISHER_ID") : System.getProperty("PUBLISHER_ID");
//         String key = StringUtils.isNotBlank(System.getenv("PUBLISHER_API_KEY")) ? System.getenv("PUBLISHER_API_KEY") : System.getProperty("PUBLISHER_API_KEY");
// 
//         if (key != null && id != null) {
//             this.publisherId = id;
//             this.publisherApiKey = key;
//         } else {
//             throw new IllegalArgumentException("No API credentials were provided! "+
//                                                "Please set PUBLISHER_ID and PUBLISHER_API_KEY ");
//         }
//     }
// 
//     public String getPublisherId() {
//         return publisherId;
//     }
// 
//     public String getPublisherApiKey() {
//         return publisherApiKey;
//     }
// }


import com.shopzilla.api.client.ProductClient;
import com.shopzilla.api.client.helper.CredentialFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/*
 * Copyright 2011 Shopzilla.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.shopzilla.api.driver;


public class ProductClientDriver {

    private static CredentialFactory credentialFactory;
    private static String apiKey;
    private static String publisherId;

    private static final String keyword = "nike+men%27s+shoes";

    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:applicationContext-client.xml");
// Path: client/src/main/java/com/shopzilla/api/client/ProductClient.java
// public class ProductClient {
// 
//     private RestOperations restTemplate;
//     private ProductService productService;
// 
//     /**
//      * Wrapper for retrieveProductResponseList(), made for parsing sets of Products from searches
//      * for a particular keyword.
//      * 
//      * @param apiKey
//      * @param publisherId
//      * @param searchKeyword
//      * @param numResults
//      * 
//      * @return ProductResponse
//      */
//     public ProductResponse doProductSearch(String apiKey, String publisherId, String searchKeyword,
//             Integer numResults) {
// 
//         ProductSearchRequest request = new ProductSearchRequest();
//         request.setApiKey(apiKey);
//         request.setPublisherId(publisherId);
//         request.setKeyword(searchKeyword);
//         request.setNumResults(numResults);
// 
//         return retrieveProductResponseList(request);
// 
//     }
// 
//     /**
//      * Multi-purpose method for fetching + parsing ProductResponse XML from Shopzilla API
//      * 
//      * @param ProductSearchRequest
//      * 
//      * @return ProductResponse
//      */
//     private ProductResponse retrieveProductResponseList(ProductSearchRequest request) {
// 
//         return restTemplate.getForObject(ProductUrl.PRODUCT_URL,
//                                          ProductResponse.class,
//                                          ProductUrl.makeParameterMap(request));
//     }
// 
//     public void setRestTemplate(RestOperations restTemplate) {
//         this.restTemplate = restTemplate;
//     }
// 
//     public void setProductService(ProductService productService) {
//         this.productService = productService;
//     }
// 
// }
// 
// Path: client/src/main/java/com/shopzilla/api/client/helper/CredentialFactory.java
// public class CredentialFactory {
//     private String publisherId;
//     private String publisherApiKey;
// 
//     public CredentialFactory() {
//         String id = StringUtils.isNotBlank(System.getenv("PUBLISHER_ID")) ? System.getenv("PUBLISHER_ID") : System.getProperty("PUBLISHER_ID");
//         String key = StringUtils.isNotBlank(System.getenv("PUBLISHER_API_KEY")) ? System.getenv("PUBLISHER_API_KEY") : System.getProperty("PUBLISHER_API_KEY");
// 
//         if (key != null && id != null) {
//             this.publisherId = id;
//             this.publisherApiKey = key;
//         } else {
//             throw new IllegalArgumentException("No API credentials were provided! "+
//                                                "Please set PUBLISHER_ID and PUBLISHER_API_KEY ");
//         }
//     }
// 
//     public String getPublisherId() {
//         return publisherId;
//     }
// 
//     public String getPublisherApiKey() {
//         return publisherApiKey;
//     }
// }


// Path: client/src/main/java/com/shopzilla/api/driver/ProductClientDriver.java
import com.shopzilla.api.client.ProductClient;
import com.shopzilla.api.client.helper.CredentialFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/*
 * Copyright 2011 Shopzilla.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.shopzilla.api.driver;


public class ProductClientDriver {

    private static CredentialFactory credentialFactory;
    private static String apiKey;
    private static String publisherId;

    private static final String keyword = "nike+men%27s+shoes";

    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:applicationContext-client.xml");
        ProductClient client = applicationContext.getBean("productClient", ProductClient.class);