Skip to content

Commit

Permalink
icons added & post, patch, delete works
Browse files Browse the repository at this point in the history
  • Loading branch information
ChungHo committed Apr 4, 2018
1 parent 526aea0 commit 490136a
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 26 deletions.
File renamed without changes
30 changes: 30 additions & 0 deletions src/firehopper/Resources/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/firehopper/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,21 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="firehopper_icon_delete" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>firehopper_icon_delete.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="firehopper_icon_get" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>firehopper_icon_get.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="firehopper_icon_keyval" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>firehopper_icon_keyval.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="firehopper_icon_patch" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>firehopper_icon_patch.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="firehopper_icon_post" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>firehopper_icon_post.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="firehopper_icon_put" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>firehopper_icon_put.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand Down
Binary file added src/firehopper/Resources/firehopper_icon_delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/firehopper/Resources/firehopper_icon_patch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/firehopper/Resources/firehopper_icon_post.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 53 additions & 12 deletions src/firehopper/firebaseManager/firebaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@ class firebaseManager
/// </summary>
public static async Task<string> getAsync(string _apiKey, string _databaseURL, string _databaseNode)
{
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(_databaseURL);
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Basic", "Bearer " + _apiKey);
HttpResponseMessage res = await httpClient.GetAsync(_databaseURL + _databaseNode + ".json");
HttpClient httpClient = setHttpClient(_apiKey, _databaseURL);
var res = await httpClient.GetAsync(_databaseURL + _databaseNode + ".json");
string responseBodyAsText = await res.Content.ReadAsStringAsync();

return responseBodyAsText;
Expand All @@ -32,6 +26,56 @@ public static async Task<string> getAsync(string _apiKey, string _databaseURL, s
/// This is a method that does the PUT request asynchronously to Firebase.
/// </summary>
public static async Task<string> putAsync(string _apiKey, string _databaseURL, string _databaseNode, string _keyValuePair)
{
HttpClient httpClient = setHttpClient(_apiKey, _databaseURL);
HttpContent httpContent = new StringContent(_keyValuePair);
var res = await httpClient.PutAsync(_databaseURL + _databaseNode + ".json", httpContent);

return res.StatusCode.ToString();
}


/// <summary>
/// This is a method that does the POST request asynchronously to Firebase.
/// </summary>
public static async Task<string> postAsync(string _apiKey, string _databaseURL, string _databaseNode, string _keyValuePair)
{
HttpClient httpClient = setHttpClient(_apiKey, _databaseURL);
HttpContent httpContent = new StringContent(_keyValuePair);
var res = await httpClient.PostAsync(_databaseURL + _databaseNode + ".json", httpContent);

return res.StatusCode.ToString();
}


/// <summary>
/// This is a method that does the PATCH request asynchronously to Firebase.
/// </summary>
public static async Task<string> patchAsync(string _apiKey, string _databaseURL, string _databaseNode, string _keyValuePair)
{
HttpClient httpClient = setHttpClient(_apiKey, _databaseURL);
HttpContent httpContent = new StringContent(_keyValuePair);
HttpRequestMessage req = new HttpRequestMessage(new HttpMethod("PATCH"), _databaseURL + _databaseNode + ".json");
req.Content = httpContent;
var res = await httpClient.SendAsync(req);
//var responseBodyAsText = await res.Content.ReadAsStringAsync();

return res.StatusCode.ToString();
}


/// <summary>
/// This is a method that does the DELETE request asynchronously to Firebase.
/// </summary>
public static async Task<string> deleteAsync(string _apiKey, string _databaseURL, string _databaseNode)
{
HttpClient httpClient = setHttpClient(_apiKey, _databaseURL);
var res = await httpClient.DeleteAsync(_databaseURL + _databaseNode + ".json");

return res.StatusCode.ToString();
}

public static HttpClient setHttpClient(string _apiKey, string _databaseURL)
{
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(_databaseURL);
Expand All @@ -41,10 +85,7 @@ public static async Task<string> putAsync(string _apiKey, string _databaseURL, s
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Basic", "Bearer " + _apiKey);

HttpContent httpContent = new StringContent(_keyValuePair);
HttpResponseMessage res = await httpClient.PutAsync(_databaseURL + _databaseNode + ".json", httpContent);

return res.StatusCode.ToString();
return httpClient;
}
}
}
9 changes: 9 additions & 0 deletions src/firehopper/firehopper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@
<ItemGroup>
<None Include="Resources\firehopper_icon_get.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\firehopper_icon_delete.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\firehopper_icon_patch.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\firehopper_icon_post.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
12 changes: 4 additions & 8 deletions src/firehopper/firehopperHTTP/GHC_fhDELETE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class fhDELETE : GH_Component
public string apiKey;
public string databaseURL;
public string databaseNode;
public string keyValuePair;
public bool trigger;

public string response;
Expand Down Expand Up @@ -37,9 +36,7 @@ protected override void RegisterInputParams(GH_Component.GH_InputParamManager pM
pManager.AddTextParameter("API Key", "AK", "API Key provided by Firebase", GH_ParamAccess.item);
pManager.AddTextParameter("Database URL", "U", "Database URL provided by Firebase", GH_ParamAccess.item);
pManager.AddTextParameter("Database Node", "N", "Database Node in the Firebase", GH_ParamAccess.item, "");
pManager.AddTextParameter("Key-Value Pair", "KVP", "Key-Value pair to save in Firebase", GH_ParamAccess.item);
pManager.AddBooleanParameter("Trigger", "T", "Trigger the PUT request", GH_ParamAccess.item);

}

/// <summary>
Expand All @@ -60,8 +57,7 @@ protected override void SolveInstance(IGH_DataAccess DA)
DA.GetData<string>(0, ref apiKey);
DA.GetData<string>(1, ref databaseURL);
DA.GetData<string>(2, ref databaseNode);
DA.GetData<string>(3, ref keyValuePair);
DA.GetData<bool>(4, ref trigger);
DA.GetData<bool>(3, ref trigger);

DA.IncrementIteration();
DA.SetData(0, response);
Expand All @@ -86,7 +82,7 @@ protected override void AfterSolveInstance()
{
try
{
firebaseManager.putAsync(apiKey, databaseURL, databaseNode, keyValuePair).ContinueWith(r =>
firebaseManager.deleteAsync(apiKey, databaseURL, databaseNode).ContinueWith(r =>
{
Grasshopper.Instances.ActiveCanvas.Invoke((Action)delegate
{
Expand All @@ -113,7 +109,7 @@ protected override System.Drawing.Bitmap Icon
{
get
{
return Resources.Resources.firehopper_icon_put;
return Resources.Resources.firehopper_icon_delete;
}
}

Expand All @@ -124,7 +120,7 @@ protected override System.Drawing.Bitmap Icon
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("39aa9974-c135-4e21-bcdf-1c4d4b0caf49"); }
get { return new Guid("8991293d-984b-4b2c-9c40-0b0cf5fd8a50"); }
}
}
}
6 changes: 3 additions & 3 deletions src/firehopper/firehopperHTTP/GHC_fhPATCH.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override void AfterSolveInstance()
{
try
{
firebaseManager.putAsync(apiKey, databaseURL, databaseNode, keyValuePair).ContinueWith(r =>
firebaseManager.patchAsync(apiKey, databaseURL, databaseNode, keyValuePair).ContinueWith(r =>
{
Grasshopper.Instances.ActiveCanvas.Invoke((Action)delegate
{
Expand All @@ -113,7 +113,7 @@ protected override System.Drawing.Bitmap Icon
{
get
{
return Resources.Resources.firehopper_icon_put;
return Resources.Resources.firehopper_icon_patch;
}
}

Expand All @@ -124,7 +124,7 @@ protected override System.Drawing.Bitmap Icon
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("39aa9974-c135-4e21-bcdf-1c4d4b0caf49"); }
get { return new Guid("1fbea561-5f8c-4a3a-9f85-d65beb4f9933"); }
}
}
}
6 changes: 3 additions & 3 deletions src/firehopper/firehopperHTTP/GHC_fhPOST.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override void AfterSolveInstance()
{
try
{
firebaseManager.putAsync(apiKey, databaseURL, databaseNode, keyValuePair).ContinueWith(r =>
firebaseManager.postAsync(apiKey, databaseURL, databaseNode, keyValuePair).ContinueWith(r =>
{
Grasshopper.Instances.ActiveCanvas.Invoke((Action)delegate
{
Expand All @@ -113,7 +113,7 @@ protected override System.Drawing.Bitmap Icon
{
get
{
return Resources.Resources.firehopper_icon_put;
return Resources.Resources.firehopper_icon_post;
}
}

Expand All @@ -124,7 +124,7 @@ protected override System.Drawing.Bitmap Icon
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("39aa9974-c135-4e21-bcdf-1c4d4b0caf49"); }
get { return new Guid("6ad1b932-1eb9-4bc1-a343-53824ed4f8a3"); }
}
}
}

0 comments on commit 490136a

Please sign in to comment.