Skip to content

Commit

Permalink
Model: Updated Headers to parse properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ong6 committed Mar 10, 2021
1 parent 1e45f87 commit 7509057
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 43 deletions.
3 changes: 0 additions & 3 deletions src/main/java/seedu/us/among/commons/util/HeaderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ public static HashMap<String, String> parseHeaders(Set<Header> headerSet) {
HashMap<String, String> headerMap = new HashMap<>();
for (Header header : headerSet) {
String headerString = header.toString();
//to-do update trimming once handling of headers is updated on add
//trim leading and trailing brackets and quotations
headerString = headerString.substring(2, headerString.length() - 2);
String[] headerPair = headerString.split(":", 2);
assert headerPair.length == 2;
headerMap.put(headerPair[0].trim(), headerPair[1].trim());
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/seedu/us/among/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,28 @@ public class AddCommand extends Command {

public static final String COMMAND_WORD = "add";

public static final String MESSAGE_API_EXAMPLE_1 = "1.\n"
public static final String MESSAGE_API_EXAMPLE_1 = "1. "
+ COMMAND_WORD + " "
+ PREFIX_METHOD + " get "
+ PREFIX_ADDRESS + " https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=2 "
+ PREFIX_DATA + " {somedata} "
+ PREFIX_TAG + " cat "
+ PREFIX_TAG + " fact\n";
+ PREFIX_METHOD + "get "
+ PREFIX_ADDRESS + "http://localhost:3000/ "
+ PREFIX_DATA + "{some data} "
+ PREFIX_HEADER + "\"key: value\" "
+ PREFIX_HEADER + "\"key: value\" "
+ PREFIX_TAG + "local "
+ PREFIX_TAG + "data\n";

public static final String MESSAGE_API_EXAMPLE_2 = "2.\n"
public static final String MESSAGE_API_EXAMPLE_2 = "2. "
+ COMMAND_WORD + " "
+ PREFIX_METHOD + " get "
+ PREFIX_ADDRESS + " https://api.data.gov.sg/v1/environment/air-temperature "
+ PREFIX_TAG + " singapore ";
+ PREFIX_METHOD + "get "
+ PREFIX_ADDRESS + "https://api.data.gov.sg/v1/environment/air-temperature ";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an API endpoint to the API endpoint list.\n"
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Adds an API endpoint to the API endpoint list.\n"
+ "Parameters: "
+ PREFIX_METHOD + " METHOD "
+ PREFIX_ADDRESS + " ADDRESS "
+ "[" + PREFIX_DATA + " DATA] "
+ "[" + PREFIX_HEADER + " HEADER] "
+ "[" + PREFIX_HEADER + " HEADER]... "
+ "[" + PREFIX_TAG + " TAG]...\n"
+ "Examples:\n"
+ MESSAGE_API_EXAMPLE_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public class AddCommandParser implements Parser<AddCommand> {
* @throws ParseException if the user input does not conform the expected format
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_METHOD,
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(
args,
PREFIX_METHOD,
PREFIX_ADDRESS,
PREFIX_DATA,
PREFIX_HEADER,
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/us/among/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
public class CliSyntax {

/* Prefix definitions */
public static final Prefix PREFIX_METHOD = new Prefix("-x");
public static final Prefix PREFIX_ADDRESS = new Prefix("-u");
public static final Prefix PREFIX_TAG = new Prefix("-t");
public static final Prefix PREFIX_HEADER = new Prefix("-h");
public static final Prefix PREFIX_DATA = new Prefix("-d");
public static final Prefix PREFIX_METHOD = new Prefix("-x ");
public static final Prefix PREFIX_ADDRESS = new Prefix("-u ");
public static final Prefix PREFIX_TAG = new Prefix("-t ");
public static final Prefix PREFIX_HEADER = new Prefix("-h ");
public static final Prefix PREFIX_DATA = new Prefix("-d ");

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ImposterParser {
* @throws ParseException if the user input does not conform the expected format
*/
public Command parseCommand(String userInput) throws ParseException {
final Matcher matcher = BASIC_COMMAND_FORMAT.matcher(userInput.trim());
final Matcher matcher = BASIC_COMMAND_FORMAT.matcher(userInput.trim().toLowerCase());
if (!matcher.matches()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/us/among/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static Header parseHeader(String header) throws ParseException {
requireNonNull(header);
String trimmedHeader = header.trim();
if (!Header.isValidHeaderName(trimmedHeader)) {
throw new ParseException(Tag.MESSAGE_CONSTRAINTS);
throw new ParseException(Header.MESSAGE_CONSTRAINTS);
}
return new Header(trimmedHeader);
}
Expand Down
11 changes: 1 addition & 10 deletions src/main/java/seedu/us/among/model/endpoint/Endpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,10 @@ public boolean isSameEndpoint(Endpoint otherEndpoint) {
return true;
}

//expanded this for more clarity
if (otherEndpoint == null) {
return false;
} else {
if (otherEndpoint.getMethod().equals(getMethod())
&& otherEndpoint.getAddress().equals(getAddress())
&& otherEndpoint.getData().equals(getData())
&& otherEndpoint.getHeaders().equals(getHeaders())
&& otherEndpoint.getTags().equals(getTags())) {
return true;
} else {
return false;
}
return this.equals(otherEndpoint);
}
}

Expand Down
19 changes: 10 additions & 9 deletions src/main/java/seedu/us/among/model/endpoint/header/Header.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
* Guarantees: immutable; name is valid as declared in {@link #isValidHeaderName(String)}
*/
public class Header {
/**
* to-do
* THIS WHOLE CLASS IS A TO-DO I JUST COPY PASTED TAGS
*/

public static final String MESSAGE_CONSTRAINTS = "Header names should be alphanumeric";
public static final String MESSAGE_CONSTRAINTS = "Headers should be enclosed with a \" example \"";
public static final String VALIDATION_REGEX = ".*";

public final String headerName;
Expand All @@ -25,15 +21,20 @@ public class Header {
*/
public Header(String headerName) {
requireNonNull(headerName);
checkArgument(isValidHeaderName(headerName), MESSAGE_CONSTRAINTS);
this.headerName = headerName;
checkArgument(isValidHeaderName(headerName), Header.MESSAGE_CONSTRAINTS);
this.headerName = headerName.substring(1, headerName.length() - 1);
}

/**
* Returns true if a given string is a valid tag name.
*/
public static boolean isValidHeaderName(String test) {
return test.matches(VALIDATION_REGEX);
String temp = test.strip();
if (temp.startsWith("\"") && temp.endsWith("\"")) {
return test.matches(VALIDATION_REGEX);
} else {
return false;
}
}

@Override
Expand All @@ -52,7 +53,7 @@ public int hashCode() {
* Format state as text for viewing.
*/
public String toString() {
return '[' + headerName + ']';
return headerName;
}

}
2 changes: 1 addition & 1 deletion src/main/java/seedu/us/among/model/tag/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
public class Tag {

public static final String MESSAGE_CONSTRAINTS = "Tags names should be alphanumeric";
public static final String MESSAGE_CONSTRAINTS = "Tags names should be alphanumeric 123";
public static final String VALIDATION_REGEX = "\\p{Alnum}+";

public final String tagName;
Expand Down

0 comments on commit 7509057

Please sign in to comment.