Permalink
Browse files

Add simple start of feedbin API proxy

  • Loading branch information...
pstuifzand committed May 1, 2018
1 parent 3bff9eb commit f5ed8dbc45231feb5b0c4216f2371230ca563d6e
Showing with 130 additions and 0 deletions.
  1. +30 −0 cmd/server/memory.go
  2. +47 −0 pkg/feedbin/feeds.go
  3. +20 −0 pkg/feedbin/requests.go
  4. +33 −0 pkg/feedbin/types.go
@@ -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 = &microsub.Content{HTML: e.Content}
item.URL = e.URL
item.Published = e.Published.Format(time.RFC3339)
item.Author = &microsub.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)
@@ -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
}
@@ -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)
}
@@ -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"`
}

0 comments on commit f5ed8db

Please sign in to comment.