test_class.declarator: LOGGER = LoggerFactory.getLogger(DemoApiToolTest.class)
test_class.modifier: private static final
test_class.original_string: private static final Logger LOGGER = LoggerFactory.getLogger(DemoApiToolTest.class);
test_class.type: Logger
test_class.var_name: LOGGER
test_class.file: samples/dianping-java-samples/src/test/java/com/dianping/open/samples/DemoApiToolTest.java
test_class.identifier: DemoApiToolTest
test_case.body: @Test
      public void testRequestApi()
      {
          String apiUrl = "http://api.dianping.com/v1/business/find_businesses";
          String appKey = "XXXXXXXX";
          String secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
          
          Map<String, String> paramMap = new HashMap<String, String>();
          paramMap.put("city", "上海");
          paramMap.put("latitude", "31.21524");
          paramMap.put("longitude", "121.420033");
          paramMap.put("category", "美食");
          paramMap.put("region", "长宁区");
          paramMap.put("limit", "20");
          paramMap.put("radius", "2000");
          paramMap.put("offset_type", "0");
          paramMap.put("has_coupon", "1");
          paramMap.put("has_deal", "1");
          paramMap.put("keyword", "泰国菜");
          paramMap.put("sort", "7");
          paramMap.put("format", "json");
          
          String requestResult = DemoApiTool.requestApi(apiUrl, appKey, secret, paramMap);
          LOGGER.info(requestResult);
          Assert.assertNotNull(requestResult);
      }
test_case.class_method_signature: DemoApiToolTest.testRequestApi()
test_case.full_signature: @Test public void testRequestApi()
test_case.identifier: testRequestApi
test_case.invocations: put put put put put put put put put put put put put requestApi info assertNotNull
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testRequestApi()
focal_class.declarator: LOGGER = LoggerFactory.getLogger(DemoApiTool.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER = LoggerFactory.getLogger(DemoApiTool.class);
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.file: samples/dianping-java-samples/src/main/java/com/dianping/open/samples/DemoApiTool.java
focal_class.identifier: DemoApiTool
focal_class.class_method_signature: DemoApiTool.sign(String appKey, String secret, Map<String, String> paramMap)
focal_class.full_signature: public static String sign(String appKey, String secret, Map<String, String> paramMap)
focal_class.identifier: sign
focal_class.modifiers: public static
focal_class.parameters: (String appKey, String secret, Map<String, String> paramMap)
focal_class.return: String
focal_class.signature: String sign(String appKey, String secret, Map<String, String> paramMap)
focal_class.class_method_signature: DemoApiTool.getQueryString(String appKey, String secret, Map<String, String> paramMap)
focal_class.full_signature: public static String getQueryString(String appKey, String secret, Map<String, String> paramMap)
focal_class.identifier: getQueryString
focal_class.modifiers: public static
focal_class.parameters: (String appKey, String secret, Map<String, String> paramMap)
focal_class.return: String
focal_class.signature: String getQueryString(String appKey, String secret, Map<String, String> paramMap)
focal_class.class_method_signature: DemoApiTool.requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_class.full_signature: public static String requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_class.identifier: requestApi
focal_class.modifiers: public static
focal_class.parameters: (String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_class.return: String
focal_class.signature: String requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_class.class_method_signature: DemoApiTool.requestPostApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_class.full_signature: public static String requestPostApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_class.identifier: requestPostApi
focal_class.modifiers: public static
focal_class.parameters: (String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_class.return: String
focal_class.signature: String requestPostApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_method.body: public static String requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)
      {
          String queryString = getQueryString(appKey, secret, paramMap);
  
          StringBuffer response = new StringBuffer();
          HttpClientParams httpConnectionParams = new HttpClientParams();
          httpConnectionParams.setConnectionManagerTimeout(1000);
          HttpClient client = new HttpClient(httpConnectionParams);
          HttpMethod method = new GetMethod(apiUrl);
  
          try
          {
              if (StringUtils.isNotBlank(queryString))
              {
                  // Encode query string with UTF-8
                  String encodeQuery = URIUtil.encodeQuery(queryString, "UTF-8");
                  LOGGER.debug("Encoded Query:" + encodeQuery);
                  method.setQueryString(encodeQuery);
              }
  
              client.executeMethod(method);
              BufferedReader reader = new BufferedReader(
                                                         new InputStreamReader(method.getResponseBodyAsStream(), "UTF-8"));
              String line = null;
              while ((line = reader.readLine()) != null)
              {
                  response.append(line).append(System.getProperty("line.separator"));
              }
              reader.close();
          }
          catch (URIException e)
          {
              LOGGER.error("Can not encode query: " + queryString + " with charset UTF-8. ", e);
          }
          catch (IOException e)
          {
              LOGGER.error("Request URL: " + apiUrl + " failed. ", e);
          }
          finally
          {
              method.releaseConnection();
          }
          return response.toString();
  
      }
focal_method.class_method_signature: DemoApiTool.requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_method.full_signature: public static String requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_method.identifier: requestApi
focal_method.invocations: getQueryString setConnectionManagerTimeout isNotBlank encodeQuery debug setQueryString executeMethod getResponseBodyAsStream readLine append append getProperty close error error releaseConnection toString
focal_method.modifiers: public static
focal_method.parameters: (String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_method.return: String
focal_method.signature: String requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)