ayanami 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b728f2a264d75fc29b0ae00a1fb06eea1653d5ab
4
+ data.tar.gz: c1343ed07ac528214b86d6c3c560deb83b4c13f0
5
+ SHA512:
6
+ metadata.gz: 17152efc7eecd7737dc6c30e6e783d20958e690a6b88337e3d1a3f1f7c9304bb39d0f7eea759b2b5fd365aa59d9513be3a7519164b045e98359f529ce17412f0
7
+ data.tar.gz: ea6f02385f60326b7794036fd46e287169b2042ac80219189166b5afc58cdbb8b20a5916d4218481bb459403cc3a161af0e3ca733068e70de9996a644e16695e
@@ -0,0 +1,18 @@
1
+ [default]
2
+ bears = FilenameBear, coalaBear, KeywordBear, SpaceConsistencyBear
3
+ files = **.txt, **.md
4
+ ignore = vendor/**
5
+ cs_keywords = FIXME
6
+ ci_keywords = FIXME
7
+ max_line_length = 100
8
+ use_spaces = True
9
+
10
+ [text]
11
+ bears = LineLengthBear
12
+ files = **.txt, **.md
13
+
14
+ [ruby]
15
+ bears = CPDBear, RuboCopBear, RubySyntaxBear
16
+ files = lib/**.rb
17
+ too_many_methods = False
18
+ language = Ruby
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rest-client'
6
+ gem 'codecov', require: false, group: :test
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Patiwan Organization and Ayanami Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,81 @@
1
+ [![codecov](https://codecov.io/gh/patiwan/Ayanami/branch/master/graph/badge.svg)]
2
+ (https://codecov.io/gh/patiOne/Ayanami)
3
+ [![CircleCI](https://circleci.com/gh/patiwan/Ayanami.svg?style=svg)]
4
+ (https://circleci.com/gh/patiOne/Ayanami)
5
+ [![Gitter](https://badges.gitter.im/patiwan/Ayanami.svg)]
6
+ (https://gitter.im/patiwan/Ayanami?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
7
+
8
+ # Ayanami
9
+
10
+ > "If I die, I can be replaced" - Rei Ayanami
11
+
12
+ A Telegram Bot API for Ruby that focuses on simplicity. Ayanami is meant to be a simple
13
+ interface to Telegram's Bot API.
14
+
15
+ The Goal of Ayanami is to keeping it simple and barebone, so other people can use it
16
+ for their own purposes/needs.
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'Ayanami'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install ayanami
33
+
34
+ ## Usage
35
+
36
+ You can start by creating a Bot object.
37
+
38
+ ```ruby
39
+ b = Ayanami::Bot.new('YOUR_BOT_TOKEN_GOES_HERE')
40
+ ```
41
+
42
+ To confirm the connection, You can invoke the `get_me` function to see your bot identity.
43
+
44
+ ```ruby
45
+ puts b.get_me
46
+ ```
47
+
48
+ To get received messages or other updates, You can invoke the `get_updates` function to
49
+ receive updates.
50
+
51
+ ```ruby
52
+ puts b.get_updates()
53
+ ```
54
+
55
+ You can also send a simple message to a group/user by invoking the `send_message` function.
56
+
57
+ ```ruby
58
+ puts b.send_message(chat_id: USER_OR_CHAT_ID_GOES_HERE, text: 'Hello :)')
59
+ ```
60
+
61
+ For more information about the included functions,
62
+ Please consult [Telegram's Bot API documentation](https://core.telegram.org/bots/api)
63
+
64
+ ## Development
65
+
66
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test`
67
+ to run the tests. You can also run `bin/console` for an interactive prompt that will allow
68
+ you to experiment.
69
+
70
+ To install this gem onto your local machine, run `bundle exec rake install`.
71
+
72
+ ## Contributing
73
+
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/patiOne/Ayanami.
75
+
76
+
77
+ ## License
78
+
79
+ The gem is available as open source under the terms of the
80
+ [MIT License](http://opensource.org/licenses/MIT).
81
+
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ayanami/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ayanami'
8
+ spec.version = Ayanami::VERSION
9
+ spec.authors = ['Kaisar Arkhan']
10
+ spec.email = ['ykno@protonmail.com']
11
+
12
+ spec.summary = 'A Telegram Bot API that focuses on simplicity'
13
+ spec.description = spec.summary
14
+ spec.homepage = 'https://github.com/patiwan/Ayanami'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.13'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'minitest', '~> 5.0'
27
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ayanami"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,15 @@
1
+ machine:
2
+ services:
3
+ - docker
4
+
5
+ dependencies:
6
+ post:
7
+ - docker pull coala/base
8
+
9
+ test:
10
+ post:
11
+ - docker run --volume=$(pwd):/app --workdir=/app coala/base coala-ci
12
+
13
+ notify:
14
+ webhooks:
15
+ - url: https://webhooks.gitter.im/e/808949c372657ad460a6
@@ -0,0 +1,7 @@
1
+ require 'ayanami/version'
2
+ require 'ayanami/bot'
3
+ require 'ayanami/generators'
4
+
5
+ # Ayanami is a Telegram Bot API that focuses on simplicity
6
+ module Ayanami
7
+ end
@@ -0,0 +1,198 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+ require 'ayanami/hacks'
4
+
5
+ module Ayanami
6
+ # Bot is an interface for a Telegram Bot
7
+ # rubocop:disable Metrics/ClassLength
8
+ class Bot
9
+ def initialize(token)
10
+ @token = token
11
+ end
12
+
13
+ def verify_arguments(**args)
14
+ args.each do |k, v|
15
+ raise ArgumentError, "#{k} can't be nil. nil values aren't allowed"\
16
+ if v.nil?
17
+ end
18
+ end
19
+
20
+ def request(method, **args)
21
+ verify_arguments(args)
22
+ res = RestClient.post("https://api.telegram.org/bot#{@token}/#{method}",
23
+ args)
24
+ return JSON.parse(res)
25
+ rescue RestClient::ExceptionWithResponse => err
26
+ err.response
27
+ end
28
+
29
+ # Returns basic information about the bot
30
+ # rubocop:disable Style/AccessorMethodName
31
+ def get_me
32
+ request('getMe')
33
+ end
34
+
35
+ # Receives incoming updates.
36
+ def get_updates(**args)
37
+ request('getUpdates', args)
38
+ end
39
+
40
+ # Sends a Message. On success, the sent Message is returned.
41
+ def send_message(chat_id: nil, text: nil, **args)
42
+ request('sendMessage', __grab_parameters(__method__, binding))
43
+ end
44
+
45
+ # Forwards a message. On success, the sent Message is returned.
46
+ def forward_message(chat_id: nil, from_chat_id: nil, message_id: nil,
47
+ **args)
48
+ request('forwardMessage', __grab_parameters(__method__, binding))
49
+ end
50
+
51
+ # Sends photos. On success, the sent Message is returned.
52
+ def send_photo(chat_id: nil, photo: nil, **args)
53
+ request('sendPhoto', __grab_parameters(__method__, binding))
54
+ end
55
+
56
+ # Sends audio. On success, the sent Message is returned.
57
+ def send_audio(chat_id: nil, audio: nil, **args)
58
+ request('sendAudio', __grab_parameters(__method__, binding))
59
+ end
60
+
61
+ # Sends documents. On success, the sent Message is returned.
62
+ # Bots can currently send files of any type of up to 50 MB in size.
63
+ def send_document(chat_id: nil, document: nil, **args)
64
+ request('sendDocument', __grab_parameters(__method__, binding))
65
+ end
66
+
67
+ # Sends stickers. On success, the sent Message is returned.
68
+ def send_sticker(chat_id: nil, sticker: nil, **args)
69
+ request('sendSticker', __grab_parameters(__method__, binding))
70
+ end
71
+
72
+ # Sends videos. Telegram clients support mp4 videos (other formats may be
73
+ # sent as Document). On success, the sent Message is returned.
74
+ # Bots can currently send video files of up to 50 MB in size.
75
+ def send_video(chat_id: nil, video: nil, **args)
76
+ request('sendVideo', __grab_parameters(__method__, binding))
77
+ end
78
+
79
+ # Sends voice messages. The audio format must be in an .ogg file encoded
80
+ # with OPUS (other formats may be sent as Audio or Document).
81
+ # On success, the sent Message is returned.
82
+ # Bots can currently send voice messages of up to 50 MB in size.
83
+ def send_voice(chat_id: nil, voice: nil, **args)
84
+ request('sendVoice', __grab_parameters(__method__, binding))
85
+ end
86
+
87
+ # Sends point on the map. On success, the sent Message is returned.
88
+ def send_location(chat_id: nil, latitude: nil, longitude: nil, **args)
89
+ request('sendLocation', __grab_parameters(__method__, binding))
90
+ end
91
+
92
+ # Sends information about a venue. On success, the sent Message is returned.
93
+ # rubocop:disable Metrics/ParameterLists
94
+ def send_venue(chat_id: nil, latitude: nil, longitude: nil, title: nil,
95
+ address: nil, **args)
96
+ request('sendVenue', __grab_parameters(__method__, binding))
97
+ end
98
+
99
+ # Sends phone contacts. On success, the sent Message is returned.
100
+ def send_contact(chat_id: nil, phone_number: nil, first_name: nil,
101
+ last_name: nil, **args)
102
+ request('sendContact', __grab_parameters(__method__, binding))
103
+ end
104
+
105
+ # Sends a status that tells something is happening. The status is set for
106
+ # 5 seconds or less. Returns True on success.
107
+ def send_chat_action(chat_id: nil, action: nil)
108
+ request('sendChatAction', __grab_parameters(__method__, binding))
109
+ end
110
+
111
+ # Returns a list of profile pictures for a user.
112
+ def get_user_profile_photos(user_id: nil, **args)
113
+ request('getUserProfilePhotos', __grab_parameters(__method__, binding))
114
+ end
115
+
116
+ # Returns a basic info about a file and prepare it for downloading.
117
+ # Bots can download files up to 20 MB in size.
118
+ def get_file(file_id: nil)
119
+ request('getFile', __grab_parameters(__method__, binding))
120
+ end
121
+
122
+ # Kicks a chat member from a group/supergroup.
123
+ def kick_chat_member(chat_id: nil, user_id: nil)
124
+ request('kickChatMember', __grab_parameters(__method__, binding))
125
+ end
126
+
127
+ # Leaves the group, supergroup, or channel.
128
+ def leave_chat(chat_id: nil)
129
+ request('leaveChat', __grab_parameters(__method__, binding))
130
+ end
131
+
132
+ # Unbans previously kicked user in a supergroup.
133
+ def unban_chat_member(chat_id: nil, user_id: nil)
134
+ request('unbanChatMember', __grab_parameters(__method__, binding))
135
+ end
136
+
137
+ # Returns information about the chat.
138
+ def get_chat(chat_id: nil)
139
+ request('getChat', __grab_parameters(__method__, binding))
140
+ end
141
+
142
+ # Returns a list of administratos in a chat.
143
+ def get_chat_administrators(chat_id: nil)
144
+ request('getChatAdministrators', __grab_parameters(__method__, binding))
145
+ end
146
+
147
+ # Returns the number of members in a chat.
148
+ def get_chat_members_count(chat_id: nil)
149
+ request('getChatMembersCount', __grab_parameters(__method__, binding))
150
+ end
151
+
152
+ # Returns an information about a member of a chat.
153
+ def get_chat_member(chat_id: nil, user_id: nil)
154
+ request('getChatMember', __grab_parameters(__method__, binding))
155
+ end
156
+
157
+ # Sends answers to callback queries sent from inline keyboards.
158
+ def answer_callback_query(callback_query_id: nil, **args)
159
+ request('answerCallbackQuery', __grab_parameters(__method__, binding))
160
+ end
161
+
162
+ # Changes text and game messages sent by the bot or via the bot (for
163
+ # inline bots).
164
+ def edit_message_text(text: nil, **args)
165
+ request('editMessageText', __grab_parameters(__method__, binding))
166
+ end
167
+
168
+ # Changes captions of messages sent by the bot or via the bot (for
169
+ # inline bots).
170
+ def edit_message_caption(**args)
171
+ request('editMessageCaption', args)
172
+ end
173
+
174
+ # Changes the markup of messages sent by the bot or via the bot (for
175
+ # inline bots).
176
+ def edit_message_reply_markup(**args)
177
+ request('editMessageReplyMarkup', args)
178
+ end
179
+
180
+ # Answers to an inline query. On success, True is returned.
181
+ def answer_inline_query(inline_query_id: nil, results: nil, **args)
182
+ request('answerInlineQuery', __grab_parameters(__method__, binding))
183
+ end
184
+
185
+ # Sends a game. On success, the sent Message is returned.
186
+ def send_game(chat_id: nil, game_short_name: nil, **args)
187
+ request('sendGame', __grab_parameters(__method__, binding))
188
+ end
189
+
190
+ # Sets the score of the specified user in a game.
191
+ # On success, if the message was sent by the bot, returns the edited
192
+ # Message, otherwise returns True. Returns an error, if the new score is
193
+ # not greater than the user's current score in the chat.
194
+ def set_game_score(used_id: nil, score: nil, **args)
195
+ request('setGameScore', __grab_parameters(__method__, binding))
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,48 @@
1
+ require 'ayanami/hacks'
2
+
3
+ module Ayanami
4
+ # Generator contains Telegram objects that are used as arguments
5
+ module Generator
6
+ def self.inline_keyboard_markup(inline_keyboard: [])
7
+ __grab_parameters(__method__, binding)
8
+ end
9
+
10
+ def self.reply_keyboard_markup(keyboard: [[]], **args)
11
+ __grab_parameters(__method__, binding)
12
+ end
13
+
14
+ def self.reply_keyboard_hide(hide_keyboard: true, **args)
15
+ __grab_parameters(__method__, binding)
16
+ end
17
+
18
+ def self.force_reply(force_reply: true, **args)
19
+ __grab_parameters(__method__, binding)
20
+ end
21
+
22
+ def self.input_text_message_content(message_text: nil, **args)
23
+ __grab_parameters(__method__, binding)
24
+ end
25
+
26
+ def self.input_location_message_content(latitude: nil, longitude: nil)
27
+ __grab_parameters(__method__, binding)
28
+ end
29
+
30
+ def self.input_venue_message_content(latitude: nil, longitude: nil,
31
+ title: nil, address: nil, **args)
32
+ __grab_parameters(__method__, binding)
33
+ end
34
+
35
+ def self.input_contact_message_content(phone_number: nil, first_name: nil,
36
+ **args)
37
+ __grab_parameters(__method__, binding)
38
+ end
39
+
40
+ def self.inline_keyboard_button(text: nil, **args)
41
+ __grab_parameters(__method__, binding)
42
+ end
43
+
44
+ def self.keyboard_button(text: nil, **args)
45
+ __grab_parameters(__method__, binding)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,18 @@
1
+ # This file contains the 'hacks' which are written to prevent
2
+ # repeating the same code all over the place.
3
+
4
+ def __grab_parameters(method, bind)
5
+ hash = {}
6
+
7
+ method(method).parameters.each do |_, n|
8
+ v = bind.local_variable_get(n)
9
+
10
+ if v.is_a? Hash
11
+ hash.merge! v
12
+ else
13
+ hash.merge! [[n, v]].to_h
14
+ end
15
+ end
16
+
17
+ hash
18
+ end
@@ -0,0 +1,3 @@
1
+ module Ayanami
2
+ VERSION = '0.1.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ayanami
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Kaisar Arkhan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: A Telegram Bot API that focuses on simplicity
56
+ email:
57
+ - ykno@protonmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".coafile"
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - ayanami.gemspec
69
+ - bin/console
70
+ - bin/setup
71
+ - circle.yml
72
+ - lib/ayanami.rb
73
+ - lib/ayanami/bot.rb
74
+ - lib/ayanami/generators.rb
75
+ - lib/ayanami/hacks.rb
76
+ - lib/ayanami/version.rb
77
+ homepage: https://github.com/patiwan/Ayanami
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.5.1
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: A Telegram Bot API that focuses on simplicity
101
+ test_files: []