ndc

package module
v0.0.0-...-6a8a7ff Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2018 License: GPL-3.0 Imports: 17 Imported by: 0

README

NDC Go SDK

This is a Golang package that wraps any NDC-compliant API.

Installation

go get github.com/open-ndc/ndc-go-sdk

go build github.com/open-ndc/ndc-go-sdk

Usage

package main

import (
  "github.com/ndc-request/ndc-go-sdk"
	"io/ioutil"
  "fmt"
)

func main() {

  client, _ := ndc.NewClient(&ndc.ClientOptions{ConfigPath: "github.com/ndc-request/ndc-go-sdk/config/ndc-openndc.yml"})
  client.HasTemplateVars = true
  params := ndc.Params{
    ndc.Param{
      "Travelers",
      ndc.Params{
        ndc.Param{
          "Traveler",
          ndc.Params{
            ndc.Param{
              "AnonymousTraveler",
              ndc.Params{
                ndc.Param{
                  "PTC", "ADT",
                },
              },
            },
          },
        },
      },
    },
    ndc.Param{
      "CoreQuery",
      ndc.Params{
        ndc.Param{
          "OriginDestinations",
          ndc.Params{
            ndc.Param{
              "OriginDestination",
              ndc.Params{
                ndc.Param{
                  "Departure",
                  ndc.Params{
                    ndc.Param{
                      "AirportCode", "LHR",
                    },
                    ndc.Param{
                      "Date", "2016-05-27",
                    },
                  },
                },
                ndc.Param{
                  "Arrival",
                  ndc.Params{
                    ndc.Param{
                      "AirportCode", "JFK",
                    },
                    ndc.Param{
                      "Date", "2016-05-29",
                    },
                  },
                },
              },
            },
          },
        },
      },
    },
  }
  response := client.Request(ndc.Message{
    Method: "AirShopping",
    Params: params,
  })

  defer response.Body.Close()

  fmt.Println( "-> Receiving response:\n---\n" )
  fmt.Println( response , "\n---\n-> Response body:\n---\n")
	body, _ := ioutil.ReadAll(response.Body)
	fmt.Println( string(body) )
  fmt.Println( "\n--\n")
}

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NDCSupportedMethods = map[string]struct{}{
	"AirShoppingRQ":      {},
	"FlightPriceRQ":      {},
	"SeatAvailabilityRQ": {},
	"ServiceListRQ":      {},
	"ServicePriceRQ":     {},
	"OrderCreateRQ":      {},
	"OrderRetrieveRQ":    {},
	"OrderListRQ":        {},
	"OrderCancelRQ":      {},
	"ItinReshopRQ":       {},
}
View Source
var TemplateVars = []string{"request_name"}

Functions

func ConfigHasTemplateVars

func ConfigHasTemplateVars(RawConfig *[]byte) int

func MapSliceToMap

func MapSliceToMap(slice yaml.MapSlice, m map[string]interface{}) map[string]interface{}

func Prettify

func Prettify(raw string, indent string) (pretty string, e error)

Prettify prints readable XML From: https://stackoverflow.com/questions/21117161/go-how-would-you-pretty-print-prettify-html#23285911

Types

type AsynchArgs

type AsynchArgs struct {
	Callback       func(string, AsynchArgs)
	HeaderCallback func(http.Header) error
	Out            http.ResponseWriter
	Flusher        http.Flusher
	WG             *sync.WaitGroup
	InitTime       time.Time
	Limit          int
}

type Client

type Client struct {
	Options         ClientOptions
	HasTemplateVars bool
	Extras          map[string]Extras
	Config          map[string]yaml.MapSlice
	RawConfig       []byte
	HttpClient      *http.Client
}

func NewClient

func NewClient(options *ClientOptions, extras map[string]Extras) (*Client, error)

func (*Client) AppendHeaders

func (client *Client) AppendHeaders(r *http.Request, HeadersConfig interface{})

func (*Client) LoadConfig

func (client *Client) LoadConfig() error

func (*Client) PrepareConfig

func (client *Client) PrepareConfig(message Message) (Config map[string]interface{})

func (*Client) Request

func (client *Client) Request(message Message) *http.Response

func (*Client) RequestAsync

func (client *Client) RequestAsync(ctx context.Context, message Message) (*http.Response, chan []byte)

func (*Client) RequestAsync2

func (client *Client) RequestAsync2(message Message, responseChannel chan []byte)

func (*Client) RequestAsynch

func (client *Client) RequestAsynch(message Message, args AsynchArgs)

func (*Client) RequestSync

func (client *Client) RequestSync(message Message) (string, http.Header)

func (*Client) RequestSynch

func (client *Client) RequestSynch(message Message) string

type ClientOptions

type ClientOptions struct {
	ConfigPath string
}

type Extras

type Extras struct {
	Value map[string]string
}

type Message

type Message struct {
	XMLName xml.Name

	Client *Client `xml:"-"`

	SoapConfig SoapConfig

	Method string `xml:"-"`
	Params Params `xml:"-"`

	IsSoap bool `xml:"-"`

	XMLNS    string `xml:"xmlns,attr,omitempty"`
	XMLNSXSI string `xml:"xmlns:xsi,attr,omitempty"`

	EchoToken             string `xml:"EchoToken,attr,omitempty"`
	TimeStamp             string `xml:"TimeStamp,attr,omitempty"`
	Version               string `xml:"Version,attr,omitempty"`
	TransactionIdentifier string `xml:"TransactionIdentifier,attr,omitempty"`

	Body       string `xml:",innerxml"`
	ParamsBody string `xml:",innerxml"`
}

func (*Message) GetSoapConfig

func (message *Message) GetSoapConfig() (config SoapConfig)

func (*Message) Prepare

func (message *Message) Prepare() ([]byte, error)

func (*Message) RenderNDCParams

func (message *Message) RenderNDCParams(enc *xml.Encoder, item interface{}, key string, attr []xml.Attr, index int, length int, parentElements []string)

func (*Message) RenderNDCWrapper

func (message *Message) RenderNDCWrapper(enc *xml.Encoder, buf *bytes.Buffer, item interface{}, key string, root bool, index int, length int, parentElements []string)

type Param

type Param struct {
	Key   interface{}
	Attr  []xml.Attr
	Value interface{}
}

type Params

type Params []Param

type SOAPBody

type SOAPBody struct {
	XMLName xml.Name `xml:"s:Body"`
	// Body string `xml:",innerxml"`
	Message *Message
}

type SOAPEnvelope

type SOAPEnvelope struct {
	XMLName xml.Name `xml:"s:Envelope"`
	Body    SOAPBody
}

type SoapConfig

type SoapConfig struct {
	RequestNamespace  string
	ResponseNamespace string
	EnvelopeTagName   string
	EnvelopeAttrs     xml.Attr
	BodyTagName       string
	BodyAttrs         xml.Attr
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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