Skip to content

Commit

Permalink
check token validity, improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
zeusbaba committed Jan 15, 2019
1 parent 8f76916 commit ddebf77
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
11 changes: 9 additions & 2 deletions baba/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package baba

import "time"
import (
"fmt"
"time"
)

type Video struct {
PersonName string `json:",omitempty"`
Expand All @@ -16,7 +19,11 @@ type Community struct {
AlbumId string
}


func DisplayTokenWarning() {
//fmt.Println("!!!vimeoToken is NOT valid!!!")
fmt.Println("!!!you MUST provide vimeoToken to be able to use Vimeo API!!!")
fmt.Println("get it from https://developer.vimeo.com/api/start ")
}
func CheckError(err error) {
if err != nil {
panic(err)
Expand Down
9 changes: 8 additions & 1 deletion baba/vimeo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ func InitVimeoClient(vimeoToken string) (vimeoClient *vimeo.Client) {
tokenContext := oauth2.NewClient(oauth2.NoContext, tokenSource)
vimeoClient = vimeo.NewClient(tokenContext, nil)

// FIXME: make a simple API call to validate the token
if !isValidToken(vimeoClient) {
vimeoClient = nil
}

return
}

func isValidToken(vimeoClient *vimeo.Client) bool {
// make a simple API call to check token validity
_, _, err := vimeoClient.CreativeCommons.List(vimeo.OptPage(1), vimeo.OptPerPage(1))
return err == nil
}
func GetAlbumVideos(vimeoClient *vimeo.Client, community Community) (videos []Video) {

optPerPage := 42
Expand Down
18 changes: 10 additions & 8 deletions crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,27 @@ import (

func main() {

// --- vimeoToken ---
// try to get vimeToken from env-vars
// try to get vimeoToken from env-vars
vimeoToken := os.Getenv("VIMEO_TOKEN")
//fmt.Printf("token from ENV: %v \n", vimeoToken)
vimeoToken = strings.TrimSpace(vimeoToken)

if len(vimeoToken) == 0 || len(vimeoToken) < 20 { // if not ask the user to enter it manually
if len(vimeoToken) == 0 || len(vimeoToken) < 20 {
// if not found then ask the user to enter it manually
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter your VIMEO token: ")
vimeoToken, _ := reader.ReadString('\n')
vimeoToken = strings.TrimSpace(vimeoToken)
if len(vimeoToken) == 0 || len(vimeoToken) < 20 {
fmt.Println("!!!MUST provide vimeoToken to be able to use Vimeo API!!!")
fmt.Println("get it from https://developer.vimeo.com/api/start ")
baba.DisplayTokenWarning()
panic("!!!missing vimeoToken!!!")
}
}
vimeoClient := baba.InitVimeoClient(vimeoToken)
if vimeoClient == nil {
baba.DisplayTokenWarning()
panic("!!!vimeoToken is NOT valid!!!")
}

loadVideosJavaZone(vimeoClient)
loadVideosNDCOslo(vimeoClient)
Expand Down Expand Up @@ -91,11 +94,10 @@ func albums(which string) (albums map[string]string){
//albums["JavaZone-2014"] = "3031533"
}


return
}

func albumName(javaZone baba.Community) (albumName string) {
/*func albumName(javaZone baba.Community) (albumName string) {
for key,val := range javaZone.Albums {
if javaZone.AlbumId == val {
Expand All @@ -105,7 +107,7 @@ func albumName(javaZone baba.Community) (albumName string) {
}
return
}
}*/



0 comments on commit ddebf77

Please sign in to comment.