ruboty-qiita_police 0.0.1

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: 6c8dd03cab7cc0399c0b8dec700c9e6afe61b926
4
+ data.tar.gz: a080dacef20fe6031a9ac8468bc9679a10e31d83
5
+ SHA512:
6
+ metadata.gz: aea517190ee3504c2da078e7f8d0ce8d771c607c3d934d3587cd2c29b1061e185aa0bf65c91a99267b152b7586de5a454723a229a54e8037a07ea7cf0d739e02
7
+ data.tar.gz: 1b7c4ff0f3ad5bd8cf0d80cfdc58dc9083834be54638285f02ad07438ae882e16421999b53092f5cd1249575602818ee2b76445859e5f668490cfb3e6b1bad8b
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-qiita_police.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ryo Nakamura
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.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # Ruboty::QiitaPolice
2
+ [Ruboty](https://github.com/r7kamura/ruboty) plug-in to police items by staff.
3
+
4
+ ## Installation
5
+ ```rb
6
+ gem "ruboty-qiita_police"
7
+ ```
8
+
9
+ ## Usage
10
+ ### Authentication
11
+ ```
12
+ @ruboty save my qiita access token 0123456789abcdef0123456789abcdef01234567
13
+ ```
14
+
15
+ ### Ban
16
+ Pass URL with reason.
17
+
18
+ ```
19
+ @ruboty ban http://qiita.com/username/items/0123456789abcdef0123 by bug
20
+ @ruboty ban http://qiita.com/username/items/0123456789abcdef0123 by notprogram
21
+ @ruboty ban http://qiita.com/username/items/0123456789abcdef0123 by request
22
+ @ruboty ban http://qiita.com/username/items/0123456789abcdef0123 by test
23
+ @ruboty ban http://qiita.com/username/items/0123456789abcdef0123 by tos
24
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,62 @@
1
+ require "qiita"
2
+
3
+ module Ruboty
4
+ module Handlers
5
+ class QiitaPolice < Base
6
+ BRAIN_NAMESPACE = "qiita-police"
7
+
8
+ REASONS_TABLE = {
9
+ "bug" => "bugreport",
10
+ "notprogram" => "notprogram",
11
+ "request" => "featurerequest",
12
+ "test" => "test",
13
+ "tos" => "tosviolation",
14
+ }
15
+
16
+ on(
17
+ %r<ban http://qiita\.com/.+/items/(?<item_id>[0-9a-f]+) for (?<reason>#{REASONS_TABLE.keys.join("|")})\z>,
18
+ description: "Ban item",
19
+ name: :ban,
20
+ )
21
+
22
+ on(
23
+ /save my qiita access token (?<token>.+)/,
24
+ description: "Save sender's Qiita access token",
25
+ name: :save,
26
+ )
27
+
28
+ def ban(message)
29
+ case
30
+ when (client = client_for(message.from_name)).nil?
31
+ message.reply("I don't know your Qiita access token")
32
+ when !REASONS_TABLE.include?(message[:reason])
33
+ false
34
+ else
35
+ response = client.put("/api/v2/items/#{message[:item_id]}/ban", reason: message[:reason])
36
+ if response.status == 204
37
+ message.reply("Banned")
38
+ else
39
+ message.reply(response.body["message"])
40
+ end
41
+ end
42
+ end
43
+
44
+ def save(message)
45
+ access_tokens_table[message.from_name] = message[:token]
46
+ message.reply("Saved #{message.from_name}'s qiita access token")
47
+ end
48
+
49
+ private
50
+
51
+ def access_tokens_table
52
+ robot.brain.data[BRAIN_NAMESPACE] ||= {}
53
+ end
54
+
55
+ def client_for(username)
56
+ if access_token = access_tokens_table[username]
57
+ Qiita::Client.new(access_token: access_token)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,2 @@
1
+ require "ruboty/handlers/qiita_police"
2
+ require "ruboty/qiita_police/version"
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module QiitaPolice
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ruboty/qiita_police/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruboty-qiita_police"
7
+ spec.version = Ruboty::QiitaPolice::VERSION
8
+ spec.authors = ["Ryo Nakamura"]
9
+ spec.email = ["r7kamura@gmail.com"]
10
+ spec.summary = "Ruboty plug-in to police items by staff"
11
+ spec.homepage = "https://github.com/increments/ruboty-qiita_police"
12
+ spec.license = "MIT"
13
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_dependency "qiita"
17
+ spec.add_dependency "ruboty"
18
+ spec.add_development_dependency "bundler", "~> 1.8"
19
+ spec.add_development_dependency "rake", "~> 10.0"
20
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-qiita_police
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: qiita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruboty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
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
+ - r7kamura@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/ruboty/handlers/qiita_police.rb
82
+ - lib/ruboty/qiita_police.rb
83
+ - lib/ruboty/qiita_police/version.rb
84
+ - ruboty-qiita_police.gemspec
85
+ homepage: https://github.com/increments/ruboty-qiita_police
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.4.5
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Ruboty plug-in to police items by staff
109
+ test_files: []
110
+ has_rdoc: