Module: Restiny::Api::Manifest

Includes:
Base
Included in:
Restiny
Defined in:
lib/restiny/api/manifest.rb

Instance Method Summary collapse

Methods included from Base

#get, #post

Instance Method Details

#download_manifest_json(locale: 'en', definitions: []) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/restiny/api/manifest.rb', line 20

def download_manifest_json(locale: 'en', definitions: [])
  raise Restiny::InvalidParamsError, 'No definitions provided' unless valid_array_param?(definitions)
  raise Restiny::InvalidParamsError, 'Unknown definitions provided' unless known_definitions?(definitions)

  paths = fetch_manifest.dig('jsonWorldComponentContentPaths', locale)
  raise Restiny::ResponseError, "Unable to find manifest JSON for locale '#{locale}'" if paths.nil?

  {}.tap do |files|
    definitions.each do |definition|
      files[definition] = download_manifest_json_by_url(BUNGIE_URL + paths[definition])
    end
  end
end

#download_manifest_json_by_url(url) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/restiny/api/manifest.rb', line 38

def download_manifest_json_by_url(url)
  filename = URI(url).path.split('/').last
  path = File.join(Dir.tmpdir, filename)

  HTTPX.get(url).copy_to(path)
  raise Restiny::Error, "Unable to download JSON from #{url}" unless File.exist?(path)

  path
rescue HTTPX::Error
  raise Restiny::ResponseError, "Unable to download #{definition} JSON file"
end

#fetch_manifestObject



13
14
15
16
17
18
# File 'lib/restiny/api/manifest.rb', line 13

def fetch_manifest
  result = get('/Destiny2/Manifest/')
  return result unless result.nil?

  raise Restiny::ResponseError, 'Unable to fetch manifest details'
end

#known_definitions?(definitions) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/restiny/api/manifest.rb', line 34

def known_definitions?(definitions)
  definitions.difference(Restiny::ManifestDefinition.values).empty?
end