Class: DaazwebApi::Request
- Inherits:
-
Object
- Object
- DaazwebApi::Request
- Defined in:
- lib/daazweb-api/request.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
60- DEFAULT_OPEN_TIMEOUT =
60
Class Attribute Summary collapse
-
.access_token ⇒ Object
Returns the value of attribute access_token.
-
.debug ⇒ Object
Returns the value of attribute debug.
-
.faraday_adapter ⇒ Object
Returns the value of attribute faraday_adapter.
-
.logger ⇒ Object
Returns the value of attribute logger.
-
.open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
.proxy ⇒ Object
Returns the value of attribute proxy.
-
.symbolize_keys ⇒ Object
Returns the value of attribute symbolize_keys.
-
.test ⇒ Object
Returns the value of attribute test.
-
.timeout ⇒ Object
Returns the value of attribute timeout.
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#faraday_adapter ⇒ Object
Returns the value of attribute faraday_adapter.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#symbolize_keys ⇒ Object
Returns the value of attribute symbolize_keys.
-
#test ⇒ Object
Returns the value of attribute test.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Class Method Summary collapse
- .method_missing(sym, *args, &block) ⇒ Object
- .respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Instance Method Summary collapse
- #create(params: nil, headers: nil, body: {}, suffix: 'create') ⇒ Object
- #delete(params: nil, headers: nil, body: {}) ⇒ Object
-
#initialize(access_token: nil, timeout: nil, open_timeout: nil, proxy: nil, faraday_adapter: nil, symbolize_keys: false, debug: false, logger: nil, test: false) ⇒ Request
constructor
A new instance of Request.
- #method_missing(method, *args) ⇒ Object
- #path ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
- #retrieve(params: nil, headers: nil, body: {}) ⇒ Object
- #send(*args) ⇒ Object
- #update(params: nil, headers: nil, body: {}) ⇒ Object
Constructor Details
#initialize(access_token: nil, timeout: nil, open_timeout: nil, proxy: nil, faraday_adapter: nil, symbolize_keys: false, debug: false, logger: nil, test: false) ⇒ Request
Returns a new instance of Request.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/daazweb-api/request.rb', line 9 def initialize(access_token: nil, timeout: nil, open_timeout: nil, proxy: nil, faraday_adapter: nil, symbolize_keys: false, debug: false, logger: nil, test: false) @path_parts = [] @access_token = access_token || self.class.access_token || DaazwebApi.generate_access_token.try(:dig, "access_token") @timeout = timeout || self.class.timeout || DEFAULT_TIMEOUT @open_timeout = open_timeout || self.class.open_timeout || DEFAULT_OPEN_TIMEOUT @proxy = proxy || self.class.proxy || ENV['DAAZWEB_API_PROXY'] @faraday_adapter = faraday_adapter || self.class.faraday_adapter || Faraday.default_adapter @symbolize_keys = symbolize_keys || self.class.symbolize_keys || false @debug = debug || self.class.debug || false @test = test || self.class.test || false @logger = logger || self.class.logger || ::Logger.new(STDOUT) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/daazweb-api/request.rb', line 24 def method_missing(method, *args) p = method.to_s.split('_').collect(&:capitalize).join p[0] = p[0].to_s.downcase @path_parts << p @path_parts << args if args.length > 0 @path_parts.flatten! self end |
Class Attribute Details
.access_token ⇒ Object
Returns the value of attribute access_token.
80 81 82 |
# File 'lib/daazweb-api/request.rb', line 80 def access_token @access_token end |
.debug ⇒ Object
Returns the value of attribute debug.
80 81 82 |
# File 'lib/daazweb-api/request.rb', line 80 def debug @debug end |
.faraday_adapter ⇒ Object
Returns the value of attribute faraday_adapter.
80 81 82 |
# File 'lib/daazweb-api/request.rb', line 80 def faraday_adapter @faraday_adapter end |
.logger ⇒ Object
Returns the value of attribute logger.
80 81 82 |
# File 'lib/daazweb-api/request.rb', line 80 def logger @logger end |
.open_timeout ⇒ Object
Returns the value of attribute open_timeout.
80 81 82 |
# File 'lib/daazweb-api/request.rb', line 80 def open_timeout @open_timeout end |
.proxy ⇒ Object
Returns the value of attribute proxy.
80 81 82 |
# File 'lib/daazweb-api/request.rb', line 80 def proxy @proxy end |
.symbolize_keys ⇒ Object
Returns the value of attribute symbolize_keys.
80 81 82 |
# File 'lib/daazweb-api/request.rb', line 80 def symbolize_keys @symbolize_keys end |
.test ⇒ Object
Returns the value of attribute test.
80 81 82 |
# File 'lib/daazweb-api/request.rb', line 80 def test @test end |
.timeout ⇒ Object
Returns the value of attribute timeout.
80 81 82 |
# File 'lib/daazweb-api/request.rb', line 80 def timeout @timeout end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
3 4 5 |
# File 'lib/daazweb-api/request.rb', line 3 def access_token @access_token end |
#debug ⇒ Object
Returns the value of attribute debug.
3 4 5 |
# File 'lib/daazweb-api/request.rb', line 3 def debug @debug end |
#faraday_adapter ⇒ Object
Returns the value of attribute faraday_adapter.
3 4 5 |
# File 'lib/daazweb-api/request.rb', line 3 def faraday_adapter @faraday_adapter end |
#logger ⇒ Object
Returns the value of attribute logger.
3 4 5 |
# File 'lib/daazweb-api/request.rb', line 3 def logger @logger end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
3 4 5 |
# File 'lib/daazweb-api/request.rb', line 3 def open_timeout @open_timeout end |
#proxy ⇒ Object
Returns the value of attribute proxy.
3 4 5 |
# File 'lib/daazweb-api/request.rb', line 3 def proxy @proxy end |
#symbolize_keys ⇒ Object
Returns the value of attribute symbolize_keys.
3 4 5 |
# File 'lib/daazweb-api/request.rb', line 3 def symbolize_keys @symbolize_keys end |
#test ⇒ Object
Returns the value of attribute test.
3 4 5 |
# File 'lib/daazweb-api/request.rb', line 3 def test @test end |
#timeout ⇒ Object
Returns the value of attribute timeout.
3 4 5 |
# File 'lib/daazweb-api/request.rb', line 3 def timeout @timeout end |
Class Method Details
.method_missing(sym, *args, &block) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/daazweb-api/request.rb', line 83 def method_missing(sym, *args, &block) new(access_token: self.access_token, timeout: self.timeout, open_timeout: self.open_timeout, faraday_adapter: self.faraday_adapter, symbolize_keys: self.symbolize_keys, debug: self.debug, proxy: self.proxy, logger: self.logger, test: self.test).send(sym, *args, &block) end |
.respond_to_missing?(method_name, include_private = false) ⇒ Boolean
91 92 93 |
# File 'lib/daazweb-api/request.rb', line 91 def respond_to_missing?(method_name, include_private = false) true end |
Instance Method Details
#create(params: nil, headers: nil, body: {}, suffix: 'create') ⇒ Object
49 50 51 52 53 |
# File 'lib/daazweb-api/request.rb', line 49 def create(params: nil, headers: nil, body: {}, suffix: 'create') APIRequest.new(builder: self).post(params: params, headers: headers, suffix: suffix, body: body) ensure reset end |
#delete(params: nil, headers: nil, body: {}) ⇒ Object
67 68 69 70 71 |
# File 'lib/daazweb-api/request.rb', line 67 def delete(params: nil, headers: nil, body: {}) APIRequest.new(builder: self).post(params: params, headers: headers, body: {}, suffix: 'delete') ensure reset end |
#path ⇒ Object
45 46 47 |
# File 'lib/daazweb-api/request.rb', line 45 def path @path_parts.join('/') end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
33 34 35 |
# File 'lib/daazweb-api/request.rb', line 33 def respond_to_missing?(method_name, include_private = false) true end |
#retrieve(params: nil, headers: nil, body: {}) ⇒ Object
61 62 63 64 65 |
# File 'lib/daazweb-api/request.rb', line 61 def retrieve(params: nil, headers: nil, body: {}) APIRequest.new(builder: self).get(params: params, headers: headers, body: body) ensure reset end |
#send(*args) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/daazweb-api/request.rb', line 37 def send(*args) if args.length == 0 method_missing(:send, args) else __send__(*args) end end |
#update(params: nil, headers: nil, body: {}) ⇒ Object
55 56 57 58 59 |
# File 'lib/daazweb-api/request.rb', line 55 def update(params: nil, headers: nil, body: {}) APIRequest.new(builder: self).post(params: params, headers: headers, suffix: 'edit', body: body) ensure reset end |