Ejemplo n.º 1
0
func (self *Service) ListQueues(id *aws.Signer, prefix string) (mq []string, err os.Error) {
	var resp *http.Response
	parms := http.Values{}
	parms.Set("Action", "ListQueues")
	if prefix != "" {
		parms.Set("QueueNamePrefix", prefix)
	}

	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	resp, err = self.conn.Request(req)
	if err == nil {
		defer resp.Body.Close()
		xresp := listQueuesResponse{}
		if resp.StatusCode == http.StatusOK {
			err = xml.Unmarshal(resp.Body, &xresp)
		} else {
			err = os.NewError("Unexpected response code")
		}
		if err == nil {
			mq = xresp.QueueURL
		}

	}
	return
}
Ejemplo n.º 2
0
// Create a queue, returning the Queue object.
func (self *Service) CreateQueue(id *aws.Signer, name string, dvtimeout int) (mq *Queue, err os.Error) {
	var resp *http.Response
	parms := http.Values{}
	parms.Set("Action", "CreateQueue")
	parms.Set("QueueName", name)
	parms.Set("DefaultVisibilityTimeout", strconv.Itoa(dvtimeout))

	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	if err == nil {
		resp, err = self.conn.Request(req)
		if err == nil {
			defer resp.Body.Close()
			if resp.StatusCode == http.StatusOK {
				xmlresp := createQueueResponse{}
				err = xml.Unmarshal(resp.Body, &xmlresp)
				if err == nil {
					var qrl *http.URL
					qrl, err = http.ParseURL(xmlresp.QueueURL)
					if err == nil {
						mq = NewQueue(qrl)
					}
				}
			} else {
				err = os.NewError("Unexpected response")
			}
		}
	}

	return
}
Ejemplo n.º 3
0
// showComments print comment list.
func showComments(auth string, id string) {
	req, err := http.NewRequest("GET", "https://code.google.com/feeds/issues/p/"+project+"/issues/"+id+"/comments/full", nil)
	if err != nil {
		log.Fatal("failed to get comments:", err)
	}
	req.Header.Set("Authorization", "GoogleLogin "+auth)
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatal("failed to get comments:", err)
	}
	defer res.Body.Close()
	if res.StatusCode != 200 {
		log.Fatal("failed to authenticate:", res.Status)
	}
	var feed Feed
	err = xml.Unmarshal(res.Body, &feed)
	if err != nil {
		log.Fatal("failed to get comments:", err)
	}
	for _, entry := range feed.Entry {
		doc, err := html.Parse(strings.NewReader(entry.Content))
		if err != nil {
			log.Fatal("failed to parse xml:", err)
		}
		text, err := dump(doc)
		if err != nil {
			log.Fatal("failed to parse xml:", err)
		}
		println(entry.Title, "\n", text)
	}
}
Ejemplo n.º 4
0
func (self *ELBHandler) CreateLoadBalancer(zones []string, listeners []ELBListener, name string) (dnsname string, err os.Error) {
	parms := map[string]string{}
	for i := range zones {
		parms["AvailabilityZones.members."+strconv.Itoa(1+i)] = zones[i]
	}
	parms["LoadBalancerName"] = name
	for i := range listeners {
		parms["Listeners.members."+strconv.Itoa(1+i)+".InstancePort"] = strconv.Itoa(listeners[i].InstancePort)
		parms["Listeners.members."+strconv.Itoa(1+i)+".LoadBalancerPort"] = strconv.Itoa(listeners[i].LoadBalancerPort)
		parms["Listeners.members."+strconv.Itoa(1+i)+".Protocol"] = listeners[i].Protocol
	}
	req, err := newQuery(self.signer, self.c.Endpoint(), "CreateLoadBalancer", parms)
	if err == nil {
		var resp *http.Response
		var eresult elbResult
		resp, err = self.c.WriteRequest(req)
		if err == nil {
			err = xml.Unmarshal(resp.Body, &eresult)
			if err == nil {
				if eresult.Error.Code != "" {
					err = eresult.Error
				} else {
					dnsname = eresult.CreateLoadBalancerResult.DNSName
				}
			}
		}
	}
	return
}
Ejemplo n.º 5
0
// Note: 0 is a valid timeout!!
func (self *Queue) Peek(id *aws.Signer, vt int) (body []byte, msgid string, err os.Error) {
	var resp *http.Response
	parms := http.Values{}
	parms.Set("Action", "ReceiveMessage")
	if vt >= 0 {
		parms.Set("VisibilityTimeout", strconv.Itoa(vt))
	}
	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	if err == nil {
		resp, err = self.conn.Request(req)
		if err == nil {
			defer resp.Body.Close()
		}
		if err == nil && resp.StatusCode != http.StatusOK {
			err = os.NewError("Unexpected response")
		}
		if err == nil {
			msg := message{}
			err = xml.Unmarshal(resp.Body, &msg)
			if err == nil {
				body, msgid = msg.Body, msg.ReceiptHandle
			}
		}
	}
	return
}
Ejemplo n.º 6
0
Archivo: dcb.go Proyecto: gaxxx/funx
func getDcbValue(period int) (string, os.Error) {
	res, _, err := http.Get(fmt.Sprintf("http://kaijiang.zhcw.com/zhcw/html/ssq/detail_%d.html", period))
	if err != nil {
		return "", err
	}
	defer res.Body.Close()
	js, _ := ioutil.ReadAll(res.Body)
	s := string(js)
	i := strings.Index(s, "中奖号码")
	if i != -1 {
		s := string(s[i:])
		b := strings.Index(s, `<li`)
		e := strings.Index(s, `</ul>`)
		if b > e {
			return "", os.NewError("parse err\n")
		}
		xmlStr := string(s[b : e-1])
		var l Xml
		xmlStr = `<?xml version="1.0" encoding="UTF-8"?><a xmlns="http://domain">` + xmlStr + "</a>"
		fmt.Printf("%s\n", xmlStr)
		if err := xml.Unmarshal(strings.NewReader(xmlStr), &l); err != nil {
			return "", err
		} else {
			var str string
			for _, v := range l.Li {
				str += fmt.Sprintf("%2d|", v)
			}
			return str, nil
		}
	} else {
		return "", os.NewError("404\n")
	}
	return "", nil
}
Ejemplo n.º 7
0
// readSheetsFromZipFile is an internal helper function that loops
// over the Worksheets defined in the XSLXWorkbook and loads them into
// Sheet objects stored in the Sheets slice of a xlsx.File struct.
func readSheetsFromZipFile(f *zip.File, file *File) ([]*Sheet, os.Error) {
	var workbook *XLSXWorkbook
	var error os.Error
	var rc io.ReadCloser
	workbook = new(XLSXWorkbook)
	rc, error = f.Open()
	if error != nil {
		return nil, error
	}
	error = xml.Unmarshal(rc, workbook)
	if error != nil {
		return nil, error
	}
	sheets := make([]*Sheet, len(workbook.Sheets.Sheet))
	for i, rawsheet := range workbook.Sheets.Sheet {
		worksheet, error := getWorksheetFromSheet(rawsheet, file.worksheets) //
		if error != nil {
			return nil, error
		}
		sheet := new(Sheet)
		sheet.Rows = readRowsFromSheet(worksheet, file.referenceTable)
		sheets[i] = sheet
	}
	return sheets, nil
}
Ejemplo n.º 8
0
func (self *Domain) GetAttribute(s *aws.Signer, item string, attrs AttributeList, consist bool) (a []Attribute, err os.Error) {
	var resp *http.Response

	vl := attrs.Values(ATTRIBUTE_LIST)

	vl.Set("Action", "GetAttributes")
	vl.Set("DomainName", self.Name)
	vl.Set("ItemName", item)

	if consist {
		vl.Set("ConsistentRead", "true")
	}

	req := aws.NewRequest(self.URL, "GET", nil, vl)
	err = s.SignRequestV2(req, aws.Canonicalize, DEFAULT_API_VERSION, 0)
	if err == nil {
		resp, err = self.conn.Request(req)
	}
	if err == nil {
		defer resp.Body.Close()
		err = aws.CodeToError(resp.StatusCode)
	}
	if err == nil {
		var response getattributesresponse
		ob, _ := http.DumpResponse(resp, true)
		os.Stdout.Write(ob)
		err = xml.Unmarshal(resp.Body, &response)
		if err == nil {
			a = response.Attributes
		}
	}
	return
}
Ejemplo n.º 9
0
// Users note: amazon will only return an error if the request is bad,
// thus an error will not be raised when deleting a non-existent LB.
func (self *Service) DeleteLoadBalancer(id *aws.Signer, name string) (err os.Error) {
	parms := http.Values{}
	parms.Set("Action", "DeleteLoadBalancer")
	parms.Set("LoadBalancerName", name)
	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 0)
	if err != nil {
		return
	}
	resp, err := self.conn.Request(req)
	if err != nil {
		return
	}
	defer resp.Body.Close()
	if resp.StatusCode != 200 {
		err = aws.CodeToError(resp.StatusCode)
	}
	qr := LoadBalancerQueryResult{}
	err = xml.Unmarshal(resp.Body, &qr)
	if err == nil {
		if qr.ErrorCode != "" {
			err = os.NewError(qr.ErrorCode)
		}
	}
	return
}
Ejemplo n.º 10
0
func (self *Service) DescribeInstances(id *aws.Signer, filter http.Values, ic chan Instance) (err os.Error) {
	if filter == nil {
		filter = http.Values{}
	}
	filter.Set("Action", "DescribeInstances")
	req := aws.NewRequest(self.URL, "GET", nil, filter)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	if err != nil {
		return
	}
	resp, err := self.conn.Request(req)
	if err == nil {
		defer resp.Body.Close()
		xresp := describeInstancesResponse{}
		err := xml.Unmarshal(resp.Body, &xresp)
		if err == nil {
			log.Printf("XRESP == %+v", xresp)
		} else {
			log.Printf("XERR == %+v", err)
		}
		ob, _ := http.DumpResponse(resp, true)
		os.Stdout.Write(ob)
	}

	return
}
Ejemplo n.º 11
0
Archivo: sns.go Proyecto: supr/sns
func (sns *SNS) query(topic *Topic, message *Message, params map[string]string, resp interface{}) os.Error {
	params["Timestamp"] = time.UTC().Format(time.RFC3339)
	url_, err := url.Parse(sns.Region.SNSEndpoint)
	if err != nil {
		return err
	}

	sign(sns.Auth, "GET", "/", params, url_.Host)
	url_.RawQuery = multimap(params).Encode()
	r, err := http.Get(url_.String())
	if err != nil {
		return err
	}
	defer r.Body.Close()

	//dump, _ := http.DumpResponse(r, true)
	//println("DUMP:\n", string(dump))
	//return nil

	if r.StatusCode != 200 {
		return buildError(r)
	}
	err = xml.Unmarshal(r.Body, resp)
	return err
}
Ejemplo n.º 12
0
// Adds common parameters to the "params" map, signs the request,
// adds the signature to the "params" map and sends the request
// to the server.  It then unmarshals the response in to the "resp"
// parameter using xml.Unmarshal()
func (mt *MTurk) query(params map[string]string, operation string, resp interface{}) os.Error {
	service := MTURK_SERVICE
	timestamp := time.UTC().Format(TIMESTAMP_FORMAT)

	params["AWSAccessKeyId"] = mt.Auth.AccessKey
	params["Service"] = service
	params["Timestamp"] = timestamp
	params["Operation"] = operation

	// make a copy
	url := *mt.URL

	sign(mt.Auth, service, operation, timestamp, params)
	url.RawQuery = multimap(params).Encode()
	r, err := http.Get(url.String())
	if err != nil {
		return err
	}
	dump, _ := http.DumpResponse(r, true)
	println("DUMP:\n", string(dump))
	if r.StatusCode != 200 {
		return os.NewError(fmt.Sprintf("%d: unexpected status code", r.StatusCode))
	}
	err = xml.Unmarshal(r.Body, resp)
	r.Body.Close()
	return err
}
Ejemplo n.º 13
0
func fetchPhotosInGallery(filename string, op Operation) {
	defer op.Done()

	f, err := os.Open(filename, os.O_RDONLY, 0)
	if err != nil {
		addError(fmt.Sprintf("Failed to open %s: %v", filename, err))
		return
	}
	defer f.Close()
	mediaSet := new(MediaSet)
	err = xml.Unmarshal(f, mediaSet)
	if err != nil {
		addError(fmt.Sprintf("Failed to unmarshal %s: %v", filename, err))
		return
	}

	// Learn about new galleries, potentially?
	for _, url := range mediaSet.LinkedFrom.InfoURL {
		noteGallery(url)
	}
	for _, url := range mediaSet.LinkedTo.InfoURL {
		noteGallery(url)
	}

	//log.Printf("Parse of %s is: %q", filename, mediaSet)
	for _, item := range mediaSet.MediaSetItems.MediaSetItem {
		item.key = findKey(item.InfoURL, picPattern)
		//log.Printf("   pic: %s", item.InfoURL)
		notePhoto(&item)
	}
}
Ejemplo n.º 14
0
// Test we can succesfully unmarshal the sheetN.xml files within and
// XLSX file into an XLSXWorksheet struct (and it's related children).
func TestUnmarshallWorksheet(t *testing.T) {
	var sheetxml = bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="A1:B2"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection activeCell="C2" sqref="C2"/></sheetView></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="15"/><sheetData><row r="1" spans="1:2"><c r="A1" t="s"><v>0</v></c><c r="B1" t="s"><v>1</v></c></row><row r="2" spans="1:2"><c r="A2" t="s"><v>2</v></c><c r="B2" t="s"><v>3</v></c></row></sheetData><pageMargins left="0.7" right="0.7" top="0.78740157499999996" bottom="0.78740157499999996" header="0.3" footer="0.3"/></worksheet>`)
	worksheet := new(XLSXWorksheet)
	error := xml.Unmarshal(sheetxml, worksheet)
	if error != nil {
		t.Error(error.String())
		return
	}
	if worksheet.Dimension.Ref != "A1:B2" {
		t.Error(fmt.Sprintf("Expected worksheet.Dimension.Ref == 'A1:B2', got %s", worksheet.Dimension.Ref))
	}
	if len(worksheet.SheetViews.SheetView) == 0 {
		t.Error(fmt.Sprintf("Expected len(worksheet.SheetViews.SheetView) == 1, got %d", len(worksheet.SheetViews.SheetView)))
	}
	sheetview := worksheet.SheetViews.SheetView[0]
	if sheetview.TabSelected != "1" {
		t.Error(fmt.Sprintf("Expected sheetview.TabSelected == '1', got %s", sheetview.TabSelected))
	}
	if sheetview.WorkbookViewID != "0" {
		t.Error(fmt.Sprintf("Expected sheetview.WorkbookViewID == '0', got %s", sheetview.WorkbookViewID))
	}
	if sheetview.Selection.ActiveCell != "C2" {
		t.Error(fmt.Sprintf("Expeceted sheetview.Selection.ActiveCell == 'C2', got %s", sheetview.Selection.ActiveCell))
	}
	if sheetview.Selection.SQRef != "C2" {
		t.Error(fmt.Sprintf("Expected sheetview.Selection.SQRef == 'C2', got %s", sheetview.Selection.SQRef))
	}
	if worksheet.SheetFormatPr.BaseColWidth != "10" {
		t.Error(fmt.Sprintf("Expected worksheet.SheetFormatPr.BaseColWidth == '10', got %s", worksheet.SheetFormatPr.BaseColWidth))
	}
	if worksheet.SheetFormatPr.DefaultRowHeight != "15" {
		t.Error(fmt.Sprintf("Expected worksheet.SheetFormatPr.DefaultRowHeight == '15', got %s", worksheet.SheetFormatPr.DefaultRowHeight))
	}
	if len(worksheet.SheetData.Row) == 0 {
		t.Error(fmt.Sprintf("Expected len(worksheet.SheetData.Row) == '2', got %d", worksheet.SheetData.Row))
	}
	row := worksheet.SheetData.Row[0]
	if row.R != "1" {
		t.Error(fmt.Sprintf("Expected row.r == '1', got %s", row.R))
	}
	if row.Spans != "1:2" {
		t.Error(fmt.Sprintf("Expected row.Spans == '1:2', got %s", row.Spans))
	}
	if len(row.C) != 2 {
		t.Error(fmt.Sprintf("Expected len(row.C) == 2, got %s", row.C))
	}
	c := row.C[0]
	if c.R != "A1" {
		t.Error(fmt.Sprintf("Expected c.R == 'A1' got %s", c.R))
	}
	if c.T != "s" {
		t.Error(fmt.Sprintf("Expected c.T == 's' got %s", c.T))
	}
	if c.V.Data != "0" {
		t.Error(fmt.Sprintf("Expected c.V.Data == '0', got %s", c.V.Data))
	}

}
Ejemplo n.º 15
0
func Unmarshal(xmlStr string) XMLdata {
	var buf = bytes.NewBuffer([]byte(xmlStr))
	r := XMLdata{}
	if err := xml.Unmarshal(buf, &r); err != nil {
		fmt.Println(err)
	}
	return r
}
Ejemplo n.º 16
0
Archivo: pmap.go Proyecto: johan/svgo
func readpmap(r io.Reader, canvas *svg.SVG) {
	var pm Pmap
	if err := xml.Unmarshal(r, &pm); err == nil {
		drawpmap(pm, canvas)
	} else {
		fmt.Fprintf(os.Stderr, "Unable to parse pmap (%v)\n", err)
	}
}
Ejemplo n.º 17
0
// readbg reads and parses the XML specification
func readbg(r io.Reader, s *svg.SVG) {
	var bg Bulletgraph
	if err := xml.Unmarshal(r, &bg); err == nil {
		drawbg(bg, s)
	} else {
		fmt.Fprintf(os.Stderr, "%v\n", err)
	}
}
Ejemplo n.º 18
0
func printMetadataForKey(c *irc.Conn, channel string, key string) {
	r, _, _ := http.Get("http://gdata.youtube.com/feeds/api/videos/" + key)
	if r.StatusCode != http.StatusOK {
		return
	}
	var m Video = Video{xml.Name{}, ""}
	xml.Unmarshal(r.Body, &m)
	c.Privmsg(channel, "  -> "+m.Title)
}
Ejemplo n.º 19
0
func parseUI(reader io.Reader) (*UI, os.Error) {
	ui := &UI{}

	if err := xml.Unmarshal(reader, ui); err != nil {
		return nil, err
	}

	return ui, nil
}
Ejemplo n.º 20
0
func (self Response) ParseResponse() (resp SimpledbResponse, err os.Error) {
	err = xml.Unmarshal(self.Body, &resp)
	if err != nil {
		return
	}
	if resp.Errors.Error.Code != "" {
		err = os.NewError(resp.Errors.Error.Code)
	}
	return
}
Ejemplo n.º 21
0
func TestCloud2D(t *testing.T) {
	var cs *cloud2dStr
	if err := xml.Unmarshal(strings.NewReader(test_aida_string), &cs); err != nil {
		t.Errorf("xml.Unmarshal: %q", err)
	}
	c := cs.Convert()
	if c.Entries2d[0].ValueX != 0.0 {
		t.Errorf("Expected %f, got %q", 0.0, c.Entries2d[0].ValueX)
	}
	fmt.Println(c)
}
Ejemplo n.º 22
0
func TestConversion(t *testing.T) {
	var cs *cloud2dStr
	if err := xml.Unmarshal(strings.NewReader(test_aida_string), &cs); err != nil {
		t.Errorf("xml.Unmarshal: %q", err)
	}
	c := cs.Convert()
	fmt.Println(reflect.Typeof(cs))
	fmt.Println(reflect.Typeof(c))
	fmt.Println(reflect.Typeof(cs).Name())
	fmt.Println(reflect.Typeof(c).Name())
}
Ejemplo n.º 23
0
func main( )
{
	file, _ := file.Open( "./user.xml", 0, 0 );

	var result = User { "emailAddress", "password" };
	
	xml.Unmarshal( file, &result );

	fmt.Printf( "%s\n", result.EmailAddress );
	fmt.Printf( "%s\n", result.Password );
}
Ejemplo n.º 24
0
func main() {
	var file, _ = os.Open("./FIX44.xml")
	r := new(Fix)
	// f := new(Field)
	var err = xml.Unmarshal(file, &r)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(r)
	}
}
Ejemplo n.º 25
0
func TestFile(t *testing.T) {
	var cs *Filestr
	if err := xml.Unmarshal(strings.NewReader(test_aida_string), &cs); err != nil {
		t.Errorf("xml.Unmarshal: %q", err)
	}
	// c := cs.Convert()
	// if c.Entries2d[0].ValueX != 0.0 {
	//     t.Errorf("Expected %f, got %q", 0.0, c.Entries2d[0].ValueX)
	// }
	fmt.Println(cs)
}
Ejemplo n.º 26
0
func NewDict(lang, title string) *Dict {
	d := emptyDict()
	parsed := new(Api)
	base := fmt.Sprintf(template, lang, http.URLEscape(title))
	response, _, _ := http.Get(base)
	defer response.Body.Close()
	xml.Unmarshal(response.Body, parsed)
	d.original = parsed.Title
	for {
		d.add(parsed.Ll)
		cont := parsed.Any.Langlinks.Llcontinue
		if cont == "" {
			break
		}
		parsed = new(Api)
		newResponse, _, _ := http.Get(base + "&llcontinue=" + cont)
		defer newResponse.Body.Close()
		xml.Unmarshal(newResponse.Body, parsed)
	}
	return d
}
Ejemplo n.º 27
0
func (self CBUIReturnVerifier) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
	if req.FormValue("signatureVersion") != "2" {
		req.Form["CBUI.Error"] = []string{"Invalid CBUI signature version"}
		self.Failure.ServeHTTP(rw, req)
		self.Logger.Printf("signatureVersion not provided: %v", req.URL.RawQuery)
		return
	}
	myurl := &http.URL{
		Host:   req.Host,
		Path:   req.URL.Path,
		Scheme: "http",
	}
	if rw.UsingTLS() {
		myurl.Scheme += "s"
	}

	vurl := &http.URL{
		Scheme: self.GatewayURL.Scheme,
		Host:   self.GatewayURL.Host,
		Path:   self.GatewayURL.Path,
		RawQuery: http.EncodeQuery(map[string][]string{
			"UrlEndPoint":    []string{myurl.String()},
			"HttpParameters": []string{req.URL.RawQuery},
			"Action":         []string{"VerifySignature"},
			"Version":        []string{"2008-09-17"},
		}),
	}

	self.Logger.Printf("Verifying signature from %s", self.GatewayURL.String())

	resp, _, err := http.Get(vurl.String())
	if err != nil {
		self.Logger.Printf("Get Failed: %v", err)
		req.Form["CBUI.Error"] = []string{err.String()}
		self.Failure.ServeHTTP(rw, req)
	} else {
		xresp := cbuiResponse{}
		err = xml.Unmarshal(resp.Body, &xresp)
		if err != nil {
			req.Form["CBUI.Error"] = []string{err.String()}
			self.Failure.ServeHTTP(rw, req)
			return
		}
		if xresp.VerifySignatureResult.VerificationStatus != "Success" {
			req.Form["CBUI.Error"] = []string{"Amazon refused signature verification"}
			self.Failure.ServeHTTP(rw, req)
			return
		}
		req.Form["CBUI.Ok"] = []string{"true"}
		self.Success.ServeHTTP(rw, req)
	}
}
Ejemplo n.º 28
0
func TestLoadAllRuns(t *testing.T) {
	file, err := os.Open("fixtures/example.xml")
	if err == nil {
		ps := new(PlusService)
		xml.Unmarshal(file, ps)
		file.Close()

		firstRun := &ps.RunList.Run[0]
		assert.Equal(t, 1484663528, firstRun.Id)
	} else {
		t.Error(err)
	}
}
Ejemplo n.º 29
0
func TestLoadIndividualRun(t *testing.T) {
	file, err := os.Open("fixtures/individual_run.xml")
	if err == nil {
		ps := new(PlusService)
		xml.Unmarshal(file, ps)
		file.Close()

		runSummary := &ps.SportsData.RunSummary
		assert.Equal(t, 3.9519, runSummary.Distance)
	} else {
		t.Error(err)
	}
}
Ejemplo n.º 30
0
Archivo: sqs.go Proyecto: supr/sqs
func buildError(r *http.Response) os.Error {
	errors := xmlErrors{}
	xml.Unmarshal(r.Body, &errors)
	var err Error
	if len(errors.Errors) > 0 {
		err = errors.Errors[0]
	}
	err.RequestId = errors.RequestId
	err.StatusCode = r.StatusCode
	if err.Message == "" {
		err.Message = r.Status
	}
	return &err
}