Add simple start of feedbin API proxy
This commit is contained in:
parent
3bff9eb481
commit
f5ed8dbc45
|
@ -30,6 +30,7 @@ import (
|
|||
|
||||
"github.com/garyburd/redigo/redis"
|
||||
"github.com/pstuifzand/microsub-server/microsub"
|
||||
"github.com/pstuifzand/microsub-server/pkg/feedbin"
|
||||
"willnorris.com/go/microformats"
|
||||
)
|
||||
|
||||
|
@ -362,6 +363,35 @@ func (b *memoryBackend) TimelineGet(after, before, channel string) microsub.Time
|
|||
conn := pool.Get()
|
||||
defer conn.Close()
|
||||
|
||||
if channel == "feedbin" {
|
||||
fb := feedbin.New(os.Getenv("FEEDBIN_USER"), os.Getenv("FEEDBIN_PASS"))
|
||||
|
||||
entries, err := fb.Entries()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var items []microsub.Item
|
||||
|
||||
for _, e := range entries {
|
||||
var item microsub.Item
|
||||
|
||||
item.Type = "entry"
|
||||
item.Name = e.Title
|
||||
item.Content = µsub.Content{HTML: e.Content}
|
||||
item.URL = e.URL
|
||||
item.Published = e.Published.Format(time.RFC3339)
|
||||
item.Author = µsub.Card{Type: "card", Name: e.Author}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
return microsub.Timeline{
|
||||
Paging: microsub.Pagination{},
|
||||
Items: items,
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("TimelineGet %s\n", channel)
|
||||
feeds := b.FollowGetList(channel)
|
||||
log.Println(feeds)
|
||||
|
|
47
pkg/feedbin/feeds.go
Normal file
47
pkg/feedbin/feeds.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package feedbin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type Feedbin struct {
|
||||
user string
|
||||
password string
|
||||
}
|
||||
|
||||
func New(user, password string) *Feedbin {
|
||||
var fb Feedbin
|
||||
fb.user = user
|
||||
fb.password = password
|
||||
return &fb
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
20
pkg/feedbin/requests.go
Normal 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
33
pkg/feedbin/types.go
Normal 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"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user