aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc/url.rb
blob: 5f763ca8a0a49b363abff48534aa8f7a5f5578a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require "forwardable"

class Hbc::URL
  FAKE_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10) http://caskroom.io".freeze

  attr_reader :using, :revision, :trust_cert, :uri, :cookies, :referer, :data

  extend Forwardable
  def_delegators :uri, :path, :scheme, :to_s

  def self.from(*args, &block)
    if block_given?
      Hbc::DSL::StanzaProxy.once(self) { new(*block.call) }
    else
      new(*args)
    end
  end

  def initialize(uri, options = {})
    @uri        = Hbc::UnderscoreSupportingURI.parse(uri)
    @user_agent = options[:user_agent]
    @cookies    = options[:cookies]
    @referer    = options[:referer]
    @using      = options[:using]
    @revision   = options[:revision]
    @trust_cert = options[:trust_cert]
    @data       = options[:data]
  end

  def user_agent
    if @user_agent == :fake
      FAKE_USER_AGENT
    else
      @user_agent
    end
  end
end