Class: Mxrb::OfficialMarketplace::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/official_marketplace.rb

Overview

Small HTTPS-only GitHub client with bounded redirects and response size.

Constant Summary collapse

MAX_BYTES =
512 * 1024 * 1024

Instance Method Summary collapse

Constructor Details

#initialize(github_token: ) ⇒ HttpClient

Returns a new instance of HttpClient.



221
222
223
# File 'lib/mxrb/official_marketplace.rb', line 221

def initialize(github_token: ENV['GITHUB_TOKEN'])
  @github_token = github_token.to_s
end

Instance Method Details

#download(url, destination, authorization: default_authorization) ⇒ Object



231
232
233
234
# File 'lib/mxrb/official_marketplace.rb', line 231

def download(url, destination, authorization: default_authorization)
  File.binwrite(destination, get(url, accept: 'application/octet-stream', authorization:))
  destination
end

#json(url, authorization: default_authorization) ⇒ Object



225
226
227
228
229
# File 'lib/mxrb/official_marketplace.rb', line 225

def json(url, authorization: default_authorization)
  JSON.parse(get(url, accept: 'application/json', authorization:))
rescue JSON::ParserError => e
  raise MarketplaceError, "invalid JSON response: #{e.message}"
end