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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2087614e3ea66777339a3d2e6bd3dee45cd60479
4
- data.tar.gz: bf96b96e7c7a28e773be584fc261d89c2d3d44a3
3
+ metadata.gz: cc7e1e11e0656503c2aabaa5e6af685624e29949
4
+ data.tar.gz: f7cb2d4644a37ba6e81f40603db7f1d5770fbbf2
5
5
  SHA512:
6
- metadata.gz: 46f59576f523cb1421b82fa6d86c3a5b62679d0a54d9f9437d06db85e7405f5cebc3c2e153ab4b3fae372f4d5b5c320362b29b874c6571a1de9fe1758a4392e2
7
- data.tar.gz: 2a19ecbe469d252c4b5e9438417d8aec50208a9089950712aeadbc047cf74ee56750b7cfda4ccb2f61f0cd0fbfcdc47e54099681ab7204cb437f67b8160c9ae6
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
@@ -65,11 +65,11 @@ module PintrestApi
65
65
  old_items_count = 0
66
66
  items = []
67
67
 
68
- until (items.count == old_items_count) && items.count > 0
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
- items = Nokogiri::HTML.parse(html).css css_selector
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
 
@@ -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 = '.Pin'
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
- @session.visit board_url
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
- @session.visit board.url
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
- binding.pry
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pintrest-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mika Kalathil