Skip to content

Commit

Permalink
Merge pull request #1 from mrobinsn/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
Michael Robinson authored Apr 8, 2018
2 parents 5894c37 + 7bf5726 commit 062d23e
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 93 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
language: go

go:
- tip
- stable
before_install:
- go get -u github.com/mattn/goveralls
script:
- go vet ./...
- goveralls -race -v -show -service=travis-ci
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# go-tvmaze
[![GoDoc](https://godoc.org/github.com/mrobinsn/go-tvmaze/tvmaze?status.svg)](https://godoc.org/github.com/mrobinsn/go-tvmaze/tvmaze)
[![Go Report Card](https://goreportcard.com/badge/github.com/mrobinsn/go-tvmaze)](https://goreportcard.com/report/github.com/mrobinsn/go-tvmaze)
[![Build Status](https://travis-ci.org/mrobinsn/go-tvmaze.svg?branch=master)](https://travis-ci.org/mrobinsn/go-tvmaze)
[![Coverage Status](https://coveralls.io/repos/github/mrobinsn/go-tvmaze/badge.svg?branch=master)](https://coveralls.io/github/mrobinsn/go-tvmaze?branch=master)
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)


> TVMaze API bindings for Go (golang)
## Documentation
https://godoc.org/github.com/mrobinsn/go-tvmaze/tvmaze
[GoDoc](https://godoc.org/github.com/mrobinsn/go-tvmaze/tvmaze)

## Features
- Search shows by name, TVMaze ID, TVDB ID, or TVRage ID
Expand Down
5 changes: 2 additions & 3 deletions tvmaze/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/url"
"strings"

log "github.com/Sirupsen/logrus"
"github.com/pkg/errors"
)

// DefaultClient is the default TV Maze client
Expand All @@ -26,10 +26,9 @@ func NewClient() Client {
}

func (c Client) get(url url.URL, ret interface{}) (err error) {
log.WithField("url", url.String()).Debug("getting url")
r, err := http.Get(url.String())
if err != nil {
return err
return errors.Wrapf(err, "failed to get url: %s", url.String())
}

defer r.Body.Close()
Expand Down
5 changes: 3 additions & 2 deletions tvmaze/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

log "github.com/Sirupsen/logrus"
"github.com/pkg/errors"
)

// ShowResponse wraps a TV Maze search response
Expand Down Expand Up @@ -191,7 +192,7 @@ func (d *Date) UnmarshalJSON(data []byte) error {
var err error
var v interface{}
if err = json.Unmarshal(data, &v); err != nil {
return err
return errors.Wrap(err, "failed to unmarshal JSON response")
}
switch x := v.(type) {
case string:
Expand All @@ -202,7 +203,7 @@ func (d *Date) UnmarshalJSON(data []byte) error {
d.Valid = false
return nil
default:
err = fmt.Errorf("json: cannot unmarshal %v into Go value of type tvmaze.Date", reflect.TypeOf(v).Name())
err = errors.Errorf("json: cannot unmarshal %v into Go value of type tvmaze.Date", reflect.TypeOf(v).Name())
}
d.Valid = err == nil
return err
Expand Down
160 changes: 75 additions & 85 deletions tvmaze/tvmaze_test.go
Original file line number Diff line number Diff line change
@@ -1,105 +1,95 @@
package tvmaze

import (
"encoding/json"
"testing"

log "github.com/Sirupsen/logrus"
. "github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/require"
)

func TestTVMaze(t *testing.T) {
log.SetLevel(log.DebugLevel)
Convey("I have setup a TVMaze client", t, func() {
c := DefaultClient
c := DefaultClient

Convey("I can find a show", func() {
results, err := c.FindShows("archer")
So(err, ShouldBeNil)
So(len(results), ShouldBeGreaterThan, 0)
//fmt.Println(JSONString(results))
So(results[0].Show.GetTitle(), ShouldNotBeBlank)
So(results[0].Show.GetDescription(), ShouldNotBeBlank)
})
t.Run("find show", func(t *testing.T) {
t.Parallel()
results, err := c.FindShows("archer")
require.NoError(t, err)
require.NotEmpty(t, results, "expected results")
require.NotEmpty(t, results[0].Show.GetTitle())
require.NotEmpty(t, results[0].Show.GetDescription())
})

Convey("I can get a show by its tvmaze id", func() {
result, err := c.GetShowWithID("315") // Archer
So(err, ShouldBeNil)
So(result, ShouldNotBeNil)
//fmt.Println(JSONString(result))
So(result.GetTitle(), ShouldEqual, "Archer")
So(result.GetDescription(), ShouldNotBeBlank)
So(result.GetTVDBID(), ShouldEqual, 110381)
So(result.GetTVRageID(), ShouldEqual, 23354)
So(result.GetIMDBID(), ShouldEqual, "tt1486217")
So(result.GetMediumPoster(), ShouldNotBeBlank)
So(result.GetOriginalPoster(), ShouldNotBeBlank)
})
t.Run("get show by id", func(t *testing.T) {
t.Parallel()
result, err := c.GetShowWithID("315") // Archer
require.NoError(t, err)
require.NotNil(t, result, "expected a result")
require.Equal(t, "Archer", result.GetTitle())
require.NotEmpty(t, result.GetDescription())
require.Equal(t, 110381, result.GetTVDBID())
require.Equal(t, 23354, result.GetTVRageID())
require.Equal(t, "tt1486217", result.GetIMDBID())
require.NotEmpty(t, result.GetMediumPoster())
require.NotEmpty(t, result.GetOriginalPoster())
})

Convey("I can get a specific episode of a show", func() {
result, err := c.GetEpisode(Show{ID: 315}, 4, 5)
So(err, ShouldBeNil)
So(result, ShouldNotBeNil)
So(result.Name, ShouldNotBeBlank)
So(result.Summary, ShouldNotBeBlank)
})
t.Run("get episode", func(t *testing.T) {
t.Parallel()
result, err := c.GetEpisode(Show{ID: 315}, 4, 5)
require.NoError(t, err)
require.NotNil(t, result, "expected a result")
require.NotEmpty(t, result.Name)
require.NotEmpty(t, result.Summary)
})

Convey("I can get a show by its tvrage id", func() {
result, err := c.GetShowWithTVRageID("23354") // Archer
So(err, ShouldBeNil)
So(result, ShouldNotBeNil)
//fmt.Println(JSONString(result))
So(result.GetTitle(), ShouldNotBeBlank)
So(result.GetDescription(), ShouldNotBeBlank)
})
t.Run("get show with tvrage id", func(t *testing.T) {
t.Parallel()
result, err := c.GetShowWithTVRageID("23354") // Archer
require.NoError(t, err)
require.NotNil(t, result, "expected a result")
require.NotEmpty(t, result.GetTitle())
require.NotEmpty(t, result.GetDescription())
})

Convey("I can get a show", func() {
result, err := c.GetShow("archer")
So(err, ShouldBeNil)
So(result, ShouldNotBeNil)
//fmt.Println(JSONString(result))
So(result.GetTitle(), ShouldNotBeBlank)
So(result.GetDescription(), ShouldNotBeBlank)
})
t.Run("get show by name", func(t *testing.T) {
t.Parallel()
result, err := c.GetShow("archer")
require.NoError(t, err)
require.NotNil(t, result, "expected a result")
require.NotEmpty(t, result.GetTitle())
require.NotEmpty(t, result.GetDescription())
})

Convey("I can refresh a show", func() {
show := Show{ID: 315} // Archer
err := c.RefreshShow(&show)
So(err, ShouldBeNil)
So(show.GetTitle(), ShouldNotBeBlank)
So(show.GetDescription(), ShouldNotBeBlank)
})
t.Run("refresh show", func(t *testing.T) {
t.Parallel()
show := Show{ID: 315} // Archer
err := c.RefreshShow(&show)

Convey("I can get episodes for a show", func() {
show := Show{ID: 315} // Archer
episodes, err := c.GetEpisodes(show)
So(err, ShouldBeNil)
//fmt.Println(JSONString(episodes))
So(len(episodes), ShouldBeGreaterThan, 0)
})
require.NoError(t, err)
require.NotEmpty(t, show.GetTitle())
require.NotEmpty(t, show.GetDescription())
})

Convey("I can get the next episode for a show", func() {
show := Show{ID: 82} // Game of Thrones
episode, err := c.GetNextEpisode(show)
So(err, ShouldBeNil)
So(episode, ShouldNotBeNil)
//fmt.Println(JSONString(episode))
})
t.Run("get episodes", func(t *testing.T) {
t.Parallel()
show := Show{ID: 315} // Archer
episodes, err := c.GetEpisodes(show)
require.NoError(t, err)
require.NotEmpty(t, episodes, "expected to get episodes")
})

Convey("null times are parsed correctly", func() {
show := Show{ID: 180} // Firefly
episodes, err := c.GetEpisodes(show)
So(err, ShouldBeNil)
//fmt.Println(JSONString(episodes))
So(len(episodes), ShouldBeGreaterThan, 0)
})
t.Run("get next episode", func(t *testing.T) {
t.Parallel()
show := Show{ID: 1864} // Superstore
episode, err := c.GetNextEpisode(show)
require.NoError(t, err)
require.NotNil(t, episode)
})
}

func JSONString(val interface{}) string {
bytes, err := json.MarshalIndent(val, "", " ")
if err != nil {
panic(err)
}
return string(bytes)
t.Run("null times", func(t *testing.T) {
t.Parallel()
show := Show{ID: 180} // Firefly
episodes, err := c.GetEpisodes(show)
require.NoError(t, err)
require.NotEmpty(t, episodes, "expected to get episodes")
})
}

0 comments on commit 062d23e

Please sign in to comment.