pintrest-api 0.0.0 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78e43f0dcae8404b412115e87d984ca40fee94f9
4
- data.tar.gz: 1c5ecad824df6a9f2153c4b50cd09e7c50a38ab0
3
+ metadata.gz: 3a0f080f36ba8229716e7e6c45a00ef4d67123ec
4
+ data.tar.gz: 43758be273a671357e625976080848b939fee6a3
5
5
  SHA512:
6
- metadata.gz: 2d231ba8313cdcd6c34991f7e7c6dd8c3fb89fa8f09372917b7a7ecdd316fe77631e3749c8589967d796680c069fe43e65bce105e69e7f84214c67eafdd4f62b
7
- data.tar.gz: f4157295bc3c898e7f2fa621fa2b2b7afc3674afd0e055ff1189576784c3827904a6b718f71727b4c68df3d3ba17fa63c33aaa3e77cd8f19aed04d45b09b82ee
6
+ metadata.gz: 7eb36e855ef82fc21f5bbed3aacf055d05f10e6aa1d46c185c718005f96de46c2a01536c2abf4a22754da89cf21fb89502fcb064193b5702b0d4904026b07ce2
7
+ data.tar.gz: ee877ed84cd1ef5f2e20616f5413747615281cd6a7a00eb1bb99d4b528510f1b85f3ffdd3b39cea0a43a4998c80a254bfb33c7742e5e54d9f8fb227839259e71
data/README.md CHANGED
@@ -3,3 +3,10 @@ Pintrest Api
3
3
 
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
+
7
+ This is still not fully working and getting individual pins from boards don't work
8
+
9
+ ### Warning
10
+ Certain issues require you to login first (getting more then 50 pins per board)
11
+ To do this when calling anything to do with pins you can pass in
12
+ `email: <email>, password: <password>` as a last parameter.
@@ -0,0 +1,20 @@
1
+ module PintrestApi
2
+ # Pintrest Boards this is used to fetch boards and related pins
3
+ module Authentication
4
+ EMAIL_INPUT_CSS = '.loginUsername input'
5
+ PASSWORD_INPUT_CSS = '.loginPassword input'
6
+ LOGIN_PAGE_BUTTON_CSS = '.formFooter .formFooterButtons'
7
+ PINTREST_LOGIN_URL = 'https://www.pinterest.com/login/'
8
+
9
+ def login(authentication)
10
+ visit PINTREST_LOGIN_URL
11
+
12
+ @session.find(EMAIL_INPUT_CSS).set authentication[:email]
13
+ @session.find(PASSWORD_INPUT_CSS).set authentication[:password]
14
+ click LOGIN_PAGE_BUTTON_CSS
15
+
16
+ sleep 5
17
+ puts 'Finished logging in'
18
+ end
19
+ end
20
+ end
@@ -1,9 +1,13 @@
1
1
  module PintrestApi
2
2
  # Pintrest Boards this is used to fetch boards and related pins
3
3
  class Board < Core
4
- attr_reader :title, :board_url
4
+ attr_reader :title, :url, :pin_count
5
5
 
6
- PINTREST_URL = 'http://www.pintrest.com/'
6
+ PINTREST_URL = 'http://www.pintrest.com/'
7
+ BOARD_PIN_COUNT_CSS = '.PinCount'
8
+ BOARD_LINK_CSS = '.boardLinkWrapper'
9
+ BOARD_TITLE_CSS = 'h3.boardName .title'
10
+ BOARD_ITEM_CSS = '.GridItems > .item'
7
11
 
8
12
  ##
9
13
  # Get a instance of a board
@@ -18,10 +22,14 @@ module PintrestApi
18
22
  # PintrestApi::Board.new('Yummy Pins', 'http://pintrest.com/mikaak/yummy-pins', 38)
19
23
  def initialize(title, board_url, pin_count)
20
24
  @title = title
21
- @board_url = board_url
25
+ @url = board_url
22
26
  @pin_count = pin_count
23
27
  end
24
28
 
29
+ def pins
30
+ Pin.get_for_board(self)
31
+ end
32
+
25
33
  class << self
26
34
  ##
27
35
  # Gets all boards from a user
@@ -34,7 +42,7 @@ module PintrestApi
34
42
  # PintrestApi::Board.all('mikakalathil')
35
43
  def all(user_name)
36
44
  visit_page user_name
37
- parse_boards get_with_ajax_scroll('.GridItems > .item')
45
+ parse_boards get_with_ajax_scroll(BOARD_ITEM_CSS)
38
46
  end
39
47
 
40
48
  ##
@@ -47,9 +55,9 @@ module PintrestApi
47
55
  # ==== Examples
48
56
  #
49
57
  # PintrestApi::Board.pins('mikakalathil', 'My Board Name!!!')
50
- def pins(user_name, board_name)
51
- board_slug = board_name.downcase.gsub(/_ /, '-').gsub(/[^a-zA-Z0-9]/, '')
52
- Pin.get_for_board_url("#{PINTREST_URL}#{user_name}/#{board_slug}")
58
+ def pins(user_name, board_name, authentication)
59
+ board_slug = board_name.downcase.gsub(/[_\s]/, '-')
60
+ Pin.get_for_board_url("#{PINTREST_URL}#{user_name}/#{board_slug}", authentication)
53
61
  end
54
62
 
55
63
  private
@@ -58,9 +66,9 @@ module PintrestApi
58
66
  items = []
59
67
 
60
68
  nokogiri_items.each do |item|
61
- board_title = item.css('h3.boardName .title').inner_text
62
- board_link = PINTREST_URL.chomp('/') + item.css('.boardLinkWrapper').attribute('href').value
63
- pin_count = item.css('.PinCount .value').inner_text
69
+ board_title = item.css(BOARD_TITLE_CSS).inner_text
70
+ board_link = PINTREST_URL.chomp('/') + item.css(BOARD_LINK_CSS).attribute('href').value
71
+ pin_count = item.css(BOARD_PIN_COUNT_CSS).inner_text.strip
64
72
 
65
73
  items << Board.new(board_title, board_link, pin_count)
66
74
  end
@@ -26,6 +26,10 @@ module PintrestApi
26
26
  @session
27
27
  end
28
28
 
29
+ def click(css)
30
+ @session.find(css).click
31
+ end
32
+
29
33
  # Create a new PhantomJS session in Capybara
30
34
  def new_session
31
35
  # Register PhantomJS (aka poltergeist) as the driver to use
@@ -49,7 +53,7 @@ module PintrestApi
49
53
 
50
54
  def scroll_page
51
55
  @session.execute_script 'window.scrollTo(0,100000)'
52
- sleep 4
56
+ sleep 5
53
57
  end
54
58
 
55
59
  # Returns the current session's page
@@ -65,6 +69,7 @@ module PintrestApi
65
69
  old_items_count = items.count
66
70
  scroll_page if old_items_count > 0
67
71
  items = Nokogiri::HTML.parse(html).css css_selector
72
+
68
73
  puts "New Count: #{items.count}\nOld Count: #{old_items_count}"
69
74
  end
70
75
 
@@ -3,20 +3,30 @@ module PintrestApi
3
3
  class Pin < Core
4
4
  attr_reader :image_url, :title, :credits_url, :url, :description
5
5
 
6
+ PIN_BASE_CSS = '.Pin'
7
+
6
8
  class << self
9
+ include Authentication
7
10
  ##
8
11
  # Gets all pins from a board url
9
12
  #
10
13
  # ==== Attributes
11
14
  #
12
15
  # * +board_url+ - Pintrest board url
16
+ # * +authentication+ -
13
17
  # ==== Examples
14
18
  #
15
19
  # PintrestApi::Pin.get_for_board_url('http://pintrest.com/mikaak/my-pins')
16
- def get_for_board_url(board_url)
17
- visit board_url
18
- increment_page_till_bottom
19
- # parse_pins get_with_ajax_scroll('.pinImg')
20
+ def get_for_board_url(board_url, authentication)
21
+ login(authentication) if authentication
22
+ @session.visit board_url
23
+ parse_pins get_with_ajax_scroll(PIN_BASE_CSS)
24
+ end
25
+
26
+ def get_for_board(board, authentication)
27
+ login(authentication) if authentication
28
+ @session.visit board.url
29
+ parse_pins get_with_ajax_scroll(PIN_BASE_CSS)
20
30
  end
21
31
 
22
32
  ## Planned
data/lib/pintrest_api.rb CHANGED
@@ -9,5 +9,6 @@ Bundler.require(:default)
9
9
  # Pintrest Api requires
10
10
  #=======================
11
11
  require 'pintrest_api/core.rb'
12
+ require 'pintrest_api/authentication.rb'
12
13
  require 'pintrest_api/board.rb'
13
14
  require 'pintrest_api/pin.rb'
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.0
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mika Kalathil
@@ -163,6 +163,7 @@ files:
163
163
  - LICENSE.txt
164
164
  - README.md
165
165
  - lib/pintrest_api.rb
166
+ - lib/pintrest_api/authentication.rb
166
167
  - lib/pintrest_api/board.rb
167
168
  - lib/pintrest_api/core.rb
168
169
  - lib/pintrest_api/pin.rb