lib/john_stamos/pinner.rb in john_stamos-0.0.2 vs lib/john_stamos/pinner.rb in john_stamos-0.0.3
- old
+ new
@@ -7,11 +7,11 @@
@client = client
@username = username
end
def url
- "http://pinterest.com/#{@username}/"
+ "http://www.pinterest.com/#{@username}/"
end
def pin_count
embedded_pinner_data("pin_count")
end
@@ -50,30 +50,18 @@
def location
embedded_pinner_data("location")
end
+
private
def page
@page ||= @client.page_content("/#{@username}/")
end
- def embedded_pinner_json
- embedded_script = page.search('script').select do |script|
- script['src'].nil? && script.content.include?('Pc.startArgs')
- end
-
- embedded_script_content = embedded_script.first.content
- # This regex used in the range snatches the parameter Pinterest uses to
- # start their app... This parameter happens to be a JSON representation of
- # the page.
- raw_json = embedded_script_content[/Pc.startArgs = (.*);/, 1]
- embedded_script_json = JSON.parse(raw_json)
-
- embedded_script_json
- end
-
def embedded_pinner_data(attribute)
+ embedded_pinner_json = JohnStamos::ExtractionHelper.embedded_page_json(page)
+
value = embedded_pinner_json["tree"]["options"]["module"]["data"][attribute]
value = "" if value.nil?
value
end
\ No newline at end of file