lita-vkontakte 0.1.0 → 1.0.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: c03ff4c1902ad82b997c83ac70689a7040c9b991
4
- data.tar.gz: 8d68cda6cff50defab4e5c4a45bf4ab281ea7d26
3
+ metadata.gz: 3f4dbbb5c1bf2ec9dcfc33984202d57931b8d351
4
+ data.tar.gz: 0d45c4b8e6db0aa797723d51aa21af79dadff766
5
5
  SHA512:
6
- metadata.gz: 197854a326fdba15f7abe3c1ea8a8e39f2dc70c3c18f579eefefff75408f880cd177208673e9da6ee655a9d5865bb1a97af9c7f6b2762aa4857f020a12981146
7
- data.tar.gz: be37cf8dccbfdcf08cb7f3eb2078ecf47ebdd45f7e94a0f2fc140c62a01ea1e86b3e07a34bc203671635e182e4d1e92e1c9dfc6d87eeb1279945e78c495d4dc7
6
+ metadata.gz: 34bb9a3454cfae7ad0ed1f689315d4e0637a459146ce65a395e22d0e364028cf83f065c9b721cb0399ceb58fb7abdea75f533c36246ac7acdccf1b8f08a7f518
7
+ data.tar.gz: 31e7ca4949d12a7b9037d9f051a80521a12cf280b86bff1fbfabeaa7289ad1bedc040060eebf17f025a89dbbe03aa54f5e8ae5b51644d9567cb9eb76a198acba
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Change Log
2
2
 
3
+ ## [v1.0.0](https://github.com/braiden-vasco/lita-vkontakte/tree/v1.0.0) (2015-06-18)
4
+
5
+ [Full Changelog](https://github.com/braiden-vasco/lita-vkontakte/compare/v0.1.0...v1.0.0)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Rename configuration fields [\#18](https://github.com/braiden-vasco/lita-vkontakte/pull/18) ([braiden-vasco](https://github.com/braiden-vasco))
10
+
11
+ - Basic testing [\#17](https://github.com/braiden-vasco/lita-vkontakte/pull/17) ([braiden-vasco](https://github.com/braiden-vasco))
12
+
13
+ - Add code documentation [\#16](https://github.com/braiden-vasco/lita-vkontakte/pull/16) ([braiden-vasco](https://github.com/braiden-vasco))
14
+
15
+ - Add instructions [\#15](https://github.com/braiden-vasco/lita-vkontakte/pull/15) ([braiden-vasco](https://github.com/braiden-vasco))
16
+
17
+ - Fix changelog generator [\#14](https://github.com/braiden-vasco/lita-vkontakte/pull/14) ([braiden-vasco](https://github.com/braiden-vasco))
18
+
3
19
  ## [v0.1.0](https://github.com/braiden-vasco/lita-vkontakte/tree/v0.1.0) (2015-06-17)
4
20
 
5
21
  **Merged pull requests:**
@@ -28,4 +44,4 @@
28
44
 
29
45
 
30
46
 
31
- \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
47
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/README.md CHANGED
@@ -5,4 +5,63 @@ Lita::Adapters::Vkontakte
5
5
  [![Build Status](https://travis-ci.org/braiden-vasco/lita-vkontakte.svg)](https://travis-ci.org/braiden-vasco/lita-vkontakte)
6
6
  [![Coverage Status](https://coveralls.io/repos/braiden-vasco/lita-vkontakte/badge.svg)](https://coveralls.io/r/braiden-vasco/lita-vkontakte)
7
7
 
8
- VKontakte adapter for the Lita chat bot
8
+ [VKontakte](https://vk.com) adapter for the [Lita](https://lita.io) chat bot.
9
+
10
+ Usage
11
+ -----
12
+
13
+ At first, see the documentation for Lita: https://docs.lita.io/
14
+
15
+ ### Installation
16
+
17
+ Add **lita-vkontakte** to your Lita instance's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'lita-vkontakte', '~> 1.0.0'
21
+ ```
22
+
23
+ ### Preparation
24
+
25
+ Go to https://vk.com/editapp?act=create and create standalone application.
26
+ Then go to application settings page and look at application ID and secure key.
27
+
28
+ Open the Ruby console (for example with `irb` command) and type the following
29
+ (replace `LITA_VK_APP_ID` with your application ID):
30
+
31
+ ```ruby
32
+ require 'vkontakte_api'
33
+
34
+ VkontakteApi.app_id = 'LITA_VK_APP_ID'
35
+ VkontakteApi.redirect_uri = 'https://oauth.vk.com/blank.html'
36
+
37
+ puts VkontakteApi.authorization_url(type: :client, scope: [:offline, :messages])
38
+ ```
39
+
40
+ You will see a link. Open it in browser where you are authorized in VKontakte
41
+ as your future chat bot's user. You will be redirected to some address.
42
+ We need a parameter `access_token` from this URL.
43
+
44
+ ### Configuration
45
+
46
+ #### Required attributes
47
+
48
+ - `app_id` (String) - An ID of your application
49
+ - `app_secret` (String) - A secure key of your application
50
+ - `access_token` (String) - An acces token from URL
51
+
52
+ #### Example
53
+
54
+ This is an example `lita_config.rb` file:
55
+
56
+ ```ruby
57
+ Lita.configure do |config|
58
+ config.robot.name = 'Lita'
59
+ config.robot.mention_name = 'lita'
60
+
61
+ config.robot.adapter = :vkontakte
62
+
63
+ config.adapters.vkontakte.app_id = '2849670'
64
+ config.adapters.vkontakte.app_secret = 'EtgJI2yFJ0GYzgDLSS8e'
65
+ config.adapters.vkontakte.access_token = '51jeIbjmmxJvKo7TTaW0Ext4cx6ajonDIbEkSjFofh7boyxH27JcjKXMODwZTaOxLA1bQbRyY0CEUM2TrXGK6'
66
+ end
67
+ ```
data/Rakefile CHANGED
@@ -5,6 +5,8 @@ gemspec = Gem::Specification.load('lita-vkontakte.gemspec')
5
5
  github_user, github_project =
6
6
  gemspec.homepage.scan(%r{^https://github\.com/([^/]+)/([^/]+)/?$})[0]
7
7
 
8
+ DEFAULT_EXCLUDE_LABELS = 'duplicate,question,invalid,wontfix'
9
+
8
10
  require 'bundler/gem_tasks'
9
11
 
10
12
  task default: [:spec, :lint]
@@ -26,6 +28,7 @@ task :changelog, [:token] do |_t, args|
26
28
  cmd << " -u #{github_user}"
27
29
  cmd << " -p #{github_project}"
28
30
  cmd << " -t #{args[:token]}" if args[:token]
31
+ cmd << " --exclude-labels version,#{DEFAULT_EXCLUDE_LABELS}"
29
32
 
30
33
  sh cmd
31
34
  end
@@ -14,20 +14,27 @@ module Lita
14
14
  # VKontakte adapter for the Lita chat bot.
15
15
  #
16
16
  class Vkontakte < Adapter
17
+ config :app_id, type: String, required: true
18
+ config :app_secret, type: String, required: true
19
+ config :access_token, type: String, required: true
20
+
21
+ # Used version of VKontakte API.
22
+ # {https://vk.com/dev/versions}
17
23
  API_VERSION = '5.34'
18
24
 
25
+ # Needed for VKontakte authentication.
19
26
  REDIRECT_URI = 'https:/oauth.vk.com/blank.html'
20
27
 
21
- config :client_id, type: String, required: true
22
- config :client_secret, type: String, required: true
23
- config :access_token, type: String, required: true
24
-
28
+ # Connects to VKontakte API.
29
+ #
30
+ # @param robot [Lita::Robot] The currently running robot.
31
+ #
25
32
  def initialize(robot)
26
33
  super
27
34
 
28
35
  VkontakteApi.configure do |vk|
29
- vk.app_id = config.client_id
30
- vk.app_secret = config.client_secret
36
+ vk.app_id = config.app_id
37
+ vk.app_secret = config.app_secret
31
38
  vk.redirect_uri = REDIRECT_URI
32
39
  vk.api_version = API_VERSION
33
40
  end
@@ -35,6 +42,10 @@ module Lita
35
42
  @vk = VkontakteApi::Client.new(config.access_token)
36
43
  end
37
44
 
45
+ # The main loop. Listens for incoming messages,
46
+ # creates {Lita::Message} objects from them,
47
+ # and dispatches them to the robot.
48
+ #
38
49
  def run # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
39
50
  robot.trigger(:connected)
40
51
 
@@ -62,6 +73,11 @@ module Lita
62
73
  robot.trigger(:disconnected)
63
74
  end
64
75
 
76
+ # Sends one or more messages to a user or room.
77
+ #
78
+ # @param target [Lita::Source] The user or room to send messages to.
79
+ # @param messages [Array<String>] An array of messages to send.
80
+ #
65
81
  def send_messages(target, messages)
66
82
  messages.reject(&:empty?).each do |message|
67
83
  send_message(target, message)
@@ -70,10 +86,17 @@ module Lita
70
86
 
71
87
  protected
72
88
 
89
+ # Handlers for events of VKontakte long poll server.
90
+ # {https://vk.com/dev/using_longpoll}
73
91
  HANDLERS = {
74
92
  4 => :get_message,
75
93
  }
76
94
 
95
+ # Handle event of VKontakte long poll server.
96
+ # {https://vk.com/dev/using_longpoll}
97
+ #
98
+ # @param a [List] Event arguments.
99
+ #
77
100
  def update(a)
78
101
  code = a[0]
79
102
  data = a[1..-1]
@@ -81,8 +104,20 @@ module Lita
81
104
  method(HANDLERS[code]).call(*data) if HANDLERS[code]
82
105
  end
83
106
 
84
- def get_message(_msg_id, flags, # rubocop:disable Metrics/ParameterLists
85
- from_id, _timestamp, subject, text, _attachments)
107
+ # Handle new message
108
+ # {https://vk.com/dev/using_longpoll}
109
+ #
110
+ # @param message_id [Integer] Message ID.
111
+ # @param flags [Integer] Message flags.
112
+ # @param from_id [Integer] ID of user who sent this message.
113
+ # @param timestamp [Integer] Message time in UNIX format.
114
+ # @param subject [String] Chat theme (" ... " for private messages).
115
+ # @param text [String] Message text.
116
+ # @param attachments [Hashie::Mash] Message attachments.
117
+ #
118
+ def get_message( # rubocop:disable Metrics/ParameterLists
119
+ _message_id, flags, from_id, _timestamp, subject, text, _attachments
120
+ )
86
121
  is_private = subject.start_with?(' ')
87
122
  is_own = flags & 2 != 0
88
123
 
@@ -96,6 +131,11 @@ module Lita
96
131
  robot.receive(message)
97
132
  end
98
133
 
134
+ # Sends one message to a user or room.
135
+ #
136
+ # @param target [Lita::Source] The user or room to send message to.
137
+ # @param messages [String] Messages to send.
138
+ #
99
139
  def send_message(target, message) # rubocop:disable Metrics/AbcSize
100
140
  is_private = target.room.start_with?(' ')
101
141
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'lita-vkontakte'
5
- spec.version = '0.1.0'
5
+ spec.version = '1.0.0'
6
6
  spec.authors = ['Braiden Vasco']
7
7
  spec.email = ['braiden-vasco@mailtor.net']
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-vkontakte
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Braiden Vasco
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-17 00:00:00.000000000 Z
11
+ date: 2015-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler