Class: YandexDostavka::Request
- Inherits:
-
Object
- Object
- YandexDostavka::Request
- Defined in:
- lib/yandex-dostavka/request.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
60- DEFAULT_OPEN_TIMEOUT =
60
Class Attribute Summary collapse
-
.api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
-
.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.
-
.ssl_options ⇒ Object
Returns the value of attribute ssl_options.
-
.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.
-
.token ⇒ Object
Returns the value of attribute token.
Instance Attribute Summary collapse
-
#api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
-
#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.
-
#ssl_options ⇒ Object
Returns the value of attribute ssl_options.
-
#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.
-
#token ⇒ Object
Returns the value of attribute token.
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: {}) ⇒ Object
- #delete(params: nil, headers: nil, body: {}) ⇒ Object
-
#initialize(token: nil, api_endpoint: nil, api_auth_method: nil, timeout: nil, open_timeout: nil, proxy: nil, ssl_options: 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(token: nil, api_endpoint: nil, api_auth_method: nil, timeout: nil, open_timeout: nil, proxy: nil, ssl_options: nil, faraday_adapter: nil, symbolize_keys: false, debug: false, logger: nil, test: false) ⇒ Request
Returns a new instance of Request.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/yandex-dostavka/request.rb', line 10 def initialize(token: nil, api_endpoint: nil, api_auth_method: nil, timeout: nil, open_timeout: nil, proxy: nil, ssl_options: nil, faraday_adapter: nil, symbolize_keys: false, debug: false, logger: nil, test: false) @path_parts = [] @token = token || self.class.token || ENV['YANDEX_DOSTAVKA_TOKEN'] @api_endpoint = api_endpoint || self.class.api_endpoint @api_endpoint = YandexDostavka::api_endpoint if @api_endpoint.nil? @timeout = timeout || self.class.timeout || DEFAULT_TIMEOUT @open_timeout = open_timeout || self.class.open_timeout || DEFAULT_OPEN_TIMEOUT @proxy = proxy || self.class.proxy || ENV['API_PROXY'] = || self.class. || { version: "TLSv1_2" } @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
30 31 32 33 34 35 |
# File 'lib/yandex-dostavka/request.rb', line 30 def method_missing(method, *args) @path_parts << method.to_s.downcase.gsub("_", "-") @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.
84 85 86 |
# File 'lib/yandex-dostavka/request.rb', line 84 def api_endpoint @api_endpoint end |
.debug ⇒ Object
Returns the value of attribute debug.
84 85 86 |
# File 'lib/yandex-dostavka/request.rb', line 84 def debug @debug end |
.faraday_adapter ⇒ Object
Returns the value of attribute faraday_adapter.
84 85 86 |
# File 'lib/yandex-dostavka/request.rb', line 84 def faraday_adapter @faraday_adapter end |
.logger ⇒ Object
Returns the value of attribute logger.
84 85 86 |
# File 'lib/yandex-dostavka/request.rb', line 84 def logger @logger end |
.open_timeout ⇒ Object
Returns the value of attribute open_timeout.
84 85 86 |
# File 'lib/yandex-dostavka/request.rb', line 84 def open_timeout @open_timeout end |
.proxy ⇒ Object
Returns the value of attribute proxy.
84 85 86 |
# File 'lib/yandex-dostavka/request.rb', line 84 def proxy @proxy end |
.ssl_options ⇒ Object
Returns the value of attribute ssl_options.
84 85 86 |
# File 'lib/yandex-dostavka/request.rb', line 84 def end |
.symbolize_keys ⇒ Object
Returns the value of attribute symbolize_keys.
84 85 86 |
# File 'lib/yandex-dostavka/request.rb', line 84 def symbolize_keys @symbolize_keys end |
.test ⇒ Object
Returns the value of attribute test.
84 85 86 |
# File 'lib/yandex-dostavka/request.rb', line 84 def test @test end |
.timeout ⇒ Object
Returns the value of attribute timeout.
84 85 86 |
# File 'lib/yandex-dostavka/request.rb', line 84 def timeout @timeout end |
.token ⇒ Object
Returns the value of attribute token.
84 85 86 |
# File 'lib/yandex-dostavka/request.rb', line 84 def token @token end |
Instance Attribute Details
#api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
3 4 5 |
# File 'lib/yandex-dostavka/request.rb', line 3 def api_endpoint @api_endpoint end |
#debug ⇒ Object
Returns the value of attribute debug.
3 4 5 |
# File 'lib/yandex-dostavka/request.rb', line 3 def debug @debug end |
#faraday_adapter ⇒ Object
Returns the value of attribute faraday_adapter.
3 4 5 |
# File 'lib/yandex-dostavka/request.rb', line 3 def faraday_adapter @faraday_adapter end |
#logger ⇒ Object
Returns the value of attribute logger.
3 4 5 |
# File 'lib/yandex-dostavka/request.rb', line 3 def logger @logger end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
3 4 5 |
# File 'lib/yandex-dostavka/request.rb', line 3 def open_timeout @open_timeout end |
#proxy ⇒ Object
Returns the value of attribute proxy.
3 4 5 |
# File 'lib/yandex-dostavka/request.rb', line 3 def proxy @proxy end |
#ssl_options ⇒ Object
Returns the value of attribute ssl_options.
3 4 5 |
# File 'lib/yandex-dostavka/request.rb', line 3 def end |
#symbolize_keys ⇒ Object
Returns the value of attribute symbolize_keys.
3 4 5 |
# File 'lib/yandex-dostavka/request.rb', line 3 def symbolize_keys @symbolize_keys end |
#test ⇒ Object
Returns the value of attribute test.
3 4 5 |
# File 'lib/yandex-dostavka/request.rb', line 3 def test @test end |
#timeout ⇒ Object
Returns the value of attribute timeout.
3 4 5 |
# File 'lib/yandex-dostavka/request.rb', line 3 def timeout @timeout end |
#token ⇒ Object
Returns the value of attribute token.
3 4 5 |
# File 'lib/yandex-dostavka/request.rb', line 3 def token @token end |
Class Method Details
.method_missing(sym, *args, &block) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/yandex-dostavka/request.rb', line 88 def method_missing(sym, *args, &block) new(token: self.token, api_endpoint: self.api_endpoint, timeout: self.timeout, open_timeout: self.open_timeout, faraday_adapter: self.faraday_adapter, symbolize_keys: self.symbolize_keys, debug: self.debug, proxy: self.proxy, ssl_options: self., logger: self.logger, test: self.test).send(sym, *args, &block) end |
.respond_to_missing?(method_name, include_private = false) ⇒ Boolean
97 98 99 |
# File 'lib/yandex-dostavka/request.rb', line 97 def respond_to_missing?(method_name, include_private = false) true end |
Instance Method Details
#create(params: nil, headers: nil, body: {}) ⇒ Object
53 54 55 56 57 |
# File 'lib/yandex-dostavka/request.rb', line 53 def create(params: nil, headers: nil, body: {}) APIRequest.new(builder: self).post(params: params, headers: headers, body: body) ensure reset end |
#delete(params: nil, headers: nil, body: {}) ⇒ Object
71 72 73 74 75 |
# File 'lib/yandex-dostavka/request.rb', line 71 def delete(params: nil, headers: nil, body: {}) APIRequest.new(builder: self).post(params: params, headers: headers, body: {}) ensure reset end |
#path ⇒ Object
49 50 51 |
# File 'lib/yandex-dostavka/request.rb', line 49 def path @path_parts.join('/') end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
37 38 39 |
# File 'lib/yandex-dostavka/request.rb', line 37 def respond_to_missing?(method_name, include_private = false) true end |
#retrieve(params: nil, headers: nil, body: {}) ⇒ Object
65 66 67 68 69 |
# File 'lib/yandex-dostavka/request.rb', line 65 def retrieve(params: nil, headers: nil, body: {}) APIRequest.new(builder: self).get(params: params, headers: headers, body: body) ensure reset end |
#send(*args) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/yandex-dostavka/request.rb', line 41 def send(*args) if args.length == 0 method_missing(:send, args) else __send__(*args) end end |
#update(params: nil, headers: nil, body: {}) ⇒ Object
59 60 61 62 63 |
# File 'lib/yandex-dostavka/request.rb', line 59 def update(params: nil, headers: nil, body: {}) APIRequest.new(builder: self).post(params: params, headers: headers, body: body) ensure reset end |