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

Add wrapper for List Tariff Charges api #1

Merged
merged 1 commit into from
Jan 5, 2021
Merged
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
7 changes: 7 additions & 0 deletions src/main/java/com/wrapper/octopusenergy/OctopusEnergyApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import com.wrapper.octopusenergy.request.ProductsRequest;
import com.wrapper.octopusenergy.request.RetrieveProductRequest;
import com.wrapper.octopusenergy.request.TariffChargesListRequest;
import com.wrapper.octopusenergy.response.data.EnergyType;
import com.wrapper.octopusenergy.response.data.RateType;
import com.wrapper.octopusenergy.service.OctopusEnergyApiService;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
Expand Down Expand Up @@ -57,4 +60,8 @@ public ProductsRequest.Builder getProductList() {
public RetrieveProductRequest.Builder getProduct(String productCode) {
return new RetrieveProductRequest.Builder(this, productCode);
}

public TariffChargesListRequest.Builder getTariffCharges(String productCode, String tariffCode, EnergyType energyType, RateType rateType) {
return new TariffChargesListRequest.Builder(this, productCode, tariffCode, energyType, rateType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void main(String[] args) {
OctopusEnergyApi api = new OctopusEnergyApi(args[0]);

// Create and execute a request
OctopusEnergyProduct product = api.getProduct("M-AND-S-SEG-FIX-12M-20-11-11")
OctopusEnergyProduct product = api.getProduct("PREPAY-VAR-18-09-21")
.tariffsActiveAt(LocalDateTime.now())
.execute();
System.out.println("productRequest: " + product);
Expand Down
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);
}
}
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();
}
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.google.gson.annotations.SerializedName;
import com.sun.istack.internal.Nullable;
import com.wrapper.octopusenergy.response.Response;
import netscape.javascript.JSObject;

public class OctopusEnergyProduct extends Response<OctopusEnergyProduct> {
@SerializedName("code")
Expand Down
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;
}
}
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;
}

}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.wrapper.octopusenergy.response.data.OctopusEnergyProduct;
import com.wrapper.octopusenergy.response.data.ProductListData;
import com.wrapper.octopusenergy.response.data.TariffChargeData;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
Expand All @@ -21,4 +22,13 @@ Call<ProductListData> getProducts(
@GET("/v1/products/{product_code}/")
Call<OctopusEnergyProduct> getProduct(@Path("product_code") String productCode,
@Query("tariffs_active_at") String tariffsActiveAt);

@GET("/v1/products/{product_code}/{energy_type}/{tariff_code}/{rate_type}/")
Call<TariffChargeData> getTariffCharges(@Path("product_code") String productCode,
@Path("tariff_code") String tariffCode,
@Path("energy_type") String energyType,
@Path("rate_type") String rateType,
@Query("period_from") String periodFrom,
@Query("period_to") String periodTo,
@Query("page_size") String pageSize);
}