Skip to content

Commit

Permalink
Add simple start of feedbin API proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
pstuifzand committed May 1, 2018
1 parent 3bff9eb commit f5ed8db
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cmd/server/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
47 changes: 47 additions & 0 deletions pkg/feedbin/feeds.go
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions pkg/feedbin/requests.go
Original file line number Diff line number Diff line change
@@ -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 changes: 33 additions & 0 deletions pkg/feedbin/types.go
Original file line number Diff line number Diff line change
@@ -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.