Coder Social home page Coder Social logo

api-client-go's Introduction

Go API client for forestvpn_api

ForestVPN - Fast, secure, and modern VPN. It offers Distributed Computing, Crypto Mining, P2P, Ad Blocking, TOR over VPN, 30+ locations, and a free version with unlimited data.

Installation

Install the following dependencies:

go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context

Put the package under your project folder and add the following in import:

import forestvpn_api "github.com/forestvpn/api-client-go"

To use a proxy, set the environment variable HTTP_PROXY:

os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")

Configuration of Server URL

Default configuration comes with Servers field that contains server objects as defined in the OpenAPI specification.

Select Server Configuration

For using other server than the one defined on index 0 set context value sw.ContextServerIndex of type int.

ctx := context.WithValue(context.Background(), forestvpn_api.ContextServerIndex, 1)

Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value sw.ContextServerVariables of type map[string]string.

ctx := context.WithValue(context.Background(), forestvpn_api.ContextServerVariables, map[string]string{
	"basePath": "v2",
})

Note, enum values are always validated and all unused variables are silently ignored.

URLs Configuration per Operation

Each operation can use different server URL defined using OperationServers map in the Configuration. An operation is uniquely identified by "{classname}Service.{nickname}" string. Similar rules for overriding default operation server index and variables applies by using sw.ContextOperationServerIndices and sw.ContextOperationServerVariables context maps.

ctx := context.WithValue(context.Background(), forestvpn_api.ContextOperationServerIndices, map[string]int{
	"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), forestvpn_api.ContextOperationServerVariables, map[string]map[string]string{
	"{classname}Service.{nickname}": {
		"port": "8443",
	},
})

Documentation for API Endpoints

All URIs are relative to https://api.forestvpn.com/v2

Class Method HTTP request Description
AdsApi CreateAdUnitRequestLog Post /ads/request-logs/ Create ad unit request log
AdsApi ListAdPlacements Get /ads/placements/ Get ad placement list
AnalyticsApi GetDataUsageStats Get /analytics/data-usage/ Data Usage Stats
AppApi GetCurrentUserDevice Get /app/devices/current/ Get user device info
AppApi UpdateCurrentUserDevice Patch /app/devices/current/ Update user device
AppleApi VerifyAppStoreReceipt Post /purchase/apple/verify/ App store receipt verification
AuthApi AuthorizeAccessTokenRequest Post /auth/access-token-requests/{requestID}/authorize/ Authorize access token request
AuthApi CreateAccessTokenRequest Post /auth/access-token-requests/ Create access token request
AuthApi GetAccessTokenRequest Get /auth/access-token-requests/{requestID}/ Get access token request details
AuthApi LoginToken Post /auth/token/login/ Login with JWT token
AuthApi MigrateLegacyAuth Get /legacy/auth/ Legacy auth migration
AuthApi ObtainToken Get /auth/token/obtain/ Obtain JWT token
AuthApi RevokeAccessTokenRequest Post /auth/access-token-requests/{requestID}/revoke/ Revoke access token request
AuthApi UpdateUserProfile Patch /auth/profile/ Update profile
AuthApi UserProfile Get /auth/profile/ Profile
AuthApi WhoAmI Get /auth/whoami/ Who am I
BillingApi CancelSubscription Delete /billing/subscriptions/{subscriptionID}/ Cancel subscription
BillingApi CreatePaymentMethodStripeSetupIntent Post /billing/payment-methods/stripe/setup-intents/ Create stripe's setup intent for add new payment method.
BillingApi CreateSubscription Post /billing/subscriptions/ Create subscription
BillingApi DeletePaymentMethod Delete /billing/payment-methods/{paymentMethodID}/ Delete payment method
BillingApi GetBillingAccount Get /billing/account/ Billing account info
BillingApi GetBillingBundle Get /billing/bundles/{bundleID}/ Bundle info
BillingApi GetBillingPaymentOption Get /billing/payment-options/{paymentOptionID}/ Payment option info
BillingApi GetBillingProduct Get /billing/products/{productID}/ Product info
BillingApi GetPaymentMethod Get /billing/payment-methods/{paymentMethodID}/ Payment method info
BillingApi GetSubscription Get /billing/subscriptions/{subscriptionID}/ Subscription info
BillingApi GetSubscriptionItem Get /billing/subscription-items/{subscriptionItemID}/ Subscription item info
BillingApi ListBillingBundles Get /billing/bundles/ Billing bundles list
BillingApi ListBillingFeatures Get /billing/features/ Billing feature list
BillingApi ListBillingPaymentOptions Get /billing/payment-options/ Billing payment option list
BillingApi ListBillingProducts Get /billing/products/ Billing products list
BillingApi ListPaymentMethods Get /billing/payment-methods/ Payment method list
BillingApi ListSubscriptionItems Get /billing/subscription-items/ Subscription items list
BillingApi ListSubscriptions Get /billing/subscriptions/ Billing subscriptions list
BillingApi ReactivateSubscription Post /billing/subscriptions/{subscriptionID}/reactivate/ Reactivate subscription
BillingApi UpdateBillingAccount Patch /billing/account/ Update billing account
BillingApi UpdateSubscriptionItem Patch /billing/subscription-items/{subscriptionItemID}/ Update subscription item
CheckoutApi ApplyCouponCheckoutSession Post /checkout/sessions/{sessionID}/apply_coupon/ Apply coupon to session
CheckoutApi CreateCheckoutSession Post /checkout/sessions/ Create checkout session
CheckoutApi CreateWaitListRequest Post /checkout/wait-list/ Create request to add country in wait list
CheckoutApi ExpireCheckoutSession Post /checkout/sessions/{sessionID}/expire/ Expire checkout session
CheckoutApi GetCheckoutSession Get /checkout/sessions/{sessionID}/ Checkout session details
CheckoutApi GetStripeCheckoutSession Get /checkout/sessions/{sessionID}/stripe/checkout/session/ Stripe checkout session details
CheckoutApi GetStripePaymentIntent Get /checkout/sessions/{sessionID}/stripe/payment/intent/ Stripe payment intent details
CheckoutApi ProcessCloudPaymentsAuth Post /checkout/sessions/{sessionID}/cloud-payments/auth/ Cloud payments auth
CheckoutApi ProcessCloudPaymentsPost3ds Post /checkout/sessions/{sessionID}/cloud-payments/post3ds/ Cloud payments post3ds
DeviceApi CreateDevice Post /devices/ Create new device
DeviceApi CreateDevicePortForwarding Post /devices/{deviceID}/port-forwarding/ Create new device port forwarding
DeviceApi DeleteDevice Delete /devices/{deviceID}/ Delete Device
DeviceApi DeleteDevicePortForwarding Delete /devices/{deviceID}/port-forwarding/{portForwardingID}/ Delete Device's Port Forwarding
DeviceApi GetDevice Get /devices/{deviceID}/ Device Info
DeviceApi GetDeviceStats Get /devices/{deviceID}/stats/{statsID}/ Device's stats detail
DeviceApi GetDeviceWireGuard Get /devices/{deviceID}/wireguards/{wireGuardID}/ Device's wireguard profile detail
DeviceApi ListDeviceBindings Get /devices/{deviceID}/bindings/ Device bindings
DeviceApi ListDeviceConnectionModes Get /devices/{deviceID}/connection-modes/ Device connection modes
DeviceApi ListDeviceDetailStats Get /devices/{deviceID}/detail-stats/ Device's detail stats list
DeviceApi ListDevicePortForwardings Get /devices/{deviceID}/port-forwarding/ Device Port Forwarding List
DeviceApi ListDeviceStats Get /devices/{deviceID}/stats/ Device's stats list
DeviceApi ListDeviceWireGuardPeers Get /devices/{deviceID}/wireguards/{wireGuardID}/peers/ Device's wireguard peers
DeviceApi ListDeviceWireGuards Get /devices/{deviceID}/wireguards/ Device's wireguard profiles list
DeviceApi ListDevices Get /devices/ Device List
DeviceApi UpdateDevice Patch /devices/{deviceID}/ Update device properties
DeviceApi UpdateDevicePortForwarding Patch /devices/{deviceID}/port-forwarding/{portForwardingID}/ Update device's port forwarding
FcmApi CreateFCMDevice Post /notification/fcm/ Device registration for push notification through out Firebase Cloud Messaging
FcmApi DeleteFCMDevice Delete /notification/fcm/{registrationID}/ Delete fcm device
FcmApi GetFCMDevice Get /notification/fcm/{registrationID}/ Device info
FcmApi UpdateFCMDevice Patch /notification/fcm/{registrationID}/ Update device fcm properties
FriendshipApi AcceptFriendshipInvitation Patch /friendship/invitations/{code}/ Accept friendship invitation
FriendshipApi CreateFriendshipInvitation Post /friendship/invitations/ Create friendship invitation
FriendshipApi DeleteFriend Delete /friendship/friends/{id}/ Delete friend
FriendshipApi GetFriend Get /friendship/friends/{id}/ Friend details
FriendshipApi GetFriendshipInvitation Get /friendship/invitations/{code}/ Friendship invitation details
FriendshipApi ListFriends Get /friendship/friends/ Get friends list
FriendshipApi RejectFriendshipInvitation Delete /friendship/invitations/{code}/ Reject friendship invitation
GeoApi ListCountries Get /geo/countries/ Countries list
GeoApi ListCurrencies Get /geo/currencies/ Correncies list
GeoApi ListLocations Get /locations/ Location list
GoogleApi VerifyPlayStorePurchase Post /purchase/google/verify/ Play store purchase verification
NotificationsApi GetNotificationsUnreadCount Get /notifications/unread_count/ Get unread notifications count
NotificationsApi ListNotifications Get /notifications/all_list/ Get notifications list
NotificationsApi UpdateNotificationMarkRead Get /notifications/mark_as_read/{slug}/ Mark notification as read by user
NotificationsApi UpdateNotificationMarkReadAll Get /notifications/mark_all_as_read/ Mark all notifications as read by user
SupportApi CreateSupportTicket Post /support/tickets/ Create support ticket
SupportApi GetSupportTicketCategory Get /support/ticket-categories/ Get ticket categories
WireguardApi GetWireGuardPeerInfo Get /wireguard/peers/{pubKey}/ Wireguard peer info
WireguardApi ListWireGuardPeers Get /wireguard/peers/ Wireguard peers list

Documentation For Models

Documentation For Authorization

bearerAuth

  • Type: HTTP Bearer token authentication

Example

auth := context.WithValue(context.Background(), sw.ContextAccessToken, "BEARER_TOKEN_STRING")
r, err := client.Service.Operation(auth, args)

wireguardAuth

  • Type: API key
  • API key parameter name: Authorization
  • Location: HTTP header

Note, each API key must be added to a map of map[string]APIKey where the key is: Authorization and passed in as the auth context for each request.

Documentation for Utility Methods

Due to the fact that model structure members are all pointers, this package contains a number of utility functions to easily obtain pointers to values of basic types. Each of these functions takes a value of the given basic type and returns a pointer to it:

  • PtrBool
  • PtrInt
  • PtrInt32
  • PtrInt64
  • PtrFloat
  • PtrFloat32
  • PtrFloat64
  • PtrString
  • PtrTime

Author

ForestVPN - [email protected]

Credits

api-client-go's People

Contributors

suquant avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

anatolio-deb

api-client-go's Issues

Unable to unmarshal Locaton list

Describe the bug
A json error in ListLocations:
json: cannot unmarshal number 25.276987 into Go struct field Location.latitude of type int32

To Reproduce
Steps to reproduce the behaviour:

  1. Execute GetLocations request as in example

Expected behaviour
Should get an array of Location structures.

Environment:

  • OS: Docker
  • Version: go version go1.18.3 linux/arm64

Additional context
The error message actually shows the latitude value as a float number coming from an API server. Both latitude and longitude are usually float numbers. At the same time, the Location structure defines their types as int32:

type Location struct {
Id string `json:"id"`
Name string `json:"name"`
Latitude int32 `json:"latitude"`
Longitude int32 `json:"longitude"`
Country Country `json:"country"`
AlternativeNames []string `json:"alternative_names,omitempty"`
}
.
Shouldn’t they be float32 or float64?

Missing the method to GET location objects by its ID

There's a ListLocations method, but I could not find the method to get a single Location object by passing its ID to the /locations/{locationID} endpoint. At the same time, this endpoint available on API. It returns the Location object.

Need that method to get the Locations after BillingFeature request, because there are only Location IDs coming in the response.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.