Class: RetroWaveImage
- Inherits:
-
Object
- Object
- RetroWaveImage
- Defined in:
- lib/photofunia_retro-wave.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(h) ⇒ RetroWaveImage
constructor
A new instance of RetroWaveImage.
- #inspect ⇒ Object
- #save(location = "") ⇒ Object
Constructor Details
#initialize(h) ⇒ RetroWaveImage
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
44 45 46 |
# File 'lib/photofunia_retro-wave.rb', line 44 def content @content end |
Instance Method Details
#generate ⇒ Object
31 32 33 34 35 36 37 38 |
# 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 ⇒ Object
40 41 42 |
# File 'lib/photofunia_retro-wave.rb', line 40 def inspect return "#<RetroWaveImage content=#{@content.inspect}>" end |
#save(location = "") ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# 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.(location), @location.split(?/)[-1] File.write(fname,@raw) return fname else if location=="" location = sprintf "%s/%s.photofunia.80s.jpg", File.(location), @location.split(?/)[-1] end location.end_with?(".jpg") || location+=".jpg" #p location File.write(location,@raw) return location end end |