/*
* Copyright (C) 2012 FiveHT Media Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.fiveht.tick.api;
import com.fiveht.tick.api.parser.ProjectParser;
import com.fiveht.tick.util.NodeListIterator;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* This service retrieves a list of projects associated with a given company,
* and accessible to a given email address.
*
* @author Nathan Crause
*/
public final class ProjectsService extends Service<List<Project>> {
public ProjectsService(String company, String emailAddress, String password) {
super(company, emailAddress, password);
}
@Override
public String getPath() {
return "projects";
}
@Override
public List<Project> request() {
try {
List<Project> results = new ArrayList<Project>();
Document doc = post();
ProjectParser parser = new ProjectParser();
for (Element e : new NodeListIterator<Element>(doc.getDocumentElement().getElementsByTagName("project"))) {
results.add(parser.parse(e));
}
return results;
} catch (Throwable thrown) {
Logger.getLogger(ProjectsService.class.getName()).log(Level.SEVERE, null, thrown);
throw new RuntimeException("PANIC!", thrown);
}
}
}