Class: Hubscreen::Request
- Inherits:
-
Object
- Object
- Hubscreen::Request
- Defined in:
- lib/hubscreen/request.rb
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.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/hubscreen/request.rb', line 7 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
18 19 20 21 22 23 24 |
# File 'lib/hubscreen/request.rb', line 18 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.
75 76 77 |
# File 'lib/hubscreen/request.rb', line 75 def api_endpoint @api_endpoint end |
.api_key ⇒ Object
Returns the value of attribute api_key.
75 76 77 |
# File 'lib/hubscreen/request.rb', line 75 def api_key @api_key end |
.proxy ⇒ Object
Returns the value of attribute proxy.
75 76 77 |
# File 'lib/hubscreen/request.rb', line 75 def proxy @proxy end |
.timeout ⇒ Object
Returns the value of attribute timeout.
75 76 77 |
# File 'lib/hubscreen/request.rb', line 75 def timeout @timeout end |
Instance Attribute Details
#api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
3 4 5 |
# File 'lib/hubscreen/request.rb', line 3 def api_endpoint @api_endpoint end |
#api_key ⇒ Object
Returns the value of attribute api_key.
3 4 5 |
# File 'lib/hubscreen/request.rb', line 3 def api_key @api_key end |
#debug ⇒ Object
Returns the value of attribute debug.
3 4 5 |
# File 'lib/hubscreen/request.rb', line 3 def debug @debug end |
#faraday_adapter ⇒ Object
Returns the value of attribute faraday_adapter.
3 4 5 |
# File 'lib/hubscreen/request.rb', line 3 def faraday_adapter @faraday_adapter end |
#proxy ⇒ Object
Returns the value of attribute proxy.
3 4 5 |
# File 'lib/hubscreen/request.rb', line 3 def proxy @proxy end |
#timeout ⇒ Object
Returns the value of attribute timeout.
3 4 5 |
# File 'lib/hubscreen/request.rb', line 3 def timeout @timeout end |
Class Method Details
.method_missing(sym, *args, &block) ⇒ Object
77 78 79 |
# File 'lib/hubscreen/request.rb', line 77 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
62 63 64 65 66 |
# File 'lib/hubscreen/request.rb', line 62 def delete(params: nil, headers: nil) APIRequest.new(builder: self).delete(params: params, headers: headers) ensure reset end |
#get(params: nil, headers: nil) ⇒ Object
56 57 58 59 60 |
# File 'lib/hubscreen/request.rb', line 56 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
44 45 46 47 48 |
# File 'lib/hubscreen/request.rb', line 44 def patch(params: nil, headers: nil, body: nil) APIRequest.new(builder: self).patch(params: params, headers: headers, body: body) ensure reset end |
#path ⇒ Object
34 35 36 |
# File 'lib/hubscreen/request.rb', line 34 def path @path_parts.join('/') end |
#post(params: nil, headers: nil, body: nil) ⇒ Object
38 39 40 41 42 |
# File 'lib/hubscreen/request.rb', line 38 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
50 51 52 53 54 |
# File 'lib/hubscreen/request.rb', line 50 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
26 27 28 29 30 31 32 |
# File 'lib/hubscreen/request.rb', line 26 def send(*args) if args.length == 0 method_missing(:send, args) else __send__(*args) end end |