twitter 4.8.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. data/CHANGELOG.md +36 -0
  2. data/CONTRIBUTING.md +13 -15
  3. data/LICENSE.md +1 -1
  4. data/README.md +401 -261
  5. data/Rakefile +6 -0
  6. data/lib/twitter/arguments.rb +14 -0
  7. data/lib/twitter/base.rb +109 -89
  8. data/lib/twitter/client.rb +38 -115
  9. data/lib/twitter/configuration.rb +5 -2
  10. data/lib/twitter/core_ext/kernel.rb +5 -1
  11. data/lib/twitter/creatable.rb +7 -4
  12. data/lib/twitter/cursor.rb +57 -45
  13. data/lib/twitter/direct_message.rb +2 -11
  14. data/lib/twitter/entity/uri.rb +14 -0
  15. data/lib/twitter/enumerable.rb +15 -0
  16. data/lib/twitter/error/already_favorited.rb +1 -1
  17. data/lib/twitter/error/already_posted.rb +10 -0
  18. data/lib/twitter/error/already_retweeted.rb +1 -1
  19. data/lib/twitter/error/bad_gateway.rb +2 -3
  20. data/lib/twitter/error/bad_request.rb +2 -2
  21. data/lib/twitter/error/forbidden.rb +2 -2
  22. data/lib/twitter/error/gateway_timeout.rb +2 -3
  23. data/lib/twitter/error/internal_server_error.rb +2 -3
  24. data/lib/twitter/error/not_acceptable.rb +2 -2
  25. data/lib/twitter/error/not_found.rb +2 -2
  26. data/lib/twitter/error/service_unavailable.rb +2 -3
  27. data/lib/twitter/error/too_many_requests.rb +2 -2
  28. data/lib/twitter/error/unauthorized.rb +2 -2
  29. data/lib/twitter/error/unprocessable_entity.rb +2 -2
  30. data/lib/twitter/error.rb +65 -14
  31. data/lib/twitter/factory.rb +13 -12
  32. data/lib/twitter/geo.rb +2 -7
  33. data/lib/twitter/geo_factory.rb +11 -7
  34. data/lib/twitter/geo_results.rb +40 -0
  35. data/lib/twitter/identity.rb +4 -34
  36. data/lib/twitter/list.rb +21 -4
  37. data/lib/twitter/media/photo.rb +6 -4
  38. data/lib/twitter/media_factory.rb +11 -7
  39. data/lib/twitter/null_object.rb +25 -0
  40. data/lib/twitter/oembed.rb +3 -2
  41. data/lib/twitter/place.rb +15 -15
  42. data/lib/twitter/profile_banner.rb +3 -2
  43. data/lib/twitter/rate_limit.rb +4 -17
  44. data/lib/twitter/relationship.rb +2 -19
  45. data/lib/twitter/rest/api/direct_messages.rb +138 -0
  46. data/lib/twitter/rest/api/favorites.rb +115 -0
  47. data/lib/twitter/rest/api/friends_and_followers.rb +287 -0
  48. data/lib/twitter/rest/api/help.rb +58 -0
  49. data/lib/twitter/rest/api/lists.rb +498 -0
  50. data/lib/twitter/rest/api/oauth.rb +62 -0
  51. data/lib/twitter/rest/api/places_and_geo.rb +86 -0
  52. data/lib/twitter/rest/api/saved_searches.rb +93 -0
  53. data/lib/twitter/rest/api/search.rb +37 -0
  54. data/lib/twitter/rest/api/spam_reporting.rb +29 -0
  55. data/lib/twitter/rest/api/suggested_users.rb +51 -0
  56. data/lib/twitter/rest/api/timelines.rb +202 -0
  57. data/lib/twitter/rest/api/trends.rb +58 -0
  58. data/lib/twitter/rest/api/tweets.rb +291 -0
  59. data/lib/twitter/rest/api/undocumented.rb +52 -0
  60. data/lib/twitter/rest/api/users.rb +383 -0
  61. data/lib/twitter/rest/api/utils.rb +246 -0
  62. data/lib/twitter/rest/client.rb +175 -0
  63. data/lib/twitter/rest/request/multipart_with_file.rb +36 -0
  64. data/lib/twitter/rest/response/parse_error_json.rb +15 -0
  65. data/lib/twitter/rest/response/parse_json.rb +31 -0
  66. data/lib/twitter/{response → rest/response}/raise_error.rb +8 -11
  67. data/lib/twitter/search_results.rb +37 -21
  68. data/lib/twitter/settings.rb +1 -6
  69. data/lib/twitter/size.rb +2 -15
  70. data/lib/twitter/streaming/client.rb +89 -0
  71. data/lib/twitter/streaming/connection.rb +22 -0
  72. data/lib/twitter/streaming/event.rb +35 -0
  73. data/lib/twitter/streaming/friend_list.rb +13 -0
  74. data/lib/twitter/streaming/message_parser.rb +18 -0
  75. data/lib/twitter/streaming/response.rb +34 -0
  76. data/lib/twitter/suggestion.rb +5 -8
  77. data/lib/twitter/token.rb +11 -1
  78. data/lib/twitter/trend.rb +4 -8
  79. data/lib/twitter/trend_results.rb +65 -0
  80. data/lib/twitter/tweet.rb +43 -92
  81. data/lib/twitter/user.rb +72 -47
  82. data/lib/twitter/version.rb +4 -4
  83. data/lib/twitter.rb +4 -39
  84. data/spec/fixtures/already_posted.json +1 -0
  85. data/spec/fixtures/ids_list.json +1 -1
  86. data/spec/fixtures/ids_list2.json +1 -1
  87. data/spec/fixtures/request_token.txt +6 -0
  88. data/spec/fixtures/search.json +1 -1
  89. data/spec/fixtures/search_malformed.json +1 -1
  90. data/spec/fixtures/track_streaming.json +3 -0
  91. data/spec/fixtures/track_streaming_user.json +5 -0
  92. data/spec/helper.rb +8 -13
  93. data/spec/twitter/base_spec.rb +13 -103
  94. data/spec/twitter/basic_user_spec.rb +3 -3
  95. data/spec/twitter/configuration_spec.rb +1 -1
  96. data/spec/twitter/cursor_spec.rb +17 -35
  97. data/spec/twitter/direct_message_spec.rb +44 -11
  98. data/spec/twitter/entity/uri_spec.rb +75 -0
  99. data/spec/twitter/error_spec.rb +59 -11
  100. data/spec/twitter/geo/point_spec.rb +6 -6
  101. data/spec/twitter/geo/polygon_spec.rb +5 -5
  102. data/spec/twitter/geo_factory_spec.rb +4 -4
  103. data/spec/twitter/geo_results_spec.rb +35 -0
  104. data/spec/twitter/geo_spec.rb +6 -6
  105. data/spec/twitter/identifiable_spec.rb +5 -26
  106. data/spec/twitter/list_spec.rb +54 -11
  107. data/spec/twitter/media/photo_spec.rb +122 -6
  108. data/spec/twitter/media_factory_spec.rb +3 -3
  109. data/spec/twitter/null_object_spec.rb +27 -0
  110. data/spec/twitter/oembed_spec.rb +69 -45
  111. data/spec/twitter/place_spec.rb +84 -28
  112. data/spec/twitter/profile_banner_spec.rb +1 -1
  113. data/spec/twitter/rate_limit_spec.rb +8 -25
  114. data/spec/twitter/relationship_spec.rb +26 -12
  115. data/spec/twitter/{api → rest/api}/direct_messages_spec.rb +28 -15
  116. data/spec/twitter/{api → rest/api}/favorites_spec.rb +80 -7
  117. data/spec/twitter/{api → rest/api}/friends_and_followers_spec.rb +121 -152
  118. data/spec/twitter/{api → rest/api}/geo_spec.rb +9 -23
  119. data/spec/twitter/{api → rest/api}/help_spec.rb +6 -6
  120. data/spec/twitter/{api → rest/api}/lists_spec.rb +116 -95
  121. data/spec/twitter/{api → rest/api}/oauth_spec.rb +21 -10
  122. data/spec/twitter/{api → rest/api}/saved_searches_spec.rb +13 -13
  123. data/spec/twitter/{api → rest/api}/search_spec.rb +8 -9
  124. data/spec/twitter/{api → rest/api}/spam_reporting_spec.rb +3 -3
  125. data/spec/twitter/{api → rest/api}/suggested_users_spec.rb +5 -5
  126. data/spec/twitter/{api → rest/api}/timelines_spec.rb +9 -9
  127. data/spec/twitter/{api → rest/api}/trends_spec.rb +6 -6
  128. data/spec/twitter/rest/api/tweets_spec.rb +503 -0
  129. data/spec/twitter/{api → rest/api}/undocumented_spec.rb +19 -45
  130. data/spec/twitter/{api → rest/api}/users_spec.rb +64 -39
  131. data/spec/twitter/rest/client_spec.rb +193 -0
  132. data/spec/twitter/saved_search_spec.rb +14 -3
  133. data/spec/twitter/search_results_spec.rb +32 -45
  134. data/spec/twitter/settings_spec.rb +17 -6
  135. data/spec/twitter/size_spec.rb +5 -15
  136. data/spec/twitter/source_user_spec.rb +3 -3
  137. data/spec/twitter/streaming/client_spec.rb +92 -0
  138. data/spec/twitter/streaming/event_spec.rb +45 -0
  139. data/spec/twitter/suggestion_spec.rb +5 -15
  140. data/spec/twitter/target_user_spec.rb +3 -3
  141. data/spec/twitter/token_spec.rb +16 -0
  142. data/spec/twitter/trend_results_spec.rb +89 -0
  143. data/spec/twitter/trend_spec.rb +26 -13
  144. data/spec/twitter/tweet_spec.rb +137 -124
  145. data/spec/twitter/user_spec.rb +139 -80
  146. data/spec/twitter_spec.rb +0 -119
  147. data/twitter.gemspec +12 -6
  148. data.tar.gz.sig +0 -0
  149. metadata +197 -138
  150. metadata.gz.sig +0 -0
  151. data/lib/twitter/action/favorite.rb +0 -19
  152. data/lib/twitter/action/follow.rb +0 -30
  153. data/lib/twitter/action/list_member_added.rb +0 -39
  154. data/lib/twitter/action/mention.rb +0 -46
  155. data/lib/twitter/action/reply.rb +0 -27
  156. data/lib/twitter/action/retweet.rb +0 -27
  157. data/lib/twitter/action/tweet.rb +0 -20
  158. data/lib/twitter/action_factory.rb +0 -22
  159. data/lib/twitter/api/arguments.rb +0 -13
  160. data/lib/twitter/api/direct_messages.rb +0 -148
  161. data/lib/twitter/api/favorites.rb +0 -126
  162. data/lib/twitter/api/friends_and_followers.rb +0 -334
  163. data/lib/twitter/api/help.rb +0 -64
  164. data/lib/twitter/api/lists.rb +0 -618
  165. data/lib/twitter/api/oauth.rb +0 -44
  166. data/lib/twitter/api/places_and_geo.rb +0 -121
  167. data/lib/twitter/api/saved_searches.rb +0 -99
  168. data/lib/twitter/api/search.rb +0 -37
  169. data/lib/twitter/api/spam_reporting.rb +0 -30
  170. data/lib/twitter/api/suggested_users.rb +0 -55
  171. data/lib/twitter/api/timelines.rb +0 -214
  172. data/lib/twitter/api/trends.rb +0 -63
  173. data/lib/twitter/api/tweets.rb +0 -304
  174. data/lib/twitter/api/undocumented.rb +0 -97
  175. data/lib/twitter/api/users.rb +0 -439
  176. data/lib/twitter/api/utils.rb +0 -187
  177. data/lib/twitter/configurable.rb +0 -96
  178. data/lib/twitter/default.rb +0 -102
  179. data/lib/twitter/entity/url.rb +0 -9
  180. data/lib/twitter/error/client_error.rb +0 -35
  181. data/lib/twitter/error/decode_error.rb +0 -9
  182. data/lib/twitter/error/identity_map_key_error.rb +0 -9
  183. data/lib/twitter/error/server_error.rb +0 -28
  184. data/lib/twitter/exceptable.rb +0 -36
  185. data/lib/twitter/identity_map.rb +0 -22
  186. data/lib/twitter/request/multipart_with_file.rb +0 -34
  187. data/lib/twitter/response/parse_json.rb +0 -25
  188. data/spec/fixtures/about_me.json +0 -1
  189. data/spec/fixtures/activity_summary.json +0 -1
  190. data/spec/fixtures/bad_gateway.json +0 -1
  191. data/spec/fixtures/bad_request.json +0 -1
  192. data/spec/fixtures/by_friends.json +0 -1
  193. data/spec/fixtures/end_session.json +0 -1
  194. data/spec/fixtures/forbidden.json +0 -1
  195. data/spec/fixtures/internal_server_error.json +0 -1
  196. data/spec/fixtures/not_acceptable.json +0 -1
  197. data/spec/fixtures/phoenix_search.phoenix +0 -1
  198. data/spec/fixtures/resolve.json +0 -1
  199. data/spec/fixtures/service_unavailable.json +0 -1
  200. data/spec/fixtures/totals.json +0 -1
  201. data/spec/fixtures/trends.json +0 -1
  202. data/spec/fixtures/unauthorized.json +0 -1
  203. data/spec/fixtures/video_facets.json +0 -1
  204. data/spec/twitter/action/favorite_spec.rb +0 -29
  205. data/spec/twitter/action/follow_spec.rb +0 -29
  206. data/spec/twitter/action/list_member_added_spec.rb +0 -41
  207. data/spec/twitter/action/mention_spec.rb +0 -52
  208. data/spec/twitter/action/reply_spec.rb +0 -41
  209. data/spec/twitter/action/retweet_spec.rb +0 -41
  210. data/spec/twitter/action_factory_spec.rb +0 -35
  211. data/spec/twitter/action_spec.rb +0 -16
  212. data/spec/twitter/api/tweets_spec.rb +0 -285
  213. data/spec/twitter/client_spec.rb +0 -223
  214. data/spec/twitter/error/client_error_spec.rb +0 -23
  215. data/spec/twitter/error/server_error_spec.rb +0 -20
@@ -0,0 +1,5 @@
1
+ {"friends":[488736931,311444249]}
2
+ {"created_at":"Wed Apr 06 19:13:37 +0000 2011","id":55709764298092545,"id_str":"55709764298092545","text":"The problem with your code is that it's doing exactly what you told it to do.","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":7505382,"id_str":"7505382","name":"Erik Michaels-Ober","screen_name":"sferik","location":"San Francisco","description":"Write code. Not too much. Mostly Ruby.","url":"https:\/\/github.com\/sferik","entities":{"url":{"urls":[{"url":"https:\/\/github.com\/sferik","expanded_url":null,"indices":[0,25]}]},"description":{"urls":[]}},"protected":false,"followers_count":2479,"friends_count":200,"listed_count":132,"created_at":"Mon Jul 16 12:59:01 +0000 2007","favourites_count":4421,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":8730,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_banner_url":"https:\/\/si0.twimg.com\/profile_banners\/7505382\/1349499693","profile_link_color":"0084B4","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":{"type":"Point","coordinates":[37.78349999,-122.39362884]},"coordinates":{"type":"Point","coordinates":[-122.39362884,37.78349999]},"place":{"id":"5c92ab5379de3839","url":"https:\/\/api.twitter.com\/1.1\/geo\/id\/5c92ab5379de3839.json","place_type":"neighborhood","name":"South Beach","full_name":"South Beach, San Francisco","country_code":"US","country":"United States","bounding_box":{"type":"Polygon","coordinates":[[[-122.403482,37.777529],[-122.387436,37.777529],[-122.387436,37.794486],[-122.403482,37.794486]]]},"attributes":{}},"contributors":null,"retweet_count":316,"entities":{"hashtags":[],"urls":[],"user_mentions":[]},"favorited":false,"retweeted":false}
3
+ {"created_at":"Wed Apr 06 19:13:37 +0000 2011","id":55709764298092545,"id_str":"55709764298092545","text":"The problem with your code is that it's doing exactly what you told it to do.","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":7505382,"id_str":"7505382","name":"Erik Michaels-Ober","screen_name":"sferik","location":"San Francisco","description":"Write code. Not too much. Mostly Ruby.","url":"https:\/\/github.com\/sferik","entities":{"url":{"urls":[{"url":"https:\/\/github.com\/sferik","expanded_url":null,"indices":[0,25]}]},"description":{"urls":[]}},"protected":false,"followers_count":2479,"friends_count":200,"listed_count":132,"created_at":"Mon Jul 16 12:59:01 +0000 2007","favourites_count":4421,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":8730,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_banner_url":"https:\/\/si0.twimg.com\/profile_banners\/7505382\/1349499693","profile_link_color":"0084B4","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":{"type":"Point","coordinates":[37.78349999,-122.39362884]},"coordinates":{"type":"Point","coordinates":[-122.39362884,37.78349999]},"place":{"id":"5c92ab5379de3839","url":"https:\/\/api.twitter.com\/1.1\/geo\/id\/5c92ab5379de3839.json","place_type":"neighborhood","name":"South Beach","full_name":"South Beach, San Francisco","country_code":"US","country":"United States","bounding_box":{"type":"Polygon","coordinates":[[[-122.403482,37.777529],[-122.387436,37.777529],[-122.387436,37.794486],[-122.403482,37.794486]]]},"attributes":{}},"contributors":null,"retweet_count":316,"entities":{"hashtags":[],"urls":[],"user_mentions":[]},"favorited":false,"retweeted":false}
4
+ {"direct_message":{"id":389327745617891328,"id_str":"389327745617891328","text":"hello bot","sender":{"id":10083602,"id_str":"10083602","name":"Adam Bird","screen_name":"adambird","location":"Nottingham, UK","url":"http:\/\/about.me\/adambird", "description":"CEO @onediaryapp, ex @esendex CTO and co-founder, still cycling","protected":false,"followers_count":1286,"friends_count":850,"listed_count":51,"created_at":"Fri Nov 09 00:35:12 +0000 2007","favourites_count":93,"utc_offset":3600,"time_zone":"London","geo_enabled":true,"verified":false,"statuses_count":13480,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/378800000477232297\/23d85bb78f71534eea1e1133fb771f86_normal.jpeg","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/378800000477232297\/23d85bb78f71534eea1e1133fb771f86_normal.jpeg","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"sender_id":10083602,"sender_id_str":"10083602","sender_screen_name":"adambird","recipient":{"id":1292911088,"id_str":"1292911088","name":"One Diary Bot","screen_name":"onediarybot","location":"","url":"http:\/\/www.onediary.com","description":"I'm the One Diary bot, here to help you with your life including personal cycling weather forecasts.","protected":false,"followers_count":113,"friends_count":148,"listed_count":1,"created_at":"Sat Mar 23 23:52:18 +0000 2013","favourites_count":0,"utc_offset":"","time_zone":"","geo_enabled":false,"verified":false,"statuses_count":7919,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/3651575369\/090551d8dd92080198f707769239ff43_normal.jpeg","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/3651575369\/090551d8dd92080198f707769239ff43_normal.jpeg","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"recipient_id":1292911088,"recipient_id_str":"1292911088","recipient_screen_name":"onediarybot","created_at":"Sun Oct 13 09:52:22 +0000 2013","entities":{"hashtags":[],"symbols":[],"urls":[],"user_mentions":[]}}}
5
+ {"event":"follow","source":{"id":10083602,"id_str":"10083602","name":"Adam Bird","screen_name":"adambird","location":"Nottingham, UK","url":"http://t.co/M1eaIKDQyz","description":"CEO @onediaryapp, ex @esendex CTO and co-founder, still cycling","protected":false,"followers_count":1295,"friends_count":850,"listed_count":53,"created_at":"Fri Nov 09 00:35:12 +0000 2007","favourites_count":93,"utc_offset":0,"time_zone":"London","geo_enabled":true,"verified":false,"statuses_count":13507,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http://abs.twimg.com/images/themes/theme1/bg.png","profile_background_image_url_https":"https://abs.twimg.com/images/themes/theme1/bg.png","profile_background_tile":false,"profile_image_url":"http://pbs.twimg.com/profile_images/378800000477232297/23d85bb78f71534eea1e1133fb771f86_normal.jpeg","profile_image_url_https":"https://pbs.twimg.com/profile_images/378800000477232297/23d85bb78f71534eea1e1133fb771f86_normal.jpeg","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"target":{"id":1292911088,"id_str":"1292911088","name":"One Diary Bot","screen_name":"onediarybot","location":null,"url":"http://t.co/etHGc0xHX4","description":"I'm the One Diary bot, here to help you with your life including personal cycling weather forecasts.","protected":false,"followers_count":123,"friends_count":157,"listed_count":1,"created_at":"Sat Mar 23 23:52:18 +0000 2013","favourites_count":0,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":9637,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http://abs.twimg.com/images/themes/theme1/bg.png","profile_background_image_url_https":"https://abs.twimg.com/images/themes/theme1/bg.png","profile_background_tile":false,"profile_image_url":"http://pbs.twimg.com/profile_images/3651575369/090551d8dd92080198f707769239ff43_normal.jpeg","profile_image_url_https":"https://pbs.twimg.com/profile_images/3651575369/090551d8dd92080198f707769239ff43_normal.jpeg","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"created_at":"Sun Oct 27 20:35:25 +0000 2013"}
data/spec/helper.rb CHANGED
@@ -8,7 +8,6 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
8
  SimpleCov.start
9
9
 
10
10
  require 'twitter'
11
- require 'twitter/identity_map'
12
11
  require 'rspec'
13
12
  require 'stringio'
14
13
  require 'tempfile'
@@ -21,42 +20,38 @@ RSpec.configure do |config|
21
20
  config.expect_with :rspec do |c|
22
21
  c.syntax = :expect
23
22
  end
24
-
25
- config.before(:each) do
26
- stub_post("/oauth2/token").with(:body => "grant_type=client_credentials").to_return(:body => fixture("bearer_token.json"), :headers => {:content_type => "application/json; charset=utf-8"})
27
- end
28
23
  end
29
24
 
30
25
  def a_delete(path)
31
- a_request(:delete, Twitter::Default::ENDPOINT + path)
26
+ a_request(:delete, Twitter::REST::Client::ENDPOINT + path)
32
27
  end
33
28
 
34
29
  def a_get(path)
35
- a_request(:get, Twitter::Default::ENDPOINT + path)
30
+ a_request(:get, Twitter::REST::Client::ENDPOINT + path)
36
31
  end
37
32
 
38
33
  def a_post(path)
39
- a_request(:post, Twitter::Default::ENDPOINT + path)
34
+ a_request(:post, Twitter::REST::Client::ENDPOINT + path)
40
35
  end
41
36
 
42
37
  def a_put(path)
43
- a_request(:put, Twitter::Default::ENDPOINT + path)
38
+ a_request(:put, Twitter::REST::Client::ENDPOINT + path)
44
39
  end
45
40
 
46
41
  def stub_delete(path)
47
- stub_request(:delete, Twitter::Default::ENDPOINT + path)
42
+ stub_request(:delete, Twitter::REST::Client::ENDPOINT + path)
48
43
  end
49
44
 
50
45
  def stub_get(path)
51
- stub_request(:get, Twitter::Default::ENDPOINT + path)
46
+ stub_request(:get, Twitter::REST::Client::ENDPOINT + path)
52
47
  end
53
48
 
54
49
  def stub_post(path)
55
- stub_request(:post, Twitter::Default::ENDPOINT + path)
50
+ stub_request(:post, Twitter::REST::Client::ENDPOINT + path)
56
51
  end
57
52
 
58
53
  def stub_put(path)
59
- stub_request(:put, Twitter::Default::ENDPOINT + path)
54
+ stub_request(:put, Twitter::REST::Client::ENDPOINT + path)
60
55
  end
61
56
 
62
57
  def fixture_path
@@ -1,116 +1,26 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Twitter::Base do
4
-
5
- context "identity map enabled" do
6
- before do
7
- Twitter.identity_map = Twitter::IdentityMap
8
- object = Twitter::Base.new(:id => 1)
9
- @base = Twitter::Base.store(object)
10
- end
11
-
12
- after do
13
- Twitter.identity_map = false
14
- end
15
-
16
- describe ".identity_map" do
17
- it "returns an instance of the identity map" do
18
- expect(Twitter::Base.identity_map).to be_a Twitter::IdentityMap
19
- end
20
- end
21
-
22
- describe ".fetch" do
23
- it "returns existing objects" do
24
- expect(Twitter::Base.fetch(:id => 1)).to be
25
- end
26
-
27
- it "raises an error on objects that don't exist" do
28
- expect{Twitter::Base.fetch(:id => 6)}.to raise_error Twitter::Error::IdentityMapKeyError
29
- end
30
- end
31
-
32
- describe ".store" do
33
- it "stores Twitter::Base objects" do
34
- object = Twitter::Base.new(:id => 4)
35
- expect(Twitter::Base.store(object)).to be_a Twitter::Base
36
- end
37
- end
38
-
39
- describe ".fetch_or_new" do
40
- it "returns existing objects" do
41
- expect(Twitter::Base.fetch_or_new(:id => 1)).to be
42
- end
43
- it "creates new objects and stores them" do
44
- expect(Twitter::Base.fetch_or_new(:id => 2)).to be
45
- expect(Twitter::Base.fetch(:id => 2)).to be
46
- end
47
- end
48
-
49
- describe "#[]" do
50
- it "calls methods using [] with symbol" do
51
- expect(@base[:object_id]).to be_an Integer
52
- end
53
- it "calls methods using [] with string" do
54
- expect(@base['object_id']).to be_an Integer
55
- end
56
- it "returns nil for missing method" do
57
- expect(@base[:foo]).to be_nil
58
- expect(@base['foo']).to be_nil
59
- end
60
- end
61
-
62
- describe "#to_hash" do
63
- it "returns a hash" do
64
- expect(@base.to_hash).to be_a Hash
65
- expect(@base.to_hash[:id]).to eq 1
66
- end
67
- end
68
-
69
- describe "identical objects" do
70
- it "have the same object_id" do
71
- expect(@base.object_id).to eq Twitter::Base.fetch(:id => 1).object_id
72
- end
73
- end
74
-
4
+ before do
5
+ @base = Twitter::Base.new(:id => 1)
75
6
  end
76
7
 
77
- context "identity map disabled" do
78
- before(:all) do
79
- Twitter.identity_map = false
8
+ describe "#[]" do
9
+ it "calls methods using [] with symbol" do
10
+ expect(@base[:object_id]).to be_an Integer
80
11
  end
81
- after(:all) do
82
- Twitter.identity_map = Twitter::IdentityMap
12
+ it "calls methods using [] with string" do
13
+ expect(@base["object_id"]).to be_an Integer
83
14
  end
84
-
85
- describe ".identity_map" do
86
- it "returns nil" do
87
- expect(Twitter::Base.identity_map).to be_nil
88
- end
89
- end
90
-
91
- describe ".fetch" do
92
- it "returns nil" do
93
- expect(Twitter::Base.fetch(:id => 1)).to be_nil
94
- end
95
- end
96
-
97
- describe ".store" do
98
- it "returns an instance of the object" do
99
- expect(Twitter::Base.store(Twitter::Base.new(:id => 1))).to be_a Twitter::Base
100
- end
101
- end
102
-
103
- describe ".fetch_or_new" do
104
- it "creates new objects" do
105
- expect(Twitter::Base.fetch_or_new(:id => 2)).to be
106
- expect(Twitter.identity_map).to be_false
107
- end
15
+ it "returns nil for missing method" do
16
+ expect(@base[:foo]).to be_nil
17
+ expect(@base["foo"]).to be_nil
108
18
  end
109
19
  end
110
20
 
111
- describe '#attrs' do
112
- it 'returns a hash of attributes' do
113
- expect(Twitter::Base.new(:id => 1).attrs).to eq({:id => 1})
21
+ describe "#attrs" do
22
+ it "returns a hash of attributes" do
23
+ expect(@base.attrs).to eq({:id => 1})
114
24
  end
115
25
  end
116
26
 
@@ -6,17 +6,17 @@ describe Twitter::BasicUser do
6
6
  it "returns true when objects IDs are the same" do
7
7
  saved_search = Twitter::BasicUser.new(:id => 1, :name => "foo")
8
8
  other = Twitter::BasicUser.new(:id => 1, :name => "bar")
9
- expect(saved_search == other).to be_true
9
+ expect(saved_search == other).to be true
10
10
  end
11
11
  it "returns false when objects IDs are different" do
12
12
  saved_search = Twitter::BasicUser.new(:id => 1)
13
13
  other = Twitter::BasicUser.new(:id => 2)
14
- expect(saved_search == other).to be_false
14
+ expect(saved_search == other).to be false
15
15
  end
16
16
  it "returns false when classes are different" do
17
17
  saved_search = Twitter::BasicUser.new(:id => 1)
18
18
  other = Twitter::Identity.new(:id => 1)
19
- expect(saved_search == other).to be_false
19
+ expect(saved_search == other).to be false
20
20
  end
21
21
  end
22
22
 
@@ -4,7 +4,7 @@ describe Twitter::Configuration do
4
4
 
5
5
  describe "#photo_sizes" do
6
6
  it "returns a hash of sizes when photo_sizes is set" do
7
- photo_sizes = Twitter::Configuration.new(:photo_sizes => {:small => {:h => 226, :w => 340, :resize => 'fit'}, :large => {:h => 466, :w => 700, :resize => 'fit'}, :medium => {:h => 399, :w => 600, :resize => 'fit'}, :thumb => {:h => 150, :w => 150, :resize => 'crop'}}).photo_sizes
7
+ photo_sizes = Twitter::Configuration.new(:photo_sizes => {:small => {:h => 226, :w => 340, :resize => "fit"}, :large => {:h => 466, :w => 700, :resize => "fit"}, :medium => {:h => 399, :w => 600, :resize => "fit"}, :thumb => {:h => 150, :w => 150, :resize => "crop"}}).photo_sizes
8
8
  expect(photo_sizes).to be_a Hash
9
9
  expect(photo_sizes[:small]).to be_a Twitter::Size
10
10
  end
@@ -2,34 +2,9 @@ require 'helper'
2
2
 
3
3
  describe Twitter::Cursor do
4
4
 
5
- describe "#collection" do
6
- it "returns a collection" do
7
- collection = Twitter::Cursor.new({:ids => [1, 2, 3, 4, 5]}, :ids, nil, Twitter::Client.new, :follower_ids, {}).collection
8
- expect(collection).to be_an Array
9
- expect(collection.first).to be_a Fixnum
10
- end
11
- end
12
-
13
- describe "#all" do
14
- before do
15
- @client = Twitter::Client.new
16
- stub_get("/1.1/followers/ids.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
17
- stub_get("/1.1/followers/ids.json").with(:query => {:cursor => "1305102810874389703", :screen_name => "sferik"}).to_return(:body => fixture("ids_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
18
- end
19
- it "requests the correct resources" do
20
- @client.follower_ids("sferik").all
21
- expect(a_get("/1.1/followers/ids.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made
22
- expect(a_get("/1.1/followers/ids.json").with(:query => {:cursor => "1305102810874389703", :screen_name => "sferik"})).to have_been_made
23
- end
24
- it "fetches all" do
25
- follower_ids = @client.follower_ids("sferik").all
26
- expect(follower_ids.size).to eq 6
27
- end
28
- end
29
-
30
5
  describe "#each" do
31
6
  before do
32
- @client = Twitter::Client.new
7
+ @client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS")
33
8
  stub_get("/1.1/followers/ids.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
34
9
  stub_get("/1.1/followers/ids.json").with(:query => {:cursor => "1305102810874389703", :screen_name => "sferik"}).to_return(:body => fixture("ids_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
35
10
  end
@@ -41,25 +16,32 @@ describe Twitter::Cursor do
41
16
  it "iterates" do
42
17
  count = 0
43
18
  @client.follower_ids("sferik").each{count += 1}
44
- expect(count).to eq 6
19
+ expect(count).to eq(6)
20
+ end
21
+ context "with start" do
22
+ it "iterates" do
23
+ count = 0
24
+ @client.follower_ids("sferik").each(5){count += 1}
25
+ expect(count).to eq(1)
26
+ end
45
27
  end
46
28
  end
47
29
 
48
30
  describe "#first?" do
49
31
  context "when previous cursor equals zero" do
50
32
  before do
51
- @cursor = Twitter::Cursor.new({:previous_cursor => 0}, :ids, nil, Twitter::Client.new, :follower_ids, {})
33
+ @cursor = Twitter::Cursor.new({:previous_cursor => 0}, :ids, nil, Twitter::REST::Client.new, :get, "/1.1/followers/ids.json", {})
52
34
  end
53
35
  it "returns true" do
54
- expect(@cursor.first?).to be_true
36
+ expect(@cursor.first?).to be true
55
37
  end
56
38
  end
57
39
  context "when previous cursor does not equal zero" do
58
40
  before do
59
- @cursor = Twitter::Cursor.new({:previous_cursor => 1}, :ids, nil, Twitter::Client.new, :follower_ids, {})
41
+ @cursor = Twitter::Cursor.new({:previous_cursor => 1}, :ids, nil, Twitter::REST::Client.new, :get, "/1.1/followers/ids.json", {})
60
42
  end
61
43
  it "returns true" do
62
- expect(@cursor.first?).to be_false
44
+ expect(@cursor.first?).to be false
63
45
  end
64
46
  end
65
47
  end
@@ -67,18 +49,18 @@ describe Twitter::Cursor do
67
49
  describe "#last?" do
68
50
  context "when next cursor equals zero" do
69
51
  before do
70
- @cursor = Twitter::Cursor.new({:next_cursor => 0}, :ids, nil, Twitter::Client.new, :follower_ids, {})
52
+ @cursor = Twitter::Cursor.new({:next_cursor => 0}, :ids, nil, Twitter::REST::Client.new, :get, "/1.1/followers/ids.json", {})
71
53
  end
72
54
  it "returns true" do
73
- expect(@cursor.last?).to be_true
55
+ expect(@cursor.last?).to be true
74
56
  end
75
57
  end
76
58
  context "when next cursor does not equal zero" do
77
59
  before do
78
- @cursor = Twitter::Cursor.new({:next_cursor => 1}, :ids, nil, Twitter::Client.new, :follower_ids, {})
60
+ @cursor = Twitter::Cursor.new({:next_cursor => 1}, :ids, nil, Twitter::REST::Client.new, :get, "/1.1/followers/ids.json", {})
79
61
  end
80
62
  it "returns false" do
81
- expect(@cursor.last?).to be_false
63
+ expect(@cursor.last?).to be false
82
64
  end
83
65
  end
84
66
  end
@@ -6,17 +6,17 @@ describe Twitter::DirectMessage do
6
6
  it "returns true when objects IDs are the same" do
7
7
  direct_message = Twitter::DirectMessage.new(:id => 1, :text => "foo")
8
8
  other = Twitter::DirectMessage.new(:id => 1, :text => "bar")
9
- expect(direct_message == other).to be_true
9
+ expect(direct_message == other).to be true
10
10
  end
11
11
  it "returns false when objects IDs are different" do
12
12
  direct_message = Twitter::DirectMessage.new(:id => 1)
13
13
  other = Twitter::DirectMessage.new(:id => 2)
14
- expect(direct_message == other).to be_false
14
+ expect(direct_message == other).to be false
15
15
  end
16
16
  it "returns false when classes are different" do
17
17
  direct_message = Twitter::DirectMessage.new(:id => 1)
18
18
  other = Twitter::Identity.new(:id => 1)
19
- expect(direct_message == other).to be_false
19
+ expect(direct_message == other).to be false
20
20
  end
21
21
  end
22
22
 
@@ -31,25 +31,58 @@ describe Twitter::DirectMessage do
31
31
  end
32
32
  end
33
33
 
34
+ describe "#created?" do
35
+ it "returns true when created_at is set" do
36
+ direct_message = Twitter::DirectMessage.new(:id => 1825786345, :created_at => "Mon Jul 16 12:59:01 +0000 2007")
37
+ expect(direct_message.created?).to be true
38
+ end
39
+ it "returns false when created_at is not set" do
40
+ direct_message = Twitter::DirectMessage.new(:id => 1825786345)
41
+ expect(direct_message.created?).to be false
42
+ end
43
+ end
44
+
34
45
  describe "#recipient" do
35
46
  it "returns a User when recipient is set" do
36
- recipient = Twitter::DirectMessage.new(:id => 1825786345, :recipient => {:id => 7505382}).recipient
37
- expect(recipient).to be_a Twitter::User
47
+ direct_message = Twitter::DirectMessage.new(:id => 1825786345, :recipient => {:id => 7505382})
48
+ expect(direct_message.recipient).to be_a Twitter::User
38
49
  end
39
50
  it "returns nil when recipient is not set" do
40
- recipient = Twitter::DirectMessage.new(:id => 1825786345).recipient
41
- expect(recipient).to be_nil
51
+ direct_message = Twitter::DirectMessage.new(:id => 1825786345)
52
+ expect(direct_message.recipient).to be_nil
53
+ end
54
+ end
55
+
56
+ describe "#recipient?" do
57
+ it "returns true when recipient is set" do
58
+ direct_message = Twitter::DirectMessage.new(:id => 1825786345, :recipient => {:id => 7505382})
59
+ expect(direct_message.recipient?).to be true
60
+ end
61
+ it "returns false when recipient is not set" do
62
+ direct_message = Twitter::DirectMessage.new(:id => 1825786345)
63
+ expect(direct_message.recipient?).to be false
42
64
  end
43
65
  end
44
66
 
45
67
  describe "#sender" do
46
68
  it "returns a User when sender is set" do
47
- sender = Twitter::DirectMessage.new(:id => 1825786345, :sender => {:id => 7505382}).sender
48
- expect(sender).to be_a Twitter::User
69
+ direct_message = Twitter::DirectMessage.new(:id => 1825786345, :sender => {:id => 7505382})
70
+ expect(direct_message.sender).to be_a Twitter::User
49
71
  end
50
72
  it "returns nil when sender is not set" do
51
- sender = Twitter::DirectMessage.new(:id => 1825786345).sender
52
- expect(sender).to be_nil
73
+ direct_message = Twitter::DirectMessage.new(:id => 1825786345)
74
+ expect(direct_message.sender).to be_nil
75
+ end
76
+ end
77
+
78
+ describe "#sender?" do
79
+ it "returns true when sender is set" do
80
+ direct_message = Twitter::DirectMessage.new(:id => 1825786345, :sender => {:id => 7505382})
81
+ expect(direct_message.sender?).to be true
82
+ end
83
+ it "returns false when sender is not set" do
84
+ direct_message = Twitter::DirectMessage.new(:id => 1825786345)
85
+ expect(direct_message.sender?).to be false
53
86
  end
54
87
  end
55
88
 
@@ -0,0 +1,75 @@
1
+ # coding: utf-8
2
+ require 'helper'
3
+
4
+ describe Twitter::Entity::URI do
5
+
6
+ describe "#display_uri" do
7
+ it "returns a String when the display_url is set" do
8
+ uri = Twitter::Entity::URI.new(:display_url => "example.com/expanded…")
9
+ expect(uri.display_uri).to be_a String
10
+ expect(uri.display_uri).to eq("example.com/expanded…")
11
+ end
12
+ it "returns nil when the display_url is not set" do
13
+ uri = Twitter::Entity::URI.new
14
+ expect(uri.display_uri).to be_nil
15
+ end
16
+ end
17
+
18
+ describe "#display_uri?" do
19
+ it "returns true when the display_url is set" do
20
+ uri = Twitter::Entity::URI.new(:display_url => "example.com/expanded…")
21
+ expect(uri.display_uri?).to be true
22
+ end
23
+ it "returns false when the display_url is not set" do
24
+ uri = Twitter::Entity::URI.new
25
+ expect(uri.display_uri?).to be false
26
+ end
27
+ end
28
+
29
+ describe "#expanded_uri" do
30
+ it "returns a URI when the expanded_url is set" do
31
+ uri = Twitter::Entity::URI.new(:expanded_url => "https://github.com/sferik")
32
+ expect(uri.expanded_uri).to be_a URI
33
+ expect(uri.expanded_uri.to_s).to eq("https://github.com/sferik")
34
+ end
35
+ it "returns nil when the expanded_url is not set" do
36
+ uri = Twitter::Entity::URI.new
37
+ expect(uri.expanded_uri).to be_nil
38
+ end
39
+ end
40
+
41
+ describe "#expanded_uri?" do
42
+ it "returns true when the expanded_url is set" do
43
+ uri = Twitter::Entity::URI.new(:expanded_url => "https://github.com/sferik")
44
+ expect(uri.expanded_uri?).to be true
45
+ end
46
+ it "returns false when the expanded_url is not set" do
47
+ uri = Twitter::Entity::URI.new
48
+ expect(uri.expanded_uri?).to be false
49
+ end
50
+ end
51
+
52
+ describe "#uri" do
53
+ it "returns a URI when the url is set" do
54
+ uri = Twitter::Entity::URI.new(:url => "https://github.com/sferik")
55
+ expect(uri.uri).to be_a URI
56
+ expect(uri.uri.to_s).to eq("https://github.com/sferik")
57
+ end
58
+ it "returns nil when the url is not set" do
59
+ uri = Twitter::Entity::URI.new
60
+ expect(uri.uri).to be_nil
61
+ end
62
+ end
63
+
64
+ describe "#uri?" do
65
+ it "returns true when the url is set" do
66
+ uri = Twitter::Entity::URI.new(:url => "https://github.com/sferik")
67
+ expect(uri.uri?).to be true
68
+ end
69
+ it "returns false when the url is not set" do
70
+ uri = Twitter::Entity::URI.new
71
+ expect(uri.uri?).to be false
72
+ end
73
+ end
74
+
75
+ end
@@ -2,19 +2,67 @@ require 'helper'
2
2
 
3
3
  describe Twitter::Error do
4
4
 
5
- describe "#initialize" do
6
- it "wraps another error class" do
7
- begin
8
- raise Faraday::Error::ClientError.new("Oops")
9
- rescue Faraday::Error::ClientError
10
- begin
11
- raise Twitter::Error
12
- rescue Twitter::Error => error
13
- expect(error.message).to eq "Oops"
14
- expect(error.wrapped_exception.class).to eq Faraday::Error::ClientError
5
+ before do
6
+ @client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS")
7
+ end
8
+
9
+ describe "#message" do
10
+ it "returns the message of the wrapped exception" do
11
+ error = Twitter::Error.new(Faraday::Error::ClientError.new("Oops"))
12
+ expect(error.message).to eq("Oops")
13
+ end
14
+ end
15
+
16
+ describe "#rate_limit" do
17
+ it "returns the wrapped exception" do
18
+ error = Twitter::Error.new(Faraday::Error::ClientError.new("Oops"))
19
+ expect(error.rate_limit).to be_a Twitter::RateLimit
20
+ end
21
+ end
22
+
23
+ describe "#wrapped_exception" do
24
+ it "returns the wrapped exception" do
25
+ error = Twitter::Error.new(Faraday::Error::ClientError.new("Oops"))
26
+ expect(error.wrapped_exception.class).to eq(Faraday::Error::ClientError)
27
+ end
28
+ end
29
+
30
+ Twitter::Error.errors.each do |status, exception|
31
+
32
+ [nil, "error", "errors"].each do |body|
33
+ context "when HTTP status is #{status} and body is #{body.inspect}" do
34
+ before do
35
+ body_message = '{"' + body + '":"Client Error"}' unless body.nil?
36
+ stub_get("/1.1/statuses/user_timeline.json").with(:query => {:screen_name => "sferik"}).to_return(:status => status, :body => body_message)
37
+ end
38
+ it "raises #{exception.name}" do
39
+ expect{@client.user_timeline("sferik")}.to raise_error exception
15
40
  end
16
41
  end
17
42
  end
18
- end
19
43
 
44
+ context "when HTTP status is #{status} and body is errors" do
45
+ context "when errors is an array of hashes" do
46
+ context "when error code is nil" do
47
+ before do
48
+ body_message = '{"errors":[{"message":"Client Error"}]}'
49
+ stub_get("/1.1/statuses/user_timeline.json").with(:query => {:screen_name => "sferik"}).to_return(:status => status, :body => body_message)
50
+ end
51
+ it "raises #{exception.name}" do
52
+ expect{@client.user_timeline("sferik")}.to raise_error{|error| expect(error.code).to be_nil}
53
+ end
54
+ context "when error code is 187" do
55
+ before do
56
+ body_message = '{"errors":[{"message":"Client Error","code":187}]}'
57
+ stub_get("/1.1/statuses/user_timeline.json").with(:query => {:screen_name => "sferik"}).to_return(:status => status, :body => body_message)
58
+ end
59
+ it "raises #{exception.name}" do
60
+ expect{@client.user_timeline("sferik")}.to raise_error{|error| expect(error.code).to eq(187)}
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ end
20
68
  end
@@ -7,22 +7,22 @@ describe Twitter::Geo::Point do
7
7
  end
8
8
 
9
9
  describe "#==" do
10
- it "returns false for empty objects" do
10
+ it "returns true for empty objects" do
11
11
  point = Twitter::Geo::Point.new
12
12
  other = Twitter::Geo::Point.new
13
- expect(point == other).to be_false
13
+ expect(point == other).to be true
14
14
  end
15
15
  it "returns true when objects coordinates are the same" do
16
16
  other = Twitter::Geo::Point.new(:coordinates => [-122.399983, 37.788299])
17
- expect(@point == other).to be_true
17
+ expect(@point == other).to be true
18
18
  end
19
19
  it "returns false when objects coordinates are different" do
20
20
  other = Twitter::Geo::Point.new(:coordinates => [37.788299, -122.399983])
21
- expect(@point == other).to be_false
21
+ expect(@point == other).to be false
22
22
  end
23
23
  it "returns false when classes are different" do
24
24
  other = Twitter::Geo.new(:coordinates => [-122.399983, 37.788299])
25
- expect(@point == other).to be_false
25
+ expect(@point == other).to be false
26
26
  end
27
27
  end
28
28
 
@@ -34,7 +34,7 @@ describe Twitter::Geo::Point do
34
34
 
35
35
  describe "#longitude" do
36
36
  it "returns the longitude" do
37
- expect(@point.longitude).to eq 37.788299
37
+ expect(@point.longitude).to eq(37.788299)
38
38
  end
39
39
  end
40
40