class GyazoSpector::Client

concreate implemtation of Client

Constants

CONTENT_TYPE
DEFAULT_ENDPOINT
DEFAULT_POLTERGEIST_OPTIONS
DEFAULT_SELECTOR
DEFAULT_SITE

Attributes

endpoint[R]
imagedata[R]
session[R]
site[R]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/gyazo_spector/client.rb, line 18
def initialize(opts = {})
  @site = opts.delete(:site) || DEFAULT_SITE
  @endpoint = opts.delete(:endpoint) || DEFAULT_ENDPOINT
  Capybara.default_selector = opts.delete(:selector) || DEFAULT_SELECTOR

  Capybara.register_driver :poltergeist do |app|
    Capybara::Poltergeist::Driver.new(
      app, DEFAULT_POLTERGEIST_OPTIONS.merge(opts)
    )
  end
end

Public Instance Methods

capture(url, options = {}) { |session| ... } click to toggle source
# File lib/gyazo_spector/client.rb, line 34
def capture(url, options = {})
  session.visit(url)
  yield(session) if block_given?
  @imagedata = Base64.decode64(session.driver.render_base64(:png, options))
  self
end
upload!() click to toggle source
# File lib/gyazo_spector/client.rb, line 41
def upload!
  Faraday.new(site) do |client|
    client.request :multipart
    client.request :url_encoded
    client.adapter Faraday.default_adapter
  end.post(
    endpoint,
    imagedata: Faraday::UploadIO.new(StringIO.new(imagedata), CONTENT_TYPE)
  ).body
end