Class: KinopoiskUnofficialApi::Client
- Inherits:
-
Object
- Object
- KinopoiskUnofficialApi::Client
- Defined in:
- lib/kinopoisk_unofficial_api/client.rb
Instance Attribute Summary collapse
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #call(method_name, raw_params = {}) ⇒ Object
- #connection ⇒ Object
-
#initialize(secret_key, url: "https://kinopoiskapiunofficial.tech") ⇒ Client
constructor
A new instance of Client.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(*args) ⇒ Boolean
Constructor Details
#initialize(secret_key, url: "https://kinopoiskapiunofficial.tech") ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/kinopoisk_unofficial_api/client.rb', line 7 def initialize(secret_key, url: "https://kinopoiskapiunofficial.tech") @secret_key = secret_key @url = url end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/kinopoisk_unofficial_api/client.rb', line 20 def method_missing(method_name, *args, &block) return super unless ENDPOINTS.key?(method_name) result = call(method_name, *args) ENDPOINTS[method_name][:response_type].call(result) end |
Instance Attribute Details
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
5 6 7 |
# File 'lib/kinopoisk_unofficial_api/client.rb', line 5 def secret_key @secret_key end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/kinopoisk_unofficial_api/client.rb', line 5 def url @url end |
Instance Method Details
#call(method_name, raw_params = {}) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/kinopoisk_unofficial_api/client.rb', line 34 def call(method_name, raw_params = {}) params = build_params(method_name, raw_params) path = build_path(method_name, params) response = connection.get(path, params) raise Exceptions::ResponseError.new(response: response) unless response.status == 200 JSON.parse(response.body) end |
#connection ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/kinopoisk_unofficial_api/client.rb', line 12 def connection @connection ||= Faraday.new(url: url, headers: { "X-API-KEY" => secret_key }) do |faraday| faraday.adapter KinopoiskUnofficialApi.configuration.adapter faraday..timeout = KinopoiskUnofficialApi.configuration.connection_timeout faraday..open_timeout = KinopoiskUnofficialApi.configuration.connection_open_timeout end end |
#respond_to_missing?(*args) ⇒ Boolean
28 29 30 31 32 |
# File 'lib/kinopoisk_unofficial_api/client.rb', line 28 def respond_to_missing?(*args) method_name = args[0] ENDPOINTS.key?(method_name) || super end |