Sha256: cf954e63dfd7ee179acda30f8a2cc0280081c0cb4cf9b320441e037e52f23a2d

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'httparty'

module Fasterer
  module Github
    class ApiWrapper
      BASE_URL = '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)
        url = build_url(path)
        HTTParty.get(url)
      end

      private

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

      def build_url(path)
        url = BASE_URL + "/repos/#{owner}/#{repo}/contents/#{path}"
        return add_access_token(url) if access_token != ''
        return add_client_id_and_secret(url) if client_id != '' && client_secret != ''
        url
      end

      def add_access_token(url)
        url + "?access_token=#{access_token}"
      end

      def add_client_id_and_secret(url)
        url + "?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.1.1 lib/fasterer/github/api_wrapper.rb
fasterer-github-0.1.0 lib/fasterer/github/api_wrapper.rb