go-force

module
v0.0.0-...-bfb7e44 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2016 License: MIT

README

go-force

wercker status

Golang API wrapper for Force.com, Salesforce.com

Installation

go get github.com/nimajalali/go-force/force

Example

package main

import (
	"fmt"
	"log"

	"github.com/nimajalali/go-force/force"
	"github.com/nimajalali/go-force/sobjects"
)

type SomeCustomSObject struct {
	sobjects.BaseSObject
	
	Active    bool   `force:"Active__c"`
	AccountId string `force:"Account__c"`
}

func (t *SomeCustomSObject) ApiName() string {
	return "SomeCustomObject__c"
}

type SomeCustomSObjectQueryResponse struct {
	sobjects.BaseQuery

	Records []*SomeCustomSObject `force:"records"`
}

func main() {
	// Init the force
	forceApi, err := force.Create(
		"YOUR-API-VERSION",
		"YOUR-CLIENT-ID",
		"YOUR-CLIENT-SECRET",
		"YOUR-USERNAME",
		"YOUR-PASSWORD",
		"YOUR-SECURITY-TOKEN",
		"YOUR-ENVIRONMENT",
	)
	if err != nil {
		log.Fatal(err)
	}

	// Get somCustomSObject by ID
	someCustomSObject := &SomeCustomSObject{}
	err = forceApi.GetSObject("Your-Object-ID", nil, someCustomSObject)
	if err != nil {
		fmt.Println(err)
	}

	fmt.Printf("%#v", someCustomSObject)

	// Query
	someCustomSObjects := &SomeCustomSObjectQueryResponse{}
	err = forceApi.Query("SELECT Id FROM SomeCustomSObject__c LIMIT 10", someCustomSObjects)
	if err != nil {
		fmt.Println(err)
	}

	fmt.Printf("%#v", someCustomSObjects)
}

func useSocksProxy() {
    auth := proxy.Auth{ User: "user", Password: "password" }
    // create a socks5 dialer
    dialer, err := proxy.SOCKS5("tcp", PROXY_ADDR, auth, proxy.Direct)
	if err != nil {
        errMsg := fmt.Fprintln(os.Stderr, "can't connect to the proxy:", err)
        log.Fatal(errMsg)
	}
	// setup a http client
	httpTransport := &http.Transport{}
	httpClient := &http.Client{Transport: httpTransport}
	// set our socks5 as the dialer
	httpTransport.Dial = dialer.Dial

    // use the client on force
    force.HttpClient = httpClient

    // Init the force
	forceApi, err := force.Create(
		"YOUR-API-VERSION",
		"YOUR-CLIENT-ID",
		"YOUR-CLIENT-SECRET",
		"YOUR-USERNAME",
		"YOUR-PASSWORD",
		"YOUR-SECURITY-TOKEN",
		"YOUR-ENVIRONMENT",
	)
	if err != nil {
		log.Fatal(err)
	}

    // all force API calls now go through socks proxy
    // ...
}


Documentation

Directories

Path Synopsis
A Go package that provides bindings to the force.com REST API See http://www.salesforce.com/us/developer/docs/api_rest/
A Go package that provides bindings to the force.com REST API See http://www.salesforce.com/us/developer/docs/api_rest/
Package json implements encoding and decoding of JSON objects as defined in RFC 4627.
Package json implements encoding and decoding of JSON objects as defined in RFC 4627.
Don't use this! It was an interesting effort but in reality all you need is a ptr to a bool.
Don't use this! It was an interesting effort but in reality all you need is a ptr to a bool.

Jump to

Keyboard shortcuts

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