telegrammer 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56ae9079cd5b8570b1ece286941bb23580f96f70
4
- data.tar.gz: f3372fc3617f6187186643616c9a4b6d4b821a5f
3
+ metadata.gz: 9ccbe938586bdb894b8bb7da76c5f4f1223e25fb
4
+ data.tar.gz: d1081a1b521c670e287ac228e962103f574dd386
5
5
  SHA512:
6
- metadata.gz: 086f116639424d0cfcabc09b93df2858763a66a70345f52135517f6eedcc9ad5cd081d1d74e68e1682bceeee3209893240d18cc323048d521f832050fb5d88f8
7
- data.tar.gz: 07ab9deec6870f74782642a49e76b83d626156e52df4b6a8e63afee0cb22d6f1f1258cdf3d8afe11718f92c0348497d8a9536b4aa352664985cfe714d758e63e
6
+ metadata.gz: 31ca5931228d51197094729224556299b4bcbbf81d9d9da4ef8cdcea90296e15de16fa67305f1d7eef54c8394fe62458654f3892cf3bd861214cbfa07c22d63d
7
+ data.tar.gz: a7029706230bfe110efac6df6fb32f793278f8b8d7c8ad5d5fe0166abc69825a0e5fcbfdd2afb82d86893b689aaf88df54e2ec7178e874e3e0a8b97a9d5699b2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ v0.6.0
2
+ ======
3
+
4
+ * New File & Chat datatypes.
5
+ * Implemented get_file operation.
6
+
1
7
  v0.5.1
2
8
  ======
3
9
 
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  # Telegrammer
7
7
 
8
- Ruby client for the [Telegram's Bot API](https://core.telegram.org/bots/api).
8
+ Ruby client for the [Telegram's Bot API](https://core.telegram.org/bots/api). Compliant with the [version 2015-10-08 of the API](https://core.telegram.org/bots/api#recent-changes).
9
9
 
10
10
  ## Installation
11
11
 
data/lib/telegrammer.rb CHANGED
@@ -6,7 +6,7 @@ require 'telegrammer/version'
6
6
 
7
7
  require 'telegrammer/data_types/base'
8
8
  require 'telegrammer/data_types/audio'
9
- require 'telegrammer/data_types/channel'
9
+ require 'telegrammer/data_types/chat'
10
10
  require 'telegrammer/data_types/contact'
11
11
  require 'telegrammer/data_types/photo_size'
12
12
  require 'telegrammer/data_types/user'
@@ -15,6 +15,7 @@ require 'telegrammer/data_types/video'
15
15
  require 'telegrammer/data_types/voice'
16
16
 
17
17
  require 'telegrammer/data_types/document'
18
+ require 'telegrammer/data_types/file'
18
19
  require 'telegrammer/data_types/force_reply'
19
20
  require 'telegrammer/data_types/group_chat'
20
21
  require 'telegrammer/data_types/location'
@@ -400,7 +400,7 @@ module Telegrammer
400
400
 
401
401
  # Get a list of profile pictures for a user.
402
402
  #
403
- # @param [Hash] params hash of paramers to send to the sendChatAction API operation.
403
+ # @param [Hash] params hash of paramers to send to the getUserProfilePhotos API operation.
404
404
  # @option params [Integer] :user_id Required. Unique identifier of the target user.
405
405
  # @option params [Integer] :offset Optional. Sequential number of the first photo to be returned. By default, all photos are returned.
406
406
  # @option params [Integer] :limit Optional. Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100.
@@ -425,6 +425,32 @@ module Telegrammer
425
425
  Telegrammer::DataTypes::UserProfilePhotos.new(response.result)
426
426
  end
427
427
 
428
+ # Get a list of profile pictures for a user.
429
+ #
430
+ # @param [Hash] params hash of paramers to send to the sendChatAction API operation.
431
+ # @option params [Integer] :user_id Required. Unique identifier of the target user.
432
+ # @option params [Integer] :offset Optional. Sequential number of the first photo to be returned. By default, all photos are returned.
433
+ # @option params [Integer] :limit Optional. Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100.
434
+ #
435
+ # @example
436
+ # bot = Telegrammer::Bot.new('[YOUR TELEGRAM TOKEN]')
437
+ # bot.get_file(file_id: 123456789)
438
+ #
439
+ # @raise [Telegrammer::Errors::BadRequestError]
440
+ # @raise [Telegrammer::Errors::ServiceUnavailableError] if Telegram servers are down
441
+ #
442
+ # @return [String] URL of the file (valid for one hour) or BadRequestError if the file_id is wrong
443
+ def get_file(params)
444
+ params_validation = {
445
+ file_id: { required: true, class: [String] }
446
+ }
447
+
448
+ response = response = api_request("getFile", params, params_validation)
449
+ file_object = Telegrammer::DataTypes::File.new(response.result)
450
+
451
+ "https://api.telegram.org/file/bot#{@api_token}/#{file_object.file_path}"
452
+ end
453
+
428
454
  private
429
455
 
430
456
  def api_request(action, params, params_validation)
@@ -0,0 +1,22 @@
1
+ module Telegrammer
2
+ module DataTypes
3
+ # Telegram Chat data type
4
+ #
5
+ # @attr [Integer] id Unique identifier for this chat, not exceeding 1e13 by absolute value
6
+ # @attr [String] type Type of chat, can be either “private”, or “group”, or “channel”
7
+ # @attr [String] title Optional. Title, for channels and group chats
8
+ # @attr [String] username Optional. Username, for private chats and channels if available
9
+ # @attr [String] first_name Optional. First name of the other party in a private chat
10
+ # @attr [String] last_name Optional. Last name of the other party in a private chat
11
+ #
12
+ # See more at https://core.telegram.org/bots/api#chat
13
+ class Chat < Telegrammer::DataTypes::Base
14
+ attribute :id, Integer
15
+ attribute :type, String
16
+ attribute :title, String
17
+ attribute :username, String
18
+ attribute :first_name, String
19
+ attribute :last_name, String
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ module Telegrammer
2
+ module DataTypes
3
+ # Telegram File data type.
4
+ #
5
+ # @attr [String] file_id Unique identifier for this file
6
+ # @attr [Integer] file_size Optional. File size, if known
7
+ # @attr [String] file_path Optional. File path. Use https://api.telegram.org/file/bot<token>/<file_path> to get the file.
8
+ #
9
+ # See more at https://core.telegram.org/bots/api#file
10
+ class File < Telegrammer::DataTypes::Base
11
+ attribute :file_id, String
12
+ attribute :file_size, Integer
13
+ attribute :file_path, String
14
+ end
15
+ end
16
+ end
@@ -5,7 +5,7 @@ module Telegrammer
5
5
  # @attr [Integer] message_id Unique message identifier
6
6
  # @attr [Telegrammer::DataTypes::User] from Sender
7
7
  # @attr [DateTime] date Date the message was sent
8
- # @attr [Telegrammer::DataTypes::Channel] chat Conversation the message belongs to — user in case of a private message, GroupChat in case of a group
8
+ # @attr [Telegrammer::DataTypes::Chat] chat Conversation the message belongs to
9
9
  # @attr [Telegrammer::DataTypes::User] forward_from Optional. For forwarded messages, sender of the original message
10
10
  # @attr [DateTime] forward_date Optional. For forwarded messages, date the original message was sent
11
11
  # @attr [Telegrammer::DataTypes::Message] reply_to_message Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
@@ -31,7 +31,7 @@ module Telegrammer
31
31
  attribute :message_id, Integer
32
32
  attribute :from, User
33
33
  attribute :date, DateTime
34
- attribute :chat, Channel
34
+ attribute :chat, Chat
35
35
  attribute :forward_from, User
36
36
  attribute :forward_date, DateTime
37
37
  attribute :reply_to_message, Message
@@ -1,3 +1,3 @@
1
1
  module Telegrammer
2
- VERSION = '0.5.1'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegrammer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis Mayoral
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2015-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -97,9 +97,10 @@ files:
97
97
  - lib/telegrammer/bot.rb
98
98
  - lib/telegrammer/data_types/audio.rb
99
99
  - lib/telegrammer/data_types/base.rb
100
- - lib/telegrammer/data_types/channel.rb
100
+ - lib/telegrammer/data_types/chat.rb
101
101
  - lib/telegrammer/data_types/contact.rb
102
102
  - lib/telegrammer/data_types/document.rb
103
+ - lib/telegrammer/data_types/file.rb
103
104
  - lib/telegrammer/data_types/force_reply.rb
104
105
  - lib/telegrammer/data_types/group_chat.rb
105
106
  - lib/telegrammer/data_types/location.rb
@@ -135,9 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
136
  version: '0'
136
137
  requirements: []
137
138
  rubyforge_project:
138
- rubygems_version: 2.4.6
139
+ rubygems_version: 2.4.5.1
139
140
  signing_key:
140
141
  specification_version: 4
141
142
  summary: Ruby client for the Telegram's Bots API
142
143
  test_files: []
143
- has_rdoc:
@@ -1,11 +0,0 @@
1
- module Telegrammer
2
- module DataTypes
3
- # Custom attribute class to handle chat attribute in Telegrammer::DataTypes::Message
4
- class Channel < Virtus::Attribute
5
- # Transforms a channel into a User object or GroupChat object
6
- def coerce(value)
7
- value.respond_to?(:first_name) ? User.new(value) : GroupChat.new(value)
8
- end
9
- end
10
- end
11
- end