Package api.http

Examples of api.http.HttpRequest


  public KeyValuePair toAuthHeader(){
    return new KeyValuePair("Authorization", String.format("GoogleLogin auth=\"%s\"", this.authToken));
  }

  private void login() throws IOException{
    HttpRequest httpRequest = new HttpRequest(new URL("https://www.google.com/accounts/ClientLogin"));
    HttpQuery httpQuery = new HttpQuery();
    httpQuery.add("Email", this.user);
    httpQuery.add("Passwd", this.password);
    httpQuery.add("service", this.service);
    httpQuery.add("source", this.source);
    httpRequest.setData(httpQuery.toString());
    String response = httpRequest.send();
    String responses[] = response.split("\n");
    String authHeader = "Auth=";
    for (String r : responses){
      if (r.indexOf(authHeader) == 0){
        this.authToken = r.substring(authHeader.length());
View Full Code Here


   * @throws SAXException the response is not a parsable XML.
   */
  public PicasaWeb(String user, GoogleAPI googleapi) throws IOException, ParserConfigurationException, SAXException{
    this.googleapi = googleapi;
    URL url = new URL("https://picasaweb.google.com/data/feed/api/user/" + user);
    HttpRequest httpRequest = new HttpRequest(url);
    if (googleapi != null){
      KeyValuePair pair = googleapi.toAuthHeader();
      httpRequest.addHeader(pair.key, pair.value);
    }
    String response = httpRequest.send();
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(response)));
    this.initial(document.getDocumentElement());
  }
View Full Code Here

    URL url = new URL(this.entryUrl.toString() + "/albumid/" + id);
    return this.getAlbum(url);
  }

  private PicasaAlbum getAlbum(URL url) throws IOException, ParserConfigurationException, SAXException{
    HttpRequest httpRequest = new HttpRequest(url);
    if (this.googleapi != null){
      KeyValuePair pair = this.googleapi.toAuthHeader();
      httpRequest.addHeader(pair.key, pair.value);
    }
    String response = httpRequest.send();
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(response)));
    return new PicasaAlbum(this, document.getDocumentElement());
  }
View Full Code Here

   * of target url.
   * @throws ParserConfigurationException the response is not a parsable XML.
   * @throws SAXException the response is not a parsable XML.
   */
  public PicasaAlbum[] listAlbums() throws IOException, ParserConfigurationException, SAXException{
    HttpRequest httpRequest = new HttpRequest(this.feedUrl);
    if (this.googleapi != null){
      KeyValuePair pair = this.googleapi.toAuthHeader();
      httpRequest.addHeader(pair.key, pair.value);
    }
    String response = httpRequest.send();
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(response)));
    List<PicasaAlbum> picasaAlbums = new ArrayList<PicasaAlbum>();
    NodeList entries = document.getElementsByTagName("entry");
    for (int i = 0; i < entries.getLength(); i++){
      Element entry = (Element)entries.item(i);
View Full Code Here

   * of target url.
   * @throws ParserConfigurationException the response is not a parsable XML.
   * @throws SAXException the response is not a parsable XML.
   */
  public PicasaAlbum createAlbum(String title, String description, String access, Date lastModified, Boolean canComment, String position, String location, URL cover) throws IOException, ParserConfigurationException, SAXException{
    HttpRequest httpRequest = new HttpRequest(this.feedUrl);
    if (this.googleapi != null){
      KeyValuePair pair = this.googleapi.toAuthHeader();
      httpRequest.addHeader(pair.key, pair.value);
    }
    String data = PicasaAlbum.createAlbumXML(title, description, access, lastModified, canComment, position, location, cover, null);
    httpRequest.setData(data);
    httpRequest.setMethod("POST");
    httpRequest.setContentType("application/atom+xml");
    String response = httpRequest.send();
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(response)));
    return new PicasaAlbum(this, document.getDocumentElement());
  }
View Full Code Here

   * @param position the position of Picasa Photo.
   * @throws IOException the url is not exist or something wrong of the server
   * of target url.
   */
  public void update(String title, String description, Date lastModified, String keywords, Boolean canComment, String position) throws IOException{
    HttpRequest httpRequest = new HttpRequest(this.editUrl);
    if (this.picasaAlbum.getPicasaWeb().getGoogleapi() != null){
      KeyValuePair pair = this.picasaAlbum.getPicasaWeb().getGoogleapi().toAuthHeader();
      httpRequest.addHeader(pair.key, pair.value);
    }
    if (title != null){
      this.title = title;
    }
    if (description != null){
      this.description = description;
    }
    if (lastModified != null){
      this.lastModified = lastModified;
    }
    if (keywords != null){
      this.keywords = keywords;
    }
    if (canComment != null){
      this.canComment = canComment;
    }
    if (position != null){
      this.position = position;
    }
    String data = PicasaPhoto.createPhotoXML(this.title, this.description, this.lastModified, this.keywords, this.canComment, this.position);
    httpRequest.setData(data);
    httpRequest.setMethod(HttpRequest.METHOD_PUT);
    httpRequest.setContentType("application/atom+xml");
    String response = httpRequest.send();
  }
View Full Code Here

   *
   * @throws IOException the url is not exist or something wrong of the server
   * of target url.
   */
  public void delete() throws IOException{
    HttpRequest httpRequest = new HttpRequest(this.editUrl);
    if (this.picasaAlbum.getPicasaWeb().getGoogleapi() != null){
      KeyValuePair pair = this.picasaAlbum.getPicasaWeb().getGoogleapi().toAuthHeader();
      httpRequest.addHeader(pair.key, pair.value);
    }
    httpRequest.setMethod(HttpRequest.METHOD_DELETE);
    httpRequest.setContentType("application/atom+xml");
    String response = httpRequest.send();
    this.title = null;
    this.photoId = null;
    this.description = null;
    this.lastModified = null;
    this.keywords = null;
View Full Code Here

    URL url = new URL(this.entryUrl.toString() + "/commentid/" + id);
    return this.getComment(url);
  }

  private PicasaComment getComment(URL url) throws IOException, ParserConfigurationException, SAXException{
    HttpRequest httpRequest = new HttpRequest(url);
    if (this.picasaAlbum.getPicasaWeb().getGoogleapi() != null){
      KeyValuePair pair = this.picasaAlbum.getPicasaWeb().getGoogleapi().toAuthHeader();
      httpRequest.addHeader(pair.key, pair.value);
    }
    String response = httpRequest.send();
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(response)));
    return new PicasaComment(this, document.getDocumentElement());
  }
View Full Code Here

   * of target url.
   * @throws ParserConfigurationException the response is not a parsable XML.
   * @throws SAXException the response is not a parsable XML.
   */
  public PicasaComment[] listComments() throws IOException, ParserConfigurationException, SAXException{
    HttpRequest httpRequest = new HttpRequest(this.feedUrl);
    if (this.picasaAlbum.getPicasaWeb().getGoogleapi() != null){
      KeyValuePair pair = this.picasaAlbum.getPicasaWeb().getGoogleapi().toAuthHeader();
      httpRequest.addHeader(pair.key, pair.value);
    }
    String response = httpRequest.send();
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(response)));
    List<PicasaComment> picasaComments = new ArrayList<PicasaComment>();
    NodeList entries = document.getElementsByTagName("entry");
    for (int i = 0; i < entries.getLength(); i++){
      Element entry = (Element)entries.item(i);
View Full Code Here

   * of target url.
   * @throws ParserConfigurationException the response is not a parsable XML.
   * @throws SAXException the response is not a parsable XML.
   */
  public PicasaComment addComment(String comment) throws IOException, ParserConfigurationException, SAXException{
    HttpRequest httpRequest = new HttpRequest(this.feedUrl);
    if (this.picasaAlbum.getPicasaWeb().getGoogleapi() != null){
      KeyValuePair pair = this.picasaAlbum.getPicasaWeb().getGoogleapi().toAuthHeader();
      httpRequest.addHeader(pair.key, pair.value);
    }
    String data = PicasaComment.createCommentXML(comment);
    httpRequest.setData(data);
    httpRequest.setMethod(HttpRequest.METHOD_POST);
    httpRequest.setContentType("application/atom+xml");
    String response = httpRequest.send();
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(response)));
    return new PicasaComment(this, document.getDocumentElement());
  }
View Full Code Here

TOP

Related Classes of api.http.HttpRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.