pintrest-api 0.0.6 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/Gemfile.lock +1 -1
- data/README.md +0 -2
- data/lib/pintrest_api/authentication.rb +1 -1
- data/lib/pintrest_api/board.rb +1 -1
- data/lib/pintrest_api/core.rb +18 -2
- data/lib/pintrest_api/pin.rb +7 -7
- data/lib/pintrest_api/version.rb +1 -1
- data/lib/pintrest_api.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c216c3168b7271066677f540a132cebbfc9d3a3d
|
4
|
+
data.tar.gz: aa9449ec04fe448b7e9dca912470791fb57e540c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61bcb16cfa708aac96c2bc6d96b20808c7c303b9c64d5589b600300574a769b89147c0a7af83388371cebf9dcf7b3fc9fa154aa317bf013ff482f43c2c40319a
|
7
|
+
data.tar.gz: 39595bf52a6f67d2398bd82bc4cb3e37cb543a9a0a629c62cdf78b585733c8bba99920a1aa5369f1b0ecc0e8fd4ada56220a28f29930c442ec35a592780dca12
|
data/.DS_Store
CHANGED
Binary file
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,8 +4,6 @@ Pintrest Api
|
|
4
4
|
An api in ruby for pulling pintrest pins. It is not very fast due to the fact
|
5
5
|
that you must use capybara to parse the page.
|
6
6
|
|
7
|
-
This is still not fully working and getting individual pins from boards don't work
|
8
|
-
|
9
7
|
### Warning
|
10
8
|
Certain issues require you to login first (getting more then 50 pins per board)
|
11
9
|
To do this when calling anything to do with pins you can pass in
|
@@ -10,11 +10,11 @@ module PintrestApi
|
|
10
10
|
|
11
11
|
def login(authentication)
|
12
12
|
visit PINTREST_LOGIN_URL
|
13
|
-
|
14
13
|
@session.find(EMAIL_INPUT_CSS).set authentication[:email]
|
15
14
|
@session.find(PASSWORD_INPUT_CSS).set authentication[:password]
|
16
15
|
click LOGIN_PAGE_BUTTON_CSS
|
17
16
|
sleep 5
|
17
|
+
|
18
18
|
puts 'Finished logging in'
|
19
19
|
end
|
20
20
|
end
|
data/lib/pintrest_api/board.rb
CHANGED
@@ -54,7 +54,7 @@ module PintrestApi
|
|
54
54
|
# * +board_name+ - Pintrest board_name
|
55
55
|
# ==== Examples
|
56
56
|
#
|
57
|
-
# PintrestApi::Board.pins('mikakalathil', 'My Board Name!!!')
|
57
|
+
# PintrestApi::Board.pins('mikakalathil', 'My Board Name!!!', {email: 'asdf@gmail.com', password: 'asdf'})
|
58
58
|
def pins(user_name, board_name, authentication)
|
59
59
|
board_slug = board_name.downcase.gsub(/[_\s]/, '-')
|
60
60
|
Pin.get_for_board_url("#{PINTREST_URL}#{user_name}/#{board_slug}", authentication)
|
data/lib/pintrest_api/core.rb
CHANGED
@@ -2,6 +2,7 @@ require 'capybara'
|
|
2
2
|
require 'capybara/dsl'
|
3
3
|
require 'capybara/poltergeist'
|
4
4
|
|
5
|
+
|
5
6
|
module PintrestApi
|
6
7
|
##
|
7
8
|
# This class is the core of the pintrest api and handles all url visiting and such
|
@@ -19,6 +20,18 @@ module PintrestApi
|
|
19
20
|
@session
|
20
21
|
end
|
21
22
|
|
23
|
+
def session_visit(url)
|
24
|
+
begin
|
25
|
+
@session.visit url
|
26
|
+
sleep 2
|
27
|
+
rescue Capybara::Poltergeist::TimeoutError
|
28
|
+
puts 'Gotten blocked by pintrest waiting 2 min to try again'
|
29
|
+
sleep 120
|
30
|
+
|
31
|
+
session_visit url
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
22
35
|
def visit(url)
|
23
36
|
new_session
|
24
37
|
@session.visit url
|
@@ -34,7 +47,7 @@ module PintrestApi
|
|
34
47
|
def new_session
|
35
48
|
# Register PhantomJS (aka poltergeist) as the driver to use
|
36
49
|
Capybara.register_driver :poltergeist do |app|
|
37
|
-
Capybara::Poltergeist::Driver.new(app)
|
50
|
+
Capybara::Poltergeist::Driver.new(app, timeout: 60)
|
38
51
|
end
|
39
52
|
|
40
53
|
# Use XPath as the default selector for the find method
|
@@ -53,7 +66,7 @@ module PintrestApi
|
|
53
66
|
|
54
67
|
def scroll_page
|
55
68
|
@session.execute_script 'window.scrollTo(0,100000)'
|
56
|
-
sleep
|
69
|
+
sleep 2
|
57
70
|
end
|
58
71
|
|
59
72
|
# Returns the current session's page
|
@@ -65,9 +78,12 @@ module PintrestApi
|
|
65
78
|
old_items_count = 0
|
66
79
|
items = []
|
67
80
|
|
81
|
+
|
82
|
+
|
68
83
|
until (items.count === old_items_count) && items.count > 0
|
69
84
|
old_items_count = items.count
|
70
85
|
scroll_page if old_items_count > 0
|
86
|
+
|
71
87
|
newItems = Nokogiri::HTML.parse(html).css css_selector
|
72
88
|
items = newItems if old_items_count === 0 || newItems.count > old_items_count
|
73
89
|
puts "New Count: #{items.count}\nOld Count: #{old_items_count}"
|
data/lib/pintrest_api/pin.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'pry'
|
1
2
|
module PintrestApi
|
2
3
|
|
3
4
|
# Pintrest Pin model
|
@@ -32,21 +33,20 @@ module PintrestApi
|
|
32
33
|
# * +authentication+ -
|
33
34
|
# ==== Examples
|
34
35
|
#
|
35
|
-
# PintrestApi::Pin.get_for_board_url('http://pintrest.com/mikaak/my-pins')
|
36
|
+
# PintrestApi::Pin.get_for_board_url('http://pintrest.com/mikaak/my-pins', , {email: 'asdf@gmail.com', password: 'asdf'})
|
36
37
|
def get_for_board_url(board_url, authentication)
|
37
|
-
login
|
38
|
+
login authentication if !@is_logged_in && authentication
|
38
39
|
@is_logged_in = true
|
39
40
|
|
40
|
-
|
41
|
-
sleep 2
|
41
|
+
session_visit http_url(board_url)
|
42
42
|
parse_pins get_with_ajax_scroll(PIN_BASE_CSS)
|
43
43
|
end
|
44
44
|
|
45
45
|
def get_for_board(board, authentication)
|
46
|
-
login
|
46
|
+
login authentication if !@is_logged_in && authentication
|
47
47
|
@is_logged_in = true
|
48
|
-
|
49
|
-
|
48
|
+
|
49
|
+
session_visit http_url(board.url)
|
50
50
|
parse_pins get_with_ajax_scroll(PIN_BASE_CSS)
|
51
51
|
end
|
52
52
|
|
data/lib/pintrest_api/version.rb
CHANGED
data/lib/pintrest_api.rb
CHANGED
@@ -8,8 +8,8 @@ Bundler.require(:default)
|
|
8
8
|
|
9
9
|
# Pintrest Api requires
|
10
10
|
#=======================
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
require_relative './pintrest_api/version.rb'
|
12
|
+
require_relative './pintrest_api/core.rb'
|
13
|
+
require_relative './pintrest_api/authentication.rb'
|
14
|
+
require_relative './pintrest_api/board.rb'
|
15
|
+
require_relative './pintrest_api/pin.rb'
|