twingly_search_client

package module
v0.0.0-...-9f98e1c Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2021 License: MIT Imports: 7 Imported by: 0

README

Twingly Search API Go

A Go package for Twingly's Blog Search API. Twingly is a blog search service that provides a searchable API known as Twingly Blog Search API

I did this for fun to try and learn the Go language, figured it was a good idea to have some sort of project alongside my Go journey.

Installation

Import the package into your code:

import (
    twinglySearchClient "github.com/chrizpy/twingly-search-api-go"
)

func main(){
    ...
}

And install it.

go get github.com/chrizpy/twingly-search-api-go

Usage

The twingly-search package talks to a commercial API and requires an API key. Set the TWINGLY_SEARCH_KEY environment variable to the obtained key.

To learn more about the capabilities of Twingly's APIs, please read the Blog Search API documentation.

Blog Search API

package main

import (
    "encoding/json"
    "fmt"
    "os"

    twinglySearchClient "github.com/twingly/twingly-search-api-go"
)

func main() {
    client, _ := twinglySearchClient.New()
    client.SetUserAgent("MyCompany/1.0")
    client.AddQuery("cop26 page-size:1")


    response, _ := client.ExecuteQuery()
}

Requirements

  • API key, sign up via twingly.com to get one
  • Go >= 1.17 (Earlier versions probably work, just developed at 1.17)

Development

Tests

Run all tests

go test ./...

TODO

This package is still very much in its infancy and could be lacking features compared to its sibling libraries

Documentation

Index

Constants

View Source
const (
	SCHEME             = "https"
	PATH               = "/blog/search/api/v3/search"
	DEFAULT_USER_AGENT = "Twingly Search Go Client/1.0"
)

Variables

This section is empty.

Functions

func New

func New() (client, error)

Types

type Post

type Post struct {
	ID           string
	Author       string
	URL          string
	Title        string
	Text         string
	LanguageCode string
	LocationCode string
	Coordinates  string
	Links        string
	Tags         []Tag
	Images       string
	IndexedAt    string
	PublishedAt  string
	ReindexedAt  string
	InlinksCount string
	BlogId       string
	BlogName     string
	BlogUrl      string
	BlogRank     string
	Authority    string
}

type Tag

type Tag struct {
	Text string
	Tag  []string
}

type TwinglyResponse

type TwinglyResponse struct {
	NumberOfMatchesReturned string
	SecondsElapsed          string
	NumberOfMatchesTotal    string
	IncompleteResult        string
	Post                    []Post
}

type Twinglydata

type Twinglydata struct {
	XMLName                 xml.Name `xml:"twinglydata"`
	Text                    string   `xml:",chardata"`
	NumberOfMatchesReturned string   `xml:"numberOfMatchesReturned,attr"`
	SecondsElapsed          string   `xml:"secondsElapsed,attr"`
	NumberOfMatchesTotal    string   `xml:"numberOfMatchesTotal,attr"`
	IncompleteResult        string   `xml:"incompleteResult,attr"`
	Post                    []struct {
		Chardata     string `xml:",chardata"`
		ID           string `xml:"id"`
		Author       string `xml:"author"`
		URL          string `xml:"url"`
		Title        string `xml:"title"`
		Text         string `xml:"text"`
		LanguageCode string `xml:"languageCode"`
		LocationCode string `xml:"locationCode"`
		Coordinates  string `xml:"coordinates"`
		Links        string `xml:"links"`
		Tags         struct {
			Text string   `xml:",chardata"`
			Tag  []string `xml:"tag"`
		} `xml:"tags"`
		Images       string `xml:"images"`
		IndexedAt    string `xml:"indexedAt"`
		PublishedAt  string `xml:"publishedAt"`
		ReindexedAt  string `xml:"reindexedAt"`
		InlinksCount string `xml:"inlinksCount"`
		BlogId       string `xml:"blogId"`
		BlogName     string `xml:"blogName"`
		BlogUrl      string `xml:"blogUrl"`
		BlogRank     string `xml:"blogRank"`
		Authority    string `xml:"authority"`
	} `xml:"post"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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