class Hubscreen::Request
Primary Request
Object for API Access
Remember to protect all API requests with error handling to catch non 200 response codes
Constants
- DEFAULT_TIMEOUT
Attributes
api_endpoint[RW]
api_key[RW]
proxy[RW]
timeout[RW]
api_endpoint[RW]
api_key[RW]
debug[RW]
faraday_adapter[RW]
proxy[RW]
timeout[RW]
Public Class Methods
new(api_key: nil, api_endpoint: nil, timeout: nil, proxy: nil, faraday_adapter: nil, debug: false)
click to toggle source
# File lib/hubscreen/request.rb, line 11 def initialize(api_key: nil, api_endpoint: nil, timeout: nil, proxy: nil, faraday_adapter: nil, debug: false) @path_parts = [] @api_key = api_key || self.class.api_key || Hubscreen::Config.hapikey @api_key = @api_key.strip if @api_key @api_endpoint = api_endpoint || self.class.api_endpoint || Hubscreen::Config.base_url @timeout = timeout || self.class.timeout || DEFAULT_TIMEOUT @proxy = proxy || self.class.proxy || ENV['HUBSCREEN_PROXY'] @faraday_adapter = faraday_adapter || Faraday.default_adapter @debug = debug end
Protected Class Methods
method_missing(sym, *args, &block)
click to toggle source
# File lib/hubscreen/request.rb, line 81 def method_missing(sym, *args, &block) new(api_key: self.api_key, api_endpoint: self.api_endpoint, timeout: self.timeout, proxy: self.proxy).send(sym, *args, &block) end
Public Instance Methods
delete(params: nil, headers: nil)
click to toggle source
# File lib/hubscreen/request.rb, line 66 def delete(params: nil, headers: nil) APIRequest.new(builder: self).delete(params: params, headers: headers) ensure reset end
get(params: nil, headers: nil)
click to toggle source
# File lib/hubscreen/request.rb, line 60 def get(params: nil, headers: nil) APIRequest.new(builder: self).get(params: params, headers: headers) ensure reset end
method_missing(method, *args)
click to toggle source
# File lib/hubscreen/request.rb, line 22 def method_missing(method, *args) @path_parts << method.to_s.downcase @path_parts << args if args.length > 0 @path_parts.flatten! self end
patch(params: nil, headers: nil, body: nil)
click to toggle source
# File lib/hubscreen/request.rb, line 48 def patch(params: nil, headers: nil, body: nil) APIRequest.new(builder: self).patch(params: params, headers: headers, body: body) ensure reset end
path()
click to toggle source
# File lib/hubscreen/request.rb, line 38 def path @path_parts.join('/') end
post(params: nil, headers: nil, body: nil)
click to toggle source
# File lib/hubscreen/request.rb, line 42 def post(params: nil, headers: nil, body: nil) APIRequest.new(builder: self).post(params: params, headers: headers, body: body) ensure reset end
put(params: nil, headers: nil, body: nil)
click to toggle source
# File lib/hubscreen/request.rb, line 54 def put(params: nil, headers: nil, body: nil) APIRequest.new(builder: self).put(params: params, headers: headers, body: body) ensure reset end
send(*args)
click to toggle source
# File lib/hubscreen/request.rb, line 30 def send(*args) if args.length == 0 method_missing(:send, args) else __send__(*args) end end
Protected Instance Methods
reset()
click to toggle source
# File lib/hubscreen/request.rb, line 74 def reset @path_parts = [] end