-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement NetworkCircuit API endpoint
* networkcircuit/details * networkcircuit/list
- Loading branch information
Showing
5 changed files
with
126 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
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
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,55 @@ | ||
package glesys | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// NetworkCircuitService provides functions to interact with NetworkCircuits | ||
type NetworkCircuitService struct { | ||
client clientInterface | ||
} | ||
|
||
// NetworkCircuit represents a networkcircuit | ||
type NetworkCircuit struct { | ||
ID string `json:"id"` | ||
Type string `json:"type"` | ||
Billing NetworkCircuitBilling `json:"billing"` | ||
} | ||
|
||
type NetworkCircuitBilling struct { | ||
Currency string `json:"currency"` | ||
Price float64 `json:"price"` | ||
Discount float64 `json:"discount"` | ||
Total float64 `json:"total"` | ||
Details []NetworkCircuitBillingDetails `json:"details,omitempty"` | ||
} | ||
|
||
type NetworkCircuitBillingDetails struct { | ||
Text string `json:"text"` | ||
PriceBeforeDiscount float64 `json:"subtotalBeforeDiscount"` | ||
DiscountAmount float64 `json:"discountAmount"` | ||
TotalBeforeTax float64 `json:"totalBeforeTax"` | ||
} | ||
|
||
// Details returns detailed information about one NetworkCircuit | ||
func (s *NetworkCircuitService) Details(context context.Context, circuitID string) (*NetworkCircuit, error) { | ||
data := struct { | ||
Response struct { | ||
NetworkCircuit NetworkCircuit | ||
} | ||
}{} | ||
err := s.client.post(context, "networkcircuit/details", &data, circuitID) | ||
return &data.Response.NetworkCircuit, err | ||
} | ||
|
||
// List returns a list of NetworkCircuits available under your account | ||
func (s *NetworkCircuitService) List(context context.Context) (*[]NetworkCircuit, error) { | ||
data := struct { | ||
Response struct { | ||
NetworkCircuits []NetworkCircuit | ||
} | ||
}{} | ||
|
||
err := s.client.get(context, "networkcircuit/list", &data) | ||
return &data.Response.NetworkCircuits, err | ||
} |
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,48 @@ | ||
package glesys | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNetworkCircuitsDetails(t *testing.T) { | ||
c := &mockClient{body: `{ "response": { "networkcircuit": { | ||
"id": "ic123456", | ||
"type": "INTERNET_PIPELINE", | ||
"billing": {"currency": "SEK", | ||
"price": "120.0", | ||
"discount": "0.0", | ||
"total": "120.0", | ||
"details": [] | ||
} | ||
} } }`} | ||
s := NetworkCircuitService{client: c} | ||
|
||
ic, _ := s.Details(context.Background(), "ic123456") | ||
|
||
assert.Equal(t, "POST", c.lastMethod, "method used is correct") | ||
assert.Equal(t, "networkcircuit/details", c.lastPath, "path used is correct") | ||
assert.Equal(t, "INTERNET_PIPELINE", ic.Type, "networkcircuit Type is correct") | ||
} | ||
|
||
func TestNetworkCircuitsList(t *testing.T) { | ||
c := &mockClient{body: `{ "response": { "networkcircuits": [{ | ||
"id": "ic123456", | ||
"type": "INTERNET_PIPELINE", | ||
"billing": {"currency": "SEK", | ||
"price": "120.0", | ||
"discount": "0.0", | ||
"total": "120.0", | ||
"details": [] | ||
} | ||
}] } }`} | ||
n := NetworkCircuitService{client: c} | ||
|
||
ics, _ := n.List(context.Background()) | ||
|
||
assert.Equal(t, "GET", c.lastMethod, "method used is correct") | ||
assert.Equal(t, "networkcircuit/list", c.lastPath, "path used is correct") | ||
assert.Equal(t, "INTERNET_PIPELINE", (*ics)[0].Type, "networkcircuit Type is correct") | ||
} |