Class: SvgIcon::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/svg_icon/fetcher.rb

Constant Summary collapse

DEFAULT_BASE_URL =
"https://raw.githubusercontent.com/iconify/icon-sets/master/json"
NAME_PATTERN =
/\A[a-z0-9\-_]+\z/

Instance Method Summary collapse

Constructor Details

#initialize(base_url: DEFAULT_BASE_URL, http: Net::HTTP) ⇒ Fetcher

Returns a new instance of Fetcher.



16
17
18
19
# File 'lib/svg_icon/fetcher.rb', line 16

def initialize(base_url: DEFAULT_BASE_URL, http: Net::HTTP)
  @base_url = base_url
  @http = http
end

Instance Method Details

#fetch(name, destination) ⇒ Object

Raises:



21
22
23
24
25
26
27
28
29
# File 'lib/svg_icon/fetcher.rb', line 21

def fetch(name, destination)
  validate_name!(name)
  response = fetch_response(name)
  raise FetchError, "Failed to fetch #{name}: HTTP #{response.code}#{not_found_hint(response.code)}" unless response.code == "200"

  parse(response.body, name)
  write(response.body, destination)
  true
end