pinterest-ruby 1.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 (150) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rubocop.yml +63 -0
  4. data/.travis-gemfile +17 -0
  5. data/.travis.yml +12 -0
  6. data/.yardopts +1 -0
  7. data/CHANGELOG.md +3 -0
  8. data/Gemfile +24 -0
  9. data/README.md +34 -0
  10. data/Rakefile +44 -0
  11. data/docs/FaradayMiddleware/SafeOj.html +218 -0
  12. data/docs/FaradayMiddleware.html +125 -0
  13. data/docs/Pinterest/Board.html +410 -0
  14. data/docs/Pinterest/Client.html +1894 -0
  15. data/docs/Pinterest/Collection.html +1877 -0
  16. data/docs/Pinterest/Endpoints/Authentication.html +578 -0
  17. data/docs/Pinterest/Endpoints/Boards.html +1443 -0
  18. data/docs/Pinterest/Endpoints/Pins.html +1296 -0
  19. data/docs/Pinterest/Endpoints/Users.html +1220 -0
  20. data/docs/Pinterest/Endpoints.html +127 -0
  21. data/docs/Pinterest/Entity.html +473 -0
  22. data/docs/Pinterest/Errors/AuthorizationError.html +158 -0
  23. data/docs/Pinterest/Errors/BadRequestError.html +158 -0
  24. data/docs/Pinterest/Errors/BaseError.html +487 -0
  25. data/docs/Pinterest/Errors/MethodNotAllowedError.html +158 -0
  26. data/docs/Pinterest/Errors/NotFoundError.html +158 -0
  27. data/docs/Pinterest/Errors/NotImplementedError.html +158 -0
  28. data/docs/Pinterest/Errors/PermissionsError.html +158 -0
  29. data/docs/Pinterest/Errors/RateLimitError.html +158 -0
  30. data/docs/Pinterest/Errors/ServerError.html +158 -0
  31. data/docs/Pinterest/Errors/TimeoutError.html +158 -0
  32. data/docs/Pinterest/Errors.html +377 -0
  33. data/docs/Pinterest/Image.html +617 -0
  34. data/docs/Pinterest/Interest.html +402 -0
  35. data/docs/Pinterest/Pin.html +511 -0
  36. data/docs/Pinterest/User.html +408 -0
  37. data/docs/Pinterest/Version.html +187 -0
  38. data/docs/Pinterest.html +130 -0
  39. data/docs/_index.html +401 -0
  40. data/docs/class_list.html +51 -0
  41. data/docs/css/common.css +1 -0
  42. data/docs/css/full_list.css +58 -0
  43. data/docs/css/style.css +492 -0
  44. data/docs/file.README.html +106 -0
  45. data/docs/file_list.html +56 -0
  46. data/docs/frames.html +17 -0
  47. data/docs/index.html +106 -0
  48. data/docs/js/app.js +243 -0
  49. data/docs/js/full_list.js +216 -0
  50. data/docs/js/jquery.js +4 -0
  51. data/docs/method_list.html +643 -0
  52. data/docs/top-level-namespace.html +110 -0
  53. data/lib/pinterest/client.rb +146 -0
  54. data/lib/pinterest/collection.rb +97 -0
  55. data/lib/pinterest/endpoints/authentication.rb +99 -0
  56. data/lib/pinterest/endpoints/boards.rb +193 -0
  57. data/lib/pinterest/endpoints/pins.rb +187 -0
  58. data/lib/pinterest/endpoints/users.rb +158 -0
  59. data/lib/pinterest/errors.rb +94 -0
  60. data/lib/pinterest/models/board.rb +34 -0
  61. data/lib/pinterest/models/entity.rb +42 -0
  62. data/lib/pinterest/models/image.rb +49 -0
  63. data/lib/pinterest/models/interest.rb +30 -0
  64. data/lib/pinterest/models/pin.rb +43 -0
  65. data/lib/pinterest/models/user.rb +33 -0
  66. data/lib/pinterest/safe_oj.rb +25 -0
  67. data/lib/pinterest/version.rb +23 -0
  68. data/lib/pinterest.rb +31 -0
  69. data/pinterest.gemspec +32 -0
  70. data/spec/cassettes/Pinterest_Client/_perform_network_request_private_/should_correctly_handle_malformed_requests.yml +51 -0
  71. data/spec/cassettes/Pinterest_Endpoints_Authentication/_fetch_access_token/should_make_the_call_to_Pinterest_and_return_the_authorization_token_also_saving_it.yml +58 -0
  72. data/spec/cassettes/Pinterest_Endpoints_Authentication/_verify_access_token/should_return_an_exception_when_using_an_invalid_token.yml +52 -0
  73. data/spec/cassettes/Pinterest_Endpoints_Authentication/_verify_access_token/should_verify_the_token.yml +59 -0
  74. data/spec/cassettes/Pinterest_Endpoints_Boards/_board/should_complain_for_invalid_boards.yml +48 -0
  75. data/spec/cassettes/Pinterest_Endpoints_Boards/_board/should_get_the_current_informations.yml +63 -0
  76. data/spec/cassettes/Pinterest_Endpoints_Boards/_board/should_restrict_to_requested_fields.yml +57 -0
  77. data/spec/cassettes/Pinterest_Endpoints_Boards/_boards/should_only_get_requested_fields.yml +57 -0
  78. data/spec/cassettes/Pinterest_Endpoints_Boards/_boards/should_return_a_list_of_boards.yml +74 -0
  79. data/spec/cassettes/Pinterest_Endpoints_Boards/_create_board/should_create_the_board_and_return_it_with_only_the_requested_fields.yml +56 -0
  80. data/spec/cassettes/Pinterest_Endpoints_Boards/_delete_board/should_perform_the_call_and_return_an_error.yml +48 -0
  81. data/spec/cassettes/Pinterest_Endpoints_Boards/_delete_board/should_perform_the_call_and_return_true.yml +109 -0
  82. data/spec/cassettes/Pinterest_Endpoints_Boards/_edit_board/should_edit_the_board_and_return_it_with_only_the_requested_fields.yml +56 -0
  83. data/spec/cassettes/Pinterest_Endpoints_Boards/_follow_board/should_complain_for_invalid_boards.yml +56 -0
  84. data/spec/cassettes/Pinterest_Endpoints_Boards/_follow_board/should_perform_the_call_and_return_true.yml +109 -0
  85. data/spec/cassettes/Pinterest_Endpoints_Boards/_following_boards/should_only_get_requested_fields.yml +59 -0
  86. data/spec/cassettes/Pinterest_Endpoints_Boards/_following_boards/should_paginate_correctly.yml +72 -0
  87. data/spec/cassettes/Pinterest_Endpoints_Boards/_following_boards/should_return_the_followed_boards.yml +72 -0
  88. data/spec/cassettes/Pinterest_Endpoints_Boards/_search_my_boards/should_only_get_requested_fields.yml +59 -0
  89. data/spec/cassettes/Pinterest_Endpoints_Boards/_search_my_boards/should_paginate_correctly.yml +66 -0
  90. data/spec/cassettes/Pinterest_Endpoints_Boards/_search_my_boards/should_search_boards.yml +75 -0
  91. data/spec/cassettes/Pinterest_Endpoints_Boards/_suggested_boards/should_return_the_suggested_boards_returning_only_the_requested_fields.yml +56 -0
  92. data/spec/cassettes/Pinterest_Endpoints_Boards/_unfollow_board/should_complain_for_invalid_boards.yml +56 -0
  93. data/spec/cassettes/Pinterest_Endpoints_Boards/_unfollow_board/should_perform_the_call_and_return_true.yml +109 -0
  94. data/spec/cassettes/Pinterest_Endpoints_Pins/_board_pins/should_only_get_requested_fields.yml +59 -0
  95. data/spec/cassettes/Pinterest_Endpoints_Pins/_board_pins/should_paginate_correctly.yml +85 -0
  96. data/spec/cassettes/Pinterest_Endpoints_Pins/_board_pins/should_return_the_pins_of_the_board.yml +85 -0
  97. data/spec/cassettes/Pinterest_Endpoints_Pins/_create_pin/should_create_a_pin_by_using_a_image_URL.yml +71 -0
  98. data/spec/cassettes/Pinterest_Endpoints_Pins/_create_pin/should_create_a_pin_by_using_a_image_file.yml +1997 -0
  99. data/spec/cassettes/Pinterest_Endpoints_Pins/_create_pin/should_return_a_pin_containing_only_requested_fields.yml +56 -0
  100. data/spec/cassettes/Pinterest_Endpoints_Pins/_delete_pin/should_perform_the_call_and_return_an_error.yml +56 -0
  101. data/spec/cassettes/Pinterest_Endpoints_Pins/_delete_pin/should_perform_the_call_and_return_true.yml +109 -0
  102. data/spec/cassettes/Pinterest_Endpoints_Pins/_edit_pin/should_edit_the_pin_and_return_it_with_only_the_requested_fields.yml +56 -0
  103. data/spec/cassettes/Pinterest_Endpoints_Pins/_likes/should_only_get_requested_fields.yml +58 -0
  104. data/spec/cassettes/Pinterest_Endpoints_Pins/_likes/should_paginate_correctly.yml +87 -0
  105. data/spec/cassettes/Pinterest_Endpoints_Pins/_likes/should_return_the_list_of_liked_pins.yml +85 -0
  106. data/spec/cassettes/Pinterest_Endpoints_Pins/_pin/should_complain_for_non_existent_pins.yml +56 -0
  107. data/spec/cassettes/Pinterest_Endpoints_Pins/_pin/should_get_the_current_informations.yml +71 -0
  108. data/spec/cassettes/Pinterest_Endpoints_Pins/_pin/should_restrict_to_requested_fields.yml +56 -0
  109. data/spec/cassettes/Pinterest_Endpoints_Pins/_pins/should_only_get_requested_fields.yml +59 -0
  110. data/spec/cassettes/Pinterest_Endpoints_Pins/_pins/should_paginate_correctly.yml +808 -0
  111. data/spec/cassettes/Pinterest_Endpoints_Pins/_pins/should_return_my_pins.yml +88 -0
  112. data/spec/cassettes/Pinterest_Endpoints_Pins/_search_my_pins/should_only_get_requested_fields.yml +61 -0
  113. data/spec/cassettes/Pinterest_Endpoints_Pins/_search_my_pins/should_paginate_correctly.yml +89 -0
  114. data/spec/cassettes/Pinterest_Endpoints_Pins/_search_my_pins/should_search_my_pins.yml +89 -0
  115. data/spec/cassettes/Pinterest_Endpoints_Users/_follow_interest/should_perform_the_call_and_return_an_error.yml +48 -0
  116. data/spec/cassettes/Pinterest_Endpoints_Users/_follow_user/should_complain_for_invalid_users.yml +56 -0
  117. data/spec/cassettes/Pinterest_Endpoints_Users/_follow_user/should_perform_the_call_and_return_true.yml +109 -0
  118. data/spec/cassettes/Pinterest_Endpoints_Users/_followers/should_only_get_requested_fields.yml +62 -0
  119. data/spec/cassettes/Pinterest_Endpoints_Users/_followers/should_paginate_correctly.yml +62 -0
  120. data/spec/cassettes/Pinterest_Endpoints_Users/_followers/should_return_a_list_of_followers.yml +62 -0
  121. data/spec/cassettes/Pinterest_Endpoints_Users/_following_users/should_only_get_requested_fields.yml +62 -0
  122. data/spec/cassettes/Pinterest_Endpoints_Users/_following_users/should_paginate_correctly.yml +131 -0
  123. data/spec/cassettes/Pinterest_Endpoints_Users/_following_users/should_return_a_list_of_followed_users.yml +66 -0
  124. data/spec/cassettes/Pinterest_Endpoints_Users/_interests/should_paginate_correctly.yml +112 -0
  125. data/spec/cassettes/Pinterest_Endpoints_Users/_interests/should_return_a_list_of_followed_interest.yml +58 -0
  126. data/spec/cassettes/Pinterest_Endpoints_Users/_me/should_get_the_current_informations.yml +62 -0
  127. data/spec/cassettes/Pinterest_Endpoints_Users/_me/should_restrict_to_requested_fields.yml +56 -0
  128. data/spec/cassettes/Pinterest_Endpoints_Users/_unfollow_interest/should_perform_the_call_and_return_an_error.yml +48 -0
  129. data/spec/cassettes/Pinterest_Endpoints_Users/_unfollow_user/should_complain_for_invalid_users.yml +56 -0
  130. data/spec/cassettes/Pinterest_Endpoints_Users/_unfollow_user/should_perform_the_call_and_return_true.yml +109 -0
  131. data/spec/cassettes/Pinterest_Endpoints_Users/_user/should_complain_for_non_existent_users.yml +56 -0
  132. data/spec/cassettes/Pinterest_Endpoints_Users/_user/should_get_the_current_informations.yml +60 -0
  133. data/spec/cassettes/Pinterest_Endpoints_Users/_user/should_restrict_to_requested_fields.yml +56 -0
  134. data/spec/pinterest/client_spec.rb +70 -0
  135. data/spec/pinterest/collection_spec.rb +82 -0
  136. data/spec/pinterest/endpoints/authentication_spec.rb +81 -0
  137. data/spec/pinterest/endpoints/boards_spec.rb +209 -0
  138. data/spec/pinterest/endpoints/pins_spec.rb +239 -0
  139. data/spec/pinterest/endpoints/users_spec.rb +194 -0
  140. data/spec/pinterest/errors_spec.rb +59 -0
  141. data/spec/pinterest/fixtures/first.jpg +0 -0
  142. data/spec/pinterest/models/board_spec.rb +48 -0
  143. data/spec/pinterest/models/entity_spec.rb +35 -0
  144. data/spec/pinterest/models/image_spec.rb +50 -0
  145. data/spec/pinterest/models/interest_spec.rb +20 -0
  146. data/spec/pinterest/models/pin_spec.rb +55 -0
  147. data/spec/pinterest/models/user_spec.rb +45 -0
  148. data/spec/spec_helper.rb +49 -0
  149. data/tester.rb +19 -0
  150. metadata +341 -0
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: delete
5
+ uri: https://api.pinterest.com/v1/me/following/interests/905661505034/
6
+ body:
7
+ encoding: UTF-8
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.10.1
12
+ Authorization:
13
+ - Bearer AVP99QpzwII-f1I2p5gyHi8CiCeQFJkDr8dP-JpDs-LEtAAyegAAAAA
14
+ Content-Type:
15
+ - application/x-www-form-urlencoded
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 404
23
+ message: NOT FOUND
24
+ headers:
25
+ Age:
26
+ - '0'
27
+ Cache-Control:
28
+ - private
29
+ Content-Type:
30
+ - application/json
31
+ X-Pinterest-Rid:
32
+ - '397753110523'
33
+ Content-Length:
34
+ - '51'
35
+ Date:
36
+ - Thu, 12 Jan 2017 11:59:45 GMT
37
+ Connection:
38
+ - keep-alive
39
+ body:
40
+ encoding: UTF-8
41
+ string: |-
42
+ {
43
+ "message": "404: Not Found",
44
+ "type": "http"
45
+ }
46
+ http_version:
47
+ recorded_at: Thu, 12 Jan 2017 11:59:45 GMT
48
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: delete
5
+ uri: https://api.pinterest.com/v1/me/following/users/invalid-user/
6
+ body:
7
+ encoding: UTF-8
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.10.1
12
+ Authorization:
13
+ - Bearer AVP99QpzwII-f1I2p5gyHi8CiCeQFJkDr8dP-JpDs-LEtAAyegAAAAA
14
+ Content-Type:
15
+ - application/x-www-form-urlencoded
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 404
23
+ message: NOT FOUND
24
+ headers:
25
+ Access-Control-Allow-Origin:
26
+ - "*"
27
+ Age:
28
+ - '0'
29
+ Cache-Control:
30
+ - private
31
+ Content-Type:
32
+ - application/json
33
+ Pinterest-Generated-By:
34
+ - None
35
+ Pinterest-Version:
36
+ - d67cb4f
37
+ X-Content-Type-Options:
38
+ - nosniff
39
+ X-Pinterest-Rid:
40
+ - '885832408482'
41
+ X-Ratelimit-Limit:
42
+ - '200'
43
+ X-Ratelimit-Remaining:
44
+ - '136'
45
+ Content-Length:
46
+ - '45'
47
+ Date:
48
+ - Thu, 12 Jan 2017 11:59:43 GMT
49
+ Connection:
50
+ - keep-alive
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"message": "User not found.", "type": "api"}'
54
+ http_version:
55
+ recorded_at: Thu, 12 Jan 2017 11:59:44 GMT
56
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,109 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: delete
5
+ uri: https://api.pinterest.com/v1/me/following/users/testerfb11/
6
+ body:
7
+ encoding: UTF-8
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.10.1
12
+ Authorization:
13
+ - Bearer AVP99QpzwII-f1I2p5gyHi8CiCeQFJkDr8dP-JpDs-LEtAAyegAAAAA
14
+ Content-Type:
15
+ - application/x-www-form-urlencoded
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Access-Control-Allow-Origin:
26
+ - "*"
27
+ Age:
28
+ - '0'
29
+ Cache-Control:
30
+ - private
31
+ Content-Type:
32
+ - application/json
33
+ Pinterest-Generated-By:
34
+ - None
35
+ Pinterest-Version:
36
+ - d67cb4f
37
+ X-Content-Type-Options:
38
+ - nosniff
39
+ X-Pinterest-Rid:
40
+ - '771241865003'
41
+ X-Ratelimit-Limit:
42
+ - '200'
43
+ X-Ratelimit-Remaining:
44
+ - '138'
45
+ Content-Length:
46
+ - '14'
47
+ Date:
48
+ - Thu, 12 Jan 2017 11:59:43 GMT
49
+ Connection:
50
+ - keep-alive
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"data": null}'
54
+ http_version:
55
+ recorded_at: Thu, 12 Jan 2017 11:59:43 GMT
56
+ - request:
57
+ method: delete
58
+ uri: https://api.pinterest.com/v1/me/following/users/testerfb11/
59
+ body:
60
+ encoding: UTF-8
61
+ string: ''
62
+ headers:
63
+ User-Agent:
64
+ - Faraday v0.10.1
65
+ Authorization:
66
+ - Bearer AVP99QpzwII-f1I2p5gyHi8CiCeQFJkDr8dP-JpDs-LEtAAyegAAAAA
67
+ Content-Type:
68
+ - application/x-www-form-urlencoded
69
+ Accept-Encoding:
70
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
71
+ Accept:
72
+ - "*/*"
73
+ response:
74
+ status:
75
+ code: 200
76
+ message: OK
77
+ headers:
78
+ Access-Control-Allow-Origin:
79
+ - "*"
80
+ Age:
81
+ - '0'
82
+ Cache-Control:
83
+ - private
84
+ Content-Type:
85
+ - application/json
86
+ Pinterest-Generated-By:
87
+ - None
88
+ Pinterest-Version:
89
+ - d67cb4f
90
+ X-Content-Type-Options:
91
+ - nosniff
92
+ X-Pinterest-Rid:
93
+ - '337944503106'
94
+ X-Ratelimit-Limit:
95
+ - '200'
96
+ X-Ratelimit-Remaining:
97
+ - '137'
98
+ Content-Length:
99
+ - '14'
100
+ Date:
101
+ - Thu, 12 Jan 2017 11:59:43 GMT
102
+ Connection:
103
+ - keep-alive
104
+ body:
105
+ encoding: UTF-8
106
+ string: '{"data": null}'
107
+ http_version:
108
+ recorded_at: Thu, 12 Jan 2017 11:59:43 GMT
109
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.pinterest.com/v1/users/invalid-user/?fields=id,username,first_name,last_name,bio,created_at,counts,image
6
+ body:
7
+ encoding: UTF-8
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.10.1
12
+ Authorization:
13
+ - Bearer AVP99QpzwII-f1I2p5gyHi8CiCeQFJkDr8dP-JpDs-LEtAAyegAAAAA
14
+ Content-Type:
15
+ - application/x-www-form-urlencoded
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 404
23
+ message: NOT FOUND
24
+ headers:
25
+ Access-Control-Allow-Origin:
26
+ - "*"
27
+ Age:
28
+ - '0'
29
+ Cache-Control:
30
+ - private
31
+ Content-Type:
32
+ - application/json
33
+ Pinterest-Generated-By:
34
+ - None
35
+ Pinterest-Version:
36
+ - d67cb4f
37
+ X-Content-Type-Options:
38
+ - nosniff
39
+ X-Pinterest-Rid:
40
+ - '641548778231'
41
+ X-Ratelimit-Limit:
42
+ - '200'
43
+ X-Ratelimit-Remaining:
44
+ - '149'
45
+ Content-Length:
46
+ - '45'
47
+ Date:
48
+ - Thu, 12 Jan 2017 11:59:39 GMT
49
+ Connection:
50
+ - keep-alive
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"message": "User not found.", "type": "api"}'
54
+ http_version:
55
+ recorded_at: Thu, 12 Jan 2017 11:59:39 GMT
56
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,60 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.pinterest.com/v1/users/testerfb11/?fields=id,username,first_name,last_name,bio,created_at,counts,image
6
+ body:
7
+ encoding: UTF-8
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.10.1
12
+ Authorization:
13
+ - Bearer AVP99QpzwII-f1I2p5gyHi8CiCeQFJkDr8dP-JpDs-LEtAAyegAAAAA
14
+ Content-Type:
15
+ - application/x-www-form-urlencoded
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Access-Control-Allow-Origin:
26
+ - "*"
27
+ Age:
28
+ - '0'
29
+ Cache-Control:
30
+ - private
31
+ Content-Type:
32
+ - application/json
33
+ Pinterest-Generated-By:
34
+ - None
35
+ Pinterest-Version:
36
+ - d67cb4f
37
+ X-Content-Type-Options:
38
+ - nosniff
39
+ X-Pinterest-Rid:
40
+ - '957602188200'
41
+ X-Ratelimit-Limit:
42
+ - '200'
43
+ X-Ratelimit-Remaining:
44
+ - '151'
45
+ Content-Length:
46
+ - '347'
47
+ Date:
48
+ - Thu, 12 Jan 2017 11:59:38 GMT
49
+ Connection:
50
+ - keep-alive
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"data": {"username": "testerfb11", "bio": "", "first_name": "Tester",
54
+ "last_name": "tes", "created_at": "2014-10-10T18:52:41", "image": {"60x60":
55
+ {"url": "https://s.pinimg.com/images/user/default_60.png", "width": 60, "height":
56
+ 60}}, "counts": {"pins": 1835, "following": 2, "followers": 6, "boards": 18,
57
+ "likes": 9}, "id": "332914734862997577"}}'
58
+ http_version:
59
+ recorded_at: Thu, 12 Jan 2017 11:59:39 GMT
60
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.pinterest.com/v1/users/testerfb11/?fields=username
6
+ body:
7
+ encoding: UTF-8
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.10.1
12
+ Authorization:
13
+ - Bearer AVP99QpzwII-f1I2p5gyHi8CiCeQFJkDr8dP-JpDs-LEtAAyegAAAAA
14
+ Content-Type:
15
+ - application/x-www-form-urlencoded
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Access-Control-Allow-Origin:
26
+ - "*"
27
+ Age:
28
+ - '0'
29
+ Cache-Control:
30
+ - private
31
+ Content-Type:
32
+ - application/json
33
+ Pinterest-Generated-By:
34
+ - None
35
+ Pinterest-Version:
36
+ - d67cb4f
37
+ X-Content-Type-Options:
38
+ - nosniff
39
+ X-Pinterest-Rid:
40
+ - '663120046495'
41
+ X-Ratelimit-Limit:
42
+ - '200'
43
+ X-Ratelimit-Remaining:
44
+ - '150'
45
+ Content-Length:
46
+ - '64'
47
+ Date:
48
+ - Thu, 12 Jan 2017 11:59:39 GMT
49
+ Connection:
50
+ - keep-alive
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"data": {"username": "testerfb11", "id": "332914734862997577"}}'
54
+ http_version:
55
+ recorded_at: Thu, 12 Jan 2017 11:59:39 GMT
56
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,70 @@
1
+ #
2
+ # This file is part of the pinterest-ruby gem. Copyright (C) 2017 and above Shogun <shogun@cowtech.it>.
3
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
+ #
5
+
6
+ require "spec_helper"
7
+
8
+ describe Pinterest::Client, vcr: true do
9
+ context "#initialize" do
10
+ it "should save the attributes and run the default block to setup the connection" do
11
+ expect_any_instance_of(Pinterest::Client).to receive(:default_connection_setup).and_call_original
12
+ subject = Pinterest::Client.new(access_token: "A", client_id: "B", client_secret: "C", verbose: "D")
13
+
14
+ expect(subject.access_token).to eq("A")
15
+ expect(subject.client_id).to eq("B")
16
+ expect(subject.client_secret).to eq("C")
17
+ expect(subject.verbose).to eq("D")
18
+ expect(subject.connection).to be_a(Faraday::Connection)
19
+ expect(subject.connection.url_prefix.to_s).to eq(::Pinterest::Client::API_URL + "/")
20
+ end
21
+
22
+ it "should run the default block" do
23
+ a = 1
24
+
25
+ Pinterest::Client.new(access_token: "A", client_id: "B", client_secret: "C", verbose: "D") do
26
+ a = 2
27
+ end
28
+
29
+ expect(a).to eq(2)
30
+ end
31
+ end
32
+
33
+ context "#ensure_array (private)" do
34
+ it "should return an array" do
35
+ subject = Pinterest::Client.new
36
+ expect(subject.send(:ensure_array, [])).to eq([])
37
+ expect(subject.send(:ensure_array, "a")).to eq(["a"])
38
+ expect(subject.send(:ensure_array, nil, "b")).to eq(["b"])
39
+ end
40
+ end
41
+
42
+ context "#ensure_param (private)" do
43
+ it "should check if parameter is present" do
44
+ subject = Pinterest::Client.new
45
+ expect(subject.send(:ensure_param, "a")).to be_truthy
46
+ expect(subject.send(:ensure_param, "")).to be_falsey
47
+ expect(subject.send(:ensure_param, " ")).to be_falsey
48
+ expect(subject.send(:ensure_param, nil)).to be_falsey
49
+ expect { subject.send(:ensure_param, "", "MESSAGE") }.to raise_error(ArgumentError, "MESSAGE")
50
+ end
51
+ end
52
+
53
+ context "#cleanup_params (private)" do
54
+ it "should remove keys which are not set" do
55
+ expect(Pinterest::Client.new.send(:cleanup_params, {a: 1, b: 2, c: nil, d: ""})).to eq({a: 1, b: 2})
56
+ end
57
+ end
58
+
59
+ context "#perform_network_request (private)" do
60
+ it "should correctly handle malformed requests" do
61
+ expect { subject.send(:perform_network_request, url: "/foo") }.to raise_error(Pinterest::Errors::NotFoundError, "[404] Invalid response from the server.")
62
+ end
63
+ end
64
+
65
+ context "#versioned_url (private)" do
66
+ it "should prepend version path to a URL" do
67
+ expect(Pinterest::Client.new.send(:versioned_url, "abc")).to eq("/v1/abc")
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,82 @@
1
+ #
2
+ # This file is part of the pinterest-ruby gem. Copyright (C) 2017 and above Shogun <shogun@cowtech.it>.
3
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
+ #
5
+
6
+ require "spec_helper"
7
+
8
+ describe Pinterest::Collection do
9
+ context "#initialize" do
10
+ it "should save limit and cursor" do
11
+ subject = Pinterest::Collection.new({}, "CURSOR", "LIMIT")
12
+ expect(subject.current_cursor).to eq("CURSOR")
13
+ expect(subject.limit).to eq("LIMIT")
14
+ end
15
+
16
+ it "should save the next_cursor" do
17
+ expect(Pinterest::Collection.new({}, "CURSOR", "LIMIT").next_cursor).to be_nil
18
+ expect(Pinterest::Collection.new({"page" => {"cursor" => "NEXT"}}, "CURSOR", "LIMIT").next_cursor).to eq("NEXT")
19
+ end
20
+
21
+ it "should save the records by applying the creator" do
22
+ subject = Pinterest::Collection.new({"data" => ["12", "34", "56"]}, "CURSOR", "LIMIT") { |r| r.reverse }
23
+ expect(subject.records).to eq(["21", "43", "65"])
24
+ end
25
+
26
+ it "should complain if invalid raw_data is passed" do
27
+ expect { Pinterest::Collection.new(nil, nil, nil) }.to raise_error(ArgumentError)
28
+ end
29
+ end
30
+
31
+ context "[]" do
32
+ it "should act as an array" do
33
+ expect(Pinterest::Collection.new({"data" => ["12", "34", "56"]}, "CURSOR", "LIMIT")[1]).to eq("34")
34
+ end
35
+ end
36
+
37
+ context "#size" do
38
+ it "should act as an array" do
39
+ expect(Pinterest::Collection.new({"data" => ["12", "34", "56"]}, "CURSOR", "LIMIT").size).to eq(3)
40
+ end
41
+ end
42
+
43
+ context "#current_page" do
44
+ it "should return the current cursor" do
45
+ expect(Pinterest::Collection.new({"data" => ["12", "34", "56"]}, "CURSOR", "LIMIT").current_page).to eq("CURSOR")
46
+ end
47
+ end
48
+
49
+ context "#next_page" do
50
+ it "should return the current cursor" do
51
+ expect(Pinterest::Collection.new({"page" => {"cursor" => "NEXT"}}, "CURSOR", "LIMIT").next_page).to eq("NEXT")
52
+ end
53
+ end
54
+
55
+ context "#empty?" do
56
+ it "should return whether the collection is empty" do
57
+ expect(Pinterest::Collection.new({"data" => ["12", "34", "56"]}, "CURSOR", "LIMIT").empty?).to be_falsey
58
+ expect(Pinterest::Collection.new({}, "CURSOR", "LIMIT").empty?).to be_truthy
59
+ end
60
+ end
61
+
62
+ context "#next?" do
63
+ it "should return whether the collection has more data on the server" do
64
+ expect(Pinterest::Collection.new({}, "CURSOR", "LIMIT").next?).to be_falsey
65
+ expect(Pinterest::Collection.new({"page" => {"cursor" => "NEXT"}}, "CURSOR", "LIMIT").next_cursor).to be_truthy
66
+ end
67
+ end
68
+
69
+ context "#as_json" do
70
+ it "should serialize the collection" do
71
+ subject = Pinterest::Collection.new({"data" => ["12", "34", "56"], "page" => {"cursor" => "NEXT"}}, "CURSOR", "LIMIT")
72
+ allow_any_instance_of(Array).to receive(:as_json){ |obj| obj }
73
+
74
+ expect(subject.as_json).to eq({
75
+ records: ["12", "34", "56"],
76
+ limit: "LIMIT",
77
+ current_cursor: "CURSOR",
78
+ next_cursor: "NEXT"
79
+ })
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,81 @@
1
+ #
2
+ # This file is part of the pinterest-ruby gem. Copyright (C) 2017 and above Shogun <shogun@cowtech.it>.
3
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
+ #
5
+
6
+ require "spec_helper"
7
+
8
+ describe Pinterest::Endpoints::Authentication, vcr: true do
9
+ subject {
10
+ Pinterest::Client.new(client_id: $pinterest_client_id, client_secret: $pinterest_client_secret)
11
+ }
12
+
13
+ context "#authorization_state" do
14
+ it "should return a string" do
15
+ expect(subject.authorization_state).to match(/^[a-f0-9]+$/)
16
+ end
17
+ end
18
+
19
+ context "#authorization_url" do
20
+ before(:each) do
21
+ allow(subject).to receive(:authorization_state).and_return("STATE")
22
+ end
23
+
24
+ it "should complain when mandatory arguments are missing" do
25
+ expect { Pinterest::Client.new.authorization_url }.to raise_error(ArgumentError, "You must specify the client_id.")
26
+ expect { subject.authorization_url }.to raise_error(ArgumentError, "You must specify the callback_url.")
27
+ expect { subject.authorization_url(1) }.to raise_error(ArgumentError, "callback_url must be a valid HTTPS URL.")
28
+ expect { subject.authorization_url("ABC") }.to raise_error(ArgumentError, "callback_url must be a valid HTTPS URL.")
29
+ expect { subject.authorization_url("http://google.it") }.to raise_error(ArgumentError, "callback_url must be a valid HTTPS URL.")
30
+ end
31
+
32
+ it "should return a valid URL requesting all scopes" do
33
+ expect(subject.authorization_url("https://localhost")).to eq(
34
+ "https://api.pinterest.com/oauth?authorization_state=STATE&client_id=#{$pinterest_client_id}&redirect_uri=https%3A%2F%2Flocalhost&response_type=code&scope=read_public%2Cwrite_public%2Cread_relationships%2Cwrite_relationships"
35
+ )
36
+ end
37
+
38
+ it "should return a valid URL requesting specified scopes and removing invalid ones" do
39
+ expect(subject.authorization_url("https://localhost", ["a", "read_public"])).to eq(
40
+ "https://api.pinterest.com/oauth?authorization_state=STATE&client_id=#{$pinterest_client_id}&redirect_uri=https%3A%2F%2Flocalhost&response_type=code&scope=read_public"
41
+ )
42
+ end
43
+ end
44
+
45
+ context "#fetch_access_token" do
46
+ it "should complain when mandatory arguments are missing" do
47
+ expect { Pinterest::Client.new.fetch_access_token("A") }.to raise_error(ArgumentError, "You must specify the client_id.")
48
+ expect { Pinterest::Client.new(client_id: $pinterest_client_id).fetch_access_token("A") }.to raise_error(ArgumentError, "You must specify the client_secret.")
49
+ expect { subject.fetch_access_token(nil) }.to raise_error(ArgumentError, "You must specify the authorization_token.")
50
+ end
51
+
52
+ it "should make the call to Pinterest and return the authorization token, also saving it" do
53
+ expect(subject.access_token).to be_nil
54
+ expect(subject.fetch_access_token("9568cec6cc78aa05")).to eq("AVP99QpzwII-f1I2p5gyHi8CiCeQFJkDr8dP-JpDs-LEtAAyegAAAAA")
55
+ expect(subject.access_token).to eq("AVP99QpzwII-f1I2p5gyHi8CiCeQFJkDr8dP-JpDs-LEtAAyegAAAAA")
56
+ end
57
+ end
58
+
59
+ context "#verify_access_token" do
60
+ it "should verify the token" do
61
+ subject.access_token = "AVP99QpzwII-f1I2p5gyHi8CiCeQFJkDr8dP-JpDs-LEtAAyegAAAAA"
62
+
63
+ expect(subject.verify_access_token).to eq({
64
+ application_id: $pinterest_client_id,
65
+ created_at: DateTime.civil(2017, 01, 12, 11, 44, 40),
66
+ scopes: ["read_public", "write_public", "read_relationships", "write_relationships"],
67
+ user_id: "559853934835925315"
68
+ })
69
+ end
70
+
71
+ it "should complain when no access token is set" do
72
+ expect { Pinterest::Client.new.fetch_access_token("A") }.to raise_error(ArgumentError, "You must specify the client_id.")
73
+ expect { subject.verify_access_token }.to raise_error(ArgumentError, "You must set the access token first.")
74
+ end
75
+
76
+ it "should return an exception when using an invalid token" do
77
+ subject.access_token = "A"
78
+ expect { subject.verify_access_token }.to raise_error(Pinterest::Errors::AuthorizationError)
79
+ end
80
+ end
81
+ end