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

Addresses issue #4 - unnecessary call to api.nuget.org #5

Open
wants to merge 4 commits 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
27 changes: 8 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
.vs/slnx.sqlite
.vs/VSWorkspaceState.json
.vs/SMSGlobal/v16/TestStore/0/002.testlog
.vs/smsglobal-dotnet/v16/.suo
.vs/smsglobal-dotnet/v16/TestStore/0/000.testlog
.vs/smsglobal-dotnet/v16/TestStore/0/testlog.manifest
SMSGlobal/bin/Debug/SMSGlobal.api.1.0.0.nupkg
SMSGlobal/obj/Debug/SMSGlobal.api.1.0.0.nuspec
SMSGlobal/obj/Release/netstandard2.0/SMSGlobal.api.AssemblyInfo.cs
SMSGlobal/obj/Release/netstandard2.0/SMSGlobal.api.AssemblyInfoInputs.cache
SMSGlobal/obj/Release/netstandard2.0/SMSGlobal.api.assets.cache
SMSGlobalTest/obj/Release/netcoreapp3.1/SMSGlobalTest.AssemblyInfo.cs
SMSGlobalTest/obj/Release/netcoreapp3.1/SMSGlobalTest.AssemblyInfoInputs.cache
SMSGlobalTest/obj/Release/netcoreapp3.1/SMSGlobalTest.assets.cache
SMSGlobalTest/obj/Release/netcoreapp3.1/SMSGlobalTest.csprojAssemblyReference.cache
# Local IDE info
.vs/
SMSGlobalTest/obj/
SMSGlobal/obj/
SMSGlobalTest/bin/
SMSGlobal/bin/
.idea/
*.user

# Build artifacts
**/obj/
**/bin/

1 change: 0 additions & 1 deletion SMSGlobal/OTP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Text;
using SMSGlobal.Response;
using System.Configuration;
using System.Net.Http;


Expand Down
5 changes: 2 additions & 3 deletions SMSGlobal/Response/Response.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Nancy.Json;
//using System.Web.Script.Serialization;
using Newtonsoft.Json;

/// <summary>
/// The response namespace.
Expand All @@ -17,7 +16,7 @@ public class Response
/// <returns>string</returns>
public override string ToString()
{
return new JavaScriptSerializer().Serialize(this);
return JsonConvert.SerializeObject(this);
}
}

Expand Down
4 changes: 1 addition & 3 deletions SMSGlobal/SMSGlobal.api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Nancy" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
17 changes: 6 additions & 11 deletions SMSGlobal/Transport/Rest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace SMSGlobal.SMS.Transport
class Rest
{
private Uri uri;
private readonly string dotnetLibVersion;

public string host { get; set; }
public string port { get; set; }
Expand All @@ -32,6 +33,10 @@ public Rest(Credentials _credentials)
version = _credentials.version;
key = _credentials.ApiKey;
secret = _credentials.ApiSecret;

// Figure out the version of this library, for use in the User-Agent header that we send.
var thisVersion = typeof(Rest).Assembly.GetName().Version;
dotnetLibVersion = $"{thisVersion.Major}.{thisVersion.Minor}.{thisVersion.Build}";
}

/// <summary>
Expand Down Expand Up @@ -338,7 +343,6 @@ public async Task<int> deleteOptOut(string number = "")
return otp;
}


/// <summary>
/// Requests information from the rest api.
/// </summary>
Expand Down Expand Up @@ -368,16 +372,7 @@ private async Task<HttpResponseMessage> Request(string path, Object payload = nu
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("MAC", credentials);

// Get latest Nuget Package version.
var packageName = "SMSGlobal";
var url = $"https://api.nuget.org/v3-flatcontainer/{packageName}/index.json";
var httpClient = new HttpClient();
var responseNuget = await httpClient.GetAsync(url);
var versionsResponse = await responseNuget.Content.ReadAsAsync<VersionsResponse>();
var lastVersion = versionsResponse.Versions[^1]; //(length-1)

client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "SMSGlobal-SDK/v2 Version/" + lastVersion + ", DotNet/" + System.Environment.Version + " (" + Environment.OSVersion + ")");
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "SMSGlobal-SDK/v2 Version/" + dotnetLibVersion + ", DotNet/" + System.Environment.Version + " (" + Environment.OSVersion + ")");

var json = JsonConvert.SerializeObject(payload);

Expand Down
2 changes: 1 addition & 1 deletion SMSGlobalTest/SMSGlobalTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down