Class: MaxApiClient::Api
- Inherits:
-
Object
- Object
- MaxApiClient::Api
- Defined in:
- lib/max_api_client/api.rb,
sig/max_api_client.rbs
Overview
High-level convenience wrapper over grouped Max Bot API endpoints.
Instance Attribute Summary collapse
-
#client ⇒ Client
readonly
Returns the value of attribute client.
-
#raw ⇒ RawApi
readonly
Returns the value of attribute raw.
-
#upload ⇒ Upload
readonly
Returns the value of attribute upload.
Instance Method Summary collapse
- #add_chat_members(chat_id, user_ids) ⇒ Object
- #answer_on_callback(callback_id, **extra) ⇒ Object
- #delete_message(message_id, **extra) ⇒ Object
-
#delete_my_commands ⇒ Object
rubocop:enable Naming/AccessorMethodName.
- #edit_chat_info(chat_id, **extra) ⇒ Object
- #edit_message(message_id, **extra) ⇒ Object
-
#edit_my_info(**extra) ⇒ Object
rubocop:enable Naming/AccessorMethodName.
- #get_all_chats(**extra) ⇒ Object
- #get_chat(chat_id) ⇒ Object
- #get_chat_admins(chat_id) ⇒ Object
- #get_chat_by_link(chat_link) ⇒ Object
- #get_chat_members(chat_id, **extra) ⇒ Object
- #get_chat_membership(chat_id) ⇒ Object
- #get_message(message_id) ⇒ Object
- #get_messages(chat_id, **extra) ⇒ Object
-
#get_my_info ⇒ Object
rubocop:disable Naming/AccessorMethodName.
- #get_pinned_message(chat_id) ⇒ Object
-
#get_subscriptions ⇒ Object
rubocop:disable Naming/AccessorMethodName.
-
#initialize(token:, base_url: Client::DEFAULT_BASE_URL, adapter: nil, open_timeout: nil, read_timeout: nil, ca_file: Client::DEFAULT_CA_FILE, verify_ssl: true, logger: nil) ⇒ Api
constructor
rubocop:disable Metrics/ParameterLists.
- #leave_chat(chat_id) ⇒ Object
- #pin_message(chat_id, message_id, **extra) ⇒ Object
- #poll_updates(types = [], marker: nil, timeout: Polling::DEFAULT_TIMEOUT, retry_interval: Polling::DEFAULT_RETRY_INTERVAL, read_timeout: nil) {|update| ... } ⇒ Polling
- #remove_chat_member(chat_id, user_id, block: nil) ⇒ Object
- #send_action(chat_id, action) ⇒ Object
- #send_message_to_chat(chat_id, text, **extra) ⇒ Object
- #send_message_to_user(user_id, text, **extra) ⇒ Object
-
#set_my_commands(commands) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
-
#subscribe(url, update_types: nil, secret: nil) ⇒ Object
rubocop:enable Naming/AccessorMethodName.
- #unpin_message(chat_id) ⇒ Object
- #unsubscribe(url) ⇒ Object
- #upload_audio(options) ⇒ AudioAttachment
- #upload_file(options) ⇒ FileAttachment
- #upload_image(options) ⇒ ImageAttachment
- #upload_video(options) ⇒ VideoAttachment
Constructor Details
#initialize(token:, base_url: Client::DEFAULT_BASE_URL, adapter: nil, open_timeout: nil, read_timeout: nil, ca_file: Client::DEFAULT_CA_FILE, verify_ssl: true, logger: nil) ⇒ Api
rubocop:disable Metrics/ParameterLists
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/max_api_client/api.rb', line 9 def initialize(token:, base_url: Client::DEFAULT_BASE_URL, adapter: nil, open_timeout: nil, read_timeout: nil, ca_file: Client::DEFAULT_CA_FILE, verify_ssl: true, logger: nil) @client = Client.new( token:, base_url:, adapter:, open_timeout:, read_timeout:, ca_file:, verify_ssl:, logger: ) @raw = RawApi.new(client) @upload = Upload.new(self) end |
Instance Attribute Details
#client ⇒ Client (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/max_api_client/api.rb', line 6 def client @client end |
#raw ⇒ RawApi (readonly)
Returns the value of attribute raw.
6 7 8 |
# File 'lib/max_api_client/api.rb', line 6 def raw @raw end |
#upload ⇒ Upload (readonly)
Returns the value of attribute upload.
6 7 8 |
# File 'lib/max_api_client/api.rb', line 6 def upload @upload end |
Instance Method Details
#add_chat_members(chat_id, user_ids) ⇒ Object
70 71 72 |
# File 'lib/max_api_client/api.rb', line 70 def add_chat_members(chat_id, user_ids) raw.chats.add_chat_members(chat_id:, user_ids:) end |
#answer_on_callback(callback_id, **extra) ⇒ Object
126 127 128 |
# File 'lib/max_api_client/api.rb', line 126 def answer_on_callback(callback_id, **extra) raw..answer_on_callback(callback_id:, **extra) end |
#delete_message(message_id, **extra) ⇒ Object
122 123 124 |
# File 'lib/max_api_client/api.rb', line 122 def (, **extra) raw..delete(message_id:, **extra) end |
#delete_my_commands ⇒ Object
rubocop:enable Naming/AccessorMethodName
42 43 44 |
# File 'lib/max_api_client/api.rb', line 42 def delete_my_commands edit_my_info(commands: []) end |
#edit_chat_info(chat_id, **extra) ⇒ Object
58 59 60 |
# File 'lib/max_api_client/api.rb', line 58 def edit_chat_info(chat_id, **extra) raw.chats.edit(chat_id:, **extra) end |
#edit_message(message_id, **extra) ⇒ Object
118 119 120 |
# File 'lib/max_api_client/api.rb', line 118 def (, **extra) raw..edit(message_id:, **extra) end |
#edit_my_info(**extra) ⇒ Object
rubocop:enable Naming/AccessorMethodName
32 33 34 |
# File 'lib/max_api_client/api.rb', line 32 def edit_my_info(**extra) raw.bots.edit_my_info(**extra) end |
#get_all_chats(**extra) ⇒ Object
46 47 48 |
# File 'lib/max_api_client/api.rb', line 46 def get_all_chats(**extra) raw.chats.get_all(**extra) end |
#get_chat(chat_id) ⇒ Object
50 51 52 |
# File 'lib/max_api_client/api.rb', line 50 def get_chat(chat_id) raw.chats.get_by_id(chat_id:) end |
#get_chat_admins(chat_id) ⇒ Object
66 67 68 |
# File 'lib/max_api_client/api.rb', line 66 def get_chat_admins(chat_id) raw.chats.get_chat_admins(chat_id:) end |
#get_chat_by_link(chat_link) ⇒ Object
54 55 56 |
# File 'lib/max_api_client/api.rb', line 54 def get_chat_by_link(chat_link) raw.chats.get_by_link(chat_link:) end |
#get_chat_members(chat_id, **extra) ⇒ Object
74 75 76 |
# File 'lib/max_api_client/api.rb', line 74 def get_chat_members(chat_id, **extra) raw.chats.get_chat_members(chat_id:, **csv_query(extra, :user_ids)) end |
#get_chat_membership(chat_id) ⇒ Object
62 63 64 |
# File 'lib/max_api_client/api.rb', line 62 def get_chat_membership(chat_id) raw.chats.get_chat_membership(chat_id:) end |
#get_message(message_id) ⇒ Object
114 115 116 |
# File 'lib/max_api_client/api.rb', line 114 def () raw..get_by_id(message_id:) end |
#get_messages(chat_id, **extra) ⇒ Object
110 111 112 |
# File 'lib/max_api_client/api.rb', line 110 def (chat_id, **extra) raw..get(chat_id:, **csv_query(extra, :message_ids)) end |
#get_my_info ⇒ Object
rubocop:disable Naming/AccessorMethodName
27 28 29 |
# File 'lib/max_api_client/api.rb', line 27 def get_my_info raw.bots.get_my_info end |
#get_pinned_message(chat_id) ⇒ Object
82 83 84 |
# File 'lib/max_api_client/api.rb', line 82 def (chat_id) raw.chats.(chat_id:) end |
#get_subscriptions ⇒ Object
rubocop:disable Naming/AccessorMethodName
131 132 133 |
# File 'lib/max_api_client/api.rb', line 131 def get_subscriptions raw.subscriptions.get_subscriptions end |
#leave_chat(chat_id) ⇒ Object
98 99 100 |
# File 'lib/max_api_client/api.rb', line 98 def leave_chat(chat_id) raw.chats.leave_chat(chat_id:) end |
#pin_message(chat_id, message_id, **extra) ⇒ Object
86 87 88 |
# File 'lib/max_api_client/api.rb', line 86 def (chat_id, , **extra) raw.chats.(chat_id:, message_id:, notify: extra[:notify]) end |
#poll_updates(types = [], marker: nil, timeout: Polling::DEFAULT_TIMEOUT, retry_interval: Polling::DEFAULT_RETRY_INTERVAL, read_timeout: nil) {|update| ... } ⇒ Polling
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/max_api_client/api.rb', line 144 def poll_updates(types = [], marker: nil, timeout: Polling::DEFAULT_TIMEOUT, retry_interval: Polling::DEFAULT_RETRY_INTERVAL, read_timeout: nil, &block) poller = Polling.new( self, types:, marker:, timeout:, retry_interval:, read_timeout: ) return poller.each unless block poller.each(&block) end |
#remove_chat_member(chat_id, user_id, block: nil) ⇒ Object
78 79 80 |
# File 'lib/max_api_client/api.rb', line 78 def remove_chat_member(chat_id, user_id, block: nil) raw.chats.remove_chat_member(chat_id:, user_id:, block:) end |
#send_action(chat_id, action) ⇒ Object
94 95 96 |
# File 'lib/max_api_client/api.rb', line 94 def send_action(chat_id, action) raw.chats.send_action(chat_id:, action:) end |
#send_message_to_chat(chat_id, text, **extra) ⇒ Object
102 103 104 |
# File 'lib/max_api_client/api.rb', line 102 def (chat_id, text, **extra) (raw..send(chat_id:, text:, **extra)) end |
#send_message_to_user(user_id, text, **extra) ⇒ Object
106 107 108 |
# File 'lib/max_api_client/api.rb', line 106 def (user_id, text, **extra) (raw..send(user_id:, text:, **extra)) end |
#set_my_commands(commands) ⇒ Object
rubocop:disable Naming/AccessorMethodName
37 38 39 |
# File 'lib/max_api_client/api.rb', line 37 def set_my_commands(commands) edit_my_info(commands:) end |
#subscribe(url, update_types: nil, secret: nil) ⇒ Object
rubocop:enable Naming/AccessorMethodName
136 137 138 |
# File 'lib/max_api_client/api.rb', line 136 def subscribe(url, update_types: nil, secret: nil) raw.subscriptions.subscribe(url:, update_types:, secret:) end |
#unpin_message(chat_id) ⇒ Object
90 91 92 |
# File 'lib/max_api_client/api.rb', line 90 def (chat_id) raw.chats.(chat_id:) end |
#unsubscribe(url) ⇒ Object
140 141 142 |
# File 'lib/max_api_client/api.rb', line 140 def unsubscribe(url) raw.subscriptions.unsubscribe(url:) end |
#upload_audio(options) ⇒ AudioAttachment
170 171 172 173 |
# File 'lib/max_api_client/api.rb', line 170 def upload_audio() data = upload.audio(**) AudioAttachment.new(token: data[:token] || data["token"]) end |
#upload_file(options) ⇒ FileAttachment
175 176 177 178 |
# File 'lib/max_api_client/api.rb', line 175 def upload_file() data = upload.file(**) FileAttachment.new(token: data[:token] || data["token"]) end |
#upload_image(options) ⇒ ImageAttachment
160 161 162 163 |
# File 'lib/max_api_client/api.rb', line 160 def upload_image() data = upload.image(**) ImageAttachment.new(token: data[:token], photos: data[:photos], url: data[:url] || data["url"]) end |
#upload_video(options) ⇒ VideoAttachment
165 166 167 168 |
# File 'lib/max_api_client/api.rb', line 165 def upload_video() data = upload.video(**) VideoAttachment.new(token: data[:token] || data["token"]) end |