objectia

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2019 License: MIT Imports: 16 Imported by: 0

README

objectia-go

Build Status

Go client for Objectia API®

Documentation

See the Go API docs.

Installation

You don't need this source code unless you want to modify the package. If you just want to use the package, just run:

$ go get -u github.com/objectia/objectia-go
Requirements
  • Go 1.8 or later
Development:
$ go get -u github.com/stretchr/testify/assert

Usage

The library needs to be configured with your account's API key. Get your own API key by signing up for a free Objectia account.

package main

import (
    "fmt"
    "github.com/objectia/objectia-go"
)

func main() {
    apiKey := "<your API key>"
    client, err := objectia.NewClient(apiKey, nil)
    if err != nil {
        panic(err)
    }

    result, err := client.GeoLocation.Get("8.8.8.8", nil)
    if err != nil {
        panic(err)
    }
    fmt.Printf("Location: %+v\n", result)
}

Look in the examples folder for more code examples.

License and Trademarks

Copyright (c) 2018-19 UAB Salesfly.

Licensed under the MIT license.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Objectia is a registered trademark of UAB Salesfly.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewError

func NewError(code, message string) error

NewError creates a new error.

func NewResponseError

func NewResponseError(status int, code, message string) error

NewResponseError creates a new API response error.

Types

type APIUsage

type APIUsage struct {
	GeoLocationRequests int `json:"geoip_requests,omitempty" xml:"geoip_requests,omitempty"`
	MailRequests        int `json:"mail_requests,omitempty" xml:"mail_requests,omitempty"`
}

APIUsage model

type Client

type Client struct {

	// Public properties
	Logger       Logger
	RetryMax     int
	RetryWaitMin time.Duration
	RetryWaitMax time.Duration
	// Public APIs:
	GeoLocation *GeoLocation
	Mail        *Mail
	Usage       *Usage
	// contains filtered or unexported fields
}

Client encapsulates the api functions - must be created with NewClient()

func NewClient

func NewClient(apiKey string, httpClient *http.Client) (*Client, error)

NewClient creates a new Client with the provided apiKey and an optional httpClient.

func (*Client) GetVersion

func (c *Client) GetVersion() string

GetVersion returns the client version string.

type ETag

type ETag struct {
	Tag          string
	LastModified time.Time
}

ETag model

type Error

type Error struct {
	Status  int    `json:"status"`
	Success bool   `json:"success"`
	Message string `json:"message"`
	Code    string `json:"code"`
}

Error for API requests

func (*Error) Error

func (e *Error) Error() string

Error() performs as String().

func (*Error) String

func (e *Error) String() string

String() converts the error into a human-readable string.

type GeoLocation

type GeoLocation struct {
	// contains filtered or unexported fields
}

GeoLocation api functions

func (*GeoLocation) Get

func (c *GeoLocation) Get(ip string, options *GeoLocationOptions) (*IPLocation, error)

Get retrieves the geolocation for the given domain or IP address

func (*GeoLocation) GetBulk

func (c *GeoLocation) GetBulk(iplist []string, options *GeoLocationOptions) ([]IPLocation, error)

GetBulk retrieves the geolocation for multiple domain names or IP addresses.

func (*GeoLocation) GetCurrent

func (c *GeoLocation) GetCurrent(options *GeoLocationOptions) (*IPLocation, error)

GetCurrent retrieves the geolocation for the requester.

type GeoLocationOptions

type GeoLocationOptions struct {
	DisplayFields    string
	LookupHostname   bool
	ShowSecurityInfo bool
}

GeoLocationOptions model

type IPCurrency

type IPCurrency struct {
	Code          string `json:"code,omitempty" xml:"code,omitempty"`
	NumericCode   string `json:"num_code,omitempty" xml:"num_code,omitempty"`
	Name          string `json:"name,omitempty" xml:"name,omitempty"`
	PluralName    string `json:"name_plural,omitempty" xml:"plural_name,omitempty"`
	Symbol        string `json:"symbol,omitempty" xml:"symbol,omitempty"`
	NativeSymbol  string `json:"symbol_native,omitempty" xml:"native_symbol,omitempty"`
	DecimalDigits int    `json:"decimal_digits,omitempty" xml:"decimal_digits,omitempty"`
}

IPCurrency model

type IPLanguage

type IPLanguage struct {
	Code       string `json:"code,omitempty" xml:"code,omitempty"`
	Code2      string `json:"code2,omitempty" xml:"code2,omitempty"`
	Name       string `json:"name,omitempty" xml:"name,omitempty"`
	NativeName string `json:"native_name,omitempty" xml:"native_name,omitempty"`
	RTL        bool   `json:"rtl" xml:"rtl"`
}

IPLanguage model

type IPLocation

type IPLocation struct {
	Index *int `json:"-" xml:"index,attr,omitempty"`
	//---
	IPAddress string `json:"ip,omitempty" xml:"ip,omitempty"`
	Type      string `json:"type,omitempty" xml:"type,omitempty"`
	Hostname  string `json:"hostname,omitempty" xml:"hostname,omitempty"`

	Continent     string `json:"continent_name,omitempty" xml:"continent_name,omitempty"`
	ContinentCode string `json:"continent_code,omitempty" xml:"continent_code,omitempty"`

	Country       string `json:"country_name,omitempty" xml:"country_name,omitempty"`
	CountryNative string `json:"country_name_native,omitempty" xml:"country_name_native,omitempty"`
	CountryCode   string `json:"country_code,omitempty" xml:"country_code,omitempty"`
	CountryCode3  string `json:"country_code3,omitempty" xml:"country_code3,omitempty"`
	Capital       string `json:"capital,omitempty" xml:"capital,omitempty"`

	Region     string `json:"region_name,omitempty" xml:"region_name,omitempty"`
	RegionCode string `json:"region_code,omitempty" xml:"region_code,omitempty"`
	City       string `json:"city,omitempty" xml:"city,omitempty"`
	Postcode   string `json:"postcode,omitempty" xml:"postcode,omitempty"`

	Latitude  float64 `json:"latitude,omitempty" xml:"latitude,omitempty"`
	Longitude float64 `json:"longitude,omitempty" xml:"longitude,omitempty"`

	PhonePrefix string       `json:"phone_prefix,omitempty" xml:"phone_prefix,omitempty"`
	Currencies  []IPCurrency `json:"currencies,omitempty" xml:"currencies,omitempty"`
	Languages   []IPLanguage `json:"languages,omitempty" xml:"languages,omitempty"`
	Flag        string       `json:"flag,omitempty" xml:"flag,omitempty"`
	FlagEmoji   string       `json:"flag_emoji,omitempty" xml:"flag_emoji,omitempty"`
	IsEU        *bool        `json:"is_eu,omitempty" xml:"is_eu,omitempty"`
	TLD         string       `json:"internet_tld,omitempty" xml:"internet_tld,omitempty"`
	ISP         string       `json:"isp,omitempty" xml:"isp,omitempty"`
	Timezone    *IPTimezone  `json:"timezone,omitempty" xml:"timezone,omitempty"`
	Security    *IPSecurity  `json:"security,omitempty" xml:"security,omitempty"`
}

IPLocation model

type IPSecurity

type IPSecurity struct {
	IsProxy     bool     `json:"is_proxy" xml:"is_proxy"`
	ProxyType   string   `json:"proxy_type,omitempty" xml:"proxy_type,omitempty"`
	IsCrawler   bool     `json:"is_crawler" xml:"is_crawler"`
	CrawlerName string   `json:"crawler_name,omitempty" xml:"crawler_name,omitempty"`
	CrawlerType string   `json:"crawler_type,omitempty" xml:"crawler_type,omitempty"`
	IsTOR       bool     `json:"is_tor" xml:"is_tor"`
	ThreatLevel string   `json:"threat_level,omitempty" xml:"threat_level,omitempty"`
	ThreatTypes []string `json:"threat_types,omitempty" xml:"threat_types,omitempty"`
}

IPSecurity model

type IPTimezone

type IPTimezone struct {
	ID             string `json:"id,omitempty" xml:"id,omitempty"` // Name not ID?
	LocalTime      string `json:"localtime,omitempty" xml:"localtime,omitempty"`
	GMTOffset      int    `json:"gmt_offset,omitempty" xml:"gmt_offset,omitempty"`
	Code           string `json:"code,omitempty" xml:"code,omitempty"`
	DaylightSaving bool   `json:"daylight_saving" xml:"daylight_saving"`
}

IPTimezone model

type Logger

type Logger interface {
	Printf(string, ...interface{})
}

Logger interface allows to use other loggers than standard log.Logger.

type Mail

type Mail struct {
	// contains filtered or unexported fields
}

Mail api functions

func (*Mail) Send

func (c *Mail) Send(message *MailMessage) (*MailReceipt, error)

Send sends a mail message

type MailMessage

type MailMessage struct {
	Date        time.Time `json:"date"`
	From        string    `json:"from"`
	FromName    string    `json:"from_name"`
	ReplyTo     string    `json:"reply_to"`
	To          []string  `json:"to"`
	Cc          []string  `json:"cc"`
	Bcc         []string  `json:"bcc"`
	Subject     string    `json:"subject"`
	Text        string    `json:"text"`
	HTML        string    `json:"html"`
	Attachments []string  `json:"attachments"`
	Tags        []string  `json:"tags"`
	Charset     string    `json:"charset,omitempty"`
	Encoding    string    `json:"encoding,omitempty"`

	// Options:
	RequireTLS             *bool `json:"require_tls,omitempty"`
	VerifyCertificate      *bool `json:"verify_cert,omitempty"`
	OpenTracking           *bool `json:"open_tracking,omitempty"`
	ClickTracking          *bool `json:"click_tracking,omitempty"`
	PlainTextClickTracking *bool `json:"text_click_tracking"`
	UnsubscribeTracking    *bool `json:"unsubscribe_tracking,omitempty"`
	TestMode               *bool `json:"test_mode,omitempty"`
}

MailMessage model

func NewMessage

func NewMessage(from, subject, text string, to ...string) *MailMessage

NewMessage ...

func (*MailMessage) AddAttachment

func (m *MailMessage) AddAttachment(fileName string)

AddAttachment ...

func (*MailMessage) AddBcc

func (m *MailMessage) AddBcc(bcc ...string)

AddBcc ...

func (*MailMessage) AddCc

func (m *MailMessage) AddCc(cc ...string)

AddCc ...

func (*MailMessage) AddTag

func (m *MailMessage) AddTag(tag string)

AddTag ...

func (*MailMessage) SetClickTracking

func (m *MailMessage) SetClickTracking(flag bool)

SetClickTracking ...

func (*MailMessage) SetHTML

func (m *MailMessage) SetHTML(html string)

SetHTML ...

func (*MailMessage) SetOpenTracking

func (m *MailMessage) SetOpenTracking(flag bool)

SetOpenTracking ...

func (*MailMessage) SetPlainTextClickTracking

func (m *MailMessage) SetPlainTextClickTracking(flag bool)

SetPlainTextClickTracking ...

func (*MailMessage) SetReplyTo

func (m *MailMessage) SetReplyTo(recipient string)

SetReplyTo ...

func (*MailMessage) SetRequireTLS

func (m *MailMessage) SetRequireTLS(flag bool)

SetRequireTLS ...

func (*MailMessage) SetTestMode

func (m *MailMessage) SetTestMode(flag bool)

SetTestMode ...

func (*MailMessage) SetUnsubscribeTracking

func (m *MailMessage) SetUnsubscribeTracking(flag bool)

SetUnsubscribeTracking ...

func (*MailMessage) SetVerifyCertificate

func (m *MailMessage) SetVerifyCertificate(flag bool)

SetVerifyCertificate ...

func (*MailMessage) ToParameters

func (m *MailMessage) ToParameters() *Parameters

ToParameters ...

type MailReceipt

type MailReceipt struct {
	ID                 string `json:"id" xml:"id"`
	AcceptedRecipients int    `json:"accepted_recipients" xml:"accepted_recipients"`
	RejectedRecipients int    `json:"rejected_recipients" xml:"rejected_recipients"`
}

MailReceipt model

type Parameters

type Parameters struct {
	// contains filtered or unexported fields
}

Parameters struct

func NewParameters

func NewParameters() *Parameters

NewParameters creates a new parameters object

func (*Parameters) Add

func (p *Parameters) Add(key string, value interface{})

Add adds a new key/value pair to payload.

func (*Parameters) AddFile

func (p *Parameters) AddFile(key, file string)

AddFile adds a new file to be uploaded

func (*Parameters) Encode

func (p *Parameters) Encode() (*bytes.Buffer, error)

Encode marshalls the payload into JSON.

func (*Parameters) GetContentType

func (p *Parameters) GetContentType() string

GetContentType returns the content type of the payload

type Response

type Response struct {
	Status  int         `json:"status"`
	Success bool        `json:"success"`
	Message string      `json:"message"`
	Code    string      `json:"code"`
	Data    interface{} `json:"data"`
}

Response model

type Usage

type Usage struct {
	// contains filtered or unexported fields
}

Usage api functions

func (*Usage) Get

func (c *Usage) Get() (*APIUsage, error)

Get returns the API usage for current month.

Directories

Path Synopsis
examples
geoip/advanced command
geoip/bulk command
geoip/requester command
geoip/simple command
mail/send command

Jump to

Keyboard shortcuts

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