Class: Hubscreen::Request
- Inherits:
-
Object
- Object
- Hubscreen::Request
- Defined in:
- lib/hubscreen/request.rb
Overview
Primary Request Object for API Access
Remember to protect all API requests with error handling to catch non 200 response codes
Constant Summary collapse
- DEFAULT_TIMEOUT =
30
Class Attribute Summary collapse
-
.api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.proxy ⇒ Object
Returns the value of attribute proxy.
-
.timeout ⇒ Object
Returns the value of attribute timeout.
Instance Attribute Summary collapse
-
#api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#faraday_adapter ⇒ Object
Returns the value of attribute faraday_adapter.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Class Method Summary collapse
Instance Method Summary collapse
- #delete(params: nil, headers: nil) ⇒ Object
- #get(params: nil, headers: nil) ⇒ Object
-
#initialize(api_key: nil, api_endpoint: nil, timeout: nil, proxy: nil, faraday_adapter: nil, debug: false) ⇒ Request
constructor
A new instance of Request.
- #method_missing(method, *args) ⇒ Object
- #patch(params: nil, headers: nil, body: nil) ⇒ Object
- #path ⇒ Object
- #post(params: nil, headers: nil, body: nil) ⇒ Object
- #put(params: nil, headers: nil, body: nil) ⇒ Object
- #send(*args) ⇒ Object
Constructor Details
#initialize(api_key: nil, api_endpoint: nil, timeout: nil, proxy: nil, faraday_adapter: nil, debug: false) ⇒ Request
Returns a new instance of Request.
11 12 13 14 15 16 17 18 19 20 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
22 23 24 25 26 27 28 |
# 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 |
Class Attribute Details
.api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
79 80 81 |
# File 'lib/hubscreen/request.rb', line 79 def api_endpoint @api_endpoint end |
.api_key ⇒ Object
Returns the value of attribute api_key.
79 80 81 |
# File 'lib/hubscreen/request.rb', line 79 def api_key @api_key end |
.proxy ⇒ Object
Returns the value of attribute proxy.
79 80 81 |
# File 'lib/hubscreen/request.rb', line 79 def proxy @proxy end |
.timeout ⇒ Object
Returns the value of attribute timeout.
79 80 81 |
# File 'lib/hubscreen/request.rb', line 79 def timeout @timeout end |
Instance Attribute Details
#api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
7 8 9 |
# File 'lib/hubscreen/request.rb', line 7 def api_endpoint @api_endpoint end |
#api_key ⇒ Object
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/hubscreen/request.rb', line 7 def api_key @api_key end |
#debug ⇒ Object
Returns the value of attribute debug.
7 8 9 |
# File 'lib/hubscreen/request.rb', line 7 def debug @debug end |
#faraday_adapter ⇒ Object
Returns the value of attribute faraday_adapter.
7 8 9 |
# File 'lib/hubscreen/request.rb', line 7 def faraday_adapter @faraday_adapter end |
#proxy ⇒ Object
Returns the value of attribute proxy.
7 8 9 |
# File 'lib/hubscreen/request.rb', line 7 def proxy @proxy end |
#timeout ⇒ Object
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/hubscreen/request.rb', line 7 def timeout @timeout end |
Class Method Details
.method_missing(sym, *args, &block) ⇒ Object
81 82 83 |
# 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 |
Instance Method Details
#delete(params: nil, headers: nil) ⇒ Object
66 67 68 69 70 |
# 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) ⇒ Object
60 61 62 63 64 |
# 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 |
#patch(params: nil, headers: nil, body: nil) ⇒ Object
48 49 50 51 52 |
# 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 ⇒ Object
38 39 40 |
# File 'lib/hubscreen/request.rb', line 38 def path @path_parts.join('/') end |
#post(params: nil, headers: nil, body: nil) ⇒ Object
42 43 44 45 46 |
# 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) ⇒ Object
54 55 56 57 58 |
# 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) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/hubscreen/request.rb', line 30 def send(*args) if args.length == 0 method_missing(:send, args) else __send__(*args) end end |