tars 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4415bd1f9dad1a5098a8c955b2de1ca1c35c0751
4
+ data.tar.gz: 48a9bbe84eda7225d1aeea31e8f9995d833f2627
5
+ SHA512:
6
+ metadata.gz: cd216d5161e618153bd580b866b817e4ef0186c105d3c8674af62faa0b1874dfe55c4fb02bcc247092108cd25348471805383185212dfbc6e48d6a1742d7369b
7
+ data.tar.gz: 416ed95b264aa835ff58190406a543f5cc9c87fe32811a57ce4a09e2ceb9773a2fc4d1a4538e6b800d8f42bc7e4f294f908578ca109c12a24682bb1de94adc6c
data/.gitignore ADDED
@@ -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/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in TARS.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # TARS - Telegram BOT API
2
+
3
+ TARS is a wrapper of Telegram Bot API with WebHook support using WEBrick as HTTP server.
4
+
5
+ This is under heavy developpement, more coming soon
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tars'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tars
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'tars'
27
+
28
+ TARS.configure do |config|
29
+ config.token = '<YOUR_TOKEN>'
30
+ config.webhook = 'https://protosify.fr/tars'
31
+ config.server = {
32
+ port: 8443,
33
+ path: '/tars'
34
+ }
35
+ end
36
+
37
+ TARS.bot.on 'Hello' do |update|
38
+ message = update.instance_variable_get('@message')
39
+ puts message['chat']['id']
40
+ from = message['from']['first_name']
41
+ TARS::API.reply_to(message['chat']['id'], "Whoop whoop whoop #{from}")
42
+ end
43
+
44
+ TARS.bootstrap
45
+ ```
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it ( https://github.com/[my-github-username]/TARS/fork )
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "TARS"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/tars/api.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'json'
2
+ require 'httparty'
3
+
4
+ module TARS
5
+ class API
6
+ include HTTParty
7
+ base_uri 'api.telegram.org'
8
+
9
+ def self.me
10
+ request 'getMe'
11
+ end
12
+
13
+ def self.updates
14
+ request 'getUpdates'
15
+ end
16
+
17
+ def self.webhook
18
+ request 'setWebhook', url: URI(TARS.config.webhook)
19
+ end
20
+
21
+ def self.reply_to(chat_id, text)
22
+ request 'sendMessage', chat_id: chat_id, text: text
23
+ end
24
+
25
+ def self.request(endpoint, options = {})
26
+ post("/bot#{TARS.config.token}/#{endpoint}", query: options)
27
+ end
28
+ private_class_method :request
29
+ end
30
+ end
data/lib/tars/bot.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'webrick'
2
+ require 'tars/update'
3
+
4
+ module TARS
5
+ class PostHandler < WEBrick::HTTPServlet::AbstractServlet
6
+ def do_POST(request, response)
7
+ parsed = parse(request.body)
8
+ TARS::Update.new(parsed)
9
+ response.status = 200
10
+ end
11
+
12
+ def parse(update)
13
+ JSON.parse(update)
14
+ end
15
+ end
16
+
17
+ class Server
18
+ def initialize
19
+ server = WEBrick::HTTPServer.new Port: TARS.config.server[:port]
20
+ server.mount TARS.config.server[:path], TARS::PostHandler
21
+ server.start
22
+ end
23
+ end
24
+
25
+ class Bot
26
+ class << self
27
+ attr_accessor :cmds
28
+ end
29
+
30
+ def initialize
31
+ @cmds = {}
32
+ end
33
+
34
+ def on(message, &block)
35
+ @cmds[message] = block
36
+ end
37
+
38
+ def execute(command, message)
39
+ return unless @cmds.key?(command)
40
+ @cmds[command].call(message)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,14 @@
1
+ module TARS
2
+ class Update
3
+ class << self
4
+ attr_reader :message, :update_id
5
+ end
6
+
7
+ def initialize(update)
8
+ update.each do |k, v|
9
+ instance_variable_set("@#{k}", v) unless v.nil?
10
+ end
11
+ TARS.bot.execute(@message['text'], self)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module TARS
2
+ VERSION = "0.1.0"
3
+ end
data/lib/tars.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'tars/version'
2
+ require 'tars/api'
3
+ require 'tars/update'
4
+ require 'tars/bot'
5
+
6
+ module TARS
7
+ class << self
8
+ attr_accessor :config, :bot
9
+ end
10
+
11
+ class Configurator
12
+ attr_accessor :token, :webhook, :server
13
+ end
14
+
15
+ def self.configure
16
+ self.config ||= Configurator.new
17
+ yield config
18
+ @bot = TARS::Bot.new
19
+ end
20
+
21
+ def self.bootstrap
22
+ me = TARS::API.me
23
+
24
+ puts "Setting webhook for Bot to #{TARS.config.webhook} ..."
25
+ TARS::API.webhook
26
+
27
+ puts 'Running local server..'
28
+
29
+ TARS::Server.new
30
+ end
31
+ end
data/tars.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tars/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tars"
8
+ spec.version = TARS::VERSION
9
+ spec.authors = ["Felix Yadomi"]
10
+ spec.email = ["felix.yadomi@gmail.com"]
11
+
12
+ spec.summary = %q{Telegram Bot API Wrapper with webhook support}
13
+ spec.homepage = "http://github.com/yadomi/TARS"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "json", "~> 1.8"
21
+ spec.add_dependency "httparty", "~> 0.13.5"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.8"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tars
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Felix Yadomi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.13.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.13.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description:
70
+ email:
71
+ - felix.yadomi@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/tars.rb
85
+ - lib/tars/api.rb
86
+ - lib/tars/bot.rb
87
+ - lib/tars/update.rb
88
+ - lib/tars/version.rb
89
+ - tars.gemspec
90
+ homepage: http://github.com/yadomi/TARS
91
+ licenses: []
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.6
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Telegram Bot API Wrapper with webhook support
113
+ test_files: []