Sha256: b002b5d88ecfdbba4f8db726f382b6e8a45867e54bea89cc796800c41faba647

Contents?: true

Size: 766 Bytes

Versions: 29

Compression:

Stored size: 766 Bytes

Contents

# encoding: utf-8

module Github
  module MimeType

    MEDIA_LOOKUP = {
      'json' => 'json',
      'blob' => 'raw',
      'raw'  => 'raw+json',
      'text' => 'text+json',
      'html' => 'html+json',
      'full' => 'full+json'
    }

    # Parse media type param
    #
    def parse(media)
      version = 'v3'
      media.sub!(/^[.]*|[.]*$/,"")
      media = media.include?('+') ? media.split('+')[0] : media
      version, media = media.split('.') if media.include?('.')
      media_type = lookup_media(media)
      "application/vnd.github.#{version}.#{media_type}"
    end

    def lookup_media(name)
      MEDIA_LOOKUP.fetch(name) do
        raise ArgumentError, "Provided Media Type #{name} is not valid"
      end
    end

  end # MimeType
end # Github

Version data entries

29 entries across 29 versions & 3 rubygems

Version Path
github_api2-1.0.1 lib/github_api2/mime_type.rb
github_api2-1.0.0 lib/github_api2/mime_type.rb
github_api-0.19.0 lib/github_api/mime_type.rb
lingfennan-github_api-0.18.2 lib/github_api/mime_type.rb
github_api-0.18.2 lib/github_api/mime_type.rb
github_api-0.18.1 lib/github_api/mime_type.rb
github_api-0.17.0 lib/github_api/mime_type.rb
github_api-0.16.0 lib/github_api/mime_type.rb
github_api-0.15.0 lib/github_api/mime_type.rb
github_api-0.14.5 lib/github_api/mime_type.rb
github_api-0.14.4 lib/github_api/mime_type.rb
github_api-0.14.3 lib/github_api/mime_type.rb
github_api-0.14.2 lib/github_api/mime_type.rb
github_api-0.14.1 lib/github_api/mime_type.rb
github_api-0.14.0 lib/github_api/mime_type.rb
github_api-0.13.1 lib/github_api/mime_type.rb
github_api-0.13.0 lib/github_api/mime_type.rb
github_api-0.12.4 lib/github_api/mime_type.rb
github_api-0.12.3 lib/github_api/mime_type.rb
github_api-0.12.2 lib/github_api/mime_type.rb