Class: Flickr
Constant Summary collapse
- IMAGE_WIDTH =
200- IMAGE_HEIGHT =
300- NO_IMAGES =
10- PROGRESSBAR =
ProgressBar.create
Class Method Summary collapse
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(keyword, index) ⇒ Flickr
constructor
A new instance of Flickr.
- #search ⇒ Object
Constructor Details
#initialize(keyword, index) ⇒ Flickr
Returns a new instance of Flickr.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/flickr.rb', line 9 def initialize(keyword, index) @options = { query: { method: 'flickr.photos.search', text: keyword, sort: 'interestingness-asc', nojsoncallback: 1, api_key: '38f8b5be4529ce3f039a5d9b94f360cd', per_page: 1 } } @index = index @url = nil end |
Class Method Details
.create_collage(file_name) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/flickr.rb', line 45 def self.create_collage(file_name) bg_image = read_bg_image result = loop_images(bg_image) write_image_to_file(result, file_name) end |
Instance Method Details
#fetch ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/flickr.rb', line 36 def fetch return false unless @url File.open("tmp/#{@index}.jpg", "wb") do |f| image = f.write HTTParty.get(@url).parsed_response end image = Magick::ImageList.new("tmp/#{@index}.jpg").resize_to_fill!(IMAGE_WIDTH, IMAGE_HEIGHT) image.write("tmp/#{@index}.jpg") end |
#search ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/flickr.rb', line 26 def search response = self.class.get("/services/rest", @options) if response["rsp"]["stat"] == "ok" result = set_image_url(response) result ? result : false else return false end end |