TwitterWall.st 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. Smalltalk current createPackage: 'TwitterWall'!
  2. Widget subclass: #Tweet
  3. instanceVariableNames: 'json'
  4. package: 'TwitterWall'!
  5. !Tweet methodsFor: 'not yet classified'!
  6. json
  7. ^json
  8. !
  9. json: aJson
  10. json := aJson
  11. !
  12. renderOn: tr
  13. | tdUser tdMessage img a pMessage pDate |
  14. tdUser := HTMLCanvas new td.
  15. tdUser element id: 'user'.
  16. tdMessage := HTMLCanvas new td.
  17. tdMessage element id: 'messageBox'.
  18. tr append: tdUser.
  19. tr append: tdMessage.
  20. img := HTMLCanvas new img src: (json at: 'profile_image_url') .
  21. img element title: (json at: 'from_user').
  22. img element longDesc: ('http://twitter.com/', (json at: 'from_user')).
  23. a := HTMLCanvas new a href: ('http://twitter.com/', (json at: 'from_user')).
  24. a append: img.
  25. tdUser append: a.
  26. pMessage := HTMLCanvas new p.
  27. pMessage element id: 'message'.
  28. pMessage append: (json at: 'text').
  29. tdMessage append: pMessage.
  30. pDate := HTMLCanvas new p.
  31. pDate element id: 'date'.
  32. pDate append: (json at: 'created_at').
  33. tdMessage append: pDate.
  34. ! !
  35. !Tweet class methodsFor: 'not yet classified'!
  36. openAt: tr with: aJson
  37. | tweet |
  38. tweet := self new.
  39. tweet json: aJson.
  40. tweet renderOn: tr.
  41. ^tr
  42. ! !
  43. Object subclass: #TwitterSearch
  44. instanceVariableNames: ''
  45. package: 'TwitterWall'!
  46. !TwitterSearch methodsFor: 'not yet classified'!
  47. query
  48. | result queryString |
  49. queryString := ('#searchQuery' asJQuery val) replace: '#' with: '%23'.
  50. result := jQuery
  51. ajax: 'http://search.twitter.com/search.json?rpp=5&q=', queryString
  52. options: #{
  53. 'type' -> 'GET'.
  54. 'success' -> [ :tmp | self success: (tmp results)].
  55. 'error' -> [window alert: 'error'].
  56. 'dataType' -> 'jsonp'
  57. }.
  58. !
  59. success: tweets
  60. | playground table tr |
  61. playground := '#playground' asJQuery.
  62. playground empty.
  63. [:html |
  64. table := html table.
  65. table element id: 'twitterwall'.
  66. tweets do: [ :tweet |
  67. tr := html tr.
  68. table append: tr.
  69. Tweet openAt: tr with: tweet
  70. ]
  71. ] appendToJQuery: playground.
  72. ! !