gs_graph 2.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (348) hide show
  1. data/.document +5 -0
  2. data/.gitattributes +22 -0
  3. data/.gitignore +26 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +3 -0
  6. data/Gemfile +11 -0
  7. data/Gemfile.lock +95 -0
  8. data/LICENSE +20 -0
  9. data/README.rdoc +314 -0
  10. data/Rakefile +25 -0
  11. data/VERSION +1 -0
  12. data/assets/fb_graph.ai +1726 -6
  13. data/assets/fb_graph.png +0 -0
  14. data/gs_graph.gemspec +28 -0
  15. data/lib/gs_graph.rb +174 -0
  16. data/lib/gs_graph/achievement.rb +44 -0
  17. data/lib/gs_graph/action.rb +12 -0
  18. data/lib/gs_graph/ad_account.rb +51 -0
  19. data/lib/gs_graph/ad_campaign.rb +39 -0
  20. data/lib/gs_graph/ad_campaign_stat.rb +22 -0
  21. data/lib/gs_graph/ad_connection_object.rb +53 -0
  22. data/lib/gs_graph/ad_creative.rb +44 -0
  23. data/lib/gs_graph/ad_group.rb +51 -0
  24. data/lib/gs_graph/ad_group_stat.rb +22 -0
  25. data/lib/gs_graph/ad_keyword.rb +20 -0
  26. data/lib/gs_graph/ad_keyword_suggestion.rb +8 -0
  27. data/lib/gs_graph/ad_keyword_valid.rb +23 -0
  28. data/lib/gs_graph/ad_preview.rb +10 -0
  29. data/lib/gs_graph/ad_user.rb +58 -0
  30. data/lib/gs_graph/age_range.rb +12 -0
  31. data/lib/gs_graph/album.rb +59 -0
  32. data/lib/gs_graph/app_request.rb +24 -0
  33. data/lib/gs_graph/application.rb +119 -0
  34. data/lib/gs_graph/auth.rb +88 -0
  35. data/lib/gs_graph/auth/cookie.rb +20 -0
  36. data/lib/gs_graph/auth/signed_request.rb +44 -0
  37. data/lib/gs_graph/broad_targeting_category.rb +13 -0
  38. data/lib/gs_graph/checkin.rb +51 -0
  39. data/lib/gs_graph/collection.rb +55 -0
  40. data/lib/gs_graph/comment.rb +24 -0
  41. data/lib/gs_graph/comparison.rb +13 -0
  42. data/lib/gs_graph/connection.rb +37 -0
  43. data/lib/gs_graph/connections.rb +3 -0
  44. data/lib/gs_graph/connections/accounts.rb +23 -0
  45. data/lib/gs_graph/connections/achievements.rb +21 -0
  46. data/lib/gs_graph/connections/activities.rb +14 -0
  47. data/lib/gs_graph/connections/ad_accounts.rb +15 -0
  48. data/lib/gs_graph/connections/ad_campaign_stats.rb +22 -0
  49. data/lib/gs_graph/connections/ad_campaigns.rb +30 -0
  50. data/lib/gs_graph/connections/ad_connection_objects.rb +14 -0
  51. data/lib/gs_graph/connections/ad_creatives.rb +14 -0
  52. data/lib/gs_graph/connections/ad_group_stats.rb +22 -0
  53. data/lib/gs_graph/connections/ad_groups.rb +35 -0
  54. data/lib/gs_graph/connections/ad_previews.rb +10 -0
  55. data/lib/gs_graph/connections/admins.rb +10 -0
  56. data/lib/gs_graph/connections/albums.rb +21 -0
  57. data/lib/gs_graph/connections/app_notifications.rb +10 -0
  58. data/lib/gs_graph/connections/app_requests.rb +21 -0
  59. data/lib/gs_graph/connections/attending.rb +26 -0
  60. data/lib/gs_graph/connections/banned.rb +31 -0
  61. data/lib/gs_graph/connections/blocked.rb +36 -0
  62. data/lib/gs_graph/connections/books.rb +14 -0
  63. data/lib/gs_graph/connections/broad_targeting_categories.rb +14 -0
  64. data/lib/gs_graph/connections/checkins.rb +21 -0
  65. data/lib/gs_graph/connections/comments.rb +21 -0
  66. data/lib/gs_graph/connections/conversations.rb +14 -0
  67. data/lib/gs_graph/connections/declined.rb +25 -0
  68. data/lib/gs_graph/connections/docs.rb +14 -0
  69. data/lib/gs_graph/connections/events.rb +21 -0
  70. data/lib/gs_graph/connections/family.rb +14 -0
  71. data/lib/gs_graph/connections/feed.rb +21 -0
  72. data/lib/gs_graph/connections/former_participants.rb +14 -0
  73. data/lib/gs_graph/connections/friend_lists.rb +21 -0
  74. data/lib/gs_graph/connections/friend_requests.rb +12 -0
  75. data/lib/gs_graph/connections/friends.rb +14 -0
  76. data/lib/gs_graph/connections/games.rb +14 -0
  77. data/lib/gs_graph/connections/groups.rb +14 -0
  78. data/lib/gs_graph/connections/home.rb +14 -0
  79. data/lib/gs_graph/connections/inbox.rb +20 -0
  80. data/lib/gs_graph/connections/insights.rb +27 -0
  81. data/lib/gs_graph/connections/interests.rb +14 -0
  82. data/lib/gs_graph/connections/invited.rb +36 -0
  83. data/lib/gs_graph/connections/likes.rb +29 -0
  84. data/lib/gs_graph/connections/links.rb +21 -0
  85. data/lib/gs_graph/connections/maybe.rb +25 -0
  86. data/lib/gs_graph/connections/members.rb +22 -0
  87. data/lib/gs_graph/connections/messages.rb +22 -0
  88. data/lib/gs_graph/connections/milestones.rb +21 -0
  89. data/lib/gs_graph/connections/movies.rb +14 -0
  90. data/lib/gs_graph/connections/music.rb +14 -0
  91. data/lib/gs_graph/connections/mutual_friends.rb +26 -0
  92. data/lib/gs_graph/connections/noreply.rb +23 -0
  93. data/lib/gs_graph/connections/notes.rb +21 -0
  94. data/lib/gs_graph/connections/notifications.rb +18 -0
  95. data/lib/gs_graph/connections/offers.rb +22 -0
  96. data/lib/gs_graph/connections/outbox.rb +20 -0
  97. data/lib/gs_graph/connections/participants.rb +14 -0
  98. data/lib/gs_graph/connections/payments.rb +14 -0
  99. data/lib/gs_graph/connections/permissions.rb +16 -0
  100. data/lib/gs_graph/connections/photos.rb +21 -0
  101. data/lib/gs_graph/connections/picture.rb +39 -0
  102. data/lib/gs_graph/connections/pokes.rb +12 -0
  103. data/lib/gs_graph/connections/posts.rb +14 -0
  104. data/lib/gs_graph/connections/promotable_posts.rb +14 -0
  105. data/lib/gs_graph/connections/question_options.rb +14 -0
  106. data/lib/gs_graph/connections/questions.rb +22 -0
  107. data/lib/gs_graph/connections/reach_estimates.rb +12 -0
  108. data/lib/gs_graph/connections/roles.rb +36 -0
  109. data/lib/gs_graph/connections/scores.rb +22 -0
  110. data/lib/gs_graph/connections/senders.rb +14 -0
  111. data/lib/gs_graph/connections/settings.rb +65 -0
  112. data/lib/gs_graph/connections/statuses.rb +14 -0
  113. data/lib/gs_graph/connections/subscribed_to.rb +14 -0
  114. data/lib/gs_graph/connections/subscribers.rb +14 -0
  115. data/lib/gs_graph/connections/subscriptions.rb +53 -0
  116. data/lib/gs_graph/connections/tabs.rb +23 -0
  117. data/lib/gs_graph/connections/tagged.rb +14 -0
  118. data/lib/gs_graph/connections/tags.rb +23 -0
  119. data/lib/gs_graph/connections/television.rb +14 -0
  120. data/lib/gs_graph/connections/test_users.rb +19 -0
  121. data/lib/gs_graph/connections/threads.rb +14 -0
  122. data/lib/gs_graph/connections/user_achievements.rb +22 -0
  123. data/lib/gs_graph/connections/user_likes.rb +19 -0
  124. data/lib/gs_graph/connections/videos.rb +21 -0
  125. data/lib/gs_graph/connections/votes.rb +9 -0
  126. data/lib/gs_graph/cover.rb +10 -0
  127. data/lib/gs_graph/debugger.rb +28 -0
  128. data/lib/gs_graph/device.rb +11 -0
  129. data/lib/gs_graph/doc.rb +18 -0
  130. data/lib/gs_graph/domain.rb +32 -0
  131. data/lib/gs_graph/education.rb +32 -0
  132. data/lib/gs_graph/event.rb +52 -0
  133. data/lib/gs_graph/exception.rb +139 -0
  134. data/lib/gs_graph/friend_list.rb +13 -0
  135. data/lib/gs_graph/friend_request.rb +14 -0
  136. data/lib/gs_graph/group.rb +29 -0
  137. data/lib/gs_graph/image.rb +11 -0
  138. data/lib/gs_graph/insight.rb +13 -0
  139. data/lib/gs_graph/klass.rb +31 -0
  140. data/lib/gs_graph/link.rb +32 -0
  141. data/lib/gs_graph/location.rb +20 -0
  142. data/lib/gs_graph/message.rb +30 -0
  143. data/lib/gs_graph/milestone.rb +26 -0
  144. data/lib/gs_graph/node.rb +149 -0
  145. data/lib/gs_graph/note.rb +32 -0
  146. data/lib/gs_graph/notification.rb +32 -0
  147. data/lib/gs_graph/offer.rb +33 -0
  148. data/lib/gs_graph/open_graph.rb +3 -0
  149. data/lib/gs_graph/open_graph/action.rb +42 -0
  150. data/lib/gs_graph/open_graph/application_context.rb +10 -0
  151. data/lib/gs_graph/open_graph/object.rb +29 -0
  152. data/lib/gs_graph/open_graph/user_context.rb +21 -0
  153. data/lib/gs_graph/order.rb +55 -0
  154. data/lib/gs_graph/page.rb +57 -0
  155. data/lib/gs_graph/page/category_attributes.rb +117 -0
  156. data/lib/gs_graph/photo.rb +48 -0
  157. data/lib/gs_graph/picture.rb +14 -0
  158. data/lib/gs_graph/place.rb +7 -0
  159. data/lib/gs_graph/poke.rb +19 -0
  160. data/lib/gs_graph/post.rb +117 -0
  161. data/lib/gs_graph/privacy.rb +27 -0
  162. data/lib/gs_graph/project.rb +4 -0
  163. data/lib/gs_graph/promotable_post.rb +34 -0
  164. data/lib/gs_graph/property.rb +13 -0
  165. data/lib/gs_graph/query.rb +47 -0
  166. data/lib/gs_graph/question.rb +26 -0
  167. data/lib/gs_graph/question_option.rb +22 -0
  168. data/lib/gs_graph/reach_estimate.rb +22 -0
  169. data/lib/gs_graph/role.rb +13 -0
  170. data/lib/gs_graph/score.rb +16 -0
  171. data/lib/gs_graph/searchable.rb +33 -0
  172. data/lib/gs_graph/searchable/result.rb +31 -0
  173. data/lib/gs_graph/serialization.rb +19 -0
  174. data/lib/gs_graph/status.rb +27 -0
  175. data/lib/gs_graph/subscription.rb +14 -0
  176. data/lib/gs_graph/tab.rb +17 -0
  177. data/lib/gs_graph/tag.rb +30 -0
  178. data/lib/gs_graph/tagged_object.rb +23 -0
  179. data/lib/gs_graph/targeting.rb +23 -0
  180. data/lib/gs_graph/test_user.rb +24 -0
  181. data/lib/gs_graph/thread.rb +71 -0
  182. data/lib/gs_graph/user.rb +153 -0
  183. data/lib/gs_graph/user_achievement.rb +35 -0
  184. data/lib/gs_graph/venue.rb +14 -0
  185. data/lib/gs_graph/video.rb +41 -0
  186. data/lib/gs_graph/work.rb +48 -0
  187. data/lib/patch/rack/oauth2/access_token.rb +11 -0
  188. data/lib/patch/rack/oauth2/access_token/introspectable.rb +37 -0
  189. data/lib/patch/rack/oauth2/client.rb +13 -0
  190. data/lib/patch/rack/oauth2/grant/fb_exchange_token.rb +11 -0
  191. data/lib/patch/rack/oauth2/util.rb +14 -0
  192. data/spec/gs_graph/achievement_spec.rb +59 -0
  193. data/spec/gs_graph/ad_account_spec.rb +124 -0
  194. data/spec/gs_graph/ad_campaign_spec.rb +99 -0
  195. data/spec/gs_graph/ad_connection_object_spec.rb +71 -0
  196. data/spec/gs_graph/ad_creative_spec.rb +87 -0
  197. data/spec/gs_graph/ad_group_spec.rb +95 -0
  198. data/spec/gs_graph/ad_keyword_spec.rb +27 -0
  199. data/spec/gs_graph/ad_keyword_suggestion_spec.rb +17 -0
  200. data/spec/gs_graph/ad_keyword_valid_spec.rb +19 -0
  201. data/spec/gs_graph/ad_user_spec.rb +67 -0
  202. data/spec/gs_graph/album_spec.rb +93 -0
  203. data/spec/gs_graph/app_request_spec.rb +40 -0
  204. data/spec/gs_graph/application_spec.rb +251 -0
  205. data/spec/gs_graph/auth/cookie_spec.rb +29 -0
  206. data/spec/gs_graph/auth/signed_request_spec.rb +22 -0
  207. data/spec/gs_graph/auth_spec.rb +223 -0
  208. data/spec/gs_graph/broad_targeting_category_spec.rb +17 -0
  209. data/spec/gs_graph/checkin_spec.rb +42 -0
  210. data/spec/gs_graph/collection_spec.rb +50 -0
  211. data/spec/gs_graph/comment_spec.rb +31 -0
  212. data/spec/gs_graph/connection_spec.rb +42 -0
  213. data/spec/gs_graph/connections/accounts_spec.rb +78 -0
  214. data/spec/gs_graph/connections/achievements_spec.rb +27 -0
  215. data/spec/gs_graph/connections/activities_spec.rb +34 -0
  216. data/spec/gs_graph/connections/ad_accounts_spec.rb +28 -0
  217. data/spec/gs_graph/connections/ad_campaign_stat_spec.rb +35 -0
  218. data/spec/gs_graph/connections/ad_campaigns_spec.rb +36 -0
  219. data/spec/gs_graph/connections/ad_connection_objects_spec.rb +20 -0
  220. data/spec/gs_graph/connections/ad_creatives_spec.rb +29 -0
  221. data/spec/gs_graph/connections/ad_group_stat_spec.rb +54 -0
  222. data/spec/gs_graph/connections/ad_groups_spec.rb +92 -0
  223. data/spec/gs_graph/connections/ad_previews_spec.rb +18 -0
  224. data/spec/gs_graph/connections/admins_spec.rb +20 -0
  225. data/spec/gs_graph/connections/albums_spec.rb +63 -0
  226. data/spec/gs_graph/connections/app_notifications_spec.rb +23 -0
  227. data/spec/gs_graph/connections/app_requests_spec.rb +28 -0
  228. data/spec/gs_graph/connections/attending_spec.rb +47 -0
  229. data/spec/gs_graph/connections/banned_spec.rb +63 -0
  230. data/spec/gs_graph/connections/blocked_spec.rb +56 -0
  231. data/spec/gs_graph/connections/books_spec.rb +32 -0
  232. data/spec/gs_graph/connections/broad_targeting_categories_spec.rb +18 -0
  233. data/spec/gs_graph/connections/checkins_spec.rb +153 -0
  234. data/spec/gs_graph/connections/comments_spec.rb +75 -0
  235. data/spec/gs_graph/connections/conversations_spec.rb +19 -0
  236. data/spec/gs_graph/connections/declined_spec.rb +47 -0
  237. data/spec/gs_graph/connections/docs_spec.rb +14 -0
  238. data/spec/gs_graph/connections/events_spec.rb +52 -0
  239. data/spec/gs_graph/connections/family_spec.rb +32 -0
  240. data/spec/gs_graph/connections/feed_spec.rb +124 -0
  241. data/spec/gs_graph/connections/former_participants_spec.rb +44 -0
  242. data/spec/gs_graph/connections/friend_lists_spec.rb +26 -0
  243. data/spec/gs_graph/connections/friend_requests_spec.rb +16 -0
  244. data/spec/gs_graph/connections/friends_spec.rb +51 -0
  245. data/spec/gs_graph/connections/games_spec.rb +20 -0
  246. data/spec/gs_graph/connections/groups_spec.rb +31 -0
  247. data/spec/gs_graph/connections/home_spec.rb +62 -0
  248. data/spec/gs_graph/connections/inbox_spec.rb +16 -0
  249. data/spec/gs_graph/connections/insights_spec.rb +104 -0
  250. data/spec/gs_graph/connections/interests_spec.rb +12 -0
  251. data/spec/gs_graph/connections/invited_spec.rb +84 -0
  252. data/spec/gs_graph/connections/likes_spec.rb +127 -0
  253. data/spec/gs_graph/connections/links_spec.rb +31 -0
  254. data/spec/gs_graph/connections/maybe_spec.rb +47 -0
  255. data/spec/gs_graph/connections/members_spec.rb +57 -0
  256. data/spec/gs_graph/connections/messages_spec.rb +58 -0
  257. data/spec/gs_graph/connections/milestones_spec.rb +40 -0
  258. data/spec/gs_graph/connections/movies_spec.rb +12 -0
  259. data/spec/gs_graph/connections/music_spec.rb +12 -0
  260. data/spec/gs_graph/connections/mutual_friends_spec.rb +28 -0
  261. data/spec/gs_graph/connections/noreply_spec.rb +39 -0
  262. data/spec/gs_graph/connections/notes_spec.rb +31 -0
  263. data/spec/gs_graph/connections/notifications_spec.rb +30 -0
  264. data/spec/gs_graph/connections/outbox_spec.rb +16 -0
  265. data/spec/gs_graph/connections/participants_spec.rb +42 -0
  266. data/spec/gs_graph/connections/payments_spec.rb +17 -0
  267. data/spec/gs_graph/connections/permissions_spec.rb +44 -0
  268. data/spec/gs_graph/connections/photos_spec.rb +39 -0
  269. data/spec/gs_graph/connections/picture_spec.rb +92 -0
  270. data/spec/gs_graph/connections/pokes_spec.rb +16 -0
  271. data/spec/gs_graph/connections/posts_spec.rb +34 -0
  272. data/spec/gs_graph/connections/promotable_posts_spec.rb +24 -0
  273. data/spec/gs_graph/connections/question_options_spec.rb +14 -0
  274. data/spec/gs_graph/connections/questions_spec.rb +31 -0
  275. data/spec/gs_graph/connections/reach_estimates_spec.rb +18 -0
  276. data/spec/gs_graph/connections/roles_spec.rb +59 -0
  277. data/spec/gs_graph/connections/scores_spec.rb +40 -0
  278. data/spec/gs_graph/connections/senders_spec.rb +42 -0
  279. data/spec/gs_graph/connections/settings_spec.rb +62 -0
  280. data/spec/gs_graph/connections/statuses_spec.rb +72 -0
  281. data/spec/gs_graph/connections/subscribed_to_spec.rb +12 -0
  282. data/spec/gs_graph/connections/subscribers_spec.rb +12 -0
  283. data/spec/gs_graph/connections/subscriptions_spec.rb +47 -0
  284. data/spec/gs_graph/connections/tabs_spec.rb +47 -0
  285. data/spec/gs_graph/connections/tagged_spec.rb +42 -0
  286. data/spec/gs_graph/connections/tags_spec.rb +30 -0
  287. data/spec/gs_graph/connections/television_spec.rb +12 -0
  288. data/spec/gs_graph/connections/test_users_spec.rb +65 -0
  289. data/spec/gs_graph/connections/threads_spec.rb +12 -0
  290. data/spec/gs_graph/connections/user_achievements_spec.rb +37 -0
  291. data/spec/gs_graph/connections/user_likes_spec.rb +55 -0
  292. data/spec/gs_graph/connections/videos_spec.rb +27 -0
  293. data/spec/gs_graph/connections/votes_spec.rb +15 -0
  294. data/spec/gs_graph/debugger_spec.rb +33 -0
  295. data/spec/gs_graph/doc_spec.rb +27 -0
  296. data/spec/gs_graph/domain_spec.rb +23 -0
  297. data/spec/gs_graph/education_spec.rb +61 -0
  298. data/spec/gs_graph/event_spec.rb +70 -0
  299. data/spec/gs_graph/exception_spec.rb +310 -0
  300. data/spec/gs_graph/friend_list_spec.rb +22 -0
  301. data/spec/gs_graph/group_spec.rb +28 -0
  302. data/spec/gs_graph/image_spec.rb +16 -0
  303. data/spec/gs_graph/insight_spec.rb +18 -0
  304. data/spec/gs_graph/link_spec.rb +41 -0
  305. data/spec/gs_graph/location_spec.rb +28 -0
  306. data/spec/gs_graph/message_spec.rb +47 -0
  307. data/spec/gs_graph/node_spec.rb +91 -0
  308. data/spec/gs_graph/note_spec.rb +37 -0
  309. data/spec/gs_graph/notification_spec.rb +59 -0
  310. data/spec/gs_graph/offer_spec.rb +30 -0
  311. data/spec/gs_graph/open_graph/action_spec.rb +112 -0
  312. data/spec/gs_graph/open_graph/application_context_spec.rb +28 -0
  313. data/spec/gs_graph/open_graph/object_spec.rb +76 -0
  314. data/spec/gs_graph/open_graph/user_context_spec.rb +33 -0
  315. data/spec/gs_graph/order_spec.rb +66 -0
  316. data/spec/gs_graph/page/local_business_spec.rb +88 -0
  317. data/spec/gs_graph/page/movie_spec.rb +25 -0
  318. data/spec/gs_graph/page/music_spec.rb +25 -0
  319. data/spec/gs_graph/page/person_spec.rb +23 -0
  320. data/spec/gs_graph/page/product_spec.rb +36 -0
  321. data/spec/gs_graph/page_spec.rb +81 -0
  322. data/spec/gs_graph/photo_spec.rb +85 -0
  323. data/spec/gs_graph/place_spec.rb +8 -0
  324. data/spec/gs_graph/post_spec.rb +238 -0
  325. data/spec/gs_graph/privacy_spec.rb +33 -0
  326. data/spec/gs_graph/project_spec.rb +46 -0
  327. data/spec/gs_graph/promotable_post_spec.rb +57 -0
  328. data/spec/gs_graph/qeustion_option_spec.rb +35 -0
  329. data/spec/gs_graph/query_spec.rb +73 -0
  330. data/spec/gs_graph/question_spec.rb +73 -0
  331. data/spec/gs_graph/reach_estimate_spec.rb +48 -0
  332. data/spec/gs_graph/searchable_spec.rb +47 -0
  333. data/spec/gs_graph/seriarization_spec.rb +29 -0
  334. data/spec/gs_graph/status_spec.rb +31 -0
  335. data/spec/gs_graph/subscription_spec.rb +5 -0
  336. data/spec/gs_graph/tag_spec.rb +34 -0
  337. data/spec/gs_graph/tagged_object_spec.rb +45 -0
  338. data/spec/gs_graph/targeting_spec.rb +34 -0
  339. data/spec/gs_graph/test_user_spec.rb +50 -0
  340. data/spec/gs_graph/thread_spec.rb +86 -0
  341. data/spec/gs_graph/user_achievement_spec.rb +53 -0
  342. data/spec/gs_graph/user_spec.rb +185 -0
  343. data/spec/gs_graph/venue_spec.rb +23 -0
  344. data/spec/gs_graph/video_spec.rb +31 -0
  345. data/spec/gs_graph/work_spec.rb +101 -0
  346. data/spec/gs_graph_spec.rb +57 -0
  347. data/spec/spec_helper.rb +9 -0
  348. metadata +538 -0
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe GSGraph::AppRequest, '.new' do
4
+ it 'should setup all supported attributes' do
5
+ attributes = {
6
+ :id => "10150111088582277",
7
+ :application => {
8
+ :name => "gem sample",
9
+ :id => "134145643294322"
10
+ },
11
+ :to => {
12
+ :name => "Nov Matake",
13
+ :id => "579612276"
14
+ },
15
+ :from => {
16
+ :name => "Nov Matake",
17
+ :id => "1575327134"
18
+ },
19
+ :data => "tracking information for the user",
20
+ :message => "You should learn more about this awesome game.",
21
+ :created_time => "2011-02-04T09:55:43+0000"
22
+ }
23
+ app_request = GSGraph::AppRequest.new(attributes.delete(:id), attributes)
24
+ app_request.identifier.should == '10150111088582277'
25
+ app_request.application.should == GSGraph::Application.new('134145643294322', :name => 'gem sample')
26
+ app_request.to.should == GSGraph::User.new('579612276', :name => 'Nov Matake')
27
+ app_request.from.should == GSGraph::User.new('1575327134', :name => 'Nov Matake')
28
+ app_request.data.should == 'tracking information for the user'
29
+ app_request.message.should == 'You should learn more about this awesome game.'
30
+ app_request.created_time.should == Time.parse('2011-02-04T09:55:43+0000')
31
+ end
32
+ end
33
+
34
+ describe GSGraph::AppRequest, '#destroy' do
35
+ it 'should request DELETE /:request_id' do
36
+ mock_graph :delete, '12345', 'true', :access_token => 'access_token' do
37
+ GSGraph::AppRequest.new('12345', :access_token => 'access_token').destroy
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,251 @@
1
+ require 'spec_helper'
2
+
3
+ describe GSGraph::Application do
4
+ let(:app) { GSGraph::Application.new('client_id') }
5
+
6
+ describe '.new' do
7
+ it 'should setup all supported attributes' do
8
+ attributes = {
9
+ :id => '12345',
10
+ :name => 'GSGraph',
11
+ :description => 'Owsome Facebook Graph Wrapper',
12
+ :canvas_name => 'gs_graph',
13
+ :category => 'Programming',
14
+ :subcategory => 'Ruby',
15
+ :link => 'http://github.com/nov/gs_graph',
16
+ :company => 'GSGraph',
17
+ :secret => 'sec sec',
18
+ :icon_url => 'http://example.com/icon.gif',
19
+ :logo_url => 'http://example.com/logo.gif',
20
+ :daily_active_users => '10',
21
+ :weekly_active_users => '5',
22
+ :monthly_active_users => '1',
23
+ :migrations => {
24
+ 'secure_stream_urls' => false,
25
+ 'expiring_offline_access_tokens' => true,
26
+ 'december_rollup' => true,
27
+ 'requires_login_secret' => false,
28
+ 'gdp_v2' => true,
29
+ 'page_hours_format' => true,
30
+ 'graph_batch_api_exception_format' => true,
31
+ 'status_checkin_perm_migration' => false
32
+ },
33
+ :namespace => 'gs_graph',
34
+ :restrictions => {
35
+ 'age_distribution' => {
36
+ 'CA,US' => '16-25'
37
+ }
38
+ },
39
+ :app_domains => [
40
+ 'example.com',
41
+ 'example.org'
42
+ ],
43
+ :auth_dialog_data_help_url => 'http://example.com/help/',
44
+ :auth_dialog_description => 'Authorize this app',
45
+ :auth_dialog_headline => "Don't think, just click",
46
+ :auth_dialog_perms_explanation => 'Trust me',
47
+ :auth_referral_user_perms => [
48
+ 'user_hometown',
49
+ 'user_activities',
50
+ 'user_online_presence'
51
+ ],
52
+ :auth_referral_default_activity_privacy => 'NONE',
53
+ :auth_referral_enabled => 1,
54
+ :auth_referral_extended_perms => [
55
+ 'status_update',
56
+ 'video_upload',
57
+ 'publish_stream'
58
+ ],
59
+ :auth_referral_response_type => 'code',
60
+ :canvas_fluid_height => false,
61
+ :canvas_fluid_width => 1,
62
+ :canvas_url => 'http://example.com/canvas/',
63
+ :contact_email => 'gs_graph@example.com',
64
+ :created_time => 1328798126,
65
+ :creator_uid => 98765,
66
+ :deauth_callback_url => 'http://example.com/death/',
67
+ :iphone_app_store_id => '4567',
68
+ :hosting_url => 'http://gs_graph.heroku.com',
69
+ :mobile_web_url => 'http://m.example.com',
70
+ :page_tab_default_name => 'gs_graph Page',
71
+ :page_tab_url => 'http://example.com/page/',
72
+ :privacy_policy_url => 'http://example.com/privacy/',
73
+ :secure_canvas_url => 'https://example.com/canvas/',
74
+ :secure_page_tab_url => 'https://example.com/page/',
75
+ :server_ip_whitelist => '127.0.0.1',
76
+ :social_discovery => 0,
77
+ :terms_of_service_url => 'http://example.com/terms/',
78
+ :user_support_email => 'gs_graph@example.org',
79
+ :user_support_url => 'http://example.com/support/',
80
+ :website_url => 'http://example.com',
81
+ :type => 'application'
82
+ }
83
+
84
+ app = GSGraph::Application.new(attributes.delete(:id), attributes)
85
+ app.identifier.should == '12345'
86
+ app.name.should == 'GSGraph'
87
+ app.description.should == 'Owsome Facebook Graph Wrapper'
88
+ app.canvas_name.should == 'gs_graph'
89
+ app.category.should == 'Programming'
90
+ app.subcategory.should == 'Ruby'
91
+ app.link.should == 'http://github.com/nov/gs_graph'
92
+ app.company.should == 'GSGraph'
93
+ app.icon_url.should == 'http://example.com/icon.gif'
94
+ app.logo_url.should == 'http://example.com/logo.gif'
95
+ app.secret.should == 'sec sec'
96
+ app.daily_active_users.should == 10
97
+ app.weekly_active_users.should == 5
98
+ app.monthly_active_users.should == 1
99
+ app.migrations.should == {
100
+ 'secure_stream_urls' => false,
101
+ 'expiring_offline_access_tokens' => true,
102
+ 'december_rollup' => true,
103
+ 'requires_login_secret' => false,
104
+ 'gdp_v2' => true,
105
+ 'page_hours_format' => true,
106
+ 'graph_batch_api_exception_format' => true,
107
+ 'status_checkin_perm_migration' => false
108
+ }
109
+ app.namespace.should == 'gs_graph'
110
+ app.restrictions.should == {
111
+ 'age_distribution' => {
112
+ 'CA,US' => '16-25'
113
+ }
114
+ }
115
+ app.app_domains.should == [
116
+ 'example.com',
117
+ 'example.org'
118
+ ]
119
+ app.auth_dialog_data_help_url.should == 'http://example.com/help/'
120
+ app.auth_dialog_description.should == 'Authorize this app'
121
+ app.auth_dialog_headline.should == "Don't think, just click"
122
+ app.auth_dialog_perms_explanation.should == 'Trust me'
123
+ app.auth_referral_user_perms.should == [
124
+ 'user_hometown',
125
+ 'user_activities',
126
+ 'user_online_presence'
127
+ ]
128
+ app.auth_referral_default_activity_privacy.should == 'NONE'
129
+ app.auth_referral_enabled.should == true
130
+ app.auth_referral_extended_perms.should == [
131
+ 'status_update',
132
+ 'video_upload',
133
+ 'publish_stream'
134
+ ]
135
+ app.auth_referral_response_type.should == 'code'
136
+ app.canvas_fluid_height.should == false
137
+ app.canvas_fluid_width.should == true
138
+ app.canvas_url.should == 'http://example.com/canvas/'
139
+ app.contact_email.should == 'gs_graph@example.com'
140
+ app.created_time.should == 1328798126
141
+ app.creator_uid.should == 98765
142
+ app.deauth_callback_url.should == 'http://example.com/death/'
143
+ app.iphone_app_store_id.should == '4567'
144
+ app.hosting_url.should == 'http://gs_graph.heroku.com'
145
+ app.mobile_web_url.should == 'http://m.example.com'
146
+ app.page_tab_default_name.should == 'gs_graph Page'
147
+ app.page_tab_url.should == 'http://example.com/page/'
148
+ app.privacy_policy_url.should == 'http://example.com/privacy/'
149
+ app.secure_canvas_url.should == 'https://example.com/canvas/'
150
+ app.secure_page_tab_url.should == 'https://example.com/page/'
151
+ app.server_ip_whitelist.should == '127.0.0.1'
152
+ app.social_discovery.should == false
153
+ app.user_support_email.should == 'gs_graph@example.org'
154
+ app.user_support_url.should == 'http://example.com/support/'
155
+ app.website_url.should == 'http://example.com'
156
+ app.type.should == 'application'
157
+ end
158
+ end
159
+
160
+ describe '#get_access_token' do
161
+ before { app.secret = 'secret' }
162
+
163
+ it 'should return Rack::OAuth2::AccessToken::Legacy' do
164
+ mock_graph :post, 'oauth/access_token', 'token_response' do
165
+ token = app.get_access_token
166
+ token.should be_instance_of(Rack::OAuth2::AccessToken::Legacy)
167
+ token.access_token.should == 'token'
168
+ end
169
+ end
170
+ end
171
+
172
+ describe '#access_token' do
173
+ context 'when access token already exists' do
174
+ before { app.access_token = "token" }
175
+ it 'should not fetch new token' do
176
+ app.should_not_receive(:get_access_token)
177
+ app.access_token
178
+ end
179
+ end
180
+
181
+ context 'otherwise' do
182
+ context 'when secret exists' do
183
+ before { app.secret = 'secret' }
184
+ it 'should fetch new token' do
185
+ app.should_receive(:get_access_token)
186
+ app.access_token
187
+ end
188
+ end
189
+
190
+ context 'otherwise' do
191
+ it 'should not fetch new token' do
192
+ app.should_not_receive(:get_access_token)
193
+ app.access_token
194
+ end
195
+ end
196
+ end
197
+ end
198
+
199
+ describe '#debug_token' do
200
+ before { app.access_token = 'app_token' }
201
+ let(:application) { GSGraph::Application.new(210798282372757, :name => 'gem sample') }
202
+ let(:user) { GSGraph::User.new(579612276) }
203
+ let(:scopes) { ['email'] }
204
+
205
+ shared_examples_for :token_debugger do
206
+ context 'when valid' do
207
+ it 'should return introspection result without error' do
208
+ mock_graph :get, 'debug_token', 'token_introspection/valid', :access_token => 'app_token', :params => {
209
+ :input_token => 'input_token'
210
+ } do
211
+ result = app.debug_token input_token
212
+ result.should be_instance_of Rack::OAuth2::AccessToken::Introspectable::Result
213
+ result.application.should == application
214
+ result.user.should == user
215
+ result.scopes.should == scopes
216
+ result.expires_at.should == Time.at(1350363600)
217
+ result.is_valid.should be_true
218
+ result.error.should be_nil
219
+ end
220
+ end
221
+ end
222
+
223
+ context 'when invalid' do
224
+ it 'should return introspection result with error' do
225
+ mock_graph :get, 'debug_token', 'token_introspection/invalid', :access_token => 'app_token', :params => {
226
+ :input_token => 'input_token'
227
+ } do
228
+ result = app.debug_token input_token
229
+ result.should be_instance_of Rack::OAuth2::AccessToken::Introspectable::Result
230
+ result.application.should == application
231
+ result.user.should == user
232
+ result.scopes.should == scopes
233
+ result.expires_at.should == Time.at(1350356400)
234
+ result.is_valid.should be_false
235
+ result.error.should be_a Hash
236
+ end
237
+ end
238
+ end
239
+ end
240
+
241
+ context 'when input_token is String' do
242
+ let(:input_token) { 'input_token' }
243
+ it_behaves_like :token_debugger
244
+ end
245
+
246
+ context 'when input_token is Rack::OAuth2::AccessToken::Legacy instance' do
247
+ let(:input_token) { Rack::OAuth2::AccessToken::Legacy.new :access_token => 'input_token' }
248
+ it_behaves_like :token_debugger
249
+ end
250
+ end
251
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe GSGraph::Auth::Cookie, '.parse' do
4
+ let(:client) { Rack::OAuth2::Client.new(:identifier => 'client_id', :secret => 'client_secret') }
5
+ let :cookie do
6
+ {
7
+ 'fbsr_client_id' => "9heZHFs6tDH/Nif4CqmBaMQ8nKEOc5g2WgVJa10LF00.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImNvZGUiOiI4ZDYwZDY4NDA4MmQ1NjczMjY3MWUxNzAuMS01Nzk2MTIyNzZ8N2pkVlp6MlNLNUY2b0gtQ21FQWtZZVpuVjEwIiwiaXNzdWVkX2F0IjoxMzEyOTUzOTcxLCJ1c2VyX2lkIjo1Nzk2MTIyNzZ9"
8
+ }
9
+ end
10
+
11
+ shared_examples_for :parsable_cookie do
12
+ it 'should be parsable' do
13
+ data[:algorithm].should == 'HMAC-SHA256'
14
+ data[:code].should == '8d60d684082d56732671e170.1-579612276|7jdVZz2SK5F6oH-CmEAkYeZnV10'
15
+ data[:issued_at].should == 1312953971
16
+ data[:user_id].should == 579612276
17
+ end
18
+ end
19
+
20
+ context 'when whole cookie is given' do
21
+ let(:data) { GSGraph::Auth::Cookie.parse(client, cookie) }
22
+ it_behaves_like :parsable_cookie
23
+ end
24
+
25
+ context 'when actual cookie string is given' do
26
+ let(:data) { GSGraph::Auth::Cookie.parse(client, cookie['fbsr_client_id']) }
27
+ it_behaves_like :parsable_cookie
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe GSGraph::Auth::SignedRequest, '.parse' do
4
+ before do
5
+ @client = Rack::OAuth2::Client.new(:identifier => 'client_id', :secret => 'client_secret')
6
+ @signed_request = "LqsgnfcsRdfjOgyW6ZuSLpGBVsxUBegEqai4EcrWS0A=.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjAsImlzc3VlZF9hdCI6MTI5ODc4MzczOSwib2F1dGhfdG9rZW4iOiIxMzQxNDU2NDMyOTQzMjJ8MmI4YTZmOTc1NTJjNmRjZWQyMDU4MTBiLTU3OTYxMjI3NnxGS1o0akdKZ0JwN2k3bFlrOVhhUk1QZ3lhNnMiLCJ1c2VyIjp7ImNvdW50cnkiOiJqcCIsImxvY2FsZSI6ImVuX1VTIiwiYWdlIjp7Im1pbiI6MjF9fSwidXNlcl9pZCI6IjU3OTYxMjI3NiJ9"
7
+ end
8
+
9
+ it 'should verify signature and return data' do
10
+ data = GSGraph::Auth::SignedRequest.verify(@client, @signed_request)
11
+ data[:expires].should == 0
12
+ data[:algorithm].should == 'HMAC-SHA256'
13
+ data[:user_id].should == '579612276'
14
+ data[:oauth_token].should == '134145643294322|2b8a6f97552c6dced205810b-579612276|FKZ4jGJgBp7i7lYk9XaRMPgya6s'
15
+ data[:issued_at].should == 1298783739
16
+ data[:user][:country].should == 'jp'
17
+ data[:user][:locale].should == 'en_US'
18
+ data[:user][:age][:min].should == 21
19
+ end
20
+ end
21
+
22
+
@@ -0,0 +1,223 @@
1
+ require 'spec_helper'
2
+
3
+ describe GSGraph::Auth do
4
+ let :optional_attributes do
5
+ {}
6
+ end
7
+ let(:auth) { GSGraph::Auth.new('client_id', 'client_secret', optional_attributes) }
8
+ subject { auth }
9
+
10
+ its(:client) { should be_a(Rack::OAuth2::Client) }
11
+ describe 'client' do
12
+ subject { auth.client }
13
+ let :optional_attributes do
14
+ {:redirect_uri => 'https://client.example.com/callback'}
15
+ end
16
+ its(:identifier) { should == 'client_id' }
17
+ its(:secret) { should == 'client_secret' }
18
+ its(:redirect_uri) { should == 'https://client.example.com/callback' }
19
+ end
20
+
21
+ context 'when invalid cookie given' do
22
+ let :optional_attributes do
23
+ {:cookie => 'invalid'}
24
+ end
25
+ it 'should raise GSGraph::VerificationFailed' do
26
+ expect { auth }.to raise_exception(GSGraph::Auth::VerificationFailed)
27
+ end
28
+ end
29
+
30
+ context 'when invalid cookie given' do
31
+ let :optional_attributes do
32
+ {:signed_request => 'invalid'}
33
+ end
34
+
35
+ it 'should raise GSGraph::VerificationFailed' do
36
+ expect { auth }.to raise_exception(GSGraph::Auth::VerificationFailed)
37
+ end
38
+ end
39
+
40
+ describe '#authorized?' do
41
+ context 'when access_token is given' do
42
+ before do
43
+ auth.access_token = 'access_token'
44
+ end
45
+ its(:authorized?) { should be_true }
46
+ end
47
+
48
+ context 'otherwise' do
49
+ its(:authorized?) { should be_false }
50
+ end
51
+ end
52
+
53
+ describe '#authorize_uri' do
54
+ let(:canvas_uri) { 'http://client.example.com/canvas' }
55
+ subject { auth.authorize_uri(canvas_uri) }
56
+ it { should == "https://www.gamestamper.com/dialog/oauth?client_id=client_id&redirect_uri=#{CGI.escape canvas_uri}" }
57
+
58
+ context 'when params are given' do
59
+ subject { auth.authorize_uri(canvas_uri, :scope => [:scope1, :scope2], :state => 'state1') }
60
+ it { should == "https://www.gamestamper.com/dialog/oauth?client_id=client_id&redirect_uri=#{CGI.escape canvas_uri}&scope=#{CGI.escape "scope1,scope2"}&state=state1" }
61
+ end
62
+ end
63
+
64
+ describe '#from_cookie' do
65
+ let :cookie do
66
+ {
67
+ 'fbsr_client_id' => "9heZHFs6tDH/Nif4CqmBaMQ8nKEOc5g2WgVJa10LF00.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImNvZGUiOiI4ZDYwZDY4NDA4MmQ1NjczMjY3MWUxNzAuMS01Nzk2MTIyNzZ8N2pkVlp6MlNLNUY2b0gtQ21FQWtZZVpuVjEwIiwiaXNzdWVkX2F0IjoxMzEyOTUzOTcxLCJ1c2VyX2lkIjo1Nzk2MTIyNzZ9"
68
+ }
69
+ end
70
+
71
+ it 'should exchange code with access token' do
72
+ expect { auth.from_cookie(cookie) }.to request_to '/oauth/access_token', :post
73
+ end
74
+
75
+ it 'should setup user and access_token' do
76
+ mock_graph :post, '/oauth/access_token', 'token_response' do
77
+ auth.access_token.should be_nil
78
+ auth.user.should be_nil
79
+ auth.from_cookie(cookie)
80
+ auth.access_token.should be_a Rack::OAuth2::AccessToken::Legacy
81
+ auth.access_token.access_token.should == 'token'
82
+ auth.user.should be_a GSGraph::User
83
+ auth.user.identifier.should == 579612276
84
+ auth.user.access_token.access_token.should == 'token'
85
+ auth.data.should == {
86
+ "algorithm" => "HMAC-SHA256",
87
+ "code" => "8d60d684082d56732671e170.1-579612276|7jdVZz2SK5F6oH-CmEAkYeZnV10",
88
+ "issued_at" => 1312953971,
89
+ "user_id" => 579612276
90
+ }
91
+ end
92
+ end
93
+
94
+ context 'when invalid cookie given' do
95
+ it 'should raise GSGraph::VerificationFailed' do
96
+ lambda do
97
+ auth.from_cookie('invalid')
98
+ end.should raise_exception(GSGraph::Auth::VerificationFailed)
99
+ end
100
+ end
101
+
102
+ context 'when Rack::OAuth2::Client::Error occurred' do
103
+ context 'when BadRequest' do
104
+ it 'should raise GSGraph::BadRequest' do
105
+ mock_graph :post, 'oauth/access_token', 'blank', :status => [400, 'BadRequest'] do
106
+ lambda do
107
+ auth.from_cookie(cookie)
108
+ end.should raise_exception GSGraph::BadRequest
109
+ end
110
+ end
111
+ end
112
+
113
+ context 'when Unauthorized' do
114
+ it 'should raise GSGraph::Unauthorized' do
115
+ mock_graph :post, 'oauth/access_token', 'blank', :status => [401, 'Unauthorized'] do
116
+ lambda do
117
+ auth.from_cookie(cookie)
118
+ end.should raise_exception GSGraph::Unauthorized
119
+ end
120
+ end
121
+ end
122
+
123
+ context 'otherwise' do
124
+ it 'should raise GSGraph::Exception' do
125
+ mock_graph :post, 'oauth/access_token', 'blank', :status => [403, 'Forbidden'] do
126
+ lambda do
127
+ auth.from_cookie(cookie)
128
+ end.should raise_exception GSGraph::Exception
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ describe '#from_signed_request' do
136
+ let :signed_request do
137
+ "LqsgnfcsRdfjOgyW6ZuSLpGBVsxUBegEqai4EcrWS0A=.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjAsImlzc3VlZF9hdCI6MTI5ODc4MzczOSwib2F1dGhfdG9rZW4iOiIxMzQxNDU2NDMyOTQzMjJ8MmI4YTZmOTc1NTJjNmRjZWQyMDU4MTBiLTU3OTYxMjI3NnxGS1o0akdKZ0JwN2k3bFlrOVhhUk1QZ3lhNnMiLCJ1c2VyIjp7ImNvdW50cnkiOiJqcCIsImxvY2FsZSI6ImVuX1VTIiwiYWdlIjp7Im1pbiI6MjF9fSwidXNlcl9pZCI6IjU3OTYxMjI3NiJ9"
138
+ end
139
+
140
+ it 'should setup user and access_token' do
141
+ auth.access_token.should be_nil
142
+ auth.user.should be_nil
143
+ auth.from_signed_request(signed_request)
144
+ auth.access_token.should be_a Rack::OAuth2::AccessToken::Legacy
145
+ auth.access_token.access_token.should == '134145643294322|2b8a6f97552c6dced205810b-579612276|FKZ4jGJgBp7i7lYk9XaRMPgya6s'
146
+ auth.user.should be_a GSGraph::User
147
+ auth.user.identifier.should == '579612276'
148
+ auth.user.access_token.access_token.should == '134145643294322|2b8a6f97552c6dced205810b-579612276|FKZ4jGJgBp7i7lYk9XaRMPgya6s'
149
+ auth.data.should include(
150
+ "expires"=>0,
151
+ "algorithm"=>"HMAC-SHA256",
152
+ "issued_at"=>1298783739
153
+ )
154
+ auth.data['user'].should include(
155
+ "country"=>"jp",
156
+ "locale"=>"en_US",
157
+ "age"=>{"min"=>21}
158
+ )
159
+ end
160
+
161
+ context 'when expires included' do
162
+ let :signed_request do
163
+ "bzMUNepndPnmce-QdJqvkigxr_6iEzOf-ZNl-ZitvpA.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEzMjA2NjAwMDAsImlzc3VlZF9hdCI6MTI5ODc4MzczOSwib2F1dGhfdG9rZW4iOiIxMzQxNDU2NDMyOTQzMjJ8MmI4YTZmOTc1NTJjNmRjZWQyMDU4MTBiLTU3OTYxMjI3NnxGS1o0akdKZ0JwN2k3bFlrOVhhUk1QZ3lhNnMiLCJ1c2VyIjp7ImNvdW50cnkiOiJqcCIsImxvY2FsZSI6ImVuX1VTIiwiYWdlIjp7Im1pbiI6MjF9fSwidXNlcl9pZCI6IjU3OTYxMjI3NiJ9"
164
+ end
165
+
166
+ it 'should have expires_in' do
167
+ auth.from_signed_request(signed_request)
168
+ auth.access_token.expires_in.should be_a Integer
169
+ end
170
+ end
171
+
172
+ context 'when invalid signed_request given' do
173
+ it 'should raise GSGraph::VerificationFailed' do
174
+ lambda do
175
+ auth.from_signed_request('invalid.signed_request')
176
+ end.should raise_exception(GSGraph::Auth::VerificationFailed)
177
+ end
178
+ end
179
+ end
180
+
181
+ describe "#exchange_token!" do
182
+ it 'should get new token' do
183
+ mock_graph :post, '/oauth/access_token', 'token_with_expiry' do
184
+ auth.exchange_token! 'old_token'
185
+ auth.access_token.access_token.should == 'new_token'
186
+ auth.access_token.expires_in.should == 3600
187
+ end
188
+ end
189
+
190
+ context 'when Rack::OAuth2::Client::Error occurred' do
191
+ context 'when BadRequest' do
192
+ it 'should raise GSGraph::BadRequest' do
193
+ mock_graph :post, 'oauth/access_token', 'blank', :status => [400, 'BadRequest'] do
194
+ lambda do
195
+ auth.exchange_token! 'old_token'
196
+ end.should raise_exception GSGraph::BadRequest
197
+ end
198
+ end
199
+ end
200
+
201
+ context 'when Unauthorized' do
202
+ it 'should raise GSGraph::Unauthorized' do
203
+ mock_graph :post, 'oauth/access_token', 'blank', :status => [401, 'Unauthorized'] do
204
+ lambda do
205
+ auth.exchange_token! 'old_token'
206
+ end.should raise_exception GSGraph::Unauthorized
207
+ end
208
+ end
209
+ end
210
+
211
+ context 'otherwise' do
212
+ it 'should raise GSGraph::Exception' do
213
+ mock_graph :post, 'oauth/access_token', 'blank', :status => [403, 'Forbidden'] do
214
+ lambda do
215
+ auth.exchange_token! 'old_token'
216
+ end.should raise_exception GSGraph::Exception
217
+ end
218
+ end
219
+ end
220
+ end
221
+ end
222
+ end
223
+