Sha256: acdb52d16a37ba151f95577e6d9fe20da7c9276265ec46cf48535d87265cde70

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

require 'httparty'

module Fasterer
  module Github
    class ApiWrapper
      BASE_URI = 'https://api.github.com'

      def initialize(owner, repo)
        @owner = owner
        @repo = repo
        @access_token = Fasterer::Github.configuration.access_token.to_s
        @client_id = Fasterer::Github.configuration.client_id.to_s
        @client_secret = Fasterer::Github.configuration.client_secret.to_s
      end

      def contents(path)
        HTTParty.get(build_uri(path), query: authorization_params)
      end

      private

      attr_reader :owner, :repo, :path, :client_id, :client_secret, :access_token

      def build_uri(path)
        BASE_URI + "/repos/#{owner}/#{repo}/contents/#{path}"
      end

      def authorization_params
        return access_token_hash unless access_token.empty?
        return client_id_secret_hash unless client_id.empty? && client_secret.empty?
      end

      def access_token_hash
        { 'access_token' => access_token }
      end

      def client_id_secret_hash
        { 'client_id' => client_id, 'client_secret' => client_secret }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fasterer-github-0.2.1 lib/fasterer/github/api_wrapper.rb
fasterer-github-0.2.0 lib/fasterer/github/api_wrapper.rb