Exemplo n.º 1
0
func TWITTER_REPLIES(c *http.Conn, req *http.Request) {
	log.Stderrf(">REPLIES:");
	s := session_service.GetSession(c,req);
	for k,v := range s.Data {
		log.Stderrf("session kv:%s:%s", k, v);
	}
	auth_token, atx := s.Data["oauth_token"];
	if atx {
		log.Stderrf("TOKEN FOUND!");
		auth_token_secret := s.Data["oauth_token_secret"];
		r, finalUrl, err := twitter_client.MakeRequest("http://twitter.com/statuses/mentions.json", map[string]string{"oauth_token":auth_token}, auth_token_secret, false); //{"since_id":s.last_reply_id})
		if err != nil {
			log.Stderrf(":REPLIES:err:%s",err);
		}
		else {
			log.Stderrf(":REPLIES:r:%s:finalUrl:%s", r, finalUrl);
			b, _ := io.ReadAll(r.Body);
			print ("REPLIES!");
			str := bytes.NewBuffer(b).String();
       			println (str);
			j, ok, errtok := json.StringToJson(str);
			log.Stderr("REPLIES:j:%s:ok:%s:errtok:%s", j, ok, errtok);
			c.Write(strings.Bytes(j.String()));
		}
	
	}
	else {
		log.Stderrf("NO TOKEN FOUND!");
		http.Redirect(c, "/login/twitter?returnto=/twitter/replies", http.StatusFound); // should be 303 instead of 302?
	}
}
Exemplo n.º 2
0
func TestMapCounter(t *testing.T) {
	colours := NewMap("bike-shed-colours");

	colours.Add("red", 1);
	colours.Add("red", 2);
	colours.Add("blue", 4);
	if x := colours.m["red"].(*Int).i; x != 3 {
		t.Errorf("colours.m[\"red\"] = %v, want 3", x);
	}
	if x := colours.m["blue"].(*Int).i; x != 4 {
		t.Errorf("colours.m[\"blue\"] = %v, want 4", x);
	}

	// colours.String() should be '{"red":3, "blue":4}',
	// though the order of red and blue could vary.
	s := colours.String();
	j, ok, errtok := json.StringToJson(s);
	if !ok {
		t.Errorf("colours.String() isn't valid JSON: %v", errtok);
	}
	if j.Kind() != json.MapKind {
		t.Error("colours.String() didn't produce a map.");
	}
	red := j.Get("red");
	if red.Kind() != json.NumberKind {
		t.Error("red.Kind() is not a NumberKind.");
	}
	if x := red.Number(); x != 3 {
		t.Error("red = %v, want 3", x);
	}
}
Exemplo n.º 3
0
// parseJson takes a string and converts it into a json object
func parseJson(jsonStr string) (result json.Json, err os.Error) {
	var ok bool
	var errtok string
	if result, ok, errtok = json.StringToJson(jsonStr); !ok {
		return nil, os.NewError("Error passing json string: " + errtok)
	}
	return result, nil
}