class RetroWaveImage
Attributes
content[RW]
Public Class Methods
new(h)
click to toggle source
# File lib/photofunia_retro-wave.rb, line 13 def initialize(h) assert h[:text1].to_s.length<=15 , "Length of text1 exceeds 15 characters" assert h[:text2].to_s.length<=12 , "Length of text2 exceeds 12 characters" assert h[:text3].to_s.length<=25 , "Length of text3 exceeds 25 characters" assert h[:bcg].to_i.between?(1,5), "Background ID is not between 1 and 5" assert h[:txt].to_i.between?(1,4), "Text style ID is not between 1 and 4" @content = { bcg: h[:bcg].to_i, txt: h[:txt].to_i, text1: h[:text1].to_s, text2: h[:text2].to_s, text3: h[:text3].to_s } end
Public Instance Methods
generate()
click to toggle source
# File lib/photofunia_retro-wave.rb, line 31 def generate conn = Faraday.new "https://photofunia.com" resp = conn.post("/categories/all_effects/retro-wave?server=2",{"current-category": "all_effects"}.merge(@content)) @location = resp.headers["location"] result = conn.get @location @raw_url = result.body.match(%r{<a[^<>]*href="([^"]+)"[^<>]*>\s*Large\s*</a>}m)[1] @raw = Faraday.get(@raw_url).body end
inspect()
click to toggle source
# File lib/photofunia_retro-wave.rb, line 40 def inspect return "#<RetroWaveImage content=#{@content.inspect}>" end
save(location="")
click to toggle source
# File lib/photofunia_retro-wave.rb, line 46 def save(location="") unless @raw puts "Content not generated yet, doing that now" generate end if File.directory?(location) fname = sprintf "%s/%s.photofunia.80s.jpg", File.expand_path(location), @location.split(?/)[-1] File.write(fname,@raw) return fname else if location=="" location = sprintf "%s/%s.photofunia.80s.jpg", File.expand_path(location), @location.split(?/)[-1] end location.end_with?(".jpg") || location+=".jpg" #p location File.write(location,@raw) return location end end
Private Instance Methods
assert(x,t=nil)
click to toggle source
# File lib/photofunia_retro-wave.rb, line 7 def assert(x,t=nil) x || raise(ArgumentError, "Assertion failed#{t ? ": #{t}" : ""}") end