Skip to content

Commit

Permalink
"Updating samples to reflect recent changes."
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffposnick committed Feb 12, 2014
1 parent 4d610aa commit a3cce3e
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions go/search_by_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type FreebaseTopic struct {
Score float64
}

// FreebaseResponse is struct for unmarshalling JSON values from the Freebase API.
// FreebaseResponse is struct for unmarshalling JSON values from the freebase API.
type FreebaseResponse struct {
Status string
Result []FreebaseTopic
Expand All @@ -60,9 +60,9 @@ func main() {
}
}

// getTopicID queries Freebase with the given string. It then prompts the user
// to select a topic, then returns the selected topic so that the topic can be
// used to search YouTube for videos, channels or playlists.
// getTopicID queries Freebase with the given string. Prompts user
// to select a topic, then returns to search YouTube for videos,
// channels or playlists with the given topic.
func getTopicID(topic string) (string, error) {
urlParams := url.Values{
"query": []string{topic},
Expand Down Expand Up @@ -95,7 +95,7 @@ func getTopicID(topic string) (string, error) {
return "", errors.New("No matching terms were found in Freebase.")
}

// Print a list of topics for the user to select.
// Print a list of topics for the user to select
fmt.Println("The following topics were found:")
for index, topic := range data.Result {
if topic.Notable.Name == "" {
Expand All @@ -114,8 +114,8 @@ func getTopicID(topic string) (string, error) {
return choice.Mid, nil
}

// readInt reads an integer from standard input and verifies that the value
// is between the allowed min and max values (inclusive).
// readInt reads an integer from standard input, validating that the input is equal to or
// greater than the min, while being equal to or lesser than the max value.
func readInt(prompt string, min int, max int) (int, error) {
// Loop until we have a valid input.
for {
Expand All @@ -133,9 +133,8 @@ func readInt(prompt string, min int, max int) (int, error) {
}
}

// youtubeSearch searches YouTube for the topic given in the query flag and
// prints the results. This function takes a mid parameter, which specifies
// a value retrieved using the Freebase API.
// youtubeSearch searches YouTube for the topic given in the query flag and prints the results.
// Takes a mid parameter as supplied by Freebase.
func youtubeSearch(mid string) error {
client := &http.Client{
Transport: &transport.APIKey{Key: developerKey},
Expand All @@ -146,7 +145,7 @@ func youtubeSearch(mid string) error {
return err
}

// Make the API call to YouTube.
// Make the API call to YouTube
call := service.Search.List("id,snippet").
TopicId(mid).
Type(*resultType).
Expand All @@ -156,7 +155,7 @@ func youtubeSearch(mid string) error {
return err
}

// Iterate through each item and output it.
// Iterate through each item and output it
for _, item := range response.Items {
itemID := ""
switch item.Id.Kind {
Expand Down

0 comments on commit a3cce3e

Please sign in to comment.