Compare commits
3 Commits
e6201eacef
...
17bee2852a
| Author | SHA1 | Date | |
|---|---|---|---|
| 17bee2852a | |||
| 5c4144444a | |||
| 07a3c1b1e3 |
|
|
@ -127,6 +127,13 @@ func (c *Client) ChannelsGetList() ([]microsub.Channel, error) {
|
||||||
return []microsub.Channel{}, err
|
return []microsub.Channel{}, err
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return []microsub.Channel{}, fmt.Errorf("HTTP Status is not 200, but %d, error while reading body", res.StatusCode)
|
||||||
|
}
|
||||||
|
return []microsub.Channel{}, fmt.Errorf("HTTP Status is not 200, but %d: %s", res.StatusCode, body)
|
||||||
|
}
|
||||||
|
|
||||||
type channelsResponse struct {
|
type channelsResponse struct {
|
||||||
Channels []microsub.Channel `json:"channels"`
|
Channels []microsub.Channel `json:"channels"`
|
||||||
|
|
@ -149,6 +156,13 @@ func (c *Client) TimelineGet(before, after, channel string) (microsub.Timeline,
|
||||||
return microsub.Timeline{}, err
|
return microsub.Timeline{}, err
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return microsub.Timeline{}, fmt.Errorf("HTTP Status is not 200, but %d, error while reading body", res.StatusCode)
|
||||||
|
}
|
||||||
|
return microsub.Timeline{}, fmt.Errorf("HTTP Status is not 200, but %d: %s", res.StatusCode, body)
|
||||||
|
}
|
||||||
dec := json.NewDecoder(res.Body)
|
dec := json.NewDecoder(res.Body)
|
||||||
var timeline microsub.Timeline
|
var timeline microsub.Timeline
|
||||||
err = dec.Decode(&timeline)
|
err = dec.Decode(&timeline)
|
||||||
|
|
@ -166,8 +180,16 @@ func (c *Client) PreviewURL(url string) (microsub.Timeline, error) {
|
||||||
return microsub.Timeline{}, err
|
return microsub.Timeline{}, err
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
dec := json.NewDecoder(res.Body)
|
|
||||||
var timeline microsub.Timeline
|
var timeline microsub.Timeline
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return timeline, fmt.Errorf("HTTP Status is not 200, but %d, error while reading body", res.StatusCode)
|
||||||
|
}
|
||||||
|
return timeline, fmt.Errorf("HTTP Status is not 200, but %d: %s", res.StatusCode, body)
|
||||||
|
}
|
||||||
|
dec := json.NewDecoder(res.Body)
|
||||||
err = dec.Decode(&timeline)
|
err = dec.Decode(&timeline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return microsub.Timeline{}, err
|
return microsub.Timeline{}, err
|
||||||
|
|
@ -183,6 +205,13 @@ func (c *Client) FollowGetList(channel string) ([]microsub.Feed, error) {
|
||||||
return []microsub.Feed{}, nil
|
return []microsub.Feed{}, nil
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return []microsub.Feed{}, fmt.Errorf("HTTP Status is not 200, but %d, error while reading body", res.StatusCode)
|
||||||
|
}
|
||||||
|
return []microsub.Feed{}, fmt.Errorf("HTTP Status is not 200, but %d: %s", res.StatusCode, body)
|
||||||
|
}
|
||||||
dec := json.NewDecoder(res.Body)
|
dec := json.NewDecoder(res.Body)
|
||||||
type followResponse struct {
|
type followResponse struct {
|
||||||
Items []microsub.Feed `json:"items"`
|
Items []microsub.Feed `json:"items"`
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -40,6 +41,14 @@ func GetEndpoints(me *url.URL) (Endpoints, error) {
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return endpoints, fmt.Errorf("error from endpoint while reading body %d", res.StatusCode)
|
||||||
|
}
|
||||||
|
return endpoints, fmt.Errorf("error from endpoint %d: %s", res.StatusCode, body)
|
||||||
|
}
|
||||||
|
|
||||||
var links linkheader.Links
|
var links linkheader.Links
|
||||||
|
|
||||||
if headers, e := res.Header["Link"]; e {
|
if headers, e := res.Header["Link"]; e {
|
||||||
|
|
|
||||||
|
|
@ -169,16 +169,21 @@ func simplify(itemType string, item map[string][]interface{}, author map[string]
|
||||||
return feedItem
|
return feedItem
|
||||||
}
|
}
|
||||||
func simplifyCard(v []interface{}) (map[string]string, error) {
|
func simplifyCard(v []interface{}) (map[string]string, error) {
|
||||||
if value, ok := v[0].(*microformats.Microformat); ok {
|
|
||||||
card := make(map[string]string)
|
card := make(map[string]string)
|
||||||
card["type"] = "card"
|
card["type"] = "card"
|
||||||
|
|
||||||
|
if value, ok := v[0].(*microformats.Microformat); ok {
|
||||||
for ik, vk := range value.Properties {
|
for ik, vk := range value.Properties {
|
||||||
if p, ok := vk[0].(string); ok {
|
if p, ok := vk[0].(string); ok {
|
||||||
card[ik] = p
|
card[ik] = p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return card, nil
|
return card, nil
|
||||||
|
} else if value, ok := v[0].(string); ok {
|
||||||
|
card["url"] = value
|
||||||
|
return card, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("not convertable to a card %q", v)
|
return nil, fmt.Errorf("not convertable to a card %q", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -226,9 +231,9 @@ func SimplifyMicroformatData(md *microformats.Data) []map[string]interface{} {
|
||||||
|
|
||||||
newItem := SimplifyMicroformat(item, nil)
|
newItem := SimplifyMicroformat(item, nil)
|
||||||
delete(newItem, "children")
|
delete(newItem, "children")
|
||||||
// if newItem["type"] == "entry" || newItem["type"] == "event" || newItem["type"] == "card" {
|
if newItem["type"] == "entry" || newItem["type"] == "event" || newItem["type"] == "card" {
|
||||||
// items = append(items, newItem)
|
items = append(items, newItem)
|
||||||
// }
|
}
|
||||||
// if c, e := newItem["children"]; e {
|
// if c, e := newItem["children"]; e {
|
||||||
// if ar, ok := c.([]map[string]interface{}); ok {
|
// if ar, ok := c.([]map[string]interface{}); ok {
|
||||||
// for _, item := range ar {
|
// for _, item := range ar {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user