-
Notifications
You must be signed in to change notification settings - Fork 3
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 #1 from faeludire/add-list-tariff-charges-api
Add wrapper for List Tariff Charges api
- Loading branch information
Showing
10 changed files
with
266 additions
and
2 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
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
18 changes: 18 additions & 0 deletions
18
src/main/java/com/wrapper/octopusenergy/example/TariffChargeRequestExample.java
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,18 @@ | ||
package com.wrapper.octopusenergy.example; | ||
|
||
import com.wrapper.octopusenergy.OctopusEnergyApi; | ||
import com.wrapper.octopusenergy.response.data.EnergyType; | ||
import com.wrapper.octopusenergy.response.data.RateType; | ||
import com.wrapper.octopusenergy.response.data.TariffChargeData; | ||
|
||
public class TariffChargeRequestExample { | ||
public static void main(String[] args) { | ||
// For all requests an API key is needed | ||
OctopusEnergyApi api = new OctopusEnergyApi(args[0]); | ||
|
||
// Create and execute a request | ||
TariffChargeData product = api.getTariffCharges("PREPAY-VAR-18-09-21", "E-1R-PREPAY-VAR-18-09-21-A", EnergyType.ELECTRICITY_TARIFFS, RateType.STANDING_CHARGES) | ||
.execute(); | ||
System.out.println("productRequest: " + product); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/com/wrapper/octopusenergy/request/TariffChargesListRequest.java
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,82 @@ | ||
package com.wrapper.octopusenergy.request; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import com.wrapper.octopusenergy.OctopusEnergyApi; | ||
import com.wrapper.octopusenergy.response.data.EnergyType; | ||
import com.wrapper.octopusenergy.response.data.RateType; | ||
import com.wrapper.octopusenergy.response.data.TariffChargeData; | ||
import com.wrapper.octopusenergy.util.ISODateFormatter; | ||
|
||
public class TariffChargesListRequest extends Request<TariffChargeData> { | ||
private final String periodTo; | ||
private final String pageSize; | ||
private final String periodFrom; | ||
private final RateType rateType; | ||
private final String tariffCode; | ||
private final String productCode; | ||
private final EnergyType energyType; | ||
|
||
TariffChargesListRequest(Builder builder) { | ||
super(builder.octopusEnergyApi); | ||
|
||
this.productCode = builder.productCode; | ||
this.tariffCode = builder.tariffCode; | ||
this.periodTo = builder.periodTo; | ||
this.pageSize = builder.pageSize; | ||
this.periodFrom = builder.periodFrom; | ||
this.rateType = builder.rateType; | ||
this.energyType = builder.energyType; | ||
} | ||
|
||
protected TariffChargeData execute() { | ||
return super.execute(octopusEnergyApi.octopusEnergyApiService() | ||
.getTariffCharges( | ||
productCode, | ||
tariffCode, | ||
energyType.getValue(), | ||
rateType.getValue(), | ||
periodFrom, | ||
periodTo, | ||
pageSize), TariffChargeData.class); | ||
} | ||
|
||
public static class Builder extends AbstractBuilder<TariffChargeData> { | ||
|
||
private String periodTo; | ||
private String pageSize; | ||
private String periodFrom; | ||
private final String tariffCode; | ||
private final RateType rateType; | ||
private final String productCode; | ||
private final EnergyType energyType; | ||
|
||
public Builder(OctopusEnergyApi octopusEnergyApi, String productCode, String tariffCode, EnergyType energyType, RateType rateType) { | ||
super(octopusEnergyApi); | ||
this.productCode = productCode; | ||
this.tariffCode = tariffCode; | ||
this.energyType = energyType; | ||
this.rateType = rateType; | ||
} | ||
|
||
public Builder periodFrom(LocalDateTime periodFrom) { | ||
this.periodFrom = ISODateFormatter.getFormattedDateTimeString(periodFrom); | ||
return this; | ||
} | ||
|
||
public Builder periodTo(LocalDateTime periodTo) { | ||
this.periodTo = ISODateFormatter.getFormattedDateTimeString(periodTo); | ||
return this; | ||
} | ||
|
||
public Builder pageSize(String pageSize) { | ||
this.pageSize = pageSize; | ||
return this; | ||
} | ||
|
||
@Override | ||
public TariffChargeData execute() { | ||
return new TariffChargesListRequest(this).execute(); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/wrapper/octopusenergy/response/data/EnergyType.java
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,17 @@ | ||
package com.wrapper.octopusenergy.response.data; | ||
|
||
public enum EnergyType { | ||
|
||
GAS_TARIFFS("gas-tariffs"), | ||
ELECTRICITY_TARIFFS("electricity-tariffs"); | ||
|
||
private final String value; | ||
|
||
EnergyType(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
src/main/java/com/wrapper/octopusenergy/response/data/RateType.java
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,18 @@ | ||
package com.wrapper.octopusenergy.response.data; | ||
|
||
public enum RateType { | ||
STANDING_CHARGES("standing-charges"), | ||
STANDARD_UNIT_RATES("standard-unit-rates"), | ||
DAY_UNIT_RATES("day-unit-rates"), | ||
NIGHT_UNIT_RATES("night-unit-rates"); | ||
|
||
private final String value; | ||
|
||
RateType(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/com/wrapper/octopusenergy/response/data/TariffCharge.java
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,53 @@ | ||
package com.wrapper.octopusenergy.response.data; | ||
|
||
import com.google.gson.annotations.Expose; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
public class TariffCharge { | ||
|
||
@SerializedName("value_exc_vat") | ||
@Expose | ||
private Double valueExcVat; | ||
@SerializedName("value_inc_vat") | ||
@Expose | ||
private Double valueIncVat; | ||
@SerializedName("valid_from") | ||
@Expose | ||
private String validFrom; | ||
@SerializedName("valid_to") | ||
@Expose | ||
private String validTo; | ||
|
||
public Double getValueExcVat() { | ||
return valueExcVat; | ||
} | ||
|
||
public void setValueExcVat(Double valueExcVat) { | ||
this.valueExcVat = valueExcVat; | ||
} | ||
|
||
public Double getValueIncVat() { | ||
return valueIncVat; | ||
} | ||
|
||
public void setValueIncVat(Double valueIncVat) { | ||
this.valueIncVat = valueIncVat; | ||
} | ||
|
||
public String getValidFrom() { | ||
return validFrom; | ||
} | ||
|
||
public void setValidFrom(String validFrom) { | ||
this.validFrom = validFrom; | ||
} | ||
|
||
public String getValidTo() { | ||
return validTo; | ||
} | ||
|
||
public void setValidTo(String validTo) { | ||
this.validTo = validTo; | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/wrapper/octopusenergy/response/data/TariffChargeData.java
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,60 @@ | ||
package com.wrapper.octopusenergy.response.data; | ||
|
||
import java.util.List; | ||
|
||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.annotations.Expose; | ||
import com.google.gson.annotations.SerializedName; | ||
import com.wrapper.octopusenergy.response.Response; | ||
|
||
public class TariffChargeData extends Response<TariffChargeData> { | ||
|
||
@SerializedName("count") | ||
@Expose | ||
private Integer count; | ||
@SerializedName("next") | ||
@Expose | ||
private Object next; | ||
@SerializedName("previous") | ||
@Expose | ||
private Object previous; | ||
@SerializedName("results") | ||
@Expose | ||
private List<TariffCharge> tariffCharges = null; | ||
|
||
public Integer getCount() { | ||
return count; | ||
} | ||
|
||
public void setCount(Integer count) { | ||
this.count = count; | ||
} | ||
|
||
public Object getNext() { | ||
return next; | ||
} | ||
|
||
public void setNext(Object next) { | ||
this.next = next; | ||
} | ||
|
||
public Object getPrevious() { | ||
return previous; | ||
} | ||
|
||
public void setPrevious(Object previous) { | ||
this.previous = previous; | ||
} | ||
|
||
public List<TariffCharge> getResults() { | ||
return tariffCharges; | ||
} | ||
|
||
public void setResults(List<TariffCharge> results) { | ||
this.tariffCharges = results; | ||
} | ||
|
||
public String toString() { | ||
return new GsonBuilder().setPrettyPrinting().create().toJson(this); | ||
} | ||
} |
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