mashable

package module
v0.0.0-...-4b5786c Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2019 License: MIT Imports: 9 Imported by: 0

README

mashable

go client for mashable


What is mashable


Mashable was created by Pete Cashmore in July 2005. Time noted Mashable as one of the 25 best blogs in 2009, and has been described as one stop shop for social media. As of November 2015, it has over 6,000,000 Twitter followers and over 3,200,000 fans on Facebook.

Background


While working on a research paper about data mining with one of my friend, i needed to parse a lot (i really mean a lot) of mashable data as my test dataset, to extract the data i desires. I was trying to write a web parser first, while i discovered the mashable api as far they have and saves me lots of time. Instead of making a web parser i then write the api clients for mashable.

Supported Resource


The api is undocumented, so the exact formats or some api endpoints can be missed. In case of scenario like, i will be happy to get suggestions or PRs.

The supported resource list by the client is follows

  • Post
    • List
    • Get
    • Get From Url
    • Comments
  • Topics
    • List
    • Get
  • User
    • Get
  • Search
    • Search with Query

If more api resources are found, will be added here.

Get The Package


$ go get -u github.com/sadlil/mashable

Usage


Create Client:

import (
   "github.com/sadlil/mashable"
)

func main() {
   c, err := mashable.New()
   if err != nil {
      panic("client creation failed")
   }
}

Get Posts:

// List returns the list of post order by post time. `ListOptions` contains two configurable
// field `page` and `per_page`. Setting `page` will return the specified page of the list. according
// `per_page`. Default values is 1 for the page and 20 for the per_page.
posts, err := c.Posts().List(&mashable.ListOptions{})

// Get a specified post by its id
post, err := c.Posts().Get(id)


// Get a specified post by its blog url. usefull if you do not know the id
post, err := c.Posts().GetFromUrl(url)

Get Topics:

// List returns the list of topic. `ListOptions` contains two configurable
// field `page` and `per_page`. Setting `page` will return the specified page of the list. according
// `per_page`. Default values is 1 for the page and 20 for the per_page.
topics, err := c.Topics().List(&mashable.ListOptions{})

// Get a specified topic by its slug
topic, err := c.Topics().Get(slug)

Get User:

// Get a specified user by his/her id
user, err := c.Users().Get(id)

Search:

// Get search result according to a search query
res, err := c.Search().Query(query)

Details of all the response types can be found in types.go file. Check tests for more examples.

License


Licensed under the MIT license. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func New

func New() (*Client, error)

func (*Client) Posts

func (c *Client) Posts() PostInterface

func (*Client) Search

func (c *Client) Search() SearchInterface

func (*Client) Topics

func (c *Client) Topics() TopicInterface

func (*Client) Users

func (c *Client) Users() UserInterface

type Collection

type Collection struct {
	Total    int           `json:"total"`
	Page     int           `json:"page"`
	PerPage  int           `json:"per_page"`
	Pages    int           `json:"pages"`
	Flags    []interface{} `json:"flags"`
	Metadata struct {
		Targeting map[string]interface{} `json:"targeting"`
	} `json:"metadata"`
	Next     string `json:"next"`
	Previous string `json:"previous"`
}

type Error

type Error struct {
	Error   int    `json:"error"`
	Message string `json:"message"`
}

type ListOptions

type ListOptions struct {
	Page    int `json:"page" url:"page"`
	PerPage int `json:"per_page" url:"per_page"`
}

func (*ListOptions) Encode

func (l *ListOptions) Encode() string

type Post

type Post struct {
	*Error      `json:"inline,omitempty"`
	ID          string            `json:"id"`
	SortKey     string            `json:"sort_key"`
	Title       string            `json:"title"`
	TitleTag    interface{}       `json:"title_tag"`
	Images      map[string]string `json:"images"`
	Topics      []string          `json:"topics"`
	Channel     string            `json:"channel"`
	ChannelName string            `json:"channel_name"`
	SubChannels []string          `json:"subchannels"`
	Author      string            `json:"author"`
	AuthorID    string            `json:"author_id"`
	PostDate    time.Time         `json:"post_date"`
	PostDateRfc string            `json:"post_date_rfc"`
	Link        string            `json:"link"`
	Content     struct {
		Excerpt string      `json:"excerpt"`
		Full    string      `json:"full"`
		Intro   interface{} `json:"intro"`
		Plain   string      `json:"plain"`
	} `json:"content"`
	Shares struct {
		Facebook   int `json:"facebook"`
		Twitter    int `json:"twitter"`
		GooglePlus int `json:"google_plus"`
		Pinterest  int `json:"pinterest"`
		LinkedIn   int `json:"linked_in"`
		Total      int `json:"total"`
	} `json:"shares"`
	CommentsCount int                    `json:"comments_count"`
	URL           string                 `json:"url"`
	Velocity      []int                  `json:"velocity"`
	ShortURL      string                 `json:"short_url"`
	Targeting     map[string]interface{} `json:"targeting"`
	ContentSource string                 `json:"content_source"`
	LeadType      string                 `json:"lead_type"`
	CommentsURL   string                 `json:"comments_url"`
	ShortcodeData struct {
		Gallery interface{} `json:"gallery"`
	} `json:"shortcode_data"`
	Webview        bool   `json:"webview"`
	SponsoredBy    string `json:"sponsored_by"`
	SponsoredByURL string `json:"sponsored_by_url"`
	SeriesType     string `json:"series_type"`
	SeriesSlug     string `json:"series_slug"`
}

type PostInterface

type PostInterface interface {
	List(*ListOptions) (*PostList, error)
	Get(string) (*Post, error)
	GetFromUrl(string) (*Post, error)
}

type PostList

type PostList struct {
	*Error     `json:"inline,omitempty"`
	Collection *Collection `json:"collection"`
	Posts      []*Post     `json:"posts"`
}

type SearchInterface

type SearchInterface interface {
	Query(string) (*SearchResult, error)
}

type SearchResult

type SearchResult struct {
	Search struct {
		Query       string      `json:"query"`
		Status      string      `json:"status"`
		Suggestions interface{} `json:"suggestions"`
		Hits        interface{} `json:"hits"`
		Results     struct {
			Posts  []*Post  `json:"posts"`
			Users  []*User  `json:"users"`
			Topics []*Topic `json:"topics"`
		} `json:"results"`
	} `json:"search"`
}

type Topic

type Topic struct {
	*Error        `json:"inline,omitempty"`
	Name          string `json:"name"`
	Followers     int    `json:"followers"`
	Posts         int    `json:"posts"`
	Article       string `json:"article"`
	ArticleSource struct {
		Text string `json:"text"`
		URL  string `json:"url"`
	} `json:"article_source"`
	Taxonomies []string `json:"taxonomies"`
	Thumb      string   `json:"thumb"`
	Slug       string   `json:"slug"`
	URL        string   `json:"url"`
}

type TopicInterface

type TopicInterface interface {
	List(*ListOptions) (*TopicList, error)
	Get(string) (*Topic, error)
}

type TopicList

type TopicList struct {
	*Error     `json:"inline,omitempty"`
	Collection *Collection `json:"collection"`
	Topics     []*Topic    `json:"topics"`
}

type User

type User struct {
	*Error      `json:"inline,omitempty"`
	ID          string    `json:"id"`
	FirstName   string    `json:"first_name"`
	LastName    string    `json:"last_name"`
	About       string    `json:"about"`
	Name        string    `json:"name"`
	CreatedAt   time.Time `json:"created_at"`
	Following   int       `json:"following"`
	Location    string    `json:"location"`
	Badges      int       `json:"badges"`
	Comments    int       `json:"comments"`
	Gender      string    `json:"gender"`
	Connections []string  `json:"connections"`
	ShareTo     []string  `json:"share_to"`
	URL         string    `json:"url"`
}

type UserInterface

type UserInterface interface {
	Get(string) (*User, error)
}

Jump to

Keyboard shortcuts

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