Skip to content

Commit

Permalink
Added JSON fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
NOX73 committed Jul 14, 2013
1 parent 517fb3e commit b320054
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions twitter_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ type Message struct {

type TweetJSON struct {
Text string
User struct {Id int; SreenName string}
User struct {
Id int
Screen_name string
Name string
Description string
Profile_image_url_https string
}
}

type Tweet struct {
Expand All @@ -52,11 +58,9 @@ func (t *Tweet) UserID() int {

func (t *Tweet) UserName() string {
if t.JSON == nil{ t.ParseJSON() }
return t.JSON.User.SreenName
return t.JSON.User.Screen_name
}



func (t *Tweet) ParseJSON() {
t.JSON = &TweetJSON{}
_ = json.Unmarshal([]byte(t.Body), t.JSON)
Expand Down
2 changes: 1 addition & 1 deletion twitter_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ func (s *OAuthSuite) TestCreateClient(c *C) {
go TwitterStream(ch, credentials, params)

message := <- ch

c.Assert(message.Response.StatusCode, Equals, 200)
c.Assert(message.Tweet, NotNil)
c.Assert(message.Tweet.Body, NotNil)
c.Assert(message.Tweet.Body, NotNil)
c.Assert(message.Tweet.Text(), NotNil)
c.Assert(message.Tweet.UserID(), NotNil)
c.Assert(message.Tweet.UserName(), NotNil)
Expand Down

0 comments on commit b320054

Please sign in to comment.