telegrammer 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +125 -0
- data/lib/telegrammer.rb +49 -0
- data/lib/telegrammer/api_response.rb +22 -0
- data/lib/telegrammer/bot.rb +240 -0
- data/lib/telegrammer/data_types/audio.rb +10 -0
- data/lib/telegrammer/data_types/base.rb +7 -0
- data/lib/telegrammer/data_types/channel.rb +11 -0
- data/lib/telegrammer/data_types/contact.rb +10 -0
- data/lib/telegrammer/data_types/document.rb +11 -0
- data/lib/telegrammer/data_types/force_reply.rb +8 -0
- data/lib/telegrammer/data_types/group_chat.rb +8 -0
- data/lib/telegrammer/data_types/location.rb +8 -0
- data/lib/telegrammer/data_types/message.rb +27 -0
- data/lib/telegrammer/data_types/photo_size.rb +10 -0
- data/lib/telegrammer/data_types/reply_keyboard_hide.rb +8 -0
- data/lib/telegrammer/data_types/reply_keyboard_markup.rb +10 -0
- data/lib/telegrammer/data_types/sticker.rb +11 -0
- data/lib/telegrammer/data_types/update.rb +8 -0
- data/lib/telegrammer/data_types/user.rb +10 -0
- data/lib/telegrammer/data_types/user_profile_photos.rb +10 -0
- data/lib/telegrammer/data_types/video.rb +14 -0
- data/lib/telegrammer/version.rb +3 -0
- data/telegrammer.gemspec +26 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2d3805e449660fb17df66abfdbf7da73d4906fed
|
4
|
+
data.tar.gz: 02a9bc4026fb9455c0e79a9d37080a543e2f8270
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4adee140cfb0c7f91cdfc8d35c9fe07f7476294ad70f6234d3ca93140405de43f960b4c5394ca8237723a6505f511c8c11c34a92d4b39399f33edd676f4451e7
|
7
|
+
data.tar.gz: e3dcdf0e42bd44a942e8a5c22139b791beb350e9727944e565814474cb12dde3a1de87437f9ac8ee412281d958d26fe23f3c710121429568dd4a485b1c9e6fdc
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Luis Mayoral
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# Telegrammer
|
2
|
+
|
3
|
+
Ruby client for the [Telegram's Bot API](https://core.telegram.org/bots/api).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'telegrammer'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
First you'll need to register your bot and get an API token. To do that you have to talk with the [@BotFather](https://telegram.me/botfather).
|
20
|
+
Learn more about this [here](https://core.telegram.org/bots).
|
21
|
+
|
22
|
+
All current actions are supported by the gem. Here's an example for each action:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'telegrammer'
|
26
|
+
|
27
|
+
bot = TelegramBot.new('[YOUR TELEGRAM TOKEN]')
|
28
|
+
|
29
|
+
# GET UPDATES
|
30
|
+
# https://core.telegram.org/bots/api/#getupdates
|
31
|
+
bot.get_updates do |message|
|
32
|
+
puts "In chat #{message.chat.id}, @#{message.from.username} said: #{message.text}"
|
33
|
+
bot.send_message(chat_id: message.chat.id, text: "You said: #{message.text}")
|
34
|
+
|
35
|
+
# Here you can also process message text to detect user commands
|
36
|
+
# To learn more about commands, see https://core.telegram.org/bots#commands
|
37
|
+
end
|
38
|
+
|
39
|
+
# SEND MESSAGES
|
40
|
+
# https://core.telegram.org/bots/api/#sendmessage
|
41
|
+
bot.send_message(chat_id: 123456789, text: "This is a text")
|
42
|
+
|
43
|
+
# https://core.telegram.org/bots/api/#replykeyboardmarkup
|
44
|
+
reply_markup = Telegrammer::DataTypes::ReplyKeyboardMarkup.new(
|
45
|
+
keyboard: [
|
46
|
+
["Option 1.1", "Option 1.2"],
|
47
|
+
["Option 2"],
|
48
|
+
["Option 3.1", "Option 3.2", "Option 3.3"]
|
49
|
+
],
|
50
|
+
resize_keyboard: false
|
51
|
+
)
|
52
|
+
|
53
|
+
# This message will activate a custom keyboard...
|
54
|
+
bot.send_message(
|
55
|
+
chat_id: 1460713,
|
56
|
+
text: "Select an option"
|
57
|
+
reply_markup: reply_markup
|
58
|
+
)
|
59
|
+
|
60
|
+
# https://core.telegram.org/bots/api/#replykeyboardhide
|
61
|
+
reply_markup = Telegrammer::DataTypes::ReplyKeyboardHide.new(
|
62
|
+
hide_keyboard: true
|
63
|
+
)
|
64
|
+
|
65
|
+
# And this message will disable it
|
66
|
+
bot.send_message(
|
67
|
+
chat_id: 1460713,
|
68
|
+
text: "Thanks",
|
69
|
+
reply_markup: reply_markup
|
70
|
+
)
|
71
|
+
|
72
|
+
# FORWARDING A MESSAGE
|
73
|
+
# https://core.telegram.org/bots/api/#forwardmessage
|
74
|
+
bot.forward_message(chat_id: 123456789, from_chat_id: 987654321, message_id: 111222333)
|
75
|
+
|
76
|
+
# SENDING PHOTOS
|
77
|
+
# https://core.telegram.org/bots/api/#sendphoto
|
78
|
+
image_file = File.open("foo.jpg")
|
79
|
+
bot.send_document(chat_id: 123456789, document: image_file)
|
80
|
+
|
81
|
+
# SENDING AUDIO FILES
|
82
|
+
# https://core.telegram.org/bots/api/#sendaudio
|
83
|
+
audio_file = File.open("foo.ogg")
|
84
|
+
bot.send_audio(chat_id: 123456789, audio: audio_file)
|
85
|
+
|
86
|
+
# SENDING DOCUMENTS
|
87
|
+
# https://core.telegram.org/bots/api/#senddocument
|
88
|
+
my_secret_file = File.open("secret.txt")
|
89
|
+
bot.send_document(chat_id: 123456789, document: my_secret_file)
|
90
|
+
|
91
|
+
# SENDING STICKERS
|
92
|
+
# https://core.telegram.org/bots/api/#sendsticker
|
93
|
+
sticker_image_file = File.open("sticker.jpg")
|
94
|
+
bot.send_sticker(chat_id: 123456789, sticker: sticker_image_file)
|
95
|
+
|
96
|
+
# SENDING VIDEOS
|
97
|
+
# https://core.telegram.org/bots/api/#sendvideo
|
98
|
+
video_file = File.open("foo.mp4")
|
99
|
+
bot.send_audio(chat_id: 123456789, video: video_file)
|
100
|
+
|
101
|
+
# SENDING DOCUMENTS
|
102
|
+
# https://core.telegram.org/bots/api/#senddocument
|
103
|
+
file = File.open("foo.ogg")
|
104
|
+
bot.send_audio(chat_id: 123456789, audio: file)
|
105
|
+
|
106
|
+
# SENDING LOCATIONS
|
107
|
+
# https://core.telegram.org/bots/api/#sendlocation
|
108
|
+
bot.send_location(chat_id: 123456789, latitude: 38.775539, longitude: -4.829988)
|
109
|
+
|
110
|
+
# SENDING CHAT ACTIONS
|
111
|
+
# https://core.telegram.org/bots/api/#sendchataction
|
112
|
+
bot.send_chat_action(chat_id: 123456789, action: "typing")
|
113
|
+
|
114
|
+
# GETTING USER PROFILE PHOTOS
|
115
|
+
# https://core.telegram.org/bots/api/#getuserprofilephotos
|
116
|
+
bot.get_user_profile_photos(user_id: 123456789)
|
117
|
+
```
|
118
|
+
|
119
|
+
## Contributing
|
120
|
+
|
121
|
+
1. Fork it ( https://github.com/mayoral/telegrammer/fork )
|
122
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
123
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
124
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
125
|
+
5. Create a new Pull Request
|
data/lib/telegrammer.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
require 'virtus'
|
3
|
+
require 'multi_json'
|
4
|
+
|
5
|
+
require "telegrammer/version"
|
6
|
+
|
7
|
+
require "telegrammer/data_types/base"
|
8
|
+
require "telegrammer/data_types/audio"
|
9
|
+
require "telegrammer/data_types/channel"
|
10
|
+
require "telegrammer/data_types/contact"
|
11
|
+
require "telegrammer/data_types/photo_size"
|
12
|
+
require "telegrammer/data_types/user"
|
13
|
+
require "telegrammer/data_types/sticker"
|
14
|
+
require "telegrammer/data_types/video"
|
15
|
+
|
16
|
+
require "telegrammer/data_types/document"
|
17
|
+
require "telegrammer/data_types/force_reply"
|
18
|
+
require "telegrammer/data_types/group_chat"
|
19
|
+
require "telegrammer/data_types/location"
|
20
|
+
require "telegrammer/data_types/message"
|
21
|
+
require "telegrammer/data_types/reply_keyboard_hide"
|
22
|
+
require "telegrammer/data_types/reply_keyboard_markup"
|
23
|
+
require "telegrammer/data_types/update"
|
24
|
+
require "telegrammer/data_types/user_profile_photos"
|
25
|
+
|
26
|
+
require "telegrammer/bot"
|
27
|
+
require "telegrammer/api_response"
|
28
|
+
|
29
|
+
module Telegrammer
|
30
|
+
module Errors
|
31
|
+
class MissingParamsError < StandardError
|
32
|
+
def initialize(parameter, action)
|
33
|
+
super("Missing parameter #{parameter} for action #{action}")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class InvalidParamTypeError < StandardError
|
38
|
+
def initialize(parameter, current_type, allowed_types)
|
39
|
+
super("Invalid parameter type: #{parameter}: #{current_type}. Allowed types: #{allowed_types.each {|type| type.class.to_s }.join(",")}.")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class BadRequestError < StandardError
|
44
|
+
def initialize(error_code, message)
|
45
|
+
super("Bad request. Error code: #{error_code} - Message: #{message}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Telegrammer
|
2
|
+
class ApiResponse
|
3
|
+
attr_reader :body
|
4
|
+
attr_reader :result
|
5
|
+
attr_reader :success
|
6
|
+
|
7
|
+
def initialize(response)
|
8
|
+
@body = response.response_body
|
9
|
+
data = MultiJson.load(@body)
|
10
|
+
|
11
|
+
@success = data["ok"]
|
12
|
+
|
13
|
+
if @success
|
14
|
+
@result = data["result"]
|
15
|
+
else
|
16
|
+
raise Telegrammer::Errors::BadRequestError.new(data["error_code"], data["description"])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
alias_method :success?, :success
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,240 @@
|
|
1
|
+
module Telegrammer
|
2
|
+
class Bot
|
3
|
+
API_ENDPOINT = 'https://api.telegram.org'
|
4
|
+
|
5
|
+
attr_reader :me
|
6
|
+
|
7
|
+
def initialize(api_token)
|
8
|
+
@api_token = api_token
|
9
|
+
@offset = 0
|
10
|
+
@timeout = 60
|
11
|
+
|
12
|
+
@me = get_me
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_updates(&block)
|
16
|
+
loop do
|
17
|
+
response = api_request("getUpdates", {offset: @offset, timeout: @timeout}, nil)
|
18
|
+
|
19
|
+
response.result.each do |raw_update|
|
20
|
+
update = Telegrammer::DataTypes::Update.new(raw_update)
|
21
|
+
@offset = update.update_id + 1
|
22
|
+
yield update.message
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_webhook(url)
|
28
|
+
response = api_request("setWebhook", {url: url}, nil)
|
29
|
+
|
30
|
+
Telegrammer::DataTypes::Update.new(response.result)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def get_me
|
35
|
+
response = api_request("getMe", nil, nil)
|
36
|
+
|
37
|
+
Telegrammer::DataTypes::User.new(response.result)
|
38
|
+
end
|
39
|
+
|
40
|
+
def send_message(params)
|
41
|
+
params_validation = {
|
42
|
+
chat_id: { required: true, class: [Fixnum] },
|
43
|
+
text: { required: true, class: [String] },
|
44
|
+
disable_web_page_preview: { required: false, class: [TrueClass, FalseClass] },
|
45
|
+
reply_to_message_id: { required: false, class: [Fixnum] },
|
46
|
+
reply_markup: { required: false, class: [
|
47
|
+
Telegrammer::DataTypes::ReplyKeyboardMarkup,
|
48
|
+
Telegrammer::DataTypes::ReplyKeyboardHide,
|
49
|
+
Telegrammer::DataTypes::ForceReply,
|
50
|
+
]}
|
51
|
+
}
|
52
|
+
|
53
|
+
response = api_request("sendMessage", params, params_validation)
|
54
|
+
|
55
|
+
Telegrammer::DataTypes::Message.new(response.result)
|
56
|
+
end
|
57
|
+
|
58
|
+
def forward_message(params)
|
59
|
+
params_validation = {
|
60
|
+
chat_id: { required: true, class: [Fixnum] },
|
61
|
+
from_chat_id: { required: true, class: [String] },
|
62
|
+
message_id: { required: true, class: [Fixnum] }
|
63
|
+
}
|
64
|
+
|
65
|
+
response = api_request("forwardMessage", params, params_validation)
|
66
|
+
|
67
|
+
Telegrammer::DataTypes::Message.new(response.result)
|
68
|
+
end
|
69
|
+
|
70
|
+
def send_photo(params)
|
71
|
+
params_validation = {
|
72
|
+
chat_id: { required: true, class: [Fixnum] },
|
73
|
+
photo: { required: true, class: [File, String] },
|
74
|
+
caption: { required: false, class: [String] },
|
75
|
+
reply_to_message_id: { required: false, class: [String] },
|
76
|
+
reply_markup: { required: false, class: [
|
77
|
+
Telegrammer::DataTypes::ReplyKeyboardMarkup,
|
78
|
+
Telegrammer::DataTypes::ReplyKeyboardHide,
|
79
|
+
Telegrammer::DataTypes::ForceReply,
|
80
|
+
]}
|
81
|
+
}
|
82
|
+
|
83
|
+
response = api_request("sendPhoto", params, params_validation)
|
84
|
+
|
85
|
+
Telegrammer::DataTypes::Message.new(response.result)
|
86
|
+
end
|
87
|
+
|
88
|
+
def send_audio(params)
|
89
|
+
params_validation = {
|
90
|
+
chat_id: { required: true, class: [Fixnum] },
|
91
|
+
audio: { required: true, class: [File, String] },
|
92
|
+
reply_to_message_id: { required: false, class: [String] },
|
93
|
+
reply_markup: { required: false, class: [
|
94
|
+
Telegrammer::DataTypes::ReplyKeyboardMarkup,
|
95
|
+
Telegrammer::DataTypes::ReplyKeyboardHide,
|
96
|
+
Telegrammer::DataTypes::ForceReply,
|
97
|
+
]}
|
98
|
+
}
|
99
|
+
|
100
|
+
response = api_request("sendAudio", params, params_validation)
|
101
|
+
|
102
|
+
Telegrammer::DataTypes::Message.new(response.result)
|
103
|
+
end
|
104
|
+
|
105
|
+
def send_document(params)
|
106
|
+
params_validation = {
|
107
|
+
chat_id: { required: true, class: [Fixnum] },
|
108
|
+
document: { required: false, class: [File, String] },
|
109
|
+
reply_markup: { required: false, class: [
|
110
|
+
Telegrammer::DataTypes::ReplyKeyboardMarkup,
|
111
|
+
Telegrammer::DataTypes::ReplyKeyboardHide,
|
112
|
+
Telegrammer::DataTypes::ForceReply,
|
113
|
+
]}
|
114
|
+
}
|
115
|
+
|
116
|
+
response = api_request("sendDocument", params, params_validation)
|
117
|
+
|
118
|
+
Telegrammer::DataTypes::Message.new(response.result)
|
119
|
+
end
|
120
|
+
|
121
|
+
def send_sticker(params)
|
122
|
+
params_validation = {
|
123
|
+
chat_id: { required: true, class: [Fixnum] },
|
124
|
+
sticker: { required: true, class: [File, String] },
|
125
|
+
reply_markup: { required: false, class: [
|
126
|
+
Telegrammer::DataTypes::ReplyKeyboardMarkup,
|
127
|
+
Telegrammer::DataTypes::ReplyKeyboardHide,
|
128
|
+
Telegrammer::DataTypes::ForceReply,
|
129
|
+
]}
|
130
|
+
}
|
131
|
+
|
132
|
+
response = api_request("sendSticker", params, params_validation)
|
133
|
+
|
134
|
+
Telegrammer::DataTypes::Message.new(response.result)
|
135
|
+
end
|
136
|
+
|
137
|
+
def send_video(params)
|
138
|
+
params_validation = {
|
139
|
+
chat_id: { required: true, class: [Fixnum] },
|
140
|
+
video: { required: true, class: [File, String] },
|
141
|
+
reply_markup: { required: false, class: [
|
142
|
+
Telegrammer::DataTypes::ReplyKeyboardMarkup,
|
143
|
+
Telegrammer::DataTypes::ReplyKeyboardHide,
|
144
|
+
Telegrammer::DataTypes::ForceReply,
|
145
|
+
]}
|
146
|
+
}
|
147
|
+
|
148
|
+
response = api_request("sendVideo", params, params_validation)
|
149
|
+
|
150
|
+
Telegrammer::DataTypes::Message.new(response.result)
|
151
|
+
end
|
152
|
+
|
153
|
+
def send_location(params)
|
154
|
+
params_validation = {
|
155
|
+
chat_id: { required: true, class: [Fixnum] },
|
156
|
+
latitude: { required: true, class: [Float] },
|
157
|
+
longitude: { required: true, class: [Float] },
|
158
|
+
reply_markup: { required: false, class: [
|
159
|
+
Telegrammer::DataTypes::ReplyKeyboardMarkup,
|
160
|
+
Telegrammer::DataTypes::ReplyKeyboardHide,
|
161
|
+
Telegrammer::DataTypes::ForceReply,
|
162
|
+
]}
|
163
|
+
}
|
164
|
+
|
165
|
+
response = api_request("sendLocation", params, params_validation)
|
166
|
+
|
167
|
+
Telegrammer::DataTypes::Message.new(response.result)
|
168
|
+
end
|
169
|
+
|
170
|
+
# bot.send_chat_action(chat_id: "1460713", action: "typing")
|
171
|
+
def send_chat_action(params)
|
172
|
+
params_validation = {
|
173
|
+
chat_id: { required: true, class: [Fixnum] },
|
174
|
+
action: { required: true, class: [String] }
|
175
|
+
}
|
176
|
+
|
177
|
+
response = api_request("sendChatAction", params, params_validation)
|
178
|
+
|
179
|
+
response.result
|
180
|
+
end
|
181
|
+
|
182
|
+
def get_user_profile_photos(params)
|
183
|
+
params_validation = {
|
184
|
+
user_id: { required: true, class: [Fixnum] },
|
185
|
+
offset: { required: false, class: [Fixnum] },
|
186
|
+
limit: { required: false, class: [Fixnum] }
|
187
|
+
}
|
188
|
+
|
189
|
+
response = api_request("getUserProfilePhotos", params, params_validation)
|
190
|
+
|
191
|
+
Telegrammer::DataTypes::UserProfilePhotos.new(response.result)
|
192
|
+
end
|
193
|
+
|
194
|
+
private
|
195
|
+
|
196
|
+
def api_request(action, params, params_validation)
|
197
|
+
api_uri = "bot#{@api_token}/#{action}"
|
198
|
+
|
199
|
+
if params_validation.nil?
|
200
|
+
validated_params = params
|
201
|
+
else
|
202
|
+
# Delete params not accepted by the API
|
203
|
+
validated_params = params.delete_if {|k, v| !params_validation.has_key?(k) }
|
204
|
+
|
205
|
+
# Check all required params by the action are present
|
206
|
+
params_validation.each do |key, value|
|
207
|
+
if params_validation[key][:required] && !params.has_key?(key)
|
208
|
+
raise Telegrammer::Errors::MissingParamsError.new(key, action)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
params.each do |key, value|
|
213
|
+
# Check param types
|
214
|
+
if !params_validation[key][:class].include?(value.class)
|
215
|
+
raise Telegrammer::Errors::InvalidParamTypeError.new(key, value.class, params_validation[key][:class])
|
216
|
+
end
|
217
|
+
|
218
|
+
# Prepare params for sending in Typhoeus post body request
|
219
|
+
params[key] = value.to_s if value.class == Fixnum
|
220
|
+
params[key] = value.to_h.to_json if [
|
221
|
+
Telegrammer::DataTypes::ReplyKeyboardMarkup,
|
222
|
+
Telegrammer::DataTypes::ReplyKeyboardHide,
|
223
|
+
Telegrammer::DataTypes::ForceReply
|
224
|
+
].include?(value.class)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
response = Typhoeus.post(
|
229
|
+
"#{API_ENDPOINT}/#{api_uri}",
|
230
|
+
body: validated_params,
|
231
|
+
headers: {
|
232
|
+
"User-Agent" => "Telegrammer/#{Telegrammer::VERSION}",
|
233
|
+
"Accept" => "application/json"
|
234
|
+
}
|
235
|
+
)
|
236
|
+
|
237
|
+
ApiResponse.new(response)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Telegrammer
|
2
|
+
module DataTypes
|
3
|
+
class Message < Telegrammer::DataTypes::Base
|
4
|
+
attribute :message_id, Integer
|
5
|
+
attribute :from, User
|
6
|
+
attribute :date, DateTime
|
7
|
+
attribute :chat, Channel
|
8
|
+
attribute :forward_from, User
|
9
|
+
attribute :forward_date, Integer
|
10
|
+
attribute :reply_to_message, Message
|
11
|
+
attribute :text, String
|
12
|
+
attribute :audio, Audio
|
13
|
+
attribute :document, Document
|
14
|
+
attribute :photo, Array[PhotoSize]
|
15
|
+
attribute :sticker, Sticker
|
16
|
+
attribute :video, Video
|
17
|
+
attribute :contact, Contact
|
18
|
+
attribute :location, Location
|
19
|
+
attribute :new_chat_participant, User
|
20
|
+
attribute :left_chat_participant, User
|
21
|
+
attribute :new_chat_title, String
|
22
|
+
attribute :new_chat_photo, String
|
23
|
+
attribute :delete_chat_photo, Boolean
|
24
|
+
attribute :group_chat_created, Boolean
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Telegrammer
|
2
|
+
module DataTypes
|
3
|
+
class ReplyKeyboardMarkup < Telegrammer::DataTypes::Base
|
4
|
+
attribute :keyboard, Array[Array[String]]
|
5
|
+
attribute :resize_keyboard, Boolean
|
6
|
+
attribute :one_time_keyboard, Boolean
|
7
|
+
attribute :selective, Boolean
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Telegrammer
|
2
|
+
module DataTypes
|
3
|
+
class Video < Telegrammer::DataTypes::Base
|
4
|
+
attribute :file_id, String
|
5
|
+
attribute :width, Integer
|
6
|
+
attribute :height, Integer
|
7
|
+
attribute :duration, Integer
|
8
|
+
attribute :thumb, PhotoSize
|
9
|
+
attribute :mime_type, String
|
10
|
+
attribute :file_size, Integer
|
11
|
+
attribute :caption, String
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/telegrammer.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'telegrammer/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "telegrammer"
|
7
|
+
spec.version = Telegrammer::VERSION
|
8
|
+
spec.authors = ["Luis Mayoral"]
|
9
|
+
spec.email = ["luis@luismayoral.com"]
|
10
|
+
spec.description = %q{Ruby client for the Telegram's Bots API}
|
11
|
+
spec.summary = %q{Ruby client for the Telegram's Bots API}
|
12
|
+
spec.homepage = "https://github.com/mayoral/telegrammer"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "typhoeus", "~> 0.7"
|
21
|
+
spec.add_dependency "virtus", "~> 1.0"
|
22
|
+
spec.add_dependency "multi_json", "~> 1.11"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.1"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: telegrammer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luis Mayoral
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: typhoeus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: virtus
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: multi_json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.11'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.1'
|
83
|
+
description: Ruby client for the Telegram's Bots API
|
84
|
+
email:
|
85
|
+
- luis@luismayoral.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- CHANGELOG.md
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- lib/telegrammer.rb
|
96
|
+
- lib/telegrammer/api_response.rb
|
97
|
+
- lib/telegrammer/bot.rb
|
98
|
+
- lib/telegrammer/data_types/audio.rb
|
99
|
+
- lib/telegrammer/data_types/base.rb
|
100
|
+
- lib/telegrammer/data_types/channel.rb
|
101
|
+
- lib/telegrammer/data_types/contact.rb
|
102
|
+
- lib/telegrammer/data_types/document.rb
|
103
|
+
- lib/telegrammer/data_types/force_reply.rb
|
104
|
+
- lib/telegrammer/data_types/group_chat.rb
|
105
|
+
- lib/telegrammer/data_types/location.rb
|
106
|
+
- lib/telegrammer/data_types/message.rb
|
107
|
+
- lib/telegrammer/data_types/photo_size.rb
|
108
|
+
- lib/telegrammer/data_types/reply_keyboard_hide.rb
|
109
|
+
- lib/telegrammer/data_types/reply_keyboard_markup.rb
|
110
|
+
- lib/telegrammer/data_types/sticker.rb
|
111
|
+
- lib/telegrammer/data_types/update.rb
|
112
|
+
- lib/telegrammer/data_types/user.rb
|
113
|
+
- lib/telegrammer/data_types/user_profile_photos.rb
|
114
|
+
- lib/telegrammer/data_types/video.rb
|
115
|
+
- lib/telegrammer/version.rb
|
116
|
+
- telegrammer.gemspec
|
117
|
+
homepage: https://github.com/mayoral/telegrammer
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.4.6
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Ruby client for the Telegram's Bots API
|
141
|
+
test_files: []
|