示例#1
0
/**
 * GetMentions gets all mentions of you using the credentials
 * saved in the Client provided.
 */
func GetMentions(client *Client) (statuses []Status, err os.Error) {
	log.Stdout("Get Mentions\n")
	// get json response from server
	var jsonStrResponse string
	var maxFetchCount = client.MaxFetchCount
	if maxFetchCount == 0 {
		maxFetchCount = DefaultMaxFetchCount
	} // use a default
	var form = map[string][]string{
		"count": []string{strconv.Itoa(maxFetchCount)},
	}

	// send request
	jsonStrResponse, err = send(URLMentions, "GET", form, client, "count="+strconv.Itoa(maxFetchCount))
	if err != nil {
		return nil, err
	}

	// parse json response
	var resultObj json.Json
	resultObj, err = parseJson(jsonStrResponse)
	if err != nil {
		return nil, err
	}

	// create status response
	var i int
	statuses = make([]Status, resultObj.Len())
	log.Stdoutf("result count: %d", resultObj.Len())
	for i = 0; i < len(statuses); i++ {
		var elem = resultObj.Elem(i)
		statuses[i] = *parseStatus(elem)
	}
	return
}
示例#2
0
/**
 * GetUserTimeline gets the user's timeline (provided by screenName) using the credentials
 * saved in the Client provided.
 */
func GetUserTimeline(client *Client, screenName string) (statuses []Status, err os.Error) {
	log.Stdout("Get User's Timeline\n")
	// get json response from server
	var jsonStrResponse string
	var maxFetchCount = client.MaxFetchCount
	if maxFetchCount == 0 {
		maxFetchCount = DefaultMaxFetchCount
	} // use a default

	// send request
	jsonStrResponse, err = send(URLUserTimeline+"?screen_name="+screenName+"&count="+strconv.Itoa(maxFetchCount), "GET", nil, client, "")
	if err != nil {
		return nil, err
	}

	// parse json response
	var resultObj json.Json
	//log.Stdout("response: %s", jsonStrResponse);
	resultObj, err = parseJson(jsonStrResponse)
	if err != nil {
		return nil, err
	}

	// create status response
	var i int
	statuses = make([]Status, resultObj.Len())
	log.Stdoutf("result count: %d", resultObj.Len())
	for i = 0; i < len(statuses); i++ {
		var elem = resultObj.Elem(i)
		//log.Stdoutf("found status: %s\n", elem.Get("text").String());
		statuses[i] = *parseStatus(elem)
	}
	return
}
示例#3
0
/**
 * GetDirectMessages gets all of your direct messages. It uses the credentials
 * saved in the Client provided.
 */
func GetDirectMessages(client *Client) (statuses []Status, err os.Error) {
	log.Stdout("Get Direct Messages\n")
	// get json response from server
	var jsonStrResponse string
	var maxFetchCount = client.MaxFetchCount
	if maxFetchCount == 0 {
		maxFetchCount = DefaultMaxFetchCount
	} // use a default

	// send request
	jsonStrResponse, err = send(URLDirectMessages+"?count="+strconv.Itoa(maxFetchCount), "GET", nil, client, "")
	if err != nil {
		return nil, err
	}

	// parse json response
	var resultObj json.Json
	//log.Stdout("response: %s", jsonStrResponse);
	resultObj, err = parseJson(jsonStrResponse)
	if err != nil {
		return nil, err
	}

	// create status response
	var i int
	statuses = make([]Status, resultObj.Len())
	log.Stdoutf("result count: %d", resultObj.Len())
	for i = 0; i < len(statuses); i++ {
		statuses[i] = *parseDirectMessage(resultObj.Elem(i))
	}
	return
}
示例#4
0
/**
 * DoSearch searches all status updates for a particular pattern.
 */
func DoSearch(client *Client, query string) (searchResults []SearchResult, err os.Error) {
	log.Stdout("Do Search\n")
	// get json response from server
	var jsonStrResponse string
	var maxFetchCount = client.MaxFetchCount
	if maxFetchCount == 0 {
		maxFetchCount = DefaultMaxFetchCount
	} // use a default
	query = http.URLEscape(query) // make query safe to travel in http body/url
	var maxFetchCountStr = strconv.Itoa(maxFetchCount)

	// send request
	log.Stdoutf("max fetch count: %s\n", maxFetchCountStr)
	var url = URLSearch + "?q=" + query + "&rpp=" + maxFetchCountStr
	jsonStrResponse, err = send(url, "GET", nil, client, "")
	if err != nil {
		return nil, err
	}

	// parse json response
	var resultObj json.Json
	resultObj, err = parseJson(jsonStrResponse)
	if err != nil {
		return nil, err
	}

	// create status response
	var i int
	resultObj = resultObj.Get("results")
	searchResults = make([]SearchResult, resultObj.Len())
	log.Stdoutf("result count: %d", resultObj.Len())
	for i = 0; i < len(searchResults); i++ {
		var elem = resultObj.Elem(i)
		searchResults[i] = *parseSearchResults(elem)
	}
	return
}
示例#5
0
/**
 * GetFriendsTimeline gets the same timeline as Home does on the web. It uses the credentials
 * saved in the Client provided.
 */
func GetFriendsTimeline(client *Client) (statuses []Status, err os.Error) {
	log.Stdout("Get Friends Timeline\n")
	jsonStrResponse, err := GetFriendsTimelineJson(client)
	if err != nil {
		return nil, err
	}

	// parse json response
	var resultObj json.Json
	//log.Stdout("response: %s", jsonStrResponse);
	resultObj, err = parseJson(jsonStrResponse)
	if err != nil {
		return nil, err
	}

	// create status response
	var i int
	statuses = make([]Status, resultObj.Len())
	log.Stdoutf("result count: %d", resultObj.Len())
	for i = 0; i < len(statuses); i++ {
		statuses[i] = *parseStatus(resultObj.Elem(i))
	}
	return
}