telbe 0.0.2 → 0.0.3

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
  SHA256:
3
- metadata.gz: df77d040b76c21d68c32b9a09310d6b315063b620d920c34daf292fb993e9de1
4
- data.tar.gz: e5c76e103192f7fd4e911d289adbf4ffc055bd1aaa9baa8c82eb97d42c1ca312
3
+ metadata.gz: 815ab89f78ce78539b82a13b665694521330064655a963a96d3b7818c4d7831b
4
+ data.tar.gz: ffd119196e75361014e5ae52304a35626ccce170ccd4d6e9b8e0d6ca390bfbad
5
5
  SHA512:
6
- metadata.gz: 1d81b93822df3ef7599c596ec78c980a3dd76bd7f49f6a054a2df0ceff0c4c37403a7e856081f4e064bc90642299dd72270b35535b9ecb630a46325f796faccb
7
- data.tar.gz: ab48686f50a5a5f8a86d9cab02465e85c899e8f0cb6cb899a1cfcf3ce5c89c2f35276cce25ae0b0cdc4055af235d656eaf7131a2efff9fdae7787ecb42dadb90
6
+ metadata.gz: 60ee12ad31f8d363d441eb8aa74c36b4de8eeda9bbf2395f5424ad5ea154006aa94dc6b71f6cdec020afb0b3d0779eb299c98c4d50d468ed47c02bced49fd225
7
+ data.tar.gz: ed4df911617b94eeda88aba20c28e358f1262bfa67d1961ebca9ca39d3b0f3d40995a13d17caa4324bbf489a89976424f1f8e7066e00c7aa7fea5d84b2cfd795
data/.gitignore CHANGED
@@ -2,4 +2,5 @@
2
2
  /Gemfile.lock
3
3
  /spec/reports/
4
4
  /tmp/
5
+ /vendor/
5
6
  *.gem
data/lib/telbe.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'excon'
2
- require 'virtus'
3
2
  require 'json'
4
3
 
4
+ require 'telbe/helper'
5
5
  require 'telbe/webhook'
6
6
  require 'telbe/user'
7
7
  require 'telbe/contact'
@@ -11,9 +11,3 @@ require 'telbe/media'
11
11
  require 'telbe/sticker'
12
12
  require 'telbe/location'
13
13
  require 'telbe/bot'
14
-
15
- module BotEngine
16
- def self.new(opts)
17
- Bot.new(opts)
18
- end
19
- end
data/lib/telbe/bot.rb CHANGED
@@ -44,100 +44,27 @@ module Telbe
44
44
  end
45
45
 
46
46
  class MessageEntity
47
- include Virtus.model
47
+ include InitializeFromHash
48
48
  end
49
49
 
50
50
  class ForceReply
51
- include Virtus.model
52
- attribute :force_reply, Boolean
53
- attribute :selective, Boolean
51
+ include InitializeFromHash
54
52
  end
55
53
 
56
54
  class MessageDescriptor
57
- include Virtus.model
58
- attribute :chat_id, Object # Integer or String - Unique identifier for the target chat or username of the target channel (in the format @channelusername)
59
- attribute :text, String # Text of the message to be sent
60
- attribute :parse_mode, String # Optional Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
61
- attribute :disable_web_page_preview, Boolean # Optional Disables link previews for links in this message
62
- attribute :disable_notification, Boolean # Optional Sends the message silently. Users will receive a notification with no sound.
63
- attribute :reply_to_message_id, Integer # Optional If the message is a reply, ID of the original message
64
- attribute :reply_markup, Object # InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply - Optional Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
55
+ include InitializeFromHash
65
56
  end
66
57
 
67
58
  class ChatPhoto
68
- include Virtus.model
69
- attribute :small_file_id, String
70
- attribute :big_file_id, String
59
+ include InitializeFromHash
71
60
  end
72
61
 
73
62
  class Chat
74
- include Virtus.model
75
- attribute :id, Integer
76
- attribute :type, String
77
- attribute :title, String
78
- attribute :username, String
79
- attribute :first_name, String
80
- attribute :last_name, String
81
- attribute :all_members_are_administrators, Boolean
82
- attribute :photo, ChatPhoto
83
- attribute :description, String
84
- attribute :invite_link, String
85
- attribute :sticker_set_name, String
86
- attribute :can_set_sticker_set, Boolean
63
+ include InitializeFromHash
87
64
  end
88
65
 
89
66
  class Message
90
- include Virtus.model
91
- attribute :message_id, Integer
92
- alias_method :id, :message_id
93
- alias_method :to_i, :id
94
- attribute :from, User
95
- alias_method :user, :from
96
- attribute :text, String
97
- attribute :date, DateTime
98
- attribute :chat, Chat
99
- attribute :forward_from, User
100
- attribute :forward_from_chat, Chat
101
- attribute :forward_from_message_id, Integer
102
- attribute :forward_signature, String
103
- attribute :forward_sender_name, String
104
- attribute :forward_date, Integer
105
- attribute :reply_to_message, Message
106
- attribute :edit_date, Integer
107
- attribute :media_group_id, String
108
- attribute :author_signature, String
109
- attribute :text, String
110
- attribute :entities, Array # of MessageEntity
111
- attribute :caption_entities, Array # of MessageEntity
112
- attribute :audio, Audio
113
- attribute :document, Document
114
- attribute :animation, Animation
115
- # attribute :game, Game
116
- attribute :photo, Array # of PhotoSize
117
- attribute :sticker, Sticker
118
- attribute :video, Video
119
- attribute :voice, Voice
120
- attribute :video_note, VideoNote
121
- attribute :caption, String
122
- attribute :contact, Contact
123
- attribute :location, Location
124
- attribute :venue, Venue
125
- attribute :poll, Poll
126
- attribute :new_chat_members, Array # of User
127
- attribute :left_chat_member , User
128
- attribute :new_chat_title, String
129
- attribute :new_chat_photo, Array # of PhotoSize
130
- attribute :delete_chat_photo, Boolean
131
- attribute :group_chat_created, Boolean
132
- attribute :supergroup_chat_created, Boolean
133
- attribute :channel_chat_created, Boolean
134
- attribute :migrate_to_chat_id, Integer
135
- attribute :migrate_from_chat_id, Integer
136
- attribute :pinned_message, Message
137
- # attribute :invoice, Invoice
138
- # attribute :successful_payment, SuccessfulPayment
139
- attribute :connected_website, String
140
- # attribute :passport_data, PassportData
67
+ include InitializeFromHash
141
68
 
142
69
  def reply(&block)
143
70
  reply = MessageDescriptor.new(chat_id: chat.id)
@@ -150,33 +77,12 @@ module Telbe
150
77
  end
151
78
  end
152
79
 
153
- class Chat
154
- attribute :pinned_message, Message
155
- end
156
-
157
80
  class Update
158
- include Virtus.model
159
- attribute :update_id, Integer
160
- alias_method :id, :update_id
161
- alias_method :to_i, :id
162
- attribute :message, Message
163
- alias_method :edited_message, :message
164
- alias_method :channel_post, :message
165
- alias_method :edited_channel_post, :message
166
- # attribute :inline_query, InlineQuery
167
- # attribute :chosen_inline_result, ChosenInlineResult
168
- # attribute :callback_query, CallbackQuery
169
- # attribute :shipping_query, ShippingQuery
170
- # attribute :pre_checkout_query, PreCheckoutQuery
171
- attribute :poll, Poll
81
+ include InitializeFromHash
172
82
  end
173
83
 
174
84
  class UpdateDescriptor
175
- include Virtus.model
176
- attribute :offset, Integer
177
- attribute :limit, Integer
178
- attribute :timeout, Integer
179
- attribute :allowed_updates, Array # of String
85
+ include InitializeFromHash
180
86
  end
181
87
 
182
88
  class ResponseError < StandardError
data/lib/telbe/contact.rb CHANGED
@@ -6,23 +6,10 @@ module Telbe
6
6
  end
7
7
 
8
8
  class Contact
9
- include Virtus.model
10
- attribute :phone_number, String
11
- attribute :first_name, String
12
- attribute :last_name, String
13
- attribute :user_id, Integer
14
- attribute :vcard, String
9
+ include InitializeFromHash
15
10
  end
16
11
 
17
12
  class ContactDescriptor
18
- include Virtus.model
19
- attribute :chat_id, Integer or String
20
- attribute :phone_number, String
21
- attribute :first_name, String
22
- attribute :last_name, String
23
- attribute :vcard, String
24
- attribute :disable_notification, Boolean
25
- attribute :reply_to_message_id, Integer
26
- attribute :reply_markup, Object #InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply
13
+ include InitializeFromHash
27
14
  end
28
15
  end
@@ -0,0 +1,46 @@
1
+ class String
2
+ def camelize
3
+ self.split('_').collect(&:capitalize).join
4
+ end
5
+ end
6
+
7
+ module Telbe
8
+ module InitializeFromHash
9
+ def initialize(opts)
10
+ opts.each_pair do |k, v|
11
+ if Telbe::const_defined?(k.to_s.camelize) then
12
+ case v
13
+ when Hash
14
+ v = Telbe::const_get(k.to_s.camelize).new(v)
15
+ when Array
16
+ v.collect! { |i| Telbe::const_get(k.to_s.camelize).new(i) }
17
+ end
18
+ end
19
+ instance_variable_set("@#{k}", v)
20
+ end
21
+ end
22
+
23
+ def to_h
24
+ h = {}
25
+ instance_variables.each do |i|
26
+ k = /\@(.*)/.match(i.to_s)[1]
27
+ v = instance_variable_get(i)
28
+ if v.class.inspect.start_with?("Telbe") then
29
+ h[k] = v.to_h
30
+ else
31
+ h[k] = v
32
+ end
33
+ end
34
+ h
35
+ end
36
+
37
+ def method_missing(m, *args, &block)
38
+ case m
39
+ when /(.*)\=$/
40
+ instance_variable_set("@#{$1}", args[0])
41
+ else
42
+ instance_variable_get("@#{m}")
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,38 +1,21 @@
1
1
  module Telbe
2
2
  class KeyboardButton
3
- include Virtus.model
4
- attribute :text, String
5
- attribute :request_contact, Boolean
6
- attribute :request_location, Boolean
3
+ include InitializeFromHash
7
4
  end
8
5
 
9
6
  class ReplyKeyboardRemove
10
- include Virtus.model
11
- attribute :remove_keyboard, Boolean
12
- attribute :selective, Boolean
7
+ include InitializeFromHash
13
8
  end
14
9
 
15
10
  class ReplyKeyboardMarkup
16
- include Virtus.model
17
- attribute :keyboard, Array # of Array of KeyboardButton
18
- attribute :resize_keyboard, Boolean
19
- attribute :one_time_keyboard, Boolean
20
- attribute :selective, Boolean
11
+ include InitializeFromHash
21
12
  end
22
13
 
23
14
  class InlineKeyboardMarkup
24
- include Virtus.model
25
- attribute :inline_keyboard, Array # of Array of InlineKeyboardButton
15
+ include InitializeFromHash
26
16
  end
27
17
 
28
18
  class InlineKeyboardButton
29
- include Virtus.model
30
- attribute :text, String
31
- attribute :url, String
32
- attribute :callback_data, String
33
- attribute :switch_inline_query, String
34
- attribute :switch_inline_query_current_chat, String
35
- # attribute :callback_game, CallbackGame
36
- # attribute :pay, Boolean
19
+ include InitializeFromHash
37
20
  end
38
21
  end
@@ -1,16 +1,9 @@
1
1
  module Telbe
2
2
  class Location
3
- include Virtus.model
4
- attribute :longitude, Float
5
- attribute :latitude, Float
3
+ include InitializeFromHash
6
4
  end
7
5
 
8
6
  class Venue
9
- include Virtus.model
10
- attribute :location, Location
11
- attribute :address, String
12
- attribute :title, String
13
- attribute :foursquare_id, String
14
- attribute :foursquare_type, String
7
+ include InitializeFromHash
15
8
  end
16
9
  end
data/lib/telbe/media.rb CHANGED
@@ -1,108 +1,48 @@
1
1
  module Telbe
2
2
  class PhotoSize
3
- include Virtus.model
4
- attribute :file_id, String
5
- attribute :width, Integer
6
- attribute :height, Integer
7
- attribute :file_size, Integer
3
+ include InitializeFromHash
8
4
  end
9
5
 
10
6
  class Animation
11
- include Virtus.model
12
- attribute :file_id, String
13
- attribute :width, Integer
14
- attribute :height, Integer
15
- attribute :duration, Integer
16
- attribute :thumb, PhotoSize
17
- attribute :file_name, String
18
- attribute :mime_type, String
19
- attribute :file_size, Integer
7
+ include InitializeFromHash
20
8
  end
21
9
 
22
10
  class Document
23
- include Virtus.model
24
- attribute :file_id, String
25
- attribute :thumb, PhotoSize
26
- attribute :file_name, String
27
- attribute :mime_type, String
28
- attribute :file_size, Integer
11
+ include InitializeFromHash
29
12
  end
30
13
 
31
14
  class Audio
32
- include Virtus.model
33
- attribute :file_id, String
34
- attribute :duration, Integer
35
- attribute :performer, String
36
- attribute :title, String
37
- attribute :mime_type, String
38
- attribute :file_size, Integer
39
- attribute :thumb, PhotoSize
15
+ include InitializeFromHash
40
16
  end
41
17
 
42
18
  class Video
43
- include Virtus.model
44
- attribute :file_id, String
45
- attribute :width, Integer
46
- attribute :height, Integer
47
- attribute :duration, Integer
48
- attribute :thumb, PhotoSize
49
- attribute :mime_type, String
50
- attribute :file_size, Integer
19
+ include InitializeFromHash
51
20
  end
52
21
 
53
22
  class Voice
54
- include Virtus.model
55
- attribute :file_id, String
56
- attribute :duration, Integer
57
- attribute :mime_type, String
58
- attribute :file_size, Integer
23
+ include InitializeFromHash
59
24
  end
60
25
 
61
26
  class VideoNote
62
- include Virtus.model
63
- attribute :file_id, String
64
- attribute :length, Integer
65
- attribute :duration, Integer
66
- attribute :thumb, PhotoSize
67
- attribute :file_size, Integer
27
+ include InitializeFromHash
68
28
  end
69
29
 
70
30
  class InputMedia
71
- include Virtus.model
72
- attribute :type, String
73
- attribute :media, String
74
- attribute :caption, String
75
- attribute :parse_mode, String
31
+ include InitializeFromHash
76
32
  end
77
33
 
78
34
  class InputMediaAnimation < InputMedia
79
- attribute :thumb, Object
80
- attribute :width, Integer
81
- attribute :height, Integer
82
- attribute :duration, Integer
83
35
  end
84
36
 
85
37
  class InputMediaDocument < InputMedia
86
- include Virtus.model
87
- attribute :thumb, Object
88
38
  end
89
39
 
90
40
  class InputMediaAudio < InputMedia
91
- include Virtus.model
92
- attribute :thumb, Object
93
- attribute :duration, Integer
94
- attribute :performer, String
95
- attribute :title, String
96
41
  end
97
42
 
98
43
  class InputMediaPhoto < InputMedia
99
44
  end
100
45
 
101
46
  class InputMediaVideo < InputMedia
102
- attribute :thumb, Object
103
- attribute :width, Integer
104
- attribute :height, Integer
105
- attribute :duration, Integer
106
- attribute :supports_streaming, Boolean
107
47
  end
108
48
  end
data/lib/telbe/poll.rb CHANGED
@@ -3,16 +3,10 @@ module Telbe
3
3
  end
4
4
 
5
5
  class PollOption
6
- include Virtus.model
7
- attribute :text, String
8
- attribute :voter_count, Integer
6
+ include InitializeFromHash
9
7
  end
10
8
 
11
9
  class Poll
12
- include Virtus.model
13
- attribute :id, String
14
- attribute :question, String
15
- attribute :options, Array # of PollOption
16
- attribute :is_closed, Boolean
10
+ include InitializeFromHash
17
11
  end
18
12
  end
data/lib/telbe/sticker.rb CHANGED
@@ -3,30 +3,14 @@ module Telbe
3
3
  end
4
4
 
5
5
  class MaskPosition
6
- include Virtus.model
7
- attribute :point, String
8
- attribute :x_shift, Float
9
- attribute :y_shift, Float
10
- attribute :scale, Float
6
+ include InitializeFromHash
11
7
  end
12
8
 
13
9
  class Sticker
14
- include Virtus.model
15
- attribute :file_id, String
16
- attribute :width, Integer
17
- attribute :height, Integer
18
- attribute :thumb, PhotoSize
19
- attribute :emoji, String
20
- attribute :set_name, String
21
- attribute :mask_position, MaskPosition
22
- attribute :file_size, Integer
10
+ include InitializeFromHash
23
11
  end
24
12
 
25
13
  class StickerSet
26
- include Virtus.model
27
- attribute :name, String
28
- attribute :title, String
29
- attribute :contains_masks, Boolean
30
- attribute :stickers, Array # of Sticker
14
+ include InitializeFromHash
31
15
  end
32
16
  end
data/lib/telbe/user.rb CHANGED
@@ -12,34 +12,10 @@ module Telbe
12
12
  end
13
13
 
14
14
  class User
15
- include Virtus.model
16
- attribute :id, Integer #Unique identifier for this user or bot
17
- alias_method :to_i, :id
18
- attribute :is_bot, Boolean
19
- attribute :first_name, String #User‘s or bot’s first name
20
- attribute :last_name, String
21
- attribute :username, String
22
- attribute :language_code, String
15
+ include InitializeFromHash
23
16
  end
24
17
 
25
18
  class ChatMember
26
- include Virtus.model
27
- attribute :user, User
28
- attribute :status, String
29
- attribute :until_date, Integer
30
- attribute :can_be_edited, Boolean
31
- attribute :can_change_info, Boolean
32
- attribute :can_post_messages, Boolean
33
- attribute :can_edit_messages, Boolean
34
- attribute :can_delete_messages, Boolean
35
- attribute :can_invite_users, Boolean
36
- attribute :can_restrict_members, Boolean
37
- attribute :can_pin_messages, Boolean
38
- attribute :can_promote_members, Boolean
39
- attribute :is_member, Boolean
40
- attribute :can_send_messages, Boolean
41
- attribute :can_send_media_messages, Boolean
42
- attribute :can_send_other_messages, Boolean
43
- attribute :can_add_web_page_previews, Boolean
19
+ include InitializeFromHash
44
20
  end
45
21
  end
data/lib/telbe/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Telbe
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/telbe/webhook.rb CHANGED
@@ -14,24 +14,14 @@ module Telbe
14
14
  end
15
15
 
16
16
  class WebHookInfo
17
- include Virtus.model
18
- attribute :url, String
19
- attribute :has_custom_certificate, Boolean
20
- attribute :pending_update_count, Integer
21
- attribute :last_error_date, Integer
22
- attribute :last_error_message, String
23
- attribute :max_connections, Integer
24
- attribute :allowed_updates, Array # of String
17
+ include InitializeFromHash
25
18
  end
26
19
 
27
20
  class InputFile
21
+ include InitializeFromHash
28
22
  end
29
23
 
30
24
  class WebHookDescriptor
31
- include Virtus.model
32
- attribute :url, String
33
- attribute :certificate, InputFile
34
- attribute :max_connections, Integer
35
- attribute :allowed_updates, Array # of String
25
+ include InitializeFromHash
36
26
  end
37
27
  end
data/telbe.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ["lib"]
18
18
 
19
19
  spec.add_dependency "excon", ">= 0.64.0"
20
- spec.add_dependency "virtus", ">= 1.0.5"
21
20
  spec.add_development_dependency "bundler", "~> 2.0"
22
21
  spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency "minitest"
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telbe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Garcia Couto
@@ -25,35 +25,35 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.64.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: virtus
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.5
34
- type: :runtime
33
+ version: '2.0'
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.0.5
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bundler
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '2.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '2.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -80,6 +80,7 @@ files:
80
80
  - lib/telbe.rb
81
81
  - lib/telbe/bot.rb
82
82
  - lib/telbe/contact.rb
83
+ - lib/telbe/helper.rb
83
84
  - lib/telbe/keyboard.rb
84
85
  - lib/telbe/location.rb
85
86
  - lib/telbe/media.rb