Compare commits

..

No commits in common. "3aa93f03cd7273ab34ff621d2d5e70fd18eda689" and "04f2af64c6a9c89f53d5c573abb63349b0d78d16" have entirely different histories.

3 changed files with 122 additions and 0 deletions

69
pkg/feedbin/feeds.go Normal file
View File

@ -0,0 +1,69 @@
package feedbin
import (
"encoding/json"
"fmt"
)
// Feedbin is the main object for calling the Feedbin API
type Feedbin struct {
user string
password string
}
// New returns a new Feedbin object with the provided user and password
func New(user, password string) *Feedbin {
var fb Feedbin
fb.user = user
fb.password = password
return &fb
}
// Taggings returns taggings
func (fb *Feedbin) Taggings() ([]Tagging, error) {
resp, err := fb.get("/v2/taggings.json")
if err != nil {
return []Tagging{}, err
}
defer resp.Body.Close()
var taggings []Tagging
dec := json.NewDecoder(resp.Body)
dec.Decode(&taggings)
return taggings, nil
}
// Feed returns a Feed for id
func (fb *Feedbin) Feed(id int64) (Feed, error) {
resp, err := fb.get(fmt.Sprintf("/v2/feeds/%d.json", id))
if err != nil {
return Feed{}, err
}
defer resp.Body.Close()
var feed Feed
dec := json.NewDecoder(resp.Body)
dec.Decode(&feed)
return feed, nil
}
// Entries return a slice of entries
func (fb *Feedbin) Entries() ([]Entry, error) {
resp, err := fb.get("/v2/entries.json")
if err != nil {
return []Entry{}, err
}
defer resp.Body.Close()
var entries []Entry
dec := json.NewDecoder(resp.Body)
dec.Decode(&entries)
return entries, nil
}

20
pkg/feedbin/requests.go Normal file
View File

@ -0,0 +1,20 @@
package feedbin
import (
"fmt"
"net/http"
)
func (fb *Feedbin) get(u string) (*http.Response, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.feedbin.com%s", u), nil)
if err != nil {
return nil, err
}
req.SetBasicAuth(fb.user, fb.password)
client := http.Client{}
return client.Do(req)
}

33
pkg/feedbin/types.go Normal file
View File

@ -0,0 +1,33 @@
package feedbin
import (
"time"
)
// Entry is a feedbin api entry
type Entry struct {
ID int64 `json:"id"`
FeedID int64 `json:"feed_id"`
Title string `json:"title"`
URL string `json:"url"`
Author string `json:"author"`
Content string `json:"content"`
Summary string `json:"summary"`
Published time.Time `json:"published"`
CreatedAt time.Time `json:"created_at"`
}
// Feed is a feedbin api feed
type Feed struct {
ID int64 `json:"id,omitempty"`
Title string `json:"title"`
FeedURL string `json:"feed_url"`
SiteURL string `json:"site_url"`
}
// Tagging is a feedbin api tagging
type Tagging struct {
ID int64 `json:"id,omitempty"`
FeedID int64 `json:"feed_id"`
Name string `json:"name"`
}