Skip to content

Commit

Permalink
pricing done
Browse files Browse the repository at this point in the history
- added the prices from the api
  • Loading branch information
lk-code committed Aug 9, 2018
1 parent f7fbd05 commit b853f73
Show file tree
Hide file tree
Showing 12 changed files with 362 additions and 109 deletions.
99 changes: 2 additions & 97 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,101 +8,6 @@ the project is a .NET Standard 2.0 Library and can be used in the most projects
- Console Application
- ASP.NET

### requirements
### documentation

- JSON.NET

# examples

## initialize
```
// this code as first in the init-method
CloudApiNet.Core.ApiCore.ApiToken = "YOUR_ACCESS_TOKEN_HERE";
```

## load server

### get all server

Server.GetAsync() is a static method and returns all server.

```
List<CloudApiNet.Api.Server> serverList = await CloudApiNet.Api.Server.GetAsync();
```

### get all server with filter

Server.GetAsync() is a static method and returns all server.

```
string serverFilter = "servername";
List<CloudApiNet.Api.Server> serverList = await CloudApiNet.Api.Server.GetAsync(serverFilter);
```

### get one server

Server.GetAsync(long id) is a static method and returns a specific server.

```
long id = 5864;
CloudApiNet.Api.Server server = await CloudApiNet.Api.Server.GetAsync(id);
```

## the server object

with the returned server object you can execute every server action.

### Server.PowerOn()

```
long id = 5864;
CloudApiNet.Api.Server server = await CloudApiNet.Api.Server.GetAsync(id);
ServerActionResponse actionResponse = await server.PowerOn();
```

### Server.Reboot()

```
long id = 5864;
CloudApiNet.Api.Server server = await CloudApiNet.Api.Server.GetAsync(id);
ServerActionResponse actionResponse = await server.Reboot();
```

### Server.Reset()

```
long id = 5864;
CloudApiNet.Api.Server server = await CloudApiNet.Api.Server.GetAsync(id);
ServerActionResponse actionResponse = await server.Reset();
```

### Server.Shutdown()

```
long id = 5864;
CloudApiNet.Api.Server server = await CloudApiNet.Api.Server.GetAsync(id);
ServerActionResponse actionResponse = await server.Shutdown();
```

### Server.PowerOff()

```
long id = 5864;
CloudApiNet.Api.Server server = await CloudApiNet.Api.Server.GetAsync(id);
ServerActionResponse actionResponse = await server.PowerOff();
```

### Server.ResetPassword()

```
long id = 5864;
CloudApiNet.Api.Server server = await CloudApiNet.Api.Server.GetAsync(id);
ServerActionResponse actionResponse = await server.Shutdown();
string newPassword = (string)actionResponse.AdditionalActionContent;
```
see the documentation on https://github.com/lk-code/hetzner-cloud-api-net/wiki
10 changes: 10 additions & 0 deletions hetzner-cloud-api-net/cloud-api-net/Api/FloatingIpPricing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace lkcode.hetznercloudapi.Api
{
public class FloatingIpPricing
{
/// <summary>
/// the cost of one floating IP per month.
/// </summary>
public PricingValue PriceMontly { get; set; } = new PricingValue();
}
}
10 changes: 10 additions & 0 deletions hetzner-cloud-api-net/cloud-api-net/Api/ImagePricing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace lkcode.hetznercloudapi.Api
{
public class ImagePricing
{
/// <summary>
/// the cost of one 1GB Image for the full month.
/// </summary>
public PricingValue PricePerGbMonth { get; set; } = new PricingValue();
}
}
85 changes: 85 additions & 0 deletions hetzner-cloud-api-net/cloud-api-net/Api/Pricing.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using lkcode.hetznercloudapi.Core;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace lkcode.hetznercloudapi.Api
Expand All @@ -16,6 +17,31 @@ public class Pricing
/// </summary>
public string VatRate { get; set; } = string.Empty;

/// <summary>
///
/// </summary>
public ImagePricing Image { get; set; } = null;

/// <summary>
///
/// </summary>
public FloatingIpPricing FloatingIp { get; set; } = null;

/// <summary>
///
/// </summary>
public TrafficPricing Traffic { get; set; } = null;

/// <summary>
///
/// </summary>
public ServerBackupPricing ServerBackup { get; set; } = null;

/// <summary>
///
/// </summary>
public List<ServerTypePricing> ServerTypes { get; set; } = null;

#region # static methods #

/// <summary>
Expand Down Expand Up @@ -49,6 +75,65 @@ private static Pricing GetPricingsFromResponseData(Objects.Pricing.Get.Response

pricings.Currency = responseData.pricing.currency;
pricings.VatRate = responseData.pricing.vat_rate;
pricings.Image = new ImagePricing()
{
PricePerGbMonth = new PricingValue()
{
Net = responseData.pricing.image.price_per_gb_month.net,
Gross = responseData.pricing.image.price_per_gb_month.gross
}
};
pricings.FloatingIp = new FloatingIpPricing()
{
PriceMontly = new PricingValue()
{
Net = responseData.pricing.floating_ip.price_monthly.net,
Gross = responseData.pricing.floating_ip.price_monthly.gross
}
};
pricings.Traffic = new TrafficPricing()
{
PricePerTb = new PricingValue()
{
Net = responseData.pricing.traffic.price_per_tb.net,
Gross = responseData.pricing.traffic.price_per_tb.gross
}
};
pricings.ServerBackup = new ServerBackupPricing()
{
Percentage = responseData.pricing.server_backup.percentage
};
pricings.ServerTypes = new List<ServerTypePricing>();

foreach (var serverType in responseData.pricing.server_types)
{
ServerTypePricing stp = new ServerTypePricing();

stp.Id = serverType.id;
stp.Name = serverType.name;
stp.Prices = new List<ServerTypePricingValue>();

foreach(var serverTypePrice in serverType.prices)
{
ServerTypePricingValue stpv = new ServerTypePricingValue();

stpv.Location = serverTypePrice.location;
stpv.PriceHourly = new PricingValue()
{
Net = serverTypePrice.price_hourly.net,
Gross = serverTypePrice.price_hourly.gross
};
stpv.PriceMontly = new PricingValue()
{
Net = serverTypePrice.price_monthly.net,
Gross = serverTypePrice.price_monthly.gross
};

stp.Prices.Add(stpv);
}

pricings.ServerTypes.Add(stp);
}

return pricings;
}
Expand Down
15 changes: 15 additions & 0 deletions hetzner-cloud-api-net/cloud-api-net/Api/PricingValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace lkcode.hetznercloudapi.Api
{
public class PricingValue
{
/// <summary>
/// the net price-value
/// </summary>
public string Net { get; set; } = string.Empty;

/// <summary>
/// the gross price-value
/// </summary>
public string Gross { get; set; } = string.Empty;
}
}
10 changes: 10 additions & 0 deletions hetzner-cloud-api-net/cloud-api-net/Api/ServerBackupPricing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace lkcode.hetznercloudapi.Api
{
public class ServerBackupPricing
{
/// <summary>
/// will increase base server costs by specific percentage.
/// </summary>
public string Percentage { get; set; } = string.Empty;
}
}
22 changes: 22 additions & 0 deletions hetzner-cloud-api-net/cloud-api-net/Api/ServerTypePricing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;

namespace lkcode.hetznercloudapi.Api
{
public class ServerTypePricing
{
/// <summary>
///
/// </summary>
public int Id { get; set; } = 0;

/// <summary>
///
/// </summary>
public string Name { get; set; } = string.Empty;

/// <summary>
///
/// </summary>
public List<ServerTypePricingValue> Prices { get; set; } = null;
}
}
24 changes: 24 additions & 0 deletions hetzner-cloud-api-net/cloud-api-net/Api/ServerTypePricingValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace lkcode.hetznercloudapi.Api
{
public class ServerTypePricingValue
{
/// <summary>
///
/// </summary>
public string Location { get; set; } = string.Empty;

/// <summary>
///
/// </summary>
public PricingValue PriceHourly { get; set; } = null;

/// <summary>
///
/// </summary>
public PricingValue PriceMontly { get; set; } = null;
}
}
10 changes: 10 additions & 0 deletions hetzner-cloud-api-net/cloud-api-net/Api/TrafficPricing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace lkcode.hetznercloudapi.Api
{
public class TrafficPricing
{
/// <summary>
/// the cost of additional traffic per TB.
/// </summary>
public PricingValue PricePerTb { get; set; } = new PricingValue();
}
}
16 changes: 16 additions & 0 deletions hetzner-cloud-api-net/cloud-api-net/hloud-net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>lkcode.hetznercloudapi</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
<FileVersion>1.0.1.0</FileVersion>
<Version>1.0.1</Version>
<Authors>lk-code</Authors>
<Company />
<Product>hetznercloudapi</Product>
<PackageId>hetznercloudapi</PackageId>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseUrl>https://raw.githubusercontent.com/lk-code/hetzner-cloud-api-net/master/LICENSE</PackageLicenseUrl>
<PackageTags>BETA</PackageTags>
<PackageReleaseNotes>this is a beta version</PackageReleaseNotes>
<Description>a hetzner cloud api library for .NET Standard. documentation at: https://github.com/lk-code/hetzner-cloud-api-net/wiki</Description>
<PackageProjectUrl>https://github.com/lk-code/hetzner-cloud-api-net</PackageProjectUrl>
<RepositoryUrl>https://github.com/lk-code/hetzner-cloud-api-net</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit b853f73

Please sign in to comment.