Class: Mxrb::OfficialMarketplace::HttpClient
- Inherits:
-
Object
- Object
- Mxrb::OfficialMarketplace::HttpClient
- 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
- #download(url, destination, authorization: default_authorization) ⇒ Object
-
#initialize(github_token: ) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #json(url, authorization: default_authorization) ⇒ Object
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
234 235 236 237 238 239 240 |
# File 'lib/mxrb/official_marketplace.rb', line 234 def download(url, destination, authorization: ) Progress.with("Downloading #{File.basename(destination)}") do |progress| progress.update(detail: URI.parse(url).host) File.binwrite(destination, get(url, accept: 'application/octet-stream', authorization:)) destination end end |
#json(url, authorization: default_authorization) ⇒ Object
225 226 227 228 229 230 231 232 |
# File 'lib/mxrb/official_marketplace.rb', line 225 def json(url, authorization: ) Progress.with('Loading Marketplace data') do |progress| progress.update(detail: URI.parse(url).host) JSON.parse(get(url, accept: 'application/json', authorization:)) end rescue JSON::ParserError => e raise MarketplaceError, "invalid JSON response: #{e.}" end |