class GitHubBub::Request
Constants
- BASE_HEADERS
- BASE_OPTIONS
- BASE_URI
- GITHUB_VERSION
- RAISE_ON_FAIL
- RETRIES
Attributes
options[RW]
token[RW]
token?[RW]
url[RW]
Public Class Methods
before_callbacks()
click to toggle source
# File lib/git_hub_bub/request.rb, line 131 def self.before_callbacks @before_callbacks ||=[] end
clear_callbacks()
click to toggle source
# File lib/git_hub_bub/request.rb, line 135 def self.clear_callbacks @before_callbacks = [] end
delete(url, query = {}, options = {})
click to toggle source
# File lib/git_hub_bub/request.rb, line 81 def self.delete(url, query = {}, options = {}) self.new(url, query, options).delete end
get(url, query = {}, options = {})
click to toggle source
# File lib/git_hub_bub/request.rb, line 39 def self.get(url, query = {}, options = {}) self.new(url, query, options).get end
head(url, query = {}, options = {})
click to toggle source
# File lib/git_hub_bub/request.rb, line 29 def self.head(url, query = {}, options = {}) self.new(url, query, options).head end
new(url, query = {}, options = {})
click to toggle source
# File lib/git_hub_bub/request.rb, line 17 def initialize(url, query = {}, options = {}) self.url = url =~ /^http(\w?)\:\/\// ? url : File.join(BASE_URI, url) @skip_token = options.delete(:skip_token) self.options = BASE_OPTIONS.merge(options || {}) self.options[:query] = query if query && !query.empty? self.options[:headers] = BASE_HEADERS.merge(options[:headers]|| {}) end
patch(url, query = {}, options = {})
click to toggle source
# File lib/git_hub_bub/request.rb, line 61 def self.patch(url, query = {}, options = {}) self.new(url, query, options).patch end
post(url, query = {}, options = {})
click to toggle source
# File lib/git_hub_bub/request.rb, line 51 def self.post(url, query = {}, options = {}) self.new(url, query, options).post end
put(url, query = {}, options = {})
click to toggle source
# File lib/git_hub_bub/request.rb, line 71 def self.put(url, query = {}, options = {}) self.new(url, query, options).put end
set_before_callback(&block)
click to toggle source
# File lib/git_hub_bub/request.rb, line 127 def self.set_before_callback(&block) before_callbacks << block end
Public Instance Methods
before_callbacks!()
click to toggle source
# File lib/git_hub_bub/request.rb, line 139 def before_callbacks! self.class.before_callbacks.each do |callback| run_callback &callback end end
delete()
click to toggle source
# File lib/git_hub_bub/request.rb, line 85 def delete wrap_request do Excon.delete(url, options) end end
get()
click to toggle source
# File lib/git_hub_bub/request.rb, line 43 def get wrap_request do ex = Excon.get(url, options) ex = Excon.get(@location, options) if @location = ex.headers["Location"] ex end end
head()
click to toggle source
# File lib/git_hub_bub/request.rb, line 33 def head wrap_request do Excon.head(url, options) end end
patch()
click to toggle source
# File lib/git_hub_bub/request.rb, line 65 def patch wrap_request do Excon.patch(url, options) end end
post()
click to toggle source
# File lib/git_hub_bub/request.rb, line 55 def post wrap_request do Excon.post(url, options) end end
put()
click to toggle source
# File lib/git_hub_bub/request.rb, line 75 def put wrap_request do Excon.put(url, options) end end
query_to_json_body!()
click to toggle source
do they take query params? do they take :body? who cares, send them both!
# File lib/git_hub_bub/request.rb, line 107 def query_to_json_body! options[:body] = options[:query].to_json if options[:query] end
run_callback() { |self| ... }
click to toggle source
# File lib/git_hub_bub/request.rb, line 145 def run_callback(&block) yield self end
set_auth_from_token!()
click to toggle source
# File lib/git_hub_bub/request.rb, line 111 def set_auth_from_token! return unless token options[:headers]["Authorization"] ||= "token #{token}" end
skip_token?()
click to toggle source
# File lib/git_hub_bub/request.rb, line 25 def skip_token? @skip_token end
wrap_request() { || ... }
click to toggle source
# File lib/git_hub_bub/request.rb, line 91 def wrap_request(&block) before_callbacks! set_auth_from_token! unless skip_token? query_to_json_body! response = RETRIES.times.retry do GitHubBub::Response.create(yield) end if RAISE_ON_FAIL raise RequestError, "message: '#{response.json_body['message']}', url: '#{url}', response: '#{response.inspect}'" unless response.success? end return response end