changin names

This commit is contained in:
Christopher Herrera 2015-07-17 16:16:57 -04:00
parent 2c12789f2c
commit 93ab936da7
2 changed files with 15 additions and 15 deletions

View file

@ -98,9 +98,9 @@ type MovieResult struct {
// Funcs // Funcs
//======================================================================= //=======================================================================
//SearchMovies search for movies given a Title and year, Year is optional you can pass nil //Search search for movies given a Title and year, Year is optional you can pass nil
func SearchMovies(title string, year string) (*SearchResponse, error) { func Search(title string, year string) (*SearchResponse, error) {
resp, err := omdbAPIRequest(title, "", "", year) resp, err := requestAPI(title, "", "", year)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -119,9 +119,9 @@ func SearchMovies(title string, year string) (*SearchResponse, error) {
return r, nil return r, nil
} }
//GetMovieByTitle returns a MovieResult given Title //MovieByTitle returns a MovieResult given Title
func GetMovieByTitle(title string, year string) (*MovieResult, error) { func MovieByTitle(title string, year string) (*MovieResult, error) {
resp, err := omdbAPIRequest("", "", title, year) resp, err := requestAPI("", "", title, year)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -139,9 +139,9 @@ func GetMovieByTitle(title string, year string) (*MovieResult, error) {
return r, nil return r, nil
} }
//GetMovieByImdbID returns a MovieResult given a ImdbID ex:"tt2015381" //MovieByImdbID returns a MovieResult given a ImdbID ex:"tt2015381"
func GetMovieByImdbID(id string) (*MovieResult, error) { func MovieByImdbID(id string) (*MovieResult, error) {
resp, err := omdbAPIRequest("", id, "", "") resp, err := requestAPI("", id, "", "")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -159,7 +159,7 @@ func GetMovieByImdbID(id string) (*MovieResult, error) {
return r, nil return r, nil
} }
func omdbAPIRequest(s string, i string, t string, y string) (resp *http.Response, err error) { func requestAPI(s string, i string, t string, y string) (resp *http.Response, err error) {
//s = Search Parameter, if this is != nil then its a searchMovies //s = Search Parameter, if this is != nil then its a searchMovies
//i = Id Parameter, if this is != nil then its a getMovieByImdbID //i = Id Parameter, if this is != nil then its a getMovieByImdbID
//t = Title Parameter, if this is != nil then its a getMovieByTitle //t = Title Parameter, if this is != nil then its a getMovieByTitle
@ -191,14 +191,14 @@ func omdbAPIRequest(s string, i string, t string, y string) (resp *http.Response
} }
URL.RawQuery = parameters.Encode() URL.RawQuery = parameters.Encode()
res, err := http.Get(URL.String()) res, err := http.Get(URL.String())
err = checkErrorStatus(res.StatusCode) err = checkErr(res.StatusCode)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return res, nil return res, nil
} }
func checkErrorStatus(status int) error { func checkErr(status int) error {
if status != 200 { if status != 200 {
return fmt.Errorf("Status Code %d received from IMDB", status) return fmt.Errorf("Status Code %d received from IMDB", status)
} }

View file

@ -3,7 +3,7 @@ package gomdb
import "testing" import "testing"
func TestImdbSearchMovies(t *testing.T) { func TestImdbSearchMovies(t *testing.T) {
resp, err := SearchMovies("Fight Club", "1999") resp, err := Search("Fight Club", "1999")
if err != nil { if err != nil {
t.Error("Failed Search Movies") t.Error("Failed Search Movies")
} }
@ -13,7 +13,7 @@ func TestImdbSearchMovies(t *testing.T) {
} }
func TestImdbGetMovieByTitle(t *testing.T) { func TestImdbGetMovieByTitle(t *testing.T) {
resp, err := GetMovieByTitle("Fight Club", "1999") resp, err := MovieByTitle("Fight Club", "1999")
if err != nil { if err != nil {
t.Error("Failed GetMovieByTitle") t.Error("Failed GetMovieByTitle")
} }
@ -23,7 +23,7 @@ func TestImdbGetMovieByTitle(t *testing.T) {
} }
func TestImdbGetMovieByImdbID(t *testing.T) { func TestImdbGetMovieByImdbID(t *testing.T) {
resp, err := GetMovieByImdbID("tt0137523") resp, err := MovieByImdbID("tt0137523")
if err != nil { if err != nil {
t.Error("Failed GetMovieByImdbID") t.Error("Failed GetMovieByImdbID")
} }