Esempio n. 1
0
func retrieveInfo(client oauth2_client.OAuth2Client, apiUrl, id string, m url.Values, value interface{}) (err error) {
	uri := TWITTER_API_ENDPOINT
	for _, s := range []string{apiUrl, id} {
		if len(s) > 0 {
			if uri[len(uri)-1] != '/' {
				uri += "/"
			}
			uri += s
		}
	}
	headers := make(http.Header)
	headers.Set("Accept", "application/json")
	if m == nil {
		m = make(url.Values)
	}
	resp, _, err := oauth2_client.AuthorizedGetRequest(client, headers, uri, m)
	if err != nil {
		return err
	}
	if resp != nil {
		if resp.StatusCode >= 400 {
			var e ErrorResponse
			b, _ := ioutil.ReadAll(resp.Body)
			json.Unmarshal(b, &e)
			if len(e.ErrorField) > 0 {
				err = errors.New(e.ErrorField)
			} else {
				err = errors.New(string(b))
			}
		} else {
			err = json.NewDecoder(resp.Body).Decode(value)
		}
	}
	return err
}
Esempio n. 2
0
func retrieveInfo(client oauth2_client.OAuth2Client, id, scope string, value interface{}) (err error) {
	uri := FACEBOOK_GRAPH_API_ENDPOINT
	for _, s := range []string{id, scope} {
		if len(s) > 0 {
			if uri[len(uri)-1] != '/' {
				uri += "/"
			}
			uri += s
		}
	}
	resp, _, err := oauth2_client.AuthorizedGetRequest(client, nil, uri, nil)
	if err != nil {
		return err
	}
	if resp != nil {
		if resp.StatusCode >= 400 {
			e := new(ErrorResponse)
			b, _ := ioutil.ReadAll(resp.Body)
			if err = json.Unmarshal(b, e); err != nil {
				err = errors.New(string(b))
			} else {
				err = e
			}
		} else {
			err = json.NewDecoder(resp.Body).Decode(value)
		}
	}
	return err
}
Esempio n. 3
0
func RetrieveContactPhoto(client oauth2_client.OAuth2Client, id string) (theimage image.Image, format string, err error) {
	uri := GOOGLE_FEEDS_API_ENDPOINT + strings.Replace(strings.Join([]string{GOOGLE_PHOTOS_SCOPE, GOOGLE_DEFAULT_USER_ID, id}, "/"), "//", "/", -1)
	resp, _, err := oauth2_client.AuthorizedGetRequest(client, nil, uri, nil)
	if err != nil {
		return theimage, format, err
	}
	if resp != nil {
		theimage, format, err = image.Decode(resp.Body)
	}
	return theimage, format, err
}
Esempio n. 4
0
func RetrieveProfileImage(client oauth2_client.OAuth2Client, screenName, size string, userId int64, includeEntities bool, m url.Values) (*http.Response, error) {
	uri := TWITTER_API_ENDPOINT + "users/profile_image"
	if m == nil {
		m = make(url.Values)
	}
	if len(screenName) > 0 {
		m.Set("screen_name", screenName)
	} else {
		return nil, errors.New("Must specify either screenName in twitter.RetrieveProfileImage()")
	}
	resp, _, err := oauth2_client.AuthorizedGetRequest(client, nil, uri, m)
	return resp, err
}
Esempio n. 5
0
func retrieveInfo(client oauth2_client.OAuth2Client, uri string, m url.Values, value interface{}) (err error) {
	resp, _, err := oauth2_client.AuthorizedGetRequest(client, nil, uri, m)
	if err != nil {
		return err
	}
	if resp != nil {
		if resp.StatusCode >= 400 {
			b, _ := ioutil.ReadAll(resp.Body)
			err = errors.New(string(b))
		} else {
			err = json.NewDecoder(resp.Body).Decode(value)
		}
	}
	return err
}
Esempio n. 6
0
func retrieveInfo(client oauth2_client.OAuth2Client, scope, userId, resourceName, resourceId, subcategory, subcategoryId, projection string, m url.Values, value interface{}) (err error) {
	var useUserId string
	if len(userId) <= 0 {
		useUserId = LINKEDIN_DEFAULT_USER_ID
	} else {
		useUserId = url.QueryEscape(userId)
	}
	uri := LINKEDIN_API_ENDPOINT
	for _, s := range []string{scope, useUserId, resourceName, resourceId, subcategory, subcategoryId} {
		if len(s) > 0 {
			if uri[len(uri)-1] != '/' {
				uri += "/"
			}
			uri += s
		}
	}
	if len(projection) > 0 {
		uri += ":(" + projection + ")"
	}
	headers := make(http.Header)
	headers.Set("Accept", "application/json")
	headers.Set("X-Li-Format", "json")
	if m == nil {
		m = make(url.Values)
	}
	resp, _, err := oauth2_client.AuthorizedGetRequest(client, headers, uri, m)
	if err != nil {
		return err
	}
	if resp != nil {
		if resp.StatusCode >= 400 {
			e := new(ErrorResponse)
			b, _ := ioutil.ReadAll(resp.Body)
			json.Unmarshal(b, e)
			if len(e.Message) > 0 {
				err = e
			} else {
				err = errors.New(string(b))
			}
		} else {
			err = json.NewDecoder(resp.Body).Decode(value)
		}
	}
	return err
}
Esempio n. 7
0
func retrieveInfo(client oauth2_client.OAuth2Client, scope, userId, projection, id string, m url.Values, value interface{}) (err error) {
	var useUserId string
	if len(userId) <= 0 {
		useUserId = GOOGLE_DEFAULT_USER_ID
	} else {
		useUserId = url.QueryEscape(userId)
	}
	if len(projection) <= 0 {
		projection = GOOGLE_DEFAULT_PROJECTION
	}
	headers := make(http.Header)
	headers.Set("GData-Version", "3.0")
	if m == nil {
		m = make(url.Values)
	}
	if len(m.Get(CONTACTS_ALT_PARAM)) <= 0 {
		m.Set(CONTACTS_ALT_PARAM, "json")
	}
	uri := GOOGLE_FEEDS_API_ENDPOINT
	for _, s := range []string{scope, useUserId, projection, id} {
		if len(s) > 0 {
			if uri[len(uri)-1] != '/' {
				uri += "/"
			}
			uri += s
		}
	}
	resp, _, err := oauth2_client.AuthorizedGetRequest(client, headers, uri, m)
	if err != nil {
		return err
	}
	if resp != nil {
		if resp.StatusCode >= 400 {
			b, _ := ioutil.ReadAll(resp.Body)
			err = errors.New(string(b))
		} else {
			err = json.NewDecoder(resp.Body).Decode(value)
		}
	}
	return err
}
Esempio n. 8
0
func retrieveInfo(client oauth2_client.OAuth2Client, method string, m url.Values, value interface{}) (err error) {
	uri := SMUGMUG_API_ENDPOINT
	headers := make(http.Header)
	headers.Set("Accept", "application/json")
	if m == nil {
		m = make(url.Values)
	}
	m.Set("method", method)
	resp, _, err := oauth2_client.AuthorizedGetRequest(client, headers, uri, m)
	if err != nil {
		return err
	}
	if resp != nil {
		var e ErrorResponse
		b, _ := ioutil.ReadAll(resp.Body)
		json.Unmarshal(b, &e)
		if e.Stat != "ok" {
			err = &e
		} else {
			err = json.Unmarshal(b, value)
		}
	}
	return err
}