Class: Telegem::API::Client
- Inherits:
-
Object
- Object
- Telegem::API::Client
- Defined in:
- lib/api/client.rb
Constant Summary collapse
- BASE_URL =
'https://api.telegram.org'
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #call(method, params = {}) ⇒ Object
- #close ⇒ Object
- #get_updates(offset: nil, timeout: 30, limit: 100) ⇒ Object
-
#initialize(token, endpoint: nil, logger: nil) ⇒ Client
constructor
A new instance of Client.
- #upload(method, params) ⇒ Object
Constructor Details
#initialize(token, endpoint: nil, logger: nil) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 |
# File 'lib/api/client.rb', line 8 def initialize(token, endpoint: nil, logger: nil) @token = token @logger = logger || Logger.new($stdout) @endpoint = endpoint || Async::HTTP::Endpoint.parse("#{BASE_URL}/bot#{token}") @client = nil @semaphore = Async::Semaphore.new(30) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/api/client.rb', line 6 def logger @logger end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/api/client.rb', line 6 def token @token end |
Instance Method Details
#call(method, params = {}) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/api/client.rb', line 16 def call(method, params = {}) Async do |task| @semaphore.async do make_request(method, clean_params(params)) end end end |
#close ⇒ Object
38 39 40 |
# File 'lib/api/client.rb', line 38 def close @client&.close end |
#get_updates(offset: nil, timeout: 30, limit: 100) ⇒ Object
32 33 34 35 36 |
# File 'lib/api/client.rb', line 32 def get_updates(offset: nil, timeout: 30, limit: 100) params = { timeout: timeout, limit: limit } params[:offset] = offset if offset call('getUpdates', params) end |
#upload(method, params) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/api/client.rb', line 24 def upload(method, params) Async do |task| @semaphore.async do make_multipart_request(method, params) end end end |