Sha256: b780135dc991ad2de47130ffbd7bcdfb3977a1d87171f1fb2abc377c69844a14

Contents?: true

Size: 1016 Bytes

Versions: 6

Compression:

Stored size: 1016 Bytes

Contents

require 'typhoeus'
require 'addressable/uri'
require 'xing/snapshot/writer'
require 'sidekiq/worker'

module Xing
  module Snapshot
    class Fetcher
      include Sidekiq::Worker
      include Writer

      def perform(url, path)
        admin_server = Rails.application.secrets.snapshot_server['url']
        user_password = "#{Rails.application.secrets.snapshot_server['user']}:#{Rails.application.secrets.snapshot_server['password']}"
        snapshot_url = Addressable::URI.join(url,path).to_s
        request = Typhoeus::Request.new(admin_server, userpwd: user_password, params: { url: snapshot_url })

        hydra = Typhoeus::Hydra.new
        hydra.queue(request)
        hydra.run

        response = request.response

        if response.success?
          html = response.body
          write(path, html)
        else
          logger.warn response.status_message
          logger.warn response.body
          raise "Query to #{admin_server} for #{path} failed!"
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
xing-backend-1.0.0.pre.beta lib/xing/snapshot/fetcher.rb
xing-backend-0.0.25 lib/xing/snapshot/fetcher.rb
xing-backend-0.0.23 lib/xing/snapshot/fetcher.rb
xing-backend-0.0.22 lib/xing/snapshot/fetcher.rb
xing-backend-0.0.21 lib/xing/snapshot/fetcher.rb
xing-backend-0.0.20 lib/xing/snapshot/fetcher.rb