forked from globelabs/api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request globelabs#1 from globelabs/master
Update from master
- Loading branch information
Showing
29 changed files
with
1,412 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NET/Nuget Source/lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<solution> | ||
<add key="disableSourceControlIntegration" value="true" /> | ||
</solution> | ||
</configuration> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir> | ||
|
||
<!-- Enable the restore command to run before builds --> | ||
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages> | ||
|
||
<!-- Property that enables building a package from a project --> | ||
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage> | ||
|
||
<!-- Determines if package restore consent is required to restore packages --> | ||
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent> | ||
|
||
<!-- Download NuGet.exe if it does not already exist --> | ||
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition=" '$(PackageSources)' == '' "> | ||
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used --> | ||
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list --> | ||
<!-- | ||
<PackageSource Include="https://www.nuget.org/api/v2/" /> | ||
<PackageSource Include="https://my-nuget-source/nuget/" /> | ||
--> | ||
</ItemGroup> | ||
|
||
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'"> | ||
<!-- Windows specific commands --> | ||
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'"> | ||
<!-- We need to launch nuget.exe with the mono command if we're not on windows --> | ||
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<PackagesProjectConfig Condition=" '$(OS)' == 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config</PackagesProjectConfig> | ||
<PackagesProjectConfig Condition=" '$(OS)' != 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config</PackagesProjectConfig> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<PackagesConfig Condition="Exists('$(MSBuildProjectDirectory)\packages.config')">$(MSBuildProjectDirectory)\packages.config</PackagesConfig> | ||
<PackagesConfig Condition="Exists('$(PackagesProjectConfig)')">$(PackagesProjectConfig)</PackagesConfig> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<!-- NuGet command --> | ||
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath> | ||
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources> | ||
|
||
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand> | ||
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 "$(NuGetExePath)"</NuGetCommand> | ||
|
||
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir> | ||
|
||
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch> | ||
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch> | ||
|
||
<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir> | ||
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir> | ||
|
||
<!-- Commands --> | ||
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand> | ||
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand> | ||
|
||
<!-- We need to ensure packages are restored prior to assembly resolve --> | ||
<BuildDependsOn Condition="$(RestorePackages) == 'true'"> | ||
RestorePackages; | ||
$(BuildDependsOn); | ||
</BuildDependsOn> | ||
|
||
<!-- Make the build depend on restore packages --> | ||
<BuildDependsOn Condition="$(BuildPackage) == 'true'"> | ||
$(BuildDependsOn); | ||
BuildPackage; | ||
</BuildDependsOn> | ||
</PropertyGroup> | ||
|
||
<Target Name="CheckPrerequisites"> | ||
<!-- Raise an error if we're unable to locate nuget.exe --> | ||
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" /> | ||
<!-- | ||
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once. | ||
This effectively acts as a lock that makes sure that the download operation will only happen once and all | ||
parallel builds will have to wait for it to complete. | ||
--> | ||
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" /> | ||
</Target> | ||
|
||
<Target Name="_DownloadNuGet"> | ||
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" /> | ||
</Target> | ||
|
||
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites"> | ||
<Exec Command="$(RestoreCommand)" | ||
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" /> | ||
|
||
<Exec Command="$(RestoreCommand)" | ||
LogStandardErrorAsError="true" | ||
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" /> | ||
</Target> | ||
|
||
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites"> | ||
<Exec Command="$(BuildCommand)" | ||
Condition=" '$(OS)' != 'Windows_NT' " /> | ||
|
||
<Exec Command="$(BuildCommand)" | ||
LogStandardErrorAsError="true" | ||
Condition=" '$(OS)' == 'Windows_NT' " /> | ||
</Target> | ||
|
||
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> | ||
<ParameterGroup> | ||
<OutputFilename ParameterType="System.String" Required="true" /> | ||
</ParameterGroup> | ||
<Task> | ||
<Reference Include="System.Core" /> | ||
<Using Namespace="System" /> | ||
<Using Namespace="System.IO" /> | ||
<Using Namespace="System.Net" /> | ||
<Using Namespace="Microsoft.Build.Framework" /> | ||
<Using Namespace="Microsoft.Build.Utilities" /> | ||
<Code Type="Fragment" Language="cs"> | ||
<![CDATA[ | ||
try { | ||
OutputFilename = Path.GetFullPath(OutputFilename); | ||
Log.LogMessage("Downloading latest version of NuGet.exe..."); | ||
WebClient webClient = new WebClient(); | ||
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename); | ||
return true; | ||
} | ||
catch (Exception ex) { | ||
Log.LogErrorFromException(ex); | ||
return false; | ||
} | ||
]]> | ||
</Code> | ||
</Task> | ||
</UsingTask> | ||
</Project> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace GlobeLabsApi | ||
{ | ||
public static class HttpExtensions | ||
{ | ||
public static string ReadResponse(this WebResponse webResponse) | ||
{ | ||
if (webResponse == null) | ||
return string.Empty; | ||
|
||
using (var responseStream = webResponse.GetResponseStream()) | ||
using (var responseReader = new StreamReader(responseStream)) | ||
{ | ||
var responseBody = responseReader.ReadToEnd(); | ||
return responseBody; | ||
} | ||
} | ||
|
||
public static HttpStatus ResponseStatus(this WebResponse webResponse) | ||
{ | ||
HttpWebResponse httpResponse = (HttpWebResponse)webResponse; | ||
|
||
return new HttpStatus | ||
{ | ||
StatusCode = (int) httpResponse.StatusCode, | ||
StatusDescription = httpResponse.StatusDescription | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Specialized; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Web; | ||
|
||
namespace GlobeLabsApi | ||
{ | ||
public static class StringExtensions | ||
{ | ||
/// <summary> | ||
/// NamedValueCollection to QueryString data | ||
/// </summary> | ||
/// <param name="collection">The collection.</param> | ||
/// <returns></returns> | ||
public static string ToQueryString(this NameValueCollection collection) | ||
{ | ||
string query = string.Join("&", collection.AllKeys.Select(key => string.Format("{0}={1}", key, HttpUtility.UrlEncode(collection[key])))); | ||
query = string.Join("&", collection.AllKeys.Where(key => !string.IsNullOrWhiteSpace(collection[key])).Select(key => string.Format("{0}={1}", key, HttpUtility.UrlEncode(collection[key])))); | ||
|
||
return query; | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace GlobeLabsApi | ||
{ | ||
public class GlobeLabs | ||
{ | ||
private string applicationId = string.Empty; | ||
private string applicationSecret = string.Empty; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="GlobeLabs"/> class. | ||
/// </summary> | ||
public GlobeLabs(string accessToken) | ||
{ | ||
this.AccessToken = accessToken; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the access token. | ||
/// </summary> | ||
/// <value> | ||
/// The access token. | ||
/// </value> | ||
public string AccessToken { get; set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="GlobeLabs"/> class. | ||
/// </summary> | ||
/// <param name="applicationId">The application identifier.</param> | ||
/// <param name="applicationSecret">The application secret.</param> | ||
public GlobeLabs(string applicationId, string applicationSecret) | ||
{ | ||
this.applicationId = applicationId; | ||
this.applicationSecret = applicationSecret; | ||
} | ||
|
||
/// <summary> | ||
/// Authorizes the specified code. | ||
/// </summary> | ||
/// <param name="code">The code.</param> | ||
/// <returns></returns> | ||
public AuthResult Authorize(string code) | ||
{ | ||
var authResult = AuthService.Instance.Authorize(code, this.applicationId, this.applicationSecret); | ||
this.AccessToken = AuthService.Instance.AccessToken; | ||
|
||
return authResult; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the authentication login URL. | ||
/// </summary> | ||
/// <returns></returns> | ||
public string GetAuthLoginUrl() | ||
{ | ||
if (string.IsNullOrEmpty(this.applicationId)) | ||
{ | ||
throw new ArgumentException("getauthloginurl - applicationId is required."); | ||
} | ||
|
||
return AuthService.Instance.GetLoginDialogUrl(this.applicationId); | ||
} | ||
|
||
/// <summary> | ||
/// Charges the specified payload. | ||
/// </summary> | ||
/// <param name="payload">The payload.</param> | ||
/// <returns></returns> | ||
public PaymentResult Charge(PaymentPayload payload) | ||
{ | ||
return PaymentService.Instance.Charge(payload, this.AccessToken); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Pushes the SMS. | ||
/// </summary> | ||
/// <param name="shortCode">The short code.</param> | ||
/// <param name="payload">The payload.</param> | ||
/// <returns></returns> | ||
public SmsResult PushSms(string shortCode, SmsPayload payload) | ||
{ | ||
return SmsService.Instance.Send(shortCode, this.AccessToken, payload); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{7CD7C280-F52B-49EB-ADAD-04AA5952C5FE}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>GlobeLabsApi</RootNamespace> | ||
<AssemblyName>GlobeLabsApi</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> | ||
<RestorePackages>true</RestorePackages> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Web" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Extensions\HttpExtensions.cs" /> | ||
<Compile Include="Extensions\StringExtensions.cs" /> | ||
<Compile Include="GlobeLabs.cs" /> | ||
<Compile Include="Helpers\Config.cs" /> | ||
<Compile Include="Models\AuthResponse.cs" /> | ||
<Compile Include="Models\JsonModels.cs" /> | ||
<Compile Include="Models\PaymentResponse.cs" /> | ||
<Compile Include="Models\SmsResponse.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Services\AuthService.cs" /> | ||
<Compile Include="Services\GlobeLabsBase.cs" /> | ||
<Compile Include="Services\PaymentService.cs" /> | ||
<Compile Include="Services\SmsService.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Import Project="$(SolutionDir)\.nuget\nuget.targets" /> | ||
<PropertyGroup> | ||
<PostBuildEvent>xcopy /y $(TargetPath) $(SolutionDir)\Binary</PostBuildEvent> | ||
</PropertyGroup> | ||
<!-- 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. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
Oops, something went wrong.