26 // Note that the caller should close the connection when it's done reading |
26 // Note that the caller should close the connection when it's done reading |
27 // the stream. |
27 // the stream. |
28 // The stream name can be "user", "public" or "hashtag". |
28 // The stream name can be "user", "public" or "hashtag". |
29 // For "hashtag", the hashTag argument cannot be empty. |
29 // For "hashtag", the hashTag argument cannot be empty. |
30 func (g *Client) openStream(streamName, hashTag string) (*http.Response, error) { |
30 func (g *Client) openStream(streamName, hashTag string) (*http.Response, error) { |
31 req := g.prepareRequest("streaming/" + streamName) |
31 params := make(apiCallParams) |
32 |
32 |
33 switch streamName { |
33 switch streamName { |
34 case "user", "public": |
34 case "user", "public": |
35 case "hashtag": |
35 case "hashtag": |
36 if hashTag == "" { |
36 if hashTag == "" { |
37 return nil, ErrInvalidParameter |
37 return nil, ErrInvalidParameter |
38 } |
38 } |
39 req.QueryParams["tag"] = hashTag |
39 params["tag"] = hashTag |
40 default: |
40 default: |
41 return nil, ErrInvalidParameter |
41 return nil, ErrInvalidParameter |
42 } |
42 } |
43 |
43 |
|
44 req := g.prepareRequest("streaming/"+streamName, rest.Get, params) |
44 reqObj, err := rest.BuildRequestObject(req) |
45 reqObj, err := rest.BuildRequestObject(req) |
45 if err != nil { |
46 if err != nil { |
46 return nil, fmt.Errorf("cannot build stream request: %s", err.Error()) |
47 return nil, fmt.Errorf("cannot build stream request: %s", err.Error()) |
47 } |
48 } |
|
49 |
48 resp, err := rest.MakeRequest(reqObj) |
50 resp, err := rest.MakeRequest(reqObj) |
49 if err != nil { |
51 if err != nil { |
50 return nil, fmt.Errorf("cannot open stream: %s", err.Error()) |
52 return nil, fmt.Errorf("cannot open stream: %s", err.Error()) |
51 } |
53 } |
52 if resp.StatusCode != 200 { |
54 if resp.StatusCode != 200 { |