pinterest-ruby 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.rubocop.yml +63 -0
- data/.travis-gemfile +17 -0
- data/.travis.yml +12 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +24 -0
- data/README.md +34 -0
- data/Rakefile +44 -0
- data/docs/FaradayMiddleware/SafeOj.html +218 -0
- data/docs/FaradayMiddleware.html +125 -0
- data/docs/Pinterest/Board.html +410 -0
- data/docs/Pinterest/Client.html +1894 -0
- data/docs/Pinterest/Collection.html +1877 -0
- data/docs/Pinterest/Endpoints/Authentication.html +578 -0
- data/docs/Pinterest/Endpoints/Boards.html +1443 -0
- data/docs/Pinterest/Endpoints/Pins.html +1296 -0
- data/docs/Pinterest/Endpoints/Users.html +1220 -0
- data/docs/Pinterest/Endpoints.html +127 -0
- data/docs/Pinterest/Entity.html +473 -0
- data/docs/Pinterest/Errors/AuthorizationError.html +158 -0
- data/docs/Pinterest/Errors/BadRequestError.html +158 -0
- data/docs/Pinterest/Errors/BaseError.html +487 -0
- data/docs/Pinterest/Errors/MethodNotAllowedError.html +158 -0
- data/docs/Pinterest/Errors/NotFoundError.html +158 -0
- data/docs/Pinterest/Errors/NotImplementedError.html +158 -0
- data/docs/Pinterest/Errors/PermissionsError.html +158 -0
- data/docs/Pinterest/Errors/RateLimitError.html +158 -0
- data/docs/Pinterest/Errors/ServerError.html +158 -0
- data/docs/Pinterest/Errors/TimeoutError.html +158 -0
- data/docs/Pinterest/Errors.html +377 -0
- data/docs/Pinterest/Image.html +617 -0
- data/docs/Pinterest/Interest.html +402 -0
- data/docs/Pinterest/Pin.html +511 -0
- data/docs/Pinterest/User.html +408 -0
- data/docs/Pinterest/Version.html +187 -0
- data/docs/Pinterest.html +130 -0
- data/docs/_index.html +401 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +492 -0
- data/docs/file.README.html +106 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +106 -0
- data/docs/js/app.js +243 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +643 -0
- data/docs/top-level-namespace.html +110 -0
- data/lib/pinterest/client.rb +146 -0
- data/lib/pinterest/collection.rb +97 -0
- data/lib/pinterest/endpoints/authentication.rb +99 -0
- data/lib/pinterest/endpoints/boards.rb +193 -0
- data/lib/pinterest/endpoints/pins.rb +187 -0
- data/lib/pinterest/endpoints/users.rb +158 -0
- data/lib/pinterest/errors.rb +94 -0
- data/lib/pinterest/models/board.rb +34 -0
- data/lib/pinterest/models/entity.rb +42 -0
- data/lib/pinterest/models/image.rb +49 -0
- data/lib/pinterest/models/interest.rb +30 -0
- data/lib/pinterest/models/pin.rb +43 -0
- data/lib/pinterest/models/user.rb +33 -0
- data/lib/pinterest/safe_oj.rb +25 -0
- data/lib/pinterest/version.rb +23 -0
- data/lib/pinterest.rb +31 -0
- data/pinterest.gemspec +32 -0
- data/spec/cassettes/Pinterest_Client/_perform_network_request_private_/should_correctly_handle_malformed_requests.yml +51 -0
- 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
- data/spec/cassettes/Pinterest_Endpoints_Authentication/_verify_access_token/should_return_an_exception_when_using_an_invalid_token.yml +52 -0
- data/spec/cassettes/Pinterest_Endpoints_Authentication/_verify_access_token/should_verify_the_token.yml +59 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_board/should_complain_for_invalid_boards.yml +48 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_board/should_get_the_current_informations.yml +63 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_board/should_restrict_to_requested_fields.yml +57 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_boards/should_only_get_requested_fields.yml +57 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_boards/should_return_a_list_of_boards.yml +74 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_create_board/should_create_the_board_and_return_it_with_only_the_requested_fields.yml +56 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_delete_board/should_perform_the_call_and_return_an_error.yml +48 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_delete_board/should_perform_the_call_and_return_true.yml +109 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_edit_board/should_edit_the_board_and_return_it_with_only_the_requested_fields.yml +56 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_follow_board/should_complain_for_invalid_boards.yml +56 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_follow_board/should_perform_the_call_and_return_true.yml +109 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_following_boards/should_only_get_requested_fields.yml +59 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_following_boards/should_paginate_correctly.yml +72 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_following_boards/should_return_the_followed_boards.yml +72 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_search_my_boards/should_only_get_requested_fields.yml +59 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_search_my_boards/should_paginate_correctly.yml +66 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_search_my_boards/should_search_boards.yml +75 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_suggested_boards/should_return_the_suggested_boards_returning_only_the_requested_fields.yml +56 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_unfollow_board/should_complain_for_invalid_boards.yml +56 -0
- data/spec/cassettes/Pinterest_Endpoints_Boards/_unfollow_board/should_perform_the_call_and_return_true.yml +109 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_board_pins/should_only_get_requested_fields.yml +59 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_board_pins/should_paginate_correctly.yml +85 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_board_pins/should_return_the_pins_of_the_board.yml +85 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_create_pin/should_create_a_pin_by_using_a_image_URL.yml +71 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_create_pin/should_create_a_pin_by_using_a_image_file.yml +1997 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_create_pin/should_return_a_pin_containing_only_requested_fields.yml +56 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_delete_pin/should_perform_the_call_and_return_an_error.yml +56 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_delete_pin/should_perform_the_call_and_return_true.yml +109 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_edit_pin/should_edit_the_pin_and_return_it_with_only_the_requested_fields.yml +56 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_likes/should_only_get_requested_fields.yml +58 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_likes/should_paginate_correctly.yml +87 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_likes/should_return_the_list_of_liked_pins.yml +85 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_pin/should_complain_for_non_existent_pins.yml +56 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_pin/should_get_the_current_informations.yml +71 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_pin/should_restrict_to_requested_fields.yml +56 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_pins/should_only_get_requested_fields.yml +59 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_pins/should_paginate_correctly.yml +808 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_pins/should_return_my_pins.yml +88 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_search_my_pins/should_only_get_requested_fields.yml +61 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_search_my_pins/should_paginate_correctly.yml +89 -0
- data/spec/cassettes/Pinterest_Endpoints_Pins/_search_my_pins/should_search_my_pins.yml +89 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_follow_interest/should_perform_the_call_and_return_an_error.yml +48 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_follow_user/should_complain_for_invalid_users.yml +56 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_follow_user/should_perform_the_call_and_return_true.yml +109 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_followers/should_only_get_requested_fields.yml +62 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_followers/should_paginate_correctly.yml +62 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_followers/should_return_a_list_of_followers.yml +62 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_following_users/should_only_get_requested_fields.yml +62 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_following_users/should_paginate_correctly.yml +131 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_following_users/should_return_a_list_of_followed_users.yml +66 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_interests/should_paginate_correctly.yml +112 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_interests/should_return_a_list_of_followed_interest.yml +58 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_me/should_get_the_current_informations.yml +62 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_me/should_restrict_to_requested_fields.yml +56 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_unfollow_interest/should_perform_the_call_and_return_an_error.yml +48 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_unfollow_user/should_complain_for_invalid_users.yml +56 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_unfollow_user/should_perform_the_call_and_return_true.yml +109 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_user/should_complain_for_non_existent_users.yml +56 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_user/should_get_the_current_informations.yml +60 -0
- data/spec/cassettes/Pinterest_Endpoints_Users/_user/should_restrict_to_requested_fields.yml +56 -0
- data/spec/pinterest/client_spec.rb +70 -0
- data/spec/pinterest/collection_spec.rb +82 -0
- data/spec/pinterest/endpoints/authentication_spec.rb +81 -0
- data/spec/pinterest/endpoints/boards_spec.rb +209 -0
- data/spec/pinterest/endpoints/pins_spec.rb +239 -0
- data/spec/pinterest/endpoints/users_spec.rb +194 -0
- data/spec/pinterest/errors_spec.rb +59 -0
- data/spec/pinterest/fixtures/first.jpg +0 -0
- data/spec/pinterest/models/board_spec.rb +48 -0
- data/spec/pinterest/models/entity_spec.rb +35 -0
- data/spec/pinterest/models/image_spec.rb +50 -0
- data/spec/pinterest/models/interest_spec.rb +20 -0
- data/spec/pinterest/models/pin_spec.rb +55 -0
- data/spec/pinterest/models/user_spec.rb +45 -0
- data/spec/spec_helper.rb +49 -0
- data/tester.rb +19 -0
- metadata +341 -0
@@ -0,0 +1,59 @@
|
|
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
|
+
require "ostruct"
|
8
|
+
|
9
|
+
describe Pinterest::Errors::BaseError do
|
10
|
+
context "#initialize" do
|
11
|
+
it "should save the code, the reason and the env" do
|
12
|
+
subject = Pinterest::Errors::BaseError.new("CODE", "REASON", "ENV")
|
13
|
+
|
14
|
+
expect(subject.message).to eq("[CODE] REASON")
|
15
|
+
expect(subject.code).to eq("CODE")
|
16
|
+
expect(subject.reason).to eq("REASON")
|
17
|
+
expect(subject.env).to eq("ENV")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe Pinterest::Errors do
|
23
|
+
context ".create" do
|
24
|
+
it "should initialize the right class" do
|
25
|
+
subject = Pinterest::Errors.create(OpenStruct.new(status: 401, body: {"error" => "ERROR"}, env: "ENV"))
|
26
|
+
expect(subject).to be_a(Pinterest::Errors::AuthorizationError)
|
27
|
+
expect(subject.code).to eq(401)
|
28
|
+
expect(subject.reason).to eq("ERROR")
|
29
|
+
expect(subject.env).to eq("ENV")
|
30
|
+
|
31
|
+
expect(Pinterest::Errors.create(OpenStruct.new(status: 400, body: {"error" => "ERROR"}, env: "ENV"))).to be_a(Pinterest::Errors::BadRequestError)
|
32
|
+
expect(Pinterest::Errors.create(OpenStruct.new(status: 403, body: {"error" => "ERROR"}, env: "ENV"))).to be_a(Pinterest::Errors::PermissionsError)
|
33
|
+
expect(Pinterest::Errors.create(OpenStruct.new(status: 404, body: {"error" => "ERROR"}, env: "ENV"))).to be_a(Pinterest::Errors::NotFoundError)
|
34
|
+
expect(Pinterest::Errors.create(OpenStruct.new(status: 405, body: {"error" => "ERROR"}, env: "ENV"))).to be_a(Pinterest::Errors::MethodNotAllowedError)
|
35
|
+
expect(Pinterest::Errors.create(OpenStruct.new(status: 408, body: {"error" => "ERROR"}, env: "ENV"))).to be_a(Pinterest::Errors::TimeoutError)
|
36
|
+
expect(Pinterest::Errors.create(OpenStruct.new(status: 429, body: {"error" => "ERROR"}, env: "ENV"))).to be_a(Pinterest::Errors::RateLimitError)
|
37
|
+
expect(Pinterest::Errors.create(OpenStruct.new(status: 501, body: {"error" => "ERROR"}, env: "ENV"))).to be_a(Pinterest::Errors::NotImplementedError)
|
38
|
+
|
39
|
+
subject = Pinterest::Errors.create(OpenStruct.new(status: 523, body: {"error" => "ERROR"}, env: "ENV"))
|
40
|
+
expect(subject).to be_a(Pinterest::Errors::ServerError)
|
41
|
+
expect(subject.code).to eq(523)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context ".create" do
|
46
|
+
it "should return the right class" do
|
47
|
+
expect(Pinterest::Errors.class_for_code(400)).to eq(Pinterest::Errors::BadRequestError)
|
48
|
+
expect(Pinterest::Errors.class_for_code(401)).to eq(Pinterest::Errors::AuthorizationError)
|
49
|
+
expect(Pinterest::Errors.class_for_code(403)).to eq(Pinterest::Errors::PermissionsError)
|
50
|
+
expect(Pinterest::Errors.class_for_code(404)).to eq(Pinterest::Errors::NotFoundError)
|
51
|
+
expect(Pinterest::Errors.class_for_code(405)).to eq(Pinterest::Errors::MethodNotAllowedError)
|
52
|
+
expect(Pinterest::Errors.class_for_code(408)).to eq(Pinterest::Errors::TimeoutError)
|
53
|
+
expect(Pinterest::Errors.class_for_code(429)).to eq(Pinterest::Errors::RateLimitError)
|
54
|
+
expect(Pinterest::Errors.class_for_code(501)).to eq(Pinterest::Errors::NotImplementedError)
|
55
|
+
expect(Pinterest::Errors.class_for_code(503)).to eq(Pinterest::Errors::ServerError)
|
56
|
+
expect(Pinterest::Errors.class_for_code(523)).to eq(Pinterest::Errors::ServerError)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
Binary file
|
@@ -0,0 +1,48 @@
|
|
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::Board do
|
9
|
+
context ".create" do
|
10
|
+
it "should create a object" do
|
11
|
+
expect(Pinterest::Board.create({})).to be_a(Pinterest::Board)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should parse dates" do
|
15
|
+
expect(Pinterest::Board.create({"created_at" => "2015-11-16T12:34:56+00:00"}).created_at).to eq(DateTime.civil(2015, 11, 16, 12, 34, 56))
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should create relationships" do
|
19
|
+
expect(Pinterest::User).to receive(:create).with("CREATOR").and_return("CREATOR-OBJ")
|
20
|
+
expect(Pinterest::Image).to receive(:new).with("IMAGE").and_return("IMAGE-OBJ")
|
21
|
+
|
22
|
+
subject = Pinterest::Board.create({"creator" => "CREATOR", "image" => "IMAGE"})
|
23
|
+
expect(subject.creator).to eq("CREATOR-OBJ")
|
24
|
+
expect(subject.image).to eq("IMAGE-OBJ")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "#as_json" do
|
29
|
+
it "should return a hash" do
|
30
|
+
expect(Pinterest::User).to receive(:create).with("CREATOR").and_return("CREATOR-OBJ")
|
31
|
+
expect(Pinterest::Image).to receive(:new).with("IMAGE").and_return("IMAGE-OBJ")
|
32
|
+
|
33
|
+
expect(Pinterest::Board.create({
|
34
|
+
"id" => "ID", "name" => "NAME", "url" => "URL", "description" => "DESCRIPTION",
|
35
|
+
"creator" => "CREATOR", "created_at" => "2015-11-16T12:34:56+00:00", "counts" => "COUNTS", "image" => "IMAGE"
|
36
|
+
}).as_json).to eq({
|
37
|
+
id: "ID",
|
38
|
+
name: "NAME",
|
39
|
+
url: "URL",
|
40
|
+
description: "DESCRIPTION",
|
41
|
+
creator: "CREATOR-OBJ",
|
42
|
+
created_at: DateTime.civil(2015, 11, 16, 12, 34, 56),
|
43
|
+
counts: "COUNTS",
|
44
|
+
image: "IMAGE-OBJ"
|
45
|
+
})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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::Entity do
|
9
|
+
class EntityMockClass < Pinterest::Entity
|
10
|
+
attr_accessor :a, :b, :c
|
11
|
+
end
|
12
|
+
|
13
|
+
context ".parse_timestamp" do
|
14
|
+
it "should parse a timestamp" do
|
15
|
+
expect(Pinterest::Entity.parse_timestamp("2015-11-16T12:34:56")).to eq(DateTime.civil(2015, 11, 16, 12, 34, 56))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "#initialize" do
|
20
|
+
it "should initialize valid keys" do
|
21
|
+
subject = EntityMockClass.new({a: 1, "b" => 2, d: 4})
|
22
|
+
expect(subject.a).to eq(1)
|
23
|
+
expect(subject.b).to eq(2)
|
24
|
+
expect(subject.c).to be_nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "#as_json" do
|
29
|
+
it "should serialize request keys" do
|
30
|
+
subject = EntityMockClass.new({a: 1, "b" => 2, d: 4})
|
31
|
+
|
32
|
+
expect(subject.as_json(["a", :c])).to eq({a: 1, c: nil})
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,50 @@
|
|
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::Image do
|
9
|
+
subject {
|
10
|
+
Pinterest::Image.new({
|
11
|
+
"a" => {"width" => 1, "height" => 2, "url" => 3},
|
12
|
+
"b" => {"width" => 4, "height" => 5, "url" => 6}
|
13
|
+
})
|
14
|
+
}
|
15
|
+
|
16
|
+
context "#initialize" do
|
17
|
+
it "should save the data" do
|
18
|
+
expect(Pinterest::Image.new("DATA").instance_variable_get(:@data)).to eq("DATA")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "#versions" do
|
23
|
+
it "should return the versions" do
|
24
|
+
expect(subject.versions).to eq(["a", "b"])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "#size" do
|
29
|
+
it "should return the sizes" do
|
30
|
+
expect(subject.size("a")).to eq({width: 1, height: 2})
|
31
|
+
expect { subject.size("c") }.to raise_error(KeyError)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "#url" do
|
36
|
+
it "should return the sizes" do
|
37
|
+
expect(subject.url("b")).to eq(6)
|
38
|
+
expect { subject.url("c") }.to raise_error(KeyError)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "#as_json" do
|
43
|
+
it "shuold simply return the data" do
|
44
|
+
expect(subject.as_json).to eq({
|
45
|
+
"a" => {"width" => 1, "height" => 2, "url" => 3},
|
46
|
+
"b" => {"width" => 4, "height" => 5, "url" => 6}
|
47
|
+
})
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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::Interest do
|
9
|
+
context ".create" do
|
10
|
+
it "should create a object" do
|
11
|
+
expect(Pinterest::Interest.create({})).to be_a(Pinterest::Interest)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context ".as_json" do
|
16
|
+
it "should return a hash" do
|
17
|
+
expect(Pinterest::Interest.create({"id" => "ID", "name" => "NAME"}).as_json).to eq({id: "ID", name: "NAME"})
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,55 @@
|
|
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::Board do
|
9
|
+
context ".create" do
|
10
|
+
it "should create a object" do
|
11
|
+
expect(Pinterest::Pin.create({})).to be_a(Pinterest::Pin)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should parse dates" do
|
15
|
+
expect(Pinterest::Board.create({"created_at" => "2015-11-16T12:34:56+00:00"}).created_at).to eq(DateTime.civil(2015, 11, 16, 12, 34, 56))
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should create relationships" do
|
19
|
+
expect(Pinterest::User).to receive(:create).with("CREATOR").and_return("CREATOR-OBJ")
|
20
|
+
expect(Pinterest::Board).to receive(:create).with("BOARD").and_return("BOARD-OBJ")
|
21
|
+
expect(Pinterest::Image).to receive(:new).with("IMAGE").and_return("IMAGE-OBJ")
|
22
|
+
|
23
|
+
subject = Pinterest::Pin.create({"creator" => "CREATOR", "board" => "BOARD", "image" => "IMAGE"})
|
24
|
+
expect(subject.creator).to eq("CREATOR-OBJ")
|
25
|
+
expect(subject.board).to eq("BOARD-OBJ")
|
26
|
+
expect(subject.image).to eq("IMAGE-OBJ")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "#as_json" do
|
31
|
+
it "should return a hash" do
|
32
|
+
expect(Pinterest::User).to receive(:create).with("CREATOR").and_return("CREATOR-OBJ")
|
33
|
+
expect(Pinterest::Board).to receive(:create).with("BOARD").and_return("BOARD-OBJ")
|
34
|
+
expect(Pinterest::Image).to receive(:new).with("IMAGE").and_return("IMAGE-OBJ")
|
35
|
+
|
36
|
+
expect(Pinterest::Pin.create({
|
37
|
+
"id" => "ID", "link" => "LINK", "url" => "URL", "creator" => "CREATOR", "board" => "BOARD", "created_at" => "2015-11-16T12:34:56+00:00",
|
38
|
+
"note" => "NOTE", "color" => "COLOR", "counts" => "COUNTS", "media" => "MEDIA", "attribution" => "ATTRIBUTION", "image" => "IMAGE"
|
39
|
+
}).as_json).to eq({
|
40
|
+
id: "ID",
|
41
|
+
link: "LINK",
|
42
|
+
url: "URL",
|
43
|
+
creator: "CREATOR-OBJ",
|
44
|
+
board: "BOARD-OBJ",
|
45
|
+
created_at: DateTime.civil(2015, 11, 16, 12, 34, 56),
|
46
|
+
note: "NOTE",
|
47
|
+
color: "COLOR",
|
48
|
+
counts: "COUNTS",
|
49
|
+
media: "MEDIA",
|
50
|
+
attribution: "ATTRIBUTION",
|
51
|
+
image: "IMAGE-OBJ"
|
52
|
+
})
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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::User do
|
9
|
+
context ".create" do
|
10
|
+
it "should create a object" do
|
11
|
+
expect(Pinterest::User.create({})).to be_a(Pinterest::User)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should parse dates" do
|
15
|
+
expect(Pinterest::User.create({"created_at" => "2015-11-16T12:34:56+00:00"}).created_at).to eq(DateTime.civil(2015, 11, 16, 12, 34, 56))
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should create relationships" do
|
19
|
+
expect(Pinterest::Image).to receive(:new).with("IMAGE").and_return("IMAGE-OBJ")
|
20
|
+
|
21
|
+
subject = Pinterest::User.create({"image" => "IMAGE"})
|
22
|
+
expect(subject.image).to eq("IMAGE-OBJ")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "#as_json" do
|
27
|
+
it "should return a hash" do
|
28
|
+
expect(Pinterest::Image).to receive(:new).with("IMAGE").and_return("IMAGE-OBJ")
|
29
|
+
|
30
|
+
expect(Pinterest::User.create({
|
31
|
+
"id" => "ID", "username" => "USERNAME", "first_name" => "FIRST", "last_name" => "LAST",
|
32
|
+
"bio" => "BIO", "created_at" => "2015-11-16T12:34:56+00:00", "counts" => "COUNTS", "image" => "IMAGE"
|
33
|
+
}).as_json).to eq({
|
34
|
+
id: "ID",
|
35
|
+
username: "USERNAME",
|
36
|
+
first_name: "FIRST",
|
37
|
+
last_name: "LAST",
|
38
|
+
bio: "BIO",
|
39
|
+
created_at: DateTime.civil(2015, 11, 16, 12, 34, 56),
|
40
|
+
counts: "COUNTS",
|
41
|
+
image: "IMAGE-OBJ"
|
42
|
+
})
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,49 @@
|
|
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 "bundler/setup"
|
7
|
+
|
8
|
+
if ENV["COVERAGE"]
|
9
|
+
require "simplecov"
|
10
|
+
require "coveralls"
|
11
|
+
|
12
|
+
Coveralls.wear! if ENV["CI"]
|
13
|
+
|
14
|
+
SimpleCov.start do
|
15
|
+
root = Pathname.new(File.dirname(__FILE__)) + ".."
|
16
|
+
|
17
|
+
add_filter do |src_file|
|
18
|
+
path = Pathname.new(src_file.filename).relative_path_from(root).to_s
|
19
|
+
path !~ /^lib/
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require "rubygems"
|
25
|
+
require "vcr"
|
26
|
+
require "rspec"
|
27
|
+
require "pinterest"
|
28
|
+
|
29
|
+
RSpec.configure do |config|
|
30
|
+
config.add_formatter RSpec::Core::Formatters::ProgressFormatter if config.formatter_loader.formatters.empty?
|
31
|
+
config.tty = true
|
32
|
+
config.color = ENV["NO_COLOR"].nil?
|
33
|
+
|
34
|
+
config.expect_with(:rspec) do |c|
|
35
|
+
c.syntax = :expect
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
VCR.configure do |config|
|
40
|
+
config.cassette_library_dir = File.dirname(__FILE__) + "/cassettes"
|
41
|
+
config.hook_into(:webmock)
|
42
|
+
config.default_cassette_options = {record: :once}
|
43
|
+
config.configure_rspec_metadata!
|
44
|
+
config.allow_http_connections_when_no_cassette = false
|
45
|
+
end
|
46
|
+
|
47
|
+
# Credentials
|
48
|
+
$pinterest_client_id = "4878490596204882047"
|
49
|
+
$pinterest_client_secret = "aaa4922dadd0a08b0d767df5263e2e8987f88faa16c4079e17c10c0447c0fce0"
|
data/tester.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$: << __dir__ + "/lib"
|
2
|
+
require "pinterest"
|
3
|
+
|
4
|
+
client_id = "4878490596204882047"
|
5
|
+
client_secret = "aaa4922dadd0a08b0d767df5263e2e8987f88faa16c4079e17c10c0447c0fce0"
|
6
|
+
callback_url = "https://local.cowtech.it:3000"
|
7
|
+
access_token = "AVP99QpzwII-f1I2p5gyHi8CiCeQFJkDr8dP-JpDs-LEtAAyegAAAAA"
|
8
|
+
client = Pinterest::Client.new(client_id: client_id, client_secret: client_secret)
|
9
|
+
|
10
|
+
# Authorization
|
11
|
+
puts client.authorization_url(callback_url)
|
12
|
+
#puts client.fetch_access_token("3baf2adea5c82d46")
|
13
|
+
client.access_token = access_token
|
14
|
+
|
15
|
+
# Verify authentication
|
16
|
+
p client.verify_access_token
|
17
|
+
|
18
|
+
# User
|
19
|
+
p client.me
|