Class: Orly::Book

Inherits:
Object
  • Object
show all
Defined in:
lib/orly/book.rb,
lib/orly/book/version.rb

Constant Summary collapse

VERSION =
"0.4.0"

Instance Method Summary collapse

Constructor Details

#initialize(filename = "orly", options = {}) ⇒ Book

Returns a new instance of Book.



6
7
8
9
10
11
12
13
14
# File 'lib/orly/book.rb', line 6

def initialize(filename="orly", options={})
  @filename = filename
  @title = URI.encode(options[:title]) || "%20"
  @top_text = URI.encode(options[:top_text]) || "%20"
  @author = URI.encode(options[:author]) || "%20"
  @theme = options[:theme] || rand(17)
  @animal = options[:animal] || rand(40)+1
  generate
end

Instance Method Details

#generateObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/orly/book.rb', line 16

def generate
  puts "Starting"
  # uri = URI("http://orly-appstore.herokuapp.com
  Net::HTTP.start("orly-appstore.herokuapp.com") do |http|
    resp = http.get("/generate?title=#{@title}&top_text=#{@top_text}&author=#{@author}&theme=#{@theme}&image_code=#{@animal}")
    open("./#{@filename}.png", "wb") do |file|
      file.write(resp.body)
    end
  end
  puts "Done!"
end