random_images 0.0.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
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.project ADDED
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>dummy_files</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ </buildSpec>
9
+ <natures>
10
+ </natures>
11
+ </projectDescription>
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jordi Noguera
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.rdoc ADDED
@@ -0,0 +1,68 @@
1
+ = dummy_files
2
+
3
+ Pull urls of random images/files from google searches to generate sample data.
4
+
5
+ = Installation
6
+
7
+ sudo gem install dummy_files
8
+
9
+ In your config/environment.rb
10
+ config.gem 'dummy_files', :version => '=>0.0.9'
11
+
12
+ = To get Images
13
+ DummyFiles::Images.get
14
+ You can also call pass parameters
15
+ DummyFiles::Images.get(number, keyword, content)
16
+ Where number is the number of images to fetch (by default 100), keyword is the keyword for the google search (by default "me") and content is the type of images, which can be "any" (ie, any image) or "face" (ie, pictures of faces, this is the default value).
17
+
18
+ You can get a single image, too
19
+ DummyFiles::Image.get
20
+ Or with parameters
21
+ DummyFiles::Image.get(keyword, content)
22
+
23
+ = To get Files
24
+ DummyFiles::Files.get(filetype)
25
+ So you are gonna be searching for files whose file type is "filetype".
26
+
27
+ Call with parameters
28
+ DummyFiles::Files.get(filetype, number, keyword)
29
+ By default keyword is "".
30
+
31
+ Single File
32
+ DummyFiles::File.get(filetype)
33
+ With parameters
34
+ DummyFiles::File.get(filetype, keyword)
35
+
36
+ = API
37
+ There's an API avalailable in my website, it returns the results as text/JSON. The calls are as follows:
38
+
39
+ Images
40
+ http://api.jordinl.com/dummy/images
41
+ Images with params
42
+ http://api.jordinl.com/dummy/images?number=[YOUR_NUMBER]&keyword=[YOUR_KEYWORD]&content=[YOUR_CONTENT]
43
+ Image
44
+ http://api.jordinl.com/dummy/image
45
+ Image with params
46
+ http://api.jordinl.com/dummy/image?keyword=[YOUR_KEYWORD]&content=[YOUR_CONTENT]
47
+ Files
48
+ http://api.jordinl.com/dummy/files?filetype=[YOUR_FILETYPE]
49
+ Files with params
50
+ http://api.jordinl.com/dummy/files?filetype=[YOUR_FILETYPE]&keyword=[YOUR_KEYWORD]&number=[YOUR_NUMBER]
51
+ File
52
+ http://api.jordinl.com/dummy/file?filetype=[YOUR_FILETYPE]
53
+ File with params
54
+ http://api.jordinl.com/dummy/file?filetype=[YOUR_FILETYPE]&keyword=[YOUR_KEYWORD]
55
+
56
+ == Note on Patches/Pull Requests
57
+
58
+ * Fork the project.
59
+ * Make your feature addition or bug fix.
60
+ * Add tests for it. This is important so I don't break it in a
61
+ future version unintentionally.
62
+ * Commit, do not mess with rakefile, version, or history.
63
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
64
+ * Send me a pull request. Bonus points for topic branches.
65
+
66
+ == Copyright
67
+
68
+ Copyright (c) 2010 Jordi Noguera. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "random_images"
8
+ gem.summary = %Q{URLs for sample data generation}
9
+ gem.description = %Q{Pull urls of random images from google searches to generate sample data.}
10
+ gem.email = "jordinoguera83@gmail.com"
11
+ gem.homepage = "http://github.com/hackdd/random_images"
12
+ gem.authors = ["Jordi Noguera"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ gem.add_dependency('nokogiri', '>= 1.4.2')
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "random_images #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,59 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+
4
+ module RandomImages
5
+
6
+ module Images
7
+
8
+ def self.get(number = 100, keyword = "me", content = "face")
9
+ max = [number / 10, 1].max
10
+ nokogiri = (1..max).map{ Nokogiri::HTML(open_page(keyword, content)) }
11
+ nokogiri.map do |n|
12
+ n.search("a img").map{ |x| x["src"].split(":http://")[1] }.compact.map(&:to_url)
13
+ end.flatten[0, number]
14
+ end
15
+
16
+ private
17
+
18
+ def self.get_url(keyword = 'me', content = 'face')
19
+ "http://www.google.com/images?q=#{keyword}&hl=en&safe=active&biw=1280&bih=653&gbv=1&as_st=y&tbs=isch:1" +
20
+ if content == "any"
21
+ "&ei=Mq9dTciKKsmytAa9lKTKCg&start=#{(1..850)}&sa=N"
22
+ else
23
+ ",itp:face&ei=cq5dTe7UFomLswajlbDXCg&start=#{(1..850).random}&sa=N"
24
+ end
25
+ end
26
+
27
+ def self.open_page(keyword, content)
28
+ open(get_url(keyword, content)).read
29
+ end
30
+
31
+ end
32
+
33
+ module Image
34
+
35
+ def self.get(keyword = "me", content = "face")
36
+ Images.get(1, keyword, content).random
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ class Array
44
+ def random
45
+ self[rand(self.length)]
46
+ end
47
+ end
48
+
49
+ class Range
50
+ def random
51
+ first + rand(last)
52
+ end
53
+ end
54
+
55
+ class String
56
+ def to_url
57
+ "http://" + self
58
+ end
59
+ end
data/tools/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'nokogiri'
4
+
5
+ @file = 'lib/random_images.rb'
6
+
7
+ require @file
8
+
9
+ def reload!
10
+ load @file
11
+ end
12
+
13
+ require 'irb'
14
+ require 'irb/completion'
15
+ IRB.start
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: random_images
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Jordi Noguera
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-15 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thoughtbot-shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: nokogiri
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 1
46
+ - 4
47
+ - 2
48
+ version: 1.4.2
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: Pull urls of random images from google searches to generate sample data.
52
+ email: jordinoguera83@gmail.com
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files:
58
+ - LICENSE
59
+ - README.rdoc
60
+ files:
61
+ - .document
62
+ - .project
63
+ - LICENSE
64
+ - README.rdoc
65
+ - Rakefile
66
+ - VERSION
67
+ - lib/random_images.rb
68
+ - tools/console
69
+ has_rdoc: true
70
+ homepage: http://github.com/hackdd/random_images
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options: []
75
+
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.3.7
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: URLs for sample data generation
103
+ test_files: []
104
+