Sha256: 01eb883ae71397dcb900f1abc88b956b686a5f22298b8e8dbb6ea24f21602fcd

Contents?: true

Size: 1.3 KB

Versions: 58

Compression:

Stored size: 1.3 KB

Contents

# encoding: utf-8

module Github
  module MimeType

    attr_accessor :accepts

    RESOURCE_LOOKUP = {
      :json           => 'json',
      :issue          => 'vnd.github-issue.',
      :issue_comment  => 'vnd.github-issuecomment.',
      :commit_comment => 'vnd.github-commitcomment.',
      :pull_request   => 'vnd.github-pull.',
      :pull_comment   => 'vnd.github-pullcomment.',
      :gist_comment   => 'vnd.github-gistcomment.',
      :blob           => 'vnd.github-blob.'
    }

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

    def parse(resource = nil, mime_type = :json)
      resource  = lookup_resource(resource) if resource
      mime_type = lookup_mime(mime_type)
      self.accepts = "application/#{resource || ''}#{mime_type}"
    end

    def lookup_resource(name)
      RESOURCE_LOOKUP.fetch(name)
    end

    def lookup_mime(name)
      MIME_LOOKUP.fetch(name)
    end

    def _normalize_name(name)
      puts "NAME: #{name}"
      case name
      when String
        name.strip.downcase.to_sym
      when Symbol
        name
      else
        raise ArgumentError, 'Provided MIME Type is not a valid or recognized entry'
      end
    end

  end # MimeType
end # Github

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
github_api-0.9.7 lib/github_api/mime_type.rb
github_api-0.9.6 lib/github_api/mime_type.rb
github_api-0.9.5 lib/github_api/mime_type.rb
github_api-0.9.4 lib/github_api/mime_type.rb
github_api-0.9.3 lib/github_api/mime_type.rb
github_api-0.9.2 lib/github_api/mime_type.rb
github_api-0.9.1 lib/github_api/mime_type.rb
github_api-0.9.0 lib/github_api/mime_type.rb
github_api-0.8.11 lib/github_api/mime_type.rb
github_api-0.8.10 lib/github_api/mime_type.rb
github_api-0.8.9 lib/github_api/mime_type.rb
github_api-0.8.8 lib/github_api/mime_type.rb
github_api-0.8.7 lib/github_api/mime_type.rb
github_api-0.8.6 lib/github_api/mime_type.rb
github_api-0.8.5 lib/github_api/mime_type.rb
github_api-0.8.4 lib/github_api/mime_type.rb
github_api-0.8.3 lib/github_api/mime_type.rb
github_api-0.8.2 lib/github_api/mime_type.rb
github_api-0.8.1 lib/github_api/mime_type.rb
github_api-0.8.0 lib/github_api/mime_type.rb