pinteresting 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pinteresting.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Pinteresting
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'pinteresting'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install pinteresting
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -1,9 +1,3 @@
1
- module Pinterest
2
- class Pins
1
+ require "pinteresting/version"
2
+ require "pinteresting/pins"
3
3
 
4
- def self.search(search_term)
5
- puts "Searching #{search_term}"
6
- end
7
-
8
- end
9
- end
@@ -0,0 +1,73 @@
1
+ require 'mechanize'
2
+
3
+ module Pinteresting
4
+ class Pins
5
+
6
+ def self.search(search_term)
7
+ puts "Searching Pinterest for #{search_term}..."
8
+ a = Mechanize.new
9
+ parse(search_term, a)
10
+ end
11
+
12
+ def self.parse(search_term, a)
13
+ page = get_search_term_page(search_term, a)
14
+ pins = get_pins(page)
15
+ parse_pins(pins)
16
+ end
17
+
18
+ def self.get_search_term_page(search_term, a)
19
+ a.get("http://pinterest.com/search/pins/?q=#{search_term}")
20
+ end
21
+
22
+ def self.get_pins(page)
23
+ page.search('//div[@class="pin"]')
24
+ end
25
+
26
+ def self.parse_pins(pins)
27
+ pins.map do |pin|
28
+ parse_pin(pin)
29
+ end
30
+ end
31
+
32
+ def self.parse_pin(pin)
33
+ {
34
+ :image_url => parse_pin_image_url(pin),
35
+ :repins => parse_pin_repins(pin),
36
+ :pinterest_id => parse_pin_id(pin),
37
+ :url => parse_pin_url(pin),
38
+ :pinner => parse_pin_pinner(pin),
39
+ :likes => parse_pin_likes(pin)
40
+ }
41
+ end
42
+
43
+ def self.parse_pin_image_url(pin)
44
+ pin.search(".//a[@class='PinImage ImgLink']/img/@src").text
45
+ end
46
+
47
+ def self.parse_pin_repins(pin)
48
+ pin_repins = pin.search(".//p[@class='stats colorless']/span[@class='RepinsCount']").text
49
+ pin_repins[/(\d+)/,1]
50
+ end
51
+
52
+ def self.parse_pin_id(pin)
53
+ # pin_id = pin.search(".//div[@class='PinHolder']/a/@href").text
54
+ # pin_id = pin.attributes["data-id"].value
55
+ pin.search("./@data-id").text
56
+ end
57
+
58
+ def self.parse_pin_url(pin)
59
+ # TODO RYAN -- How can I DRY this up?
60
+ pin_url = pin.search("./@data-id").text
61
+ "http://pinterest.com/pin/#{pin_url}"
62
+ end
63
+
64
+ def self.parse_pin_pinner(pin)
65
+ pin.search(".//div[@class='convo attribution clearfix']/a/@href").text
66
+ end
67
+
68
+ def self.parse_pin_likes(pin)
69
+ pin_likes = pin.search(".//p[@class='stats colorless']/span[@class='LikesCount']").text
70
+ pin_likes[/(\d+)/,1]
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module Pinteresting
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pinteresting/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "pinteresting"
8
+ gem.version = Pinteresting::VERSION
9
+ gem.authors = ["Kendra Osburn", "Ryan Urabe"]
10
+ gem.email = ["kdosburn@gmail.com"]
11
+ gem.description = %q{Pin it. Pin it good.}
12
+ gem.summary = %q{Oh! So Pinteresting!}
13
+ gem.homepage = "https://github.com/kdosburn/pinteresting"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency('mechanize')
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinteresting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,15 +11,40 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
  date: 2013-03-24 00:00:00.000000000 Z
14
- dependencies: []
15
- description: A simple, yet pinteresting, gem.
16
- email: kdosburn@gmail.com
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mechanize
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ description: Pin it. Pin it good.
32
+ email:
33
+ - kdosburn@gmail.com
17
34
  executables: []
18
35
  extensions: []
19
36
  extra_rdoc_files: []
20
37
  files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
21
43
  - lib/pinteresting.rb
22
- homepage: http://rubygems.org/gems/pinteresting
44
+ - lib/pinteresting/pins.rb
45
+ - lib/pinteresting/version.rb
46
+ - pinteresting.gemspec
47
+ homepage: https://github.com/kdosburn/pinteresting
23
48
  licenses: []
24
49
  post_install_message:
25
50
  rdoc_options: []
@@ -42,5 +67,5 @@ rubyforge_project:
42
67
  rubygems_version: 1.8.24
43
68
  signing_key:
44
69
  specification_version: 3
45
- summary: PIN IT. PIN IT GOOD.
70
+ summary: Oh! So Pinteresting!
46
71
  test_files: []