telegramAPI 1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +36 -6
  3. data/lib/telegramAPI.rb +48 -44
  4. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4d4ed6e7f6b6e7bab1bd1fccfe9ba95db51ed19
4
- data.tar.gz: fdd8295ba7c49a574ccf848fcaceaa5ce0529288
3
+ metadata.gz: 0fc39dcbfb6e5779994efe355d537f07dc9bc13a
4
+ data.tar.gz: 86afed760ceda0247d43085e157f10260efde302
5
5
  SHA512:
6
- metadata.gz: b5001ef8a7d75604c7e7e03e6f8c069451b50d284928ac630ae35ea0a841846de17b9fd53172f4a3f03f387a35430db6cc4f76bc857edca5b09effc314c17198
7
- data.tar.gz: 860db86abaf052d0722ebe85899d586457f22e8f611526211e759c4c4b7ca1986949f880591a10754911b8a5b2ccaea97df294a771d17090f4bcafe0f58e8d85
6
+ metadata.gz: 8a2829f16b4634493f653c3aa6e04d555fbd439a9e2bb2ac43ddcd23f53cded4160e09c5eea91601c3e0fa3b3a2512295e365fcd9dbe2c4ae3924b7fcb965abc
7
+ data.tar.gz: 536686e959139a08c2b5f075eb8cb8f92aa1c0865fa1f347af93f975e7c6d6c5c92a5eb6194ea2a471006f47e9d40c8758c2d8de581bff04e22494bb6d12be8f
data/README.md CHANGED
@@ -41,6 +41,35 @@ puts "But you can call me @#{bot['username']}"
41
41
 
42
42
  Here you can use the Telegram official [documentation](https://core.telegram.org/bots/api#available-methods)
43
43
 
44
+ ## List of methods available
45
+
46
+ Every method has a optional parameter. See the Send Custom Keyboard example for more.
47
+
48
+ * ```getUpdates()```
49
+ * ```getMe()```
50
+ * ```sendMessage(chat_id, text)```
51
+ * ```forwardMessage(chat_id, from_chat_id, message_id)```
52
+ * ```sendPhoto(chat_id, path)```
53
+ * ```sendAudio(chat_id, path)```
54
+ * ```sendDocument(chat_id, path)```
55
+ * ```sendStickerFromFile(chat_id, path)```
56
+ * ```sendSticker(chat_id, sticker_id)```
57
+ * ```sendVideo(chat_id, path)```
58
+ * ```sendVoice(chat_id, path)```
59
+ * ```sendLocation(chat_id, latitude, longitude)```
60
+ * ```sendVenue(chat_id, latitude, longitude, title, address)```
61
+ * ```sendContact(chat_id, phone_number, first_name)```
62
+ * ```sendChatAction(chat_id, action)```
63
+ * ```getUserProfilePhotos(user_id)```
64
+ * ```getFile(file_id)```
65
+ * ```kickChatMember(chat_id, user_id)```
66
+ * ```leaveChat(chat_id)```
67
+ * ```unbanChatMember(chat_id, user_id)```
68
+ * ```getChat(chat_id)```
69
+ * ```getChatAdministrators(chat_id)```
70
+ * ```getChatMembersCount(chat_id)```
71
+ * ```getChatMember(chat_id, user_id)```
72
+
44
73
  ## Examples
45
74
 
46
75
  ### Echo Server
@@ -60,17 +89,17 @@ end
60
89
  ### Send Media
61
90
 
62
91
  ```ruby
63
- api.sendSticker m.message.chat.id, sticker_id
92
+ api.sendSticker m['message']['chat']['id'], sticker_id
64
93
 
65
- api.sendPhoto m.message.chat.id, "/home/path-of-image/image.jpg"
94
+ api.sendPhoto m['message']['chat']['id'], "/home/path-of-image/image.jpg"
66
95
 
67
- api.sendDocument m.message.chat.id, "/home/path-of-document/doc.gif"
96
+ api.sendDocument m['message']['chat']['id'], "/home/path-of-document/doc.gif"
68
97
 
69
- api.sendAudio m.message.chat.id, "/home/path-of-audio/audio.opus"
98
+ api.sendAudio m['message']['chat']['id'], "/home/path-of-audio/audio.opus"
70
99
 
71
- api.sendVideo m.message.chat.id, "/home/path-of-video/video.mp4"
100
+ api.sendVideo m['message']['chat']['id'], "/home/path-of-video/video.mp4"
72
101
 
73
- api.sendLocation m.message.chat.id, 45.462781, 9.177732
102
+ api.sendLocation m['message']['chat']['id'], 45.462781, 9.177732
74
103
  ```
75
104
  **Note:** According to Telegram, each audio must be encoded in **Ogg OPUS**, and each video must be encoded in **mp4**.
76
105
 
@@ -91,3 +120,4 @@ markup = {
91
120
 
92
121
  api.sendMessage m['message']['chat']['id'], "Am I sexy?", {"reply_markup"=>markup}
93
122
  ```
123
+
data/lib/telegramAPI.rb CHANGED
@@ -3,7 +3,6 @@ require 'net/http'
3
3
  require 'net/https'
4
4
  require 'uri'
5
5
  require 'rest-client'
6
- require 'ostruct'
7
6
 
8
7
  # This library provides an easy way to access to the Telegram Bot API
9
8
  # Author:: Benedetto Nespoli
@@ -32,11 +31,11 @@ class TelegramAPI
32
31
  params.each do |param| p << param.join("=") end
33
32
  params_s = "?#{p.join("&")}" if p.length!=0
34
33
 
35
- JSON.parse(RestClient.get(@@core+@token+"/"+api+params_s).body)
34
+ JSON.parse(RestClient.get(@@core+@token+"/"+api+params_s).body)["result"]
36
35
  end
37
36
 
38
37
  def post api, name, path, to, options={}
39
- JSON.parse(RestClient.post(@@core+@token+api, {name=>File.new(path,'rb'), :chat_id=>to.to_s}.merge(parse_hash(options))).body, object_class: OpenStruct)["result"]
38
+ JSON.parse(RestClient.post(@@core+@token+api, {name=>File.new(path,'rb'), :chat_id=>to.to_s}.merge(parse_hash(options))).body)["result"]
40
39
  end
41
40
 
42
41
  def getUpdates options={"timeout"=>0, "limit"=>100}
@@ -54,11 +53,11 @@ class TelegramAPI
54
53
  if options.has_key?"reply_markup" then
55
54
  options["reply_markup"]=options["reply_markup"].to_json
56
55
  end
57
- self.query("sendMessage", {"chat_id"=>to.to_s, "text"=>URI::encode(text)}.merge(parse_hash(options)))["result"]
56
+ self.query("sendMessage", {:chat_id=>to.to_s, :text=>URI::encode(text)}.merge(parse_hash(options)))
58
57
  end
59
58
 
60
59
  def forwardMessage to, from, msg
61
- self.query("forwardMessage", {"chat_id"=>to, "from_chat_id"=>from, "message_id"=>msg})["result"]
60
+ self.query("forwardMessage", {:chat_id=>to, :from_chat_id=>from, :message_id=>msg})
62
61
  end
63
62
 
64
63
  def sendPhoto to, path, options={}
@@ -69,72 +68,77 @@ class TelegramAPI
69
68
  self.post "/sendAudio", :audio, path, to, options
70
69
  end
71
70
 
72
- # Send a general document (file, image, audio)
73
- # @param (see #sendPhoto)
74
- # @return (see #sendPhoto)
75
71
  def sendDocument to, path, options={}
76
72
  self.post "/sendDocument", :document, path, to, options
77
73
  end
78
74
 
79
- # Send a Sticker from File
80
- # @param (see #sendPhoto)
81
- # @return (see #sendSticker)
82
75
  def sendStickerFromFile to, path, options={}
83
76
  self.post "/sendSticker", :sticker, path, to, options
84
77
  end
85
78
 
86
- # Send a Sticker through its ID
87
- # @param to (see #sendPhoto)
88
- # @param id [Integer] the ID of the sticker to send
89
- # @param options (see #sendPhoto)
90
- # @return (see #sendPhoto)
91
79
  def sendSticker to, id, options={}
92
- JSON.parse(RestClient.post(@@core+@token+"/sendSticker", {:sticker=>id, :chat_id=>to.to_s}.merge(parse_hash(options))).body)["result"]
80
+ RestClient.post(@@core+@token+"/sendSticker", {:sticker=>id, :chat_id=>to.to_s}.merge(parse_hash(options))).body
93
81
  end
94
82
 
95
- # Send a video file in mp4 format of max 50MB
96
- # @param (see #sendPhoto)
97
- # @return (see #sendPhoto)
98
83
  def sendVideo to, path, options={}
99
84
  self.post "/sendVideo", :video, path, to, options
100
85
  end
101
-
102
- # Send a location
103
- # @param to (see #sendPhoto)
104
- # @param lat [Float] Latitude
105
- # @param long [Float] Longitude
106
- # @param options (see #sendPhoto)
107
- # @return (see #sendPhoto)
86
+
87
+ def sendVoice to, path, options={}
88
+ self.post "/sendVoice", :voice, path, to, options
89
+ end
90
+
108
91
  def sendLocation to, lat, long, options={}
109
- self.query("sendLocation", {"chat_id"=>to, "latitude"=>lat, "longitude"=>long}.merge(parse_hash(options)))["result"]
92
+ self.query("sendLocation", {:chat_id=>to, :latitude=>lat, :longitude=>long}.merge(parse_hash(options)))
93
+ end
94
+
95
+ def sendVenue to, lat, long, title, address, options={}
96
+ self.query("sendVenue", {:chat_id=>to, :latitude=>lat, :longitude=>long, :title=>title, :address=>address}.merge(parse_hash(options)))
97
+ end
98
+
99
+ def sendContact to, phone_number, first_name, options={}
100
+ self.query("sendContact", {:chat_id=>to, :phone_number=>phone_number, :first_name=>first_name}.merge(parse_hash(options)))
110
101
  end
111
102
 
112
- # Send a Chat Action
113
- # @param to (see #sendPhoto)
114
- # @param act [String] One of: typing, upload_photo, record_video, record_audio, upload_audio, upload_document, find_location
103
+ # act is one between: typing, upload_photo, record_video, record_audio, upload_audio, upload_document, find_location
115
104
  def sendChatAction to, act
116
- self.query "sendChatAction", {"chat_id"=>to, "action"=>act}
105
+ self.query "sendChatAction", {:chat_id=>to, :action=>act}
117
106
  end
118
107
 
119
- # Get a list of user profile photos, in up to 4 sizes each
120
- # @param id [Integer] ID user whom getting the photos
121
- # @param options (see #sendPhoto)
122
- # @return [UserProfilePhotos]
123
108
  def getUserProfilePhotos id, options={}
124
- self.query("getUserProfilePhotos", {"user_id"=>id}.merge(parse_hash(options)))["result"]
109
+ self.query("getUserProfilePhotos", {:user_id=>id}.merge(parse_hash(options)))
110
+ end
111
+
112
+ def getFile file_id
113
+ self.query("getFile", {:file_id=>file_id})
125
114
  end
126
115
 
127
- # Kick the user user_id from the chat chat_id
128
- # @param chat_id [Integer or String] ID of the chat, or @publicname
129
- # @param user_id [Integer] ID of the user to kick
130
116
  def kickChatMember chat_id, user_id
131
- self.query "kickChatMember", {"chat_id"=>chat_id, "user_id"=>user_id}
117
+ self.query("kickChatMember", {:chat_id=>chat_id, :user_id=>user_id})
118
+ end
119
+
120
+ def leaveChat chat_id
121
+ self.query("leaveChat", {:chat_id=>chat_id})
132
122
  end
133
123
 
134
- # Unban user_id from chat_id
135
- # see kickChatMember
136
124
  def unbanChatMember chat_id, user_id
137
- self.query "unbanChatMember", {"chat_id"=>chat_id, "user_id"=>user_id}
125
+ self.query("unbanChatMember", {:chat_id=>chat_id, :user_id=>user_id})
126
+ end
127
+
128
+ def getChat chat_id
129
+ self.query("getChat", {:chat_id=>chat_id})
130
+ end
131
+
132
+ def getChatAdministrators chat_id
133
+ self.query("getChatAdministrators", {:chat_id=>chat_id})
134
+ end
135
+
136
+ def getChatMembersCount chat_id
137
+ self.query("getChatMembersCount", {:chat_id=>chat_id})
138
+ end
139
+
140
+ def getChatMember chat_id, user_id
141
+ self.query("getChatMember", {:chat_id=>chat_id, :user_id=>user_id})
138
142
  end
139
143
 
140
144
  protected :query, :parse_hash, :post
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegramAPI
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benedetto Nespoli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-07 00:00:00.000000000 Z
11
+ date: 2016-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '2.0'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: 1.7.3
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '1.7'
29
+ version: '2.0'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.7.3