Class: GyazoSpector::Client
- Inherits:
-
Object
- Object
- GyazoSpector::Client
- Defined in:
- lib/gyazo_spector/client.rb
Overview
concreate implemtation of Client
Constant Summary collapse
- CONTENT_TYPE =
'image/png'.freeze
- DEFAULT_SITE =
'http://gyazo.com'.freeze
- DEFAULT_ENDPOINT =
'/'.freeze
- DEFAULT_POLTERGEIST_OPTIONS =
{ js_errors: false, timeout: 1000, debug: false }.freeze
- DEFAULT_SELECTOR =
:css
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#imagedata ⇒ Object
readonly
Returns the value of attribute imagedata.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
- #capture(url, options = {}) {|session| ... } ⇒ Object
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #upload! ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
18 19 20 21 22 23 24 25 26 27 28 |
# 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 |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
16 17 18 |
# File 'lib/gyazo_spector/client.rb', line 16 def endpoint @endpoint end |
#imagedata ⇒ Object (readonly)
Returns the value of attribute imagedata.
16 17 18 |
# File 'lib/gyazo_spector/client.rb', line 16 def imagedata @imagedata end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
16 17 18 |
# File 'lib/gyazo_spector/client.rb', line 16 def session @session end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
16 17 18 |
# File 'lib/gyazo_spector/client.rb', line 16 def site @site end |
Instance Method Details
#capture(url, options = {}) {|session| ... } ⇒ Object
34 35 36 37 38 39 |
# File 'lib/gyazo_spector/client.rb', line 34 def capture(url, = {}) session.visit(url) yield(session) if block_given? @imagedata = Base64.decode64(session.driver.render_base64(:png, )) self end |
#upload! ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# 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 |