Sha256: 54cb5724a15d4ca881ec769f219d3e4846d74e333de9be6c7545113bf721e22a

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

require 'octokit'
require 'octoauth'

module Targit
  ##
  # Helper module to load a GitHub API client object
  module Client
    private

    def client
      @client ||= _client
    end

    def _client
      auth = Octoauth.new octoauth_options
      Octokit::Client.new({
        access_token: auth.token,
        api_endpoint: @options[:api_endpoint],
        web_endpoint: @options[:api_endpoint],
        auto_paginate: true,
        middleware: middleware
      }.compact)
    end

    def middleware
      @middleware ||= Faraday::RackBuilder.new do |builder|
        builder.use Octokit::Response::RaiseError
        builder.request :multipart
      end
    end

    def octoauth_options
      {
        note: 'targit',
        files: authfiles,
        autosave: @options[:autosave] || true,
        api_endpoint: @options[:api_endpoint],
        scopes: ['public_repo']
      }
    end

    def authfiles
      return [:default] unless @options[:authfile]
      @authfiles ||= @options[:authfile].split(',')
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
targit-2.5.2 lib/targit/client.rb
targit-2.5.1 lib/targit/client.rb
targit-2.5.0 lib/targit/client.rb
targit-2.4.8 lib/targit/client.rb