jaconda_telegram 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +2 -0
- data/jaconda_telegram.gemspec +23 -0
- data/lib/jaconda_telegram.rb +67 -0
- data/lib/jaconda_telegram/version.rb +3 -0
- metadata +102 -0
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015 Alexander Tsirel
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# JacondaTelegram
|
|
2
|
+
|
|
3
|
+
Ruby gem to interact with Jaconda.im
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'jaconda_telegram'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install jaconda_telegram
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
- Get token from your account at https://jaconda.im/rest_api
|
|
24
|
+
|
|
25
|
+
Example code:
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
jaconda = JacondaTelegram::Api.new('YOUR_TOKEN')
|
|
29
|
+
```
|
|
30
|
+
```ruby
|
|
31
|
+
# Get all available groups
|
|
32
|
+
jaconda.list_groups
|
|
33
|
+
# Send Message
|
|
34
|
+
jaconda.send_message(126, 'Hello there!')
|
|
35
|
+
# Send Photo
|
|
36
|
+
jaconda.send_media(126, 'PATH_TO_FILE')
|
|
37
|
+
```
|
data/Rakefile
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |spec|
|
|
5
|
+
spec.name = "jaconda_telegram"
|
|
6
|
+
spec.version = '1.0'
|
|
7
|
+
spec.authors = ["Alexander Tsirel", "Anton Mironov"]
|
|
8
|
+
spec.email = ["noma4i@gmail.com"]
|
|
9
|
+
spec.summary = %q{Jaconda.im api wrapper}
|
|
10
|
+
spec.description = %q{Jaconda Telegram send text and media to selected groups}
|
|
11
|
+
spec.homepage = ""
|
|
12
|
+
spec.license = "MIT"
|
|
13
|
+
|
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
17
|
+
spec.require_paths = ['lib']
|
|
18
|
+
|
|
19
|
+
spec.add_dependency 'rest-client'
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
23
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require 'jaconda_telegram/version'
|
|
2
|
+
require 'rest_client'
|
|
3
|
+
|
|
4
|
+
module JacondaTelegram
|
|
5
|
+
class Api
|
|
6
|
+
ENDPOINT = 'https://jaconda.im/api/v1/endpoint'
|
|
7
|
+
@@token = nil
|
|
8
|
+
def initialize(token)
|
|
9
|
+
@@token = token
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def list_groups
|
|
13
|
+
begin
|
|
14
|
+
result = RestClient.get "#{ENDPOINT}/groups", { params: { token: @@token } }
|
|
15
|
+
rescue Exception => e
|
|
16
|
+
parse_exception e
|
|
17
|
+
end
|
|
18
|
+
parse_result result.body
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def get_group(id)
|
|
22
|
+
begin
|
|
23
|
+
result = RestClient.get "#{ENDPOINT}/groups", { params: { token: @@token, id: id } }
|
|
24
|
+
rescue Exception => e
|
|
25
|
+
parse_exception e
|
|
26
|
+
end
|
|
27
|
+
parse_result result.body
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def send_message(group_id, text)
|
|
31
|
+
begin
|
|
32
|
+
result = RestClient.post "#{ENDPOINT}/groups/#{group_id}/messages", { token: @@token, text: text }
|
|
33
|
+
rescue Exception => e
|
|
34
|
+
parse_exception e
|
|
35
|
+
end
|
|
36
|
+
parse_result result.body
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def send_media(group_id, file_path)
|
|
40
|
+
begin
|
|
41
|
+
result = RestClient.post "#{ENDPOINT}/groups/#{group_id}/media", { token: @@token, file: File.new(file_path, 'rb') }
|
|
42
|
+
rescue Exception => e
|
|
43
|
+
parse_exception e
|
|
44
|
+
end
|
|
45
|
+
parse_result result.body
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
protected
|
|
49
|
+
|
|
50
|
+
def parse_exception(e)
|
|
51
|
+
if e.message.eql?('401 Unauthorized')
|
|
52
|
+
fail 'Invalid Token!'
|
|
53
|
+
else
|
|
54
|
+
fail 'Jaconda is unreachable!'
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def parse_result(data)
|
|
59
|
+
begin
|
|
60
|
+
json_result = JSON.parse data
|
|
61
|
+
rescue
|
|
62
|
+
fail 'Expected JSON got some crap'
|
|
63
|
+
end
|
|
64
|
+
return json_result
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jaconda_telegram
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: '1.0'
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Alexander Tsirel
|
|
9
|
+
- Anton Mironov
|
|
10
|
+
autorequire:
|
|
11
|
+
bindir: bin
|
|
12
|
+
cert_chain: []
|
|
13
|
+
date: 2015-05-12 00:00:00.000000000 Z
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: rest-client
|
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
|
18
|
+
none: false
|
|
19
|
+
requirements:
|
|
20
|
+
- - ! '>='
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '0'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
none: false
|
|
27
|
+
requirements:
|
|
28
|
+
- - ! '>='
|
|
29
|
+
- !ruby/object:Gem::Version
|
|
30
|
+
version: '0'
|
|
31
|
+
- !ruby/object:Gem::Dependency
|
|
32
|
+
name: bundler
|
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
|
34
|
+
none: false
|
|
35
|
+
requirements:
|
|
36
|
+
- - ~>
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '1.7'
|
|
39
|
+
type: :development
|
|
40
|
+
prerelease: false
|
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
+
none: false
|
|
43
|
+
requirements:
|
|
44
|
+
- - ~>
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '1.7'
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: rake
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
none: false
|
|
51
|
+
requirements:
|
|
52
|
+
- - ~>
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.0'
|
|
55
|
+
type: :development
|
|
56
|
+
prerelease: false
|
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
58
|
+
none: false
|
|
59
|
+
requirements:
|
|
60
|
+
- - ~>
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '10.0'
|
|
63
|
+
description: Jaconda Telegram send text and media to selected groups
|
|
64
|
+
email:
|
|
65
|
+
- noma4i@gmail.com
|
|
66
|
+
executables: []
|
|
67
|
+
extensions: []
|
|
68
|
+
extra_rdoc_files: []
|
|
69
|
+
files:
|
|
70
|
+
- Gemfile
|
|
71
|
+
- LICENSE.txt
|
|
72
|
+
- README.md
|
|
73
|
+
- Rakefile
|
|
74
|
+
- jaconda_telegram.gemspec
|
|
75
|
+
- lib/jaconda_telegram.rb
|
|
76
|
+
- lib/jaconda_telegram/version.rb
|
|
77
|
+
homepage: ''
|
|
78
|
+
licenses:
|
|
79
|
+
- MIT
|
|
80
|
+
post_install_message:
|
|
81
|
+
rdoc_options: []
|
|
82
|
+
require_paths:
|
|
83
|
+
- lib
|
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
|
+
none: false
|
|
86
|
+
requirements:
|
|
87
|
+
- - ! '>='
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
|
+
none: false
|
|
92
|
+
requirements:
|
|
93
|
+
- - ! '>='
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
requirements: []
|
|
97
|
+
rubyforge_project:
|
|
98
|
+
rubygems_version: 1.8.25
|
|
99
|
+
signing_key:
|
|
100
|
+
specification_version: 3
|
|
101
|
+
summary: Jaconda.im api wrapper
|
|
102
|
+
test_files: []
|