Skip to content

Commit

Permalink
- Fix Java client initialization
Browse files Browse the repository at this point in the history
- Fix Goland import
- Fix Error Guide examples in Java, .NET and Go
  • Loading branch information
nwithan8 committed Jun 4, 2024
1 parent 2aa847c commit 99cd215
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package example

import (
"fmt"
"github.com/EasyPost/easypost-go/v4"
)

func main() {
Expand Down
31 changes: 22 additions & 9 deletions official/guides/errors-guide/csharp/catch-error.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyPost;
using EasyPost.Models.API;
using EasyPost.Parameters;

try
namespace EasyPostExamples
{
Dictionary<string, object> parameters = new Dictionary<string, object> {
{ "verify_strict", True}
}
await Address.Create(parameters);
}
catch (EasyPost.Exceptions.API.ApiError error)
{
Console.Write(error.Code); // ADDRESS.VERIFY.FAILURE
public class Examples
{
public static async Task Main()
{
var client = new EasyPost.Client(new EasyPost.ClientConfiguration("EASYPOST_API_KEY"));

try {
Parameters.Address.Create parameters = new()
{
VerifyStrict = true
};
Address address = await client.Address.Create(parameters);
} catch (EasyPost.Exceptions.API.ApiError error) {
Console.Write(error.Code); // ADDRESS.VERIFY.FAILURE
}
}
}
}
7 changes: 2 additions & 5 deletions official/guides/errors-guide/golang/catch-error.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ package example

import (
"fmt"
"os"

"github.com/EasyPost/easypost-go/v2"
"github.com/EasyPost/easypost-go/v4"
)

func main() {
apiKey := os.Getenv("<YOUR_TEST/PRODUCTION_API_KEY>")
client := easypost.New(apiKey)
client := easypost.New("EASYPOST_API_KEY")

_, err := client.CreateAddress(
&easypost.Address{
Expand Down
8 changes: 4 additions & 4 deletions official/guides/errors-guide/java/catch-error.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

public class CatchError {
public static void main(String[] args) throws EasyPostException {
EasyPost.apiKey = System.getenv("EASYPOST_API_KEY");
EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY");

try {
Map<String, Object> address = new HashMap<String, Object>();
Map<String, Object> addressData = new HashMap<String, Object>();

address.put("verify_strict", true);
addressData.put("verify_strict", true);

Address.create(address);
Address address = client.address.create(address);
} catch (APIException error) {
System.err.println(error.getCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package example
import (
"os"

"github.com/EasyPost/easypost-go/v2"
"github.com/EasyPost/easypost-go/v4"
)

func main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package example
import (
"os"

"github.com/EasyPost/easypost-go/v2"
"github.com/EasyPost/easypost-go/v4"
)

func main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

public class RetrieveReferralUsers {
public static void main(String[] args) throws EasyPostException {
EasyPost.apiKey = System.getenv("EASYPOST_API_KEY");
EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY");

Map<String, Object> params = new HashMap<String, Object>();
params.put("recharge_threshold", "50.00");

User me = User.retrieveMe();
me.update(params);
User me = client.user.retrieveMe();
me = client.user.update(me.getId(), params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

public class RetrieveReferralUsers {
public static void main(String[] args) throws EasyPostException {
EasyPost.apiKey = System.getenv("EASYPOST_API_KEY");
EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY");

Billing.fundWallet("2000", PaymentMethod.Priority.PRIMARY);
client.billing.fundWallet("2000", PaymentMethod.Priority.PRIMARY);
}
}
5 changes: 2 additions & 3 deletions official/guides/tracking-guide/golang/create-shipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package example
import (
"os"

"github.com/EasyPost/easypost-go/v2"
"github.com/EasyPost/easypost-go/v4"
)

func main() {
apiKey := os.Getenv("<YOUR_TEST/PRODUCTION_API_KEY>")
client := easypost.New(apiKey)
client := easypost.New("EASYPOST_API_KEY")

shipment, err := client.CreateShipment(
&easypost.Shipment{
Expand Down
6 changes: 3 additions & 3 deletions official/guides/tracking-guide/java/create-shipment.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class CreateShipment {
public static void main(String[] args) throws EasyPostException {
EasyPost.apiKey = System.getenv("EASYPOST_API_KEY");
EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY");

HashMap<String, Object> fromAddressMap = new HashMap<String, Object>();
fromAddressMap.put("company", "EasyPost");
Expand Down Expand Up @@ -37,8 +37,8 @@ public static void main(String[] args) throws EasyPostException {
shipmentMap.put("from_address", fromAddressMap);
shipmentMap.put("parcel", parcelMap);

Shipment shipment = Shipment.create(shipmentMap);
Shipment shipment = client.shipment.create(shipmentMap);

shipment.buy(shipment.lowestRate());
client.Shipment.buy(shipment.getId(), shipment.lowestRate());
}
}
5 changes: 3 additions & 2 deletions official/guides/tracking-guide/java/create-tracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

public class CreateTracker {
public static void main(String[] args) throws EasyPostException {
EasyPost.apiKey = System.getenv("EASYPOST_API_KEY");
EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY");

// Creating a Tracker
Map<String, Object> params = new HashMap<String, Object>();
params.put("tracking_code", "EZ4000000004");
params.put("carrier", "UPS");
Tracker tracker = Tracker.create(params);

Tracker tracker = client.tracker.create(params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class PrintShipmentTrackingCode {
public static void main(String[] args) throws EasyPostException {
EasyPost.apiKey = System.getenv("EASYPOST_API_KEY");
EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY");

// Print Tracking Code
System.out.println(shipment.postage_label.tracking_code);
Expand Down
5 changes: 2 additions & 3 deletions official/guides/webhooks-guide/golang/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package example
import (
"os"

"github.com/EasyPost/easypost-go/v2"
"github.com/EasyPost/easypost-go/v4"
)

func main() {
apiKey := os.Getenv("<YOUR_TEST/PRODUCTION_API_KEY>")
client := easypost.New(apiKey)
client := easypost.New("EASYPOST_API_KEY")

_, _ = client.CreateWebhookWithDetails(
&easypost.CreateUpdateWebhookOptions{
Expand Down
4 changes: 2 additions & 2 deletions official/guides/webhooks-guide/java/create.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

public class Create {
public static void main(String[] args) throws EasyPostException {
EasyPost.apiKey = System.getenv("EASYPOST_API_KEY");
EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY");

Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("url", "https://example.com");
paramMap.put("webhook_secret", "A1B2C3");

Webhook webhook = Webhook.create(paramMap);
Webhook webhook = client.webhook.create(paramMap);
}
}

0 comments on commit 99cd215

Please sign in to comment.