Class: Artbase::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/originals/service.rb

Overview

main artbase service handler / machinery

Constant Summary collapse

DEFAULT_BASE_URL =
'https://pixelartexchange.herokuapp.com'

Instance Method Summary collapse

Constructor Details

#initialize(base_url = DEFAULT_BASE_URL) ⇒ Service

Returns a new instance of Service.



55
56
57
# File 'lib/originals/service.rb', line 55

def initialize( base_url=DEFAULT_BASE_URL )
  @base_url = base_url
end

Instance Method Details

#get(collection, id) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/originals/service.rb', line 59

def get( collection, id )

  url = "#{@base_url}/#{collection}/#{id}.png"
  res = Webclient.get( url )

  puts "#{res.status.code} #{res.status.message}"
  puts "    content_type: #{res.content_type}"
  puts "    content_length: #{res.content_length} bytes (#{res.content_length.class.name})"

  if res.status.ok?
    ## todo/fix: move to Pixelart::Image itself
    ##     use from_blob or such - why? why not
    img_inner = ChunkyPNG::Image.from_blob( res.blob )
    img = Artbase::Image.new( img_inner.width, img_inner.height, img_inner )
    img
  else
    puts "!! HTTP ERROR - image data request failed; sorry"
    return nil
  end
end