예제 #1
0
파일: test.go 프로젝트: jfgobin/Gostuff
func main() {
	var s string
	var v url.Values
	s = "Hello "
	s = s + "World"
	v.Add(blob, "yeah")
	fmt.Printf("%s\n", s)
	fmt.Println(v)
}
예제 #2
0
func (p *YahooContactService) RetrieveGroups(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, next NextToken) ([]*Group, NextToken, os.Error) {
	var m url.Values
	m = make(url.Values)
	m.Add("count", "max")
	if next == nil {
	} else if start, ok := next.(int); ok {
		m.Add("start", strconv.Itoa(start))
	}
	resp, err := yahoo.RetrieveCategories(client, m)
	if resp == nil || resp.Categories.Categories == nil || len(resp.Categories.Categories) == 0 || err != nil {
		return make([]*Group, 0), nil, err
	}
	groups := make([]*Group, len(resp.Categories.Categories))
	externalServiceId := p.ServiceId()
	userInfo, err := client.RetrieveUserInfo()
	externalUserId := userInfo.Guid()
	var useErr os.Error = nil
	for i, yahooGroup := range resp.Categories.Categories {
		var externalGroupId string
		if yahooGroup.Id > 0 {
			externalGroupId = strconv.Itoa64(yahooGroup.Id)
		}
		var origDsocialGroup *dm.Group = nil
		dsocialGroupId := ""
		if len(externalGroupId) > 0 {
			dsocialGroupId, err = ds.DsocialIdForExternalGroupId(externalServiceId, externalUserId, dsocialUserId, externalGroupId)
			if err != nil {
				if useErr == nil {
					useErr = err
				}
				continue
			}
			if dsocialGroupId != "" {
				origDsocialGroup, _, err = ds.RetrieveDsocialGroupForExternalGroup(externalServiceId, externalUserId, externalGroupId, dsocialUserId)
				if err != nil {
					if useErr == nil {
						useErr = err
					}
					continue
				}
			} else {
				ds.StoreExternalGroup(externalServiceId, externalUserId, dsocialUserId, externalGroupId, &yahooGroup)
			}
		}
		var dsocialGroup *dm.Group = dm.YahooCategoryToDsocial(&yahooGroup, origDsocialGroup, dsocialUserId)
		groups[i] = &Group{
			ExternalServiceId: p.ServiceId(),
			ExternalUserId:    externalUserId,
			ExternalGroupId:   externalGroupId,
			DsocialUserId:     dsocialUserId,
			DsocialGroupId:    dsocialGroupId,
			Value:             dsocialGroup,
		}
	}
	return groups, nil, useErr
}
예제 #3
0
func (p *YahooContactService) RetrieveContacts(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, next NextToken) ([]*Contact, NextToken, os.Error) {
	var m url.Values
	m = make(url.Values)
	m.Add("count", "max")
	if next == nil {
	} else if start, ok := next.(int); ok {
		m.Add("start", strconv.Itoa(start))
	}
	resp, err := yahoo.RetrieveContacts(client, m)
	if resp == nil || resp.Contacts.Contacts == nil || len(resp.Contacts.Contacts) == 0 || err != nil {
		return make([]*Contact, 0), nil, err
	}
	contacts := make([]*Contact, len(resp.Contacts.Contacts))
	externalServiceId := p.ServiceId()
	userInfo, err := client.RetrieveUserInfo()
	externalUserId := userInfo.Guid()
	var useErr os.Error = nil
	for i, yahooContact := range resp.Contacts.Contacts {
		externalContactId := strconv.Itoa64(yahooContact.Id)
		dsocialContactId := ""
		var origDsocialContact *dm.Contact = nil
		if len(externalContactId) > 0 {
			dsocialContactId, err = ds.DsocialIdForExternalContactId(externalServiceId, externalUserId, dsocialUserId, externalContactId)
			if err != nil {
				useErr = err
				continue
			}
			if dsocialContactId != "" {
				origDsocialContact, _, err = ds.RetrieveDsocialContactForExternalContact(externalServiceId, externalUserId, externalContactId, dsocialUserId)
				if err != nil {
					useErr = err
					continue
				}
			} else {
				ds.StoreExternalContact(externalServiceId, externalUserId, dsocialUserId, externalContactId, &yahooContact)
			}
		}
		dsocialContact := dm.YahooContactToDsocial(&yahooContact, origDsocialContact, dsocialUserId)
		contacts[i] = &Contact{
			ExternalServiceId: p.ServiceId(),
			ExternalUserId:    externalUserId,
			ExternalContactId: externalContactId,
			DsocialUserId:     dsocialUserId,
			DsocialContactId:  dsocialContactId,
			Value:             dsocialContact,
		}
	}
	return contacts, nil, useErr
}
예제 #4
0
파일: gohub.go 프로젝트: supr/gohub
func (p *PullRequest) NewIssueComment(body string) (*Comment, os.Error) {
	url_ := fmt.Sprintf("%v/repos/%v/%v/issues/%v/comments", p.g.apiHost, p.Head.Repo.Name, p.Head.Repo.Owner.Login, p.Number)
	params := url.Values{}
	params.Add("body", body)
	out, err := p.g.makePostRequest(url_, strings.NewReader(params.Encode()))
	if err != nil {
		return nil, err
	}

	var comment Comment
	err = json.Unmarshal(out, &comment)
	if err != nil {
		return nil, err
	}

	return &comment, nil
}
예제 #5
0
파일: amzses.go 프로젝트: rsec/amzses
func sesGet(data url.Values) (string, os.Error) {
	data.Add("AWSAccessKeyId", accessKey)
	urlstr := fmt.Sprintf("%s?%s", endpoint, data.Encode())
	endpointURL, _ := url.Parse(urlstr)
	headers := map[string][]string{}

	now := time.UTC()
	date := now.Format("Mon, 02 Jan 2006 15:04:05 -0700")
	headers["Date"] = []string{date}

	h := hmac.NewSHA256([]uint8(secretKey))
	h.Write([]uint8(date))
	signature := base64.StdEncoding.EncodeToString(h.Sum())
	auth := fmt.Sprintf("AWS3-HTTPS AWSAccessKeyId=%s, Algorithm=HmacSHA256, Signature=%s", accessKey, signature)
	headers["X-Amzn-Authorization"] = []string{auth}

	req := http.Request{
		URL:        endpointURL,
		Method:     "GET",
		ProtoMajor: 1,
		ProtoMinor: 1,
		Close:      true,
		Header:     headers,
	}

	r, err := http.DefaultClient.Do(&req)
	if err != nil {
		return "", err
	}

	resultbody, _ := ioutil.ReadAll(r.Body)
	r.Body.Close()

	if r.StatusCode != 200 {
		return "", os.NewError(string(resultbody))
	}

	return string(resultbody), nil
}
예제 #6
0
파일: notifo.go 프로젝트: chrisfarms/notifo
// optional params for "options" map are:
//
// label: label describing the "application" (used only if being sent from a User account; the Service label is automatically applied if being sent from a Service account)
// title: name of "notification event
// uri: the uri that will be loaded when the notification is opened; if specified, must be urlencoded; if a web address, must start with http:// or https://
//
func (nc *Client) Send(to string, msg string, options ...M) os.Error {
	data := url.Values{}
	data.Add("to", to)
	data.Add("msg", msg)
	// grab optional parameters
	for _, option := range options {
		for k, v := range option {
			data.Add(k, v)
		}
	}
	_, err := nc.request("/send_notification", data)
	return err
}
예제 #7
0
파일: notifo.go 프로젝트: chrisfarms/notifo
// Register a client
func (nc *Client) Subscribe(username string) os.Error {
	data := url.Values{}
	data.Add("username", username)
	_, err := nc.request("/subscribe_user", data)
	return err
}
예제 #8
0
func (p *GoogleContactService) RetrieveGroups(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, next NextToken) ([]*Group, NextToken, os.Error) {
	var m url.Values
	if next == nil {
	} else if s, ok := next.(string); ok {
		if s != "" {
			if strings.HasPrefix(s, "https://www.google.com/") {
				uri, err := url.Parse(s)
				if err == nil {
					q, err := url.ParseQuery(uri.RawQuery)
					if err == nil {
						m = q
					}
				}
			}
			if m == nil {
				m = make(url.Values)
				m.Add("q", s)
			}
		}
	} else if maxResults, ok := next.(int); ok {
		m = make(url.Values)
		m.Add("max-results", strconv.Itoa(maxResults))
	} else if maxResults, ok := next.(int64); ok {
		m = make(url.Values)
		m.Add("max-results", strconv.Itoa64(maxResults))
	} else if gq, ok := next.(*google.GroupQuery); ok {
		m = make(url.Values)
		if gq.Alt != "" {
			m.Add("alt", gq.Alt)
		}
		if gq.Q != "" {
			m.Add("q", gq.Q)
		}
		if gq.MaxResults > 0 {
			m.Add("max-results", strconv.Itoa64(gq.MaxResults))
		}
		if gq.StartIndex > 0 {
			m.Add("start-index", strconv.Itoa64(gq.StartIndex))
		}
		if gq.UpdatedMin != "" {
			m.Add("updated-min", gq.UpdatedMin)
		}
		if gq.OrderBy != "" {
			m.Add("orderby", gq.OrderBy)
		}
		if gq.ShowDeleted {
			m.Add("showdeleted", "true")
		}
		if gq.RequireAllDeleted {
			m.Add("requirealldeleted", "true")
		}
		if gq.SortOrder != "" {
			m.Add("sortorder", gq.SortOrder)
		}
	}
	resp, err := google.RetrieveGroups(client, m)
	var theNextToken NextToken = nil
	if resp != nil && resp.Feed != nil && resp.Feed.Links != nil && len(resp.Feed.Links) > 0 {
		for _, link := range resp.Feed.Links {
			if link.Rel == "next" {
				theNextToken = link.Href
			}
		}
	}
	if resp == nil || resp.Feed == nil || resp.Feed.Entries == nil || len(resp.Feed.Entries) == 0 || err != nil {
		return make([]*Group, 0), theNextToken, err
	}
	groups := make([]*Group, len(resp.Feed.Entries))
	externalServiceId := p.ServiceId()
	userInfo, err := client.RetrieveUserInfo()
	externalUserId := userInfo.Guid()
	var useErr os.Error = nil
	for i, googleGroup := range resp.Feed.Entries {
		externalGroupId := googleGroup.GroupId()
		var origDsocialGroup *dm.Group = nil
		dsocialGroupId := ""
		if len(externalGroupId) > 0 {
			dsocialGroupId, err = ds.DsocialIdForExternalGroupId(externalServiceId, externalUserId, dsocialUserId, externalGroupId)
			if err != nil {
				if useErr == nil {
					useErr = err
				}
				continue
			}
			if dsocialGroupId != "" {
				origDsocialGroup, _, err = ds.RetrieveDsocialGroupForExternalGroup(externalServiceId, externalUserId, externalGroupId, dsocialUserId)
				if err != nil {
					if useErr == nil {
						useErr = err
					}
					continue
				}
			} else {
				ds.StoreExternalGroup(externalServiceId, externalUserId, dsocialUserId, externalGroupId, &googleGroup)
			}
		}
		var dsocialGroup *dm.Group = dm.GoogleGroupToDsocial(&googleGroup, origDsocialGroup, dsocialUserId)
		groups[i] = &Group{
			ExternalServiceId: p.ServiceId(),
			ExternalUserId:    googleGroup.GroupUserId(),
			ExternalGroupId:   googleGroup.GroupId(),
			DsocialUserId:     dsocialUserId,
			DsocialGroupId:    dsocialGroupId,
			Value:             dsocialGroup,
		}
	}
	return groups, theNextToken, useErr
}