ro

package module
v0.0.0-...-b24cf60 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2018 License: Apache-2.0 Imports: 9 Imported by: 4

README ¶

UnOfficial Raja Ongkir SDK for Go Programming Language

Raja Ongkir's Website (https://rajaongkir.com)

Build Status License

Bhinneka 💙 Golang

Install

go get github.com/Bhinneka/go-rajaongkir

Simple Usage

  • Get Cost Data

    package main
    
    import (
    	"fmt"
    	"time"
    
    	"github.com/Bhinneka/go-rajaongkir"
    )
    
    func main() {
    
      // Raja Ongkir Constructor, simply call ro.New
      // Parameter 1: "Raja Ongkir API KEY"
      // Parameter 2: HTTP Request Timeout
    	raja := ro.New("your-api-key", 10*time.Second)
      //by default after construct, raja ongkir used Starter Env(Free account)
      //to change Env, simply just change the env
      //raja.Env = ro.Basic for basic account
      //or raja.Env = ro.Pro for pro account
    
      // Parameter 1: City Origin ID
      // Parameter 2: City Destination ID
      // Parameter 3: Item's Weight
      // Parameter 4: Courier's Name
    	q := ro.QueryRequest{Origin: "501", Destination: "114", Weight: 1700, Courier: "tiki"}
    	result := raja.GetCost(q)
    
    	if result.Error != nil {
    		fmt.Println(result.Error.Error())
    	}
    
    	cost, ok := result.Result.(ro.Cost)
    	if !ok {
    		fmt.Println("Result is not Cost")
    	}
    
    	fmt.Println(cost)
    }
    
    

TODO

  • Create Service for Starter(Free Account)
  • Create Service for Basic and Pro Raja Ongkir Account
  • Create Unit Testing
  • Integration with Travis CI

Authors

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func New ¶

func New(apiKey string, timeout time.Duration) *rajaOngkir

New function, create rajaOngkir pointer required parameter, your Raja Ongkir API KEY and timeout(http request timeout)

Types ¶

type City ¶

type City struct {
	CityID     string `json:"city_id"`
	ProvinceID string `json:"province_id"`
	Province   string `json:"province"`
	Type       string `json:"type"`
	CityName   string `json:"city_name"`
	PostalCode string `json:"postal_code"`
}

City response

type Cost ¶

type Cost struct {
	OriginDetails      City       `json:"origin_details"`
	DestinationDetails City       `json:"destination_details"`
	Providers          []Provider `json:"results"`
}

Cost

type CostWrapper ¶

type CostWrapper struct {
	Rajaongkir struct {
		Query struct {
			Origin      string `json:"origin"`
			Destination string `json:"destination"`
			Weight      int    `json:"weight"`
			Courier     string `json:"courier"`
		} `json:"query"`
		Status             Status     `json:"status"`
		OriginDetails      City       `json:"origin_details"`
		DestinationDetails City       `json:"destination_details"`
		Results            []Provider `json:"results"`
	} `json:"rajaongkir"`
}

CostWrapper

type Env ¶

type Env int

Env type

const (
	//Starter Env, enviroment constant for Starter Raja Ongkir Account
	Starter Env = iota

	//Basic Env, enviroment constant for Basic Raja Ongkir Account
	Basic Env = iota

	//Pro Env, enviroment constant for Pro Raja Ongkir Account
	Pro Env = iota
)

func (Env) String ¶

func (e Env) String() string

String function, return Env as a string

type Provider ¶

type Provider struct {
	Code  string        `json:"code"`
	Name  string        `json:"name"`
	Costs []ServiceCost `json:"costs"`
}

Provider response

type Province ¶

type Province struct {
	ProvinceID string `json:"province_id"`
	Province   string `json:"province"`
}

Province response

type QueryRequest ¶

type QueryRequest struct {
	CityID      string
	ProvinceID  string
	Origin      string
	Destination string
	Weight      int
	Courier     string
}

QueryRequest set of query paramters

type RajaOngkirService ¶

type RajaOngkirService interface {
	GetProvince(QueryRequest) ServiceResult
	GetCity(QueryRequest) ServiceResult
	GetCost(QueryRequest) ServiceResult
}

RajaOngkirService Generic abstraction for Raja Ongkir Service

type ServiceCost ¶

type ServiceCost struct {
	Service     string              `json:"service"`
	Description string              `json:"description"`
	Cost        []ServiceCostDetail `json:"cost"`
}

ServiceCost response

type ServiceCostDetail ¶

type ServiceCostDetail struct {
	Value        int    `json:"value"`
	EstimatedDay string `json:"etd"`
	Note         string `json:"note"`
}

ServiceCostDetail response

type ServiceResult ¶

type ServiceResult struct {
	Result interface{}
	Error  error
}

ServiceResult

type Status ¶

type Status struct {
	Code        int    `json:"code"`
	Description string `json:"description"`
}

Status response

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL