Sha256: a63242dcc6391571e7982bea9691116693994b279cfd3559a50c36f90095217e

Contents?: true

Size: 1.23 KB

Versions: 9

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require 'net/http'
require 'app_store_dev_api/specification/component/schema'

module AppStoreDevApi
  class Specification
    def initialize(hash)
      @hash = hash
    end

    def find(version, type)
      @hash['paths'].find do |path, _declaration|
        path == "/#{version}/#{type}"
      end&.[](-1)
    end

    def component_schema(ref)
      Component::Schema.new(traverse(ref))
    end

    def traverse(ref)
      _, *parts = ref.split('/')

      @hash.dig(*parts)
    end

    def create_request_schema_ref(version, type)
      declarations = find(version, type)
      declarations['post']['requestBody']['content']['application/json']['schema']['$ref']
    end

    def self.read(path)
      require 'zip'

      Zip::File.open(path) do |zip_file|
        entry, = zip_file.entries
        content = entry.get_input_stream(&:read)

        JSON.parse(content)
      end
    end

    def self.download(path)
      uri = URI('https://developer.apple.com/sample-code/app-store-connect/app-store-connect-openapi-specification.zip')

      Net::HTTP.start(uri.host, uri.port, { use_ssl: true }) do |http|
        response = http.get(uri.path)

        File.write(path, response.body)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
app_store_dev_api-0.1.9 lib/app_store_dev_api/specification.rb
app_store_dev_api-0.1.8 lib/app_store_dev_api/specification.rb
app_store_dev_api-0.1.7 lib/app_store_dev_api/specification.rb
app_store_dev_api-0.1.6 lib/app_store_dev_api/specification.rb
app_store_dev_api-0.1.4 lib/app_store_dev_api/specification.rb
app_store_dev_api-0.1.3 lib/app_store_dev_api/specification.rb
app_store_dev_api-0.1.2 lib/app_store_dev_api/specification.rb
app_store_dev_api-0.1.1 lib/app_store_dev_api/specification.rb
app_store_dev_api-0.1.0 lib/app_store_dev_api/specification.rb