File: custom_limit.rb

package info (click to toggle)
ruby-gh 0.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,644 kB
  • sloc: ruby: 1,793; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 657 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

module GH
  # Adds Client info so even unauthenticated requests can use a custom request limit
  class CustomLimit < Wrapper
    attr_accessor :client_id, :client_secret

    def setup(backend, options)
      @client_id = options[:client_id]
      @client_secret = options[:client_secret]
      super
    end

    def full_url(key)
      return super unless client_id

      url = super
      params = url.query_values || {}

      unless params.include? 'client_id'
        params['client_id'] = client_id
        params['client_secret'] = client_secret
      end

      url.query_values = params
      url
    end
  end
end