photoinfo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-18mode # JRuby in 1.8 mode
5
+ - jruby-19mode # JRuby in 1.9 mode
6
+ - rbx-18mode
7
+ - rbx-19mode
8
+ - 1.8.7
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.8.0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.2.3"
12
+ gem "jeweler", "~> 1.8.4"
13
+ gem "nokogiri", "~> 1.5.5"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.8.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rdoc
11
+ json (1.7.5)
12
+ nokogiri (1.5.5)
13
+ rake (10.0.2)
14
+ rdoc (3.12)
15
+ json (~> 1.4)
16
+ rspec (2.8.0)
17
+ rspec-core (~> 2.8.0)
18
+ rspec-expectations (~> 2.8.0)
19
+ rspec-mocks (~> 2.8.0)
20
+ rspec-core (2.8.0)
21
+ rspec-expectations (2.8.0)
22
+ diff-lcs (~> 1.1.2)
23
+ rspec-mocks (2.8.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.2.3)
30
+ jeweler (~> 1.8.4)
31
+ nokogiri (~> 1.5.5)
32
+ rdoc (~> 3.12)
33
+ rspec (~> 2.8.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Eddie Lee
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,65 @@
1
+ # photoinfo
2
+
3
+ [![Build Status](https://travis-ci.org/patternchef/photoinfo.png)](https://travis-ci.org/patternchef/photoinfo)
4
+
5
+ This simple gem will be able to fetch the metadata of a specific istockphoto.com image from the website if the ID of a photo is provided.
6
+
7
+ This is a class project, and the purpose of this gem is to learn and demonstrate how to isolate and select the contents of a web page. Please do not abuse istockphoto.com.
8
+
9
+ ## How to use it
10
+
11
+ Instantiate an object and provide an istockphoto.com photo ID as an argument.
12
+
13
+ object = Photoinfo.new (insert an istockphoto.com photo ID number)
14
+
15
+ Get the title by:
16
+
17
+ object.title
18
+
19
+ Get the description by:
20
+
21
+ object.description
22
+
23
+ Get the contributor by:
24
+
25
+ object.contributor
26
+
27
+ Get the keywords by:
28
+
29
+ object.keywords
30
+
31
+ Get the collection info by:
32
+
33
+ object.collection
34
+
35
+ Get the uploaded on info by:
36
+
37
+ object.uploadedon
38
+
39
+ To save the metadata to a YAML file:
40
+
41
+ object.save
42
+
43
+ *Note: When you use the save method, it will fetch all the metadata and save it to a YAML file.*
44
+
45
+ ## This gem requires:
46
+ * open-uri
47
+ * nokogiri
48
+ * yaml
49
+
50
+ ## Contributing to photoinfo
51
+
52
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
53
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
54
+ * Fork the project.
55
+ * Start a feature/bugfix branch.
56
+ * Commit and push until you are happy with your contribution.
57
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
58
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
59
+
60
+ ## Copyright
61
+
62
+ Copyright (c) 2012 Eddie Lee. See LICENSE.txt for further details.
63
+
64
+
65
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "photoinfo"
18
+ gem.homepage = "http://github.com/patternchef/photoinfo"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{istockphoto.com photo metadata fetcher}
21
+ gem.description = %Q{istockphoto.com photo metadata fetcher}
22
+ gem.email = "minidsl@hotmail.com"
23
+ gem.authors = ["Eddie Lee"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "photoinfo #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/photoinfo.rb ADDED
@@ -0,0 +1,66 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'yaml'
4
+
5
+ class Photoinfo
6
+ attr_reader :photoid, :webpage, :title, :description, :contributor, :keywords, :collection, :uploadedon, :info
7
+ def initialize(photoid)
8
+ @photoid = photoid.to_i
9
+ # puts "Please input istockphoto id: "
10
+ # @photoid = gets.chomp!.to_i
11
+ # sample istockphoto id "21846754"
12
+ end
13
+ def read
14
+ @webpage = Nokogiri::HTML(open("http://www.istockphoto.com/search/text/#@photoid").read)
15
+ @webpage.encoding = 'utf-8'
16
+ end
17
+ def isTitle
18
+ @title = @webpage.css('span#iSFileTitle').text.strip
19
+ end
20
+ def isDescription
21
+ a = @webpage.xpath('//*[@id="artist-description-container"]').text
22
+ b = a.match (/(\n)(.+)(\n)(.+)/)
23
+ @description = b[4].sub(/\s+/, "")
24
+ "Description: #@description"
25
+ end
26
+ def isContributor
27
+ @contributor = @webpage.xpath('//*[@id="file-details-table"]//td[2]/ul/li/a[2]').text.strip
28
+ end
29
+ def isKeywords
30
+ @keywords = []
31
+ @webpage.xpath('//*[@id="file-details-table"]//tr[2]/td[2]/a').each do |m|
32
+ @keywords += [m.text]
33
+ end
34
+ @keywords = @keywords.join(", ")
35
+ end
36
+ def isCollection
37
+ @collection = @webpage.xpath('//*[@id="file-subHeader"]//ul/li[1]').text.strip
38
+ end
39
+ def isUploadedOn
40
+ @uploadedon = @webpage.xpath('//*[@id="file-details-table"]//tr[6]/td[2]').text.strip
41
+ end
42
+ def prepareToSave
43
+ read
44
+ isTitle
45
+ isDescription
46
+ isContributor
47
+ isKeywords
48
+ isCollection
49
+ isUploadedOn
50
+ end
51
+ def save
52
+ self.prepareToSave
53
+ @info = {
54
+ :title => @title,
55
+ :description => @description,
56
+ :contributor => @contributor,
57
+ :keywords => @keywords.to_s,
58
+ :collection => @collection,
59
+ :uploadedon => @uploadedon
60
+ }
61
+ output = File.new('istockphoto.yml', 'a+')
62
+ output.puts YAML.dump(@info)
63
+ output.close
64
+ end
65
+ end
66
+
@@ -0,0 +1,58 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Photoinfo" do
4
+ before do
5
+ @photoinfo = Photoinfo.new(21846754)
6
+ @photoinfo.read
7
+ end
8
+ it "should have a have a photoid number" do
9
+ @photoinfo.photoid.should be_a_kind_of(Numeric)
10
+ end
11
+ describe "#read" do
12
+ it "should read the istockphoto webpage using the photoid" do
13
+ @photoinfo.webpage.should be_a_kind_of(Nokogiri::HTML::Document)
14
+ end
15
+ end
16
+ describe "#isTitle" do
17
+ it "should return the title of the photo" do
18
+ @photoinfo.isTitle
19
+ @photoinfo.title.should eq "Quiet alpine scene"
20
+ end
21
+ end
22
+ describe "#isDescription" do
23
+ it "should return the description of the photo" do
24
+ @photoinfo.isDescription
25
+ @photoinfo.description.should eq "Small chapel on the hill in a beautiful mountain landscape"
26
+ end
27
+ end
28
+ describe "#isContributor" do
29
+ it "should return the contributor of the photo" do
30
+ @photoinfo.isContributor
31
+ @photoinfo.contributor.should eq "Scacciamosche"
32
+ end
33
+ end
34
+ describe "#isKeywords" do
35
+ it "should return the keywords of the photo" do
36
+ @photoinfo.isKeywords
37
+ @photoinfo.keywords.should eq "Woods, Forest, Nature, Idyllic, Tirol, Symbols Of Peace, Horizon Over Land, Horizon, Horizontal, Relaxation, Scenics, Panoramic, Mountain Peak, Grass, Twilight, Outdoors, Photography, Nobody, Color Image, Descriptive Color, Merano, Valley, European Alps, Mountain, Architecture, Building Exterior, Hill, Old, Landscaped, Landscape, Tranquil Scene, Tree, Spring, Wood, Alto Adige, Beauty In Nature, Chapel, Church, Non-Urban Scene, Rural Scene, Famous Place, Snow, Green, Sunset, Dawn"
38
+ end
39
+ end
40
+ describe "#isCollection" do
41
+ it "should return the collection info of the photo" do
42
+ @photoinfo.isCollection
43
+ @photoinfo.collection.should eq "Vetta Stock Photo"
44
+ end
45
+ end
46
+ describe "#isUploadedOn" do
47
+ it "should should return the uploaded on info of the photo" do
48
+ @photoinfo.isUploadedOn
49
+ @photoinfo.uploadedon.should eq "10-13-12 @ Anita Stizzoli"
50
+ end
51
+ end
52
+ describe "#save" do
53
+ it "should include the photo's meta data" do
54
+ @photoinfo.save
55
+ @photoinfo.info.should include({:title=>"Quiet alpine scene", :description=>"Small chapel on the hill in a beautiful mountain landscape", :contributor=>"Scacciamosche", :keywords=>"Woods, Forest, Nature, Idyllic, Tirol, Symbols Of Peace, Horizon Over Land, Horizon, Horizontal, Relaxation, Scenics, Panoramic, Mountain Peak, Grass, Twilight, Outdoors, Photography, Nobody, Color Image, Descriptive Color, Merano, Valley, European Alps, Mountain, Architecture, Building Exterior, Hill, Old, Landscaped, Landscape, Tranquil Scene, Tree, Spring, Wood, Alto Adige, Beauty In Nature, Chapel, Church, Non-Urban Scene, Rural Scene, Famous Place, Snow, Green, Sunset, Dawn", :collection=>"Vetta Stock Photo", :uploadedon=>"10-13-12 @ Anita Stizzoli"})
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'photoinfo'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: photoinfo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eddie Lee
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.8.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.8.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.12'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.12'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.3
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.3
62
+ - !ruby/object:Gem::Dependency
63
+ name: jeweler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.8.4
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.8.4
78
+ - !ruby/object:Gem::Dependency
79
+ name: nokogiri
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.5.5
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.5.5
94
+ description: istockphoto.com photo metadata fetcher
95
+ email: minidsl@hotmail.com
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files:
99
+ - LICENSE.txt
100
+ - README.markdown
101
+ files:
102
+ - .document
103
+ - .rspec
104
+ - .travis.yml
105
+ - Gemfile
106
+ - Gemfile.lock
107
+ - LICENSE.txt
108
+ - README.markdown
109
+ - Rakefile
110
+ - VERSION
111
+ - lib/photoinfo.rb
112
+ - spec/photoinfo_spec.rb
113
+ - spec/spec_helper.rb
114
+ homepage: http://github.com/patternchef/photoinfo
115
+ licenses:
116
+ - MIT
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ segments:
128
+ - 0
129
+ hash: 1056897114414388988
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 1.8.24
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: istockphoto.com photo metadata fetcher
142
+ test_files: []