pintrest-api 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -5
- data/lib/pintrest_api/authentication.rb +8 -0
- data/lib/pintrest_api/board.rb +12 -5
- data/lib/pintrest_api/core.rb +27 -6
- data/lib/pintrest_api/pin.rb +36 -8
- data/lib/pintrest_api/version.rb +1 -1
- 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: acd0a776db77d64d5fc3432055f521d8a932c996
|
4
|
+
data.tar.gz: cc004b329fbc2554b82c49b7ffa5981083b8bf49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84860239e11a1145ccb306fd3af6464c6b888617df7ed190876cbc631ffebdb661832f40caee81c4ff7ff70c4c50df68e3dd4abf9ce25c5b3075f6fc720b58b2
|
7
|
+
data.tar.gz: 8f6cc6f2a94de1f9f0e6d533222ea51f99ed9468b1c2562030783eca78a93257f47120c93ee8537a6e6e8e705fa72abd9439fe6703e5a10f10e5b3c268449f67
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pintrest-api (0.1.
|
4
|
+
pintrest-api (0.1.2)
|
5
5
|
capybara (~> 2.4)
|
6
6
|
nokogiri (~> 1.6)
|
7
7
|
poltergeist (~> 1.5)
|
@@ -24,12 +24,12 @@ GEM
|
|
24
24
|
mime-types (2.4.3)
|
25
25
|
mini_portile (0.6.2)
|
26
26
|
minitest (5.5.1)
|
27
|
-
multi_json (1.
|
27
|
+
multi_json (1.11.0)
|
28
28
|
nokogiri (1.6.6.2)
|
29
29
|
mini_portile (~> 0.6.0)
|
30
30
|
parser (2.2.0.2)
|
31
31
|
ast (>= 1.1, < 3.0)
|
32
|
-
poltergeist (1.
|
32
|
+
poltergeist (1.6.0)
|
33
33
|
capybara (~> 2.1)
|
34
34
|
cliver (~> 0.3.1)
|
35
35
|
multi_json (~> 1.0)
|
@@ -54,9 +54,9 @@ GEM
|
|
54
54
|
ruby-progressbar (1.7.1)
|
55
55
|
slop (3.6.0)
|
56
56
|
terminal-notifier (1.6.2)
|
57
|
-
websocket-driver (0.5.
|
57
|
+
websocket-driver (0.5.3)
|
58
58
|
websocket-extensions (>= 0.1.0)
|
59
|
-
websocket-extensions (0.1.
|
59
|
+
websocket-extensions (0.1.2)
|
60
60
|
xpath (2.0.0)
|
61
61
|
nokogiri (~> 1.3)
|
62
62
|
|
@@ -8,11 +8,19 @@ module PintrestApi
|
|
8
8
|
LOGIN_PAGE_BUTTON_CSS = '.formFooter .formFooterButtons'
|
9
9
|
PINTREST_LOGIN_URL = 'https://www.pinterest.com/login/'
|
10
10
|
|
11
|
+
def try_or_check_login(authentication)
|
12
|
+
login authentication if !@is_logged_in && authentication
|
13
|
+
@is_logged_in = true
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
11
18
|
def login(authentication)
|
12
19
|
visit PINTREST_LOGIN_URL
|
13
20
|
@session.find(EMAIL_INPUT_CSS).set authentication[:email]
|
14
21
|
@session.find(PASSWORD_INPUT_CSS).set authentication[:password]
|
15
22
|
click LOGIN_PAGE_BUTTON_CSS
|
23
|
+
puts 'Clicking Login button'
|
16
24
|
sleep 5
|
17
25
|
|
18
26
|
puts 'Finished logging in'
|
data/lib/pintrest_api/board.rb
CHANGED
@@ -3,11 +3,11 @@ module PintrestApi
|
|
3
3
|
class Board < Core
|
4
4
|
attr_reader :title, :url, :pin_count
|
5
5
|
|
6
|
-
PINTREST_URL
|
6
|
+
PINTREST_URL = 'http://www.pinterest.com/'
|
7
7
|
BOARD_PIN_COUNT_CSS = '.PinCount'
|
8
8
|
BOARD_LINK_CSS = '.boardLinkWrapper'
|
9
9
|
BOARD_TITLE_CSS = 'h3.boardName .title'
|
10
|
-
BOARD_ITEM_CSS = '.
|
10
|
+
BOARD_ITEM_CSS = '.UserBoards .item'
|
11
11
|
|
12
12
|
##
|
13
13
|
# Get a instance of a board
|
@@ -31,6 +31,7 @@ module PintrestApi
|
|
31
31
|
end
|
32
32
|
|
33
33
|
class << self
|
34
|
+
include Authentication
|
34
35
|
##
|
35
36
|
# Gets all boards from a user
|
36
37
|
#
|
@@ -40,8 +41,12 @@ module PintrestApi
|
|
40
41
|
# ==== Examples
|
41
42
|
#
|
42
43
|
# PintrestApi::Board.all('mikakalathil')
|
43
|
-
def all(user_name)
|
44
|
-
|
44
|
+
def all(user_name, authentication)
|
45
|
+
try_or_check_login authentication
|
46
|
+
|
47
|
+
session_visit user_name
|
48
|
+
@session.save_and_open_page
|
49
|
+
|
45
50
|
parse_boards get_with_ajax_scroll(BOARD_ITEM_CSS)
|
46
51
|
end
|
47
52
|
|
@@ -56,8 +61,10 @@ module PintrestApi
|
|
56
61
|
#
|
57
62
|
# PintrestApi::Board.pins('mikakalathil', 'My Board Name!!!', {email: 'asdf@gmail.com', password: 'asdf'})
|
58
63
|
def pins(user_name, board_name, authentication)
|
64
|
+
try_or_check_login authentication
|
65
|
+
|
59
66
|
board_slug = board_name.downcase.gsub(/[_\s]/, '-')
|
60
|
-
Pin.get_for_board_url("#{
|
67
|
+
Pin.get_for_board_url("#{user_name}/#{board_slug}", authentication)
|
61
68
|
end
|
62
69
|
|
63
70
|
private
|
data/lib/pintrest_api/core.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'capybara'
|
2
2
|
require 'capybara/dsl'
|
3
3
|
require 'capybara/poltergeist'
|
4
|
+
require 'pry'
|
4
5
|
|
5
6
|
|
6
7
|
module PintrestApi
|
@@ -10,7 +11,7 @@ module PintrestApi
|
|
10
11
|
attr_accessor :session
|
11
12
|
include Capybara::DSL
|
12
13
|
|
13
|
-
PINTREST_URL = 'http://www.
|
14
|
+
PINTREST_URL = 'http://www.pinterest.com/'
|
14
15
|
|
15
16
|
class << self
|
16
17
|
def visit_page(user_name)
|
@@ -21,9 +22,11 @@ module PintrestApi
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def session_visit(url)
|
25
|
+
url = PINTREST_URL + url if url !~ /pinterest/
|
26
|
+
|
24
27
|
begin
|
25
28
|
@session.visit url
|
26
|
-
sleep
|
29
|
+
sleep 3
|
27
30
|
rescue Capybara::Poltergeist::TimeoutError
|
28
31
|
puts 'Gotten blocked by pintrest waiting 2 min to try again'
|
29
32
|
sleep 120
|
@@ -47,10 +50,10 @@ module PintrestApi
|
|
47
50
|
def new_session
|
48
51
|
# Register PhantomJS (aka poltergeist) as the driver to use
|
49
52
|
Capybara.register_driver :poltergeist do |app|
|
50
|
-
Capybara::Poltergeist::Driver.new(app, timeout: 60)
|
53
|
+
Capybara::Poltergeist::Driver.new(app, timeout: 60, js_errors: false)
|
51
54
|
end
|
52
55
|
|
53
|
-
# Use
|
56
|
+
# Use CSS as the default selector for the find method
|
54
57
|
Capybara.default_selector = :css
|
55
58
|
|
56
59
|
# Start up a new thread
|
@@ -84,8 +87,26 @@ module PintrestApi
|
|
84
87
|
old_items_count = items.count
|
85
88
|
scroll_page if old_items_count > 0
|
86
89
|
|
87
|
-
|
88
|
-
items =
|
90
|
+
new_items = Nokogiri::HTML.parse(html).css css_selector
|
91
|
+
items = new_items if old_items_count === 0 || new_items.count > old_items_count
|
92
|
+
puts "New Count: #{items.count}\nOld Count: #{old_items_count}"
|
93
|
+
end
|
94
|
+
|
95
|
+
items
|
96
|
+
end
|
97
|
+
|
98
|
+
def stream_with_ajax_scroll(css_selector)
|
99
|
+
old_items_count = 0
|
100
|
+
items = []
|
101
|
+
|
102
|
+
until (items.count === old_items_count) && items.count > 0
|
103
|
+
old_items_count = items.count
|
104
|
+
scroll_page if old_items_count > 0
|
105
|
+
|
106
|
+
items = Nokogiri::HTML.parse(html).css css_selector if old_items_count === 0 || items.count > old_items_count
|
107
|
+
|
108
|
+
yield items[old_items_count..-1] if items.count > old_items_count
|
109
|
+
|
89
110
|
puts "New Count: #{items.count}\nOld Count: #{old_items_count}"
|
90
111
|
end
|
91
112
|
|
data/lib/pintrest_api/pin.rb
CHANGED
@@ -5,8 +5,8 @@ module PintrestApi
|
|
5
5
|
class Pin < Core
|
6
6
|
attr_reader :image_url, :title, :credits_url, :url, :description
|
7
7
|
|
8
|
-
PINTREST_URL = 'http://www.
|
9
|
-
PIN_BASE_CSS = '.Grid .
|
8
|
+
PINTREST_URL = 'http://www.pinterest.com'
|
9
|
+
PIN_BASE_CSS = '.Grid .Pin'
|
10
10
|
PIN_IMAGE_CSS = '.pinHolder .pinImg'
|
11
11
|
PIN_TITLE_CSS = '.richPinGridTitle'
|
12
12
|
PIN_CREDIT_CSS = '.creditItem a'
|
@@ -33,23 +33,51 @@ module PintrestApi
|
|
33
33
|
# * +authentication+ -
|
34
34
|
# ==== Examples
|
35
35
|
#
|
36
|
-
# 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'})
|
37
37
|
def get_for_board_url(board_url, authentication)
|
38
|
-
|
39
|
-
@is_logged_in = true
|
38
|
+
try_or_check_login authentication
|
40
39
|
|
41
40
|
session_visit http_url(board_url)
|
42
41
|
parse_pins get_with_ajax_scroll(PIN_BASE_CSS)
|
43
42
|
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
##
|
45
|
+
# Gets all pins from a board url
|
46
|
+
#
|
47
|
+
# ==== Attributes
|
48
|
+
#
|
49
|
+
# * +board+ - Pintrest board
|
50
|
+
# * +authentication+ -
|
51
|
+
# ==== Examples
|
52
|
+
#
|
53
|
+
# PintrestApi::Pin.get_for_board(board, {email: 'asdf@gmail.com', password: 'asdf'})
|
54
|
+
def get_for_board(board, authentication = nil)
|
55
|
+
try_or_check_login authentication
|
48
56
|
|
49
57
|
session_visit http_url(board.url)
|
50
58
|
parse_pins get_with_ajax_scroll(PIN_BASE_CSS)
|
51
59
|
end
|
52
60
|
|
61
|
+
##
|
62
|
+
# Gets all pins from a board url
|
63
|
+
#
|
64
|
+
# ==== Attributes
|
65
|
+
#
|
66
|
+
# * +board+ - Pintrest board
|
67
|
+
# * +authentication+ -
|
68
|
+
# * +&block+ - a stream of every 25ish pins
|
69
|
+
# ==== Examples
|
70
|
+
#
|
71
|
+
# PintrestApi::Pin.get_for_board_stream(board, {email: 'asdf@gmail.com', password: 'asdf'}) do |pins| end
|
72
|
+
def get_for_board_stream(board, authentication = nil)
|
73
|
+
try_or_check_login authentication
|
74
|
+
|
75
|
+
session_visit http_url(board.url)
|
76
|
+
stream_with_ajax_scroll(PIN_BASE_CSS) do |pins|
|
77
|
+
yield parse_pins pins
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
53
81
|
## Planned
|
54
82
|
# def top(count)
|
55
83
|
# # Raise error if over 800 as page will freeze if higher
|
data/lib/pintrest_api/version.rb
CHANGED