pintrest-api 0.0.3 → 0.0.4
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/lib/pintrest_api/authentication.rb +2 -1
- data/lib/pintrest_api/core.rb +3 -3
- data/lib/pintrest_api/pin.rb +45 -6
- 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: cc7e1e11e0656503c2aabaa5e6af685624e29949
|
4
|
+
data.tar.gz: f7cb2d4644a37ba6e81f40603db7f1d5770fbbf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7253e96507a8db4d140c0bd388f46077914b4a9030642ba70bb435c3f9197b351d3616a06822e52eeb562c2e0cd307f891e2e547acdbdb90355ffd0cf68f73ec
|
7
|
+
data.tar.gz: 59edf10e9fcd4f266ab1210f2cce94302bf41ad8d5b52005304f6fbb50fb21dad87dc258e50eb71691123b1be217cd49a248daa9414f9f88908f61e162ba966a
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module PintrestApi
|
2
2
|
# Pintrest Boards this is used to fetch boards and related pins
|
3
3
|
module Authentication
|
4
|
+
attr_accessor :is_logged_in
|
5
|
+
|
4
6
|
EMAIL_INPUT_CSS = '.loginUsername input'
|
5
7
|
PASSWORD_INPUT_CSS = '.loginPassword input'
|
6
8
|
LOGIN_PAGE_BUTTON_CSS = '.formFooter .formFooterButtons'
|
@@ -12,7 +14,6 @@ module PintrestApi
|
|
12
14
|
@session.find(EMAIL_INPUT_CSS).set authentication[:email]
|
13
15
|
@session.find(PASSWORD_INPUT_CSS).set authentication[:password]
|
14
16
|
click LOGIN_PAGE_BUTTON_CSS
|
15
|
-
|
16
17
|
sleep 5
|
17
18
|
puts 'Finished logging in'
|
18
19
|
end
|
data/lib/pintrest_api/core.rb
CHANGED
@@ -65,11 +65,11 @@ module PintrestApi
|
|
65
65
|
old_items_count = 0
|
66
66
|
items = []
|
67
67
|
|
68
|
-
until (items.count
|
68
|
+
until (items.count === old_items_count) && items.count > 0
|
69
69
|
old_items_count = items.count
|
70
70
|
scroll_page if old_items_count > 0
|
71
|
-
|
72
|
-
|
71
|
+
newItems = Nokogiri::HTML.parse(html).css css_selector
|
72
|
+
items = newItems if old_items_count === 0 || newItems.count > old_items_count
|
73
73
|
puts "New Count: #{items.count}\nOld Count: #{old_items_count}"
|
74
74
|
end
|
75
75
|
|
data/lib/pintrest_api/pin.rb
CHANGED
@@ -4,10 +4,24 @@ module PintrestApi
|
|
4
4
|
class Pin < Core
|
5
5
|
attr_reader :image_url, :title, :credits_url, :url, :description
|
6
6
|
|
7
|
-
PIN_BASE_CSS
|
7
|
+
PIN_BASE_CSS = '.Grid .Module.Pin.PinBase'
|
8
|
+
PIN_IMAGE_CSS = '.pinHolder .pinImg'
|
9
|
+
PIN_TITLE_CSS = '.richPinGridTitle'
|
10
|
+
PIN_CREDIT_CSS = '.creditItem a'
|
11
|
+
PIN_URL_CSS = '.pinImageActionButtonWrapper .pinNavLink'
|
12
|
+
PIN_DESCRIPT_CSS = '.pinDescription'
|
13
|
+
|
14
|
+
def initialize(image_url, title, credits_url, url, description)
|
15
|
+
@image_url = image_url
|
16
|
+
@title = title
|
17
|
+
@credits_url = credits_url
|
18
|
+
@url = url
|
19
|
+
@description = description
|
20
|
+
end
|
8
21
|
|
9
22
|
class << self
|
10
23
|
include Authentication
|
24
|
+
attr_accessor :is_logged_in
|
11
25
|
##
|
12
26
|
# Gets all pins from a board url
|
13
27
|
#
|
@@ -19,14 +33,18 @@ module PintrestApi
|
|
19
33
|
#
|
20
34
|
# PintrestApi::Pin.get_for_board_url('http://pintrest.com/mikaak/my-pins')
|
21
35
|
def get_for_board_url(board_url, authentication)
|
22
|
-
login(authentication) if authentication
|
23
|
-
@
|
36
|
+
login(authentication) if !@is_logged_in || authentication
|
37
|
+
@is_logged_in = true
|
38
|
+
|
39
|
+
@session.visit http_url(board_url)
|
40
|
+
sleep 2
|
24
41
|
parse_pins get_with_ajax_scroll(PIN_BASE_CSS)
|
25
42
|
end
|
26
43
|
|
27
44
|
def get_for_board(board, authentication)
|
28
|
-
login(authentication) if authentication
|
29
|
-
@
|
45
|
+
login(authentication) if !@is_logged_in || authentication
|
46
|
+
@is_logged_in = true
|
47
|
+
@session.visit http_url(board.url)
|
30
48
|
parse_pins get_with_ajax_scroll(PIN_BASE_CSS)
|
31
49
|
end
|
32
50
|
|
@@ -38,8 +56,29 @@ module PintrestApi
|
|
38
56
|
|
39
57
|
private
|
40
58
|
|
59
|
+
def http_url(url)
|
60
|
+
url =~ /http/ ? url : "http://#{url}"
|
61
|
+
end
|
62
|
+
|
41
63
|
def parse_pins(nokogiri_items)
|
42
|
-
|
64
|
+
pins = []
|
65
|
+
|
66
|
+
nokogiri_items.each do |item|
|
67
|
+
pin_image = attribute_value(item, PIN_IMAGE_CSS, 'src')
|
68
|
+
pin_credits = attribute_value(item, PIN_CREDIT_CSS, 'href')
|
69
|
+
pin_url = attribute_value(item, PIN_URL_CSS, 'href')
|
70
|
+
pin_description = item.css(PIN_DESCRIPT_CSS).inner_text.strip
|
71
|
+
pin_title = item.css('.richPinGridTitle').inner_text.strip
|
72
|
+
|
73
|
+
pins << Pin.new(pin_image, pin_title, pin_credits, pin_url, pin_description)
|
74
|
+
end
|
75
|
+
|
76
|
+
pins
|
77
|
+
end
|
78
|
+
|
79
|
+
def attribute_value(item, css, attrib)
|
80
|
+
item_value = item.css(css)
|
81
|
+
item_value.any? && item_value.attribute(attrib).value
|
43
82
|
end
|
44
83
|
end
|
45
84
|
end
|