Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+ RestifizerRequest: Get() is now accepting parameters #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions RestifizerRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public void Get(Action<RestifizerResponse> callback = null) {
performRequest("get", null, callback);
}

public void Get(Hashtable parameters = null, Action<RestifizerResponse> callback = null) {
performRequest("get", parameters, callback);
}

public void Post(Hashtable parameters = null, Action<RestifizerResponse> callback = null) {
performRequest("post", parameters, callback);
}
Expand Down Expand Up @@ -134,6 +138,16 @@ public RestifizerRequest Copy() {
return restifizerRequest;
}

private string addQuery (string currentStr, Hashtable parameters) {
foreach (string key in parameters.Keys) {
if (currentStr.Length > 0) {
currentStr += "&";
}
currentStr += key + "=" + parameters[key];
}
return currentStr;
}

private void performRequest(string method, Hashtable parameters = null, Action<RestifizerResponse> callback = null) {

HTTP.Request someRequest;
Expand Down Expand Up @@ -166,12 +180,12 @@ private void performRequest(string method, Hashtable parameters = null, Action<R

// extra params
if (extraQuery != null && extraQuery.Count > 0) {
foreach (string key in extraQuery.Keys) {
if (queryStr.Length > 0) {
queryStr += "&";
}
queryStr += key + "=" + extraQuery[key];
}
queryStr = addQuery(queryStr, extraQuery);
}

if (method == "get" && parameters != null && parameters.Count > 0) {
queryStr = addQuery(queryStr, parameters);
parameters = null;
}

if (queryStr.Length > 0) {
Expand Down
7 changes: 7 additions & 0 deletions RestifizerResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ public class RestifizerResponse {
public string Tag;
public HTTP.Request Request;

public Hashtable getFirst () {
IEnumerator enumerator = ResourceList.GetEnumerator();
enumerator.MoveNext();

return (Hashtable)enumerator.Current;
}

public RestifizerResponse(HTTP.Request request, Hashtable result, string tag) {
this.IsList = false;
this.Status = request.response.status;
Expand Down