Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ndolestudio/mobilenig-go
Unofficial Go Client for the MobileNig API
https://github.com/ndolestudio/mobilenig-go
Last synced: about 2 months ago
JSON representation
Unofficial Go Client for the MobileNig API
- Host: GitHub
- URL: https://github.com/ndolestudio/mobilenig-go
- Owner: NdoleStudio
- License: mit
- Created: 2021-08-21T03:08:29.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-25T07:40:29.000Z (almost 3 years ago)
- Last Synced: 2024-06-21T04:34:49.100Z (7 months ago)
- Language: Go
- Homepage: https://mobilenig.com/API/docs/index
- Size: 32.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MobileNig Go
[![Build](https://github.com/NdoleStudio/mobilenig-go/actions/workflows/main.yml/badge.svg)](https://github.com/NdoleStudio/mobilenig-go/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/NdoleStudio/mobilenig-go/branch/main/graph/badge.svg)](https://codecov.io/gh/NdoleStudio/mobilenig-go)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/NdoleStudio/mobilenig-go/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/NdoleStudio/mobilenig-go/?branch=main)
[![Go Report Card](https://goreportcard.com/badge/github.com/NdoleStudio/mobilenig-go)](https://goreportcard.com/report/github.com/NdoleStudio/mobilenig-go)
[![GitHub contributors](https://img.shields.io/github/contributors/NdoleStudio/mobilenig-go)](https://github.com/NdoleStudio/mobilenig-go/graphs/contributors)
[![GitHub license](https://img.shields.io/github/license/NdoleStudio/mobilenig-go?color=brightgreen)](https://github.com/NdoleStudio/mobilenig-go/blob/master/LICENSE)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/NdoleStudio/mobilenig-go)](https://pkg.go.dev/github.com/NdoleStudio/mobilenig-go)This package provides a `go` client for interacting with the [MobileNig API](https://mobilenig.com/API/docs/index)
## Installation
`mobilenig-go` is compatible with modern Go releases in module mode, with Go installed:
```bash
go get github.com/NdoleStudio/mobilenig-go
```Alternatively the same can be achieved if you use `import` in a package:
```go
import "github.com/NdoleStudio/mobilenig-go"
```## Implemented
- [Bills](#bills)
- DStv
- `GET /bills/user_check` - Validate a DStv user
- `GET /bills/dstv` - Pay a DStv subscription
- `GET /bills/query` - Fetch a DStv transaction
- `GET /bills/get_package` - Fetch current DStv package## Usage
### Initializing the Client
An instance of the `mobilenig` client can be created using `New()`. The `http.Client` supplied will be used to make requests to the API.
```go
package mainimport (
"github.com/NdoleStudio/mobilenig-go"
)func main() {
client := mobilenig.New(
mobilenig.WithUsername("" /* MobileNig Username */),
mobilenig.WithAPIKey("" /* MobileNig API Key */),
mobilenig.WithEnvironment(mobilenig.TestEnvironment),
)
}
```### Error handling
All API calls return an `error` as the last return object. All successful calls will return a `nil` error.
```go
payload, response, err := mobilenigClient.Token(context.Background())
if err != nil {
//handle error
}
```### Bills
This handles all API requests whose URL begins with `/bills/`
#### DStv
##### Validate DStv User
`GET /bills/user_check`: Validate a DStv user
```go
user, _, err := mobilenigClient.Bills.CheckDStvUser(context.Background(), "4131953321")if err != nil {
log.Fatal(err)
}log.Println(user.Details.LastName) // e.g INI OBONG BASSEY
```##### Pay a DStv subscription
`GET /bills/dstv` - Pay a DStv subscription
```go
transaction, _, _ = client.Bills.PayDStv(context.Background(), &PayDstvOptions{
TransactionID: "122790223",
Price: "790",
ProductCode: "PRWE36",
CustomerName: "ESU INI OBONG BASSEY",
CustomerNumber: "275953782",
SmartcardNumber: "4131953321",
})log.Println(transaction.TransactionID) // e.g 122790223
```##### Fetch a DStv transaction
`GET /bills/query` - Fetch a DStv transaction
```go
transaction, _, err := client.Bills.QueryDStv(context.Background(), "122790223")
if err != nil {
log.Fatal(err)
}log.Println(transaction.TransactionID) // e.g 122790223
```##### Get current DStv package
`GET /bills/get_package` - Returns the client's current DStv package
```go
dstvPackage, _, err := client.Bills.GetDStvPackage(context.Background(), "122790223")
if err != nil {
log.Fatal(err)
}log.Println(dstvPackage) // e.g DStv French Touch
```## Testing
You can run the unit tests for this SDK from the root directory using the command below:
```bash
go test -v
```## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details