ruboty-qiitateam_template 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +58 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ruboty/handlers/qiitateam_template.rb +69 -0
- data/lib/ruboty/qiitateam_template.rb +8 -0
- data/lib/ruboty/qiitateam_template/version.rb +5 -0
- data/ruboty-qiitateam_template.gemspec +35 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 95c5704e310bacd1a5fc852bcda862159e814ad4
|
4
|
+
data.tar.gz: 7269aff012cb1ae597be611afbbc49c0c450e838
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f3ca24d439d68388a556f221c7f9e1543f37182c614a15244136fc783c2a04cc77f9ad2844ce8e97e7003c8c34a2a6263cc8f1b03a1de039aafc2cd1e674cdb5
|
7
|
+
data.tar.gz: 4da7f1c9d9bec8099cdc0d59e2a1fa7a274f3d6479a2f92d607707678140f7f3a5d7f468f7e4a5f8dcccadea8aaabe7c31b55a47ccb4e264ad9c840cd3b2efe0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 MiZUP
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Ruboty::QiitateamTemplate
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ruboty/qiitateam_template`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ruboty-qiitateam_template, :git => 'https://github.com/mizukmb/ruboty-qiitateam_template.git
|
13
|
+
```
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
**Requre**
|
17
|
+
Set environment
|
18
|
+
|
19
|
+
```
|
20
|
+
export ORGANIZATION_NAME={your organization name}
|
21
|
+
export QIITA_ACCESS_TOKEN={your qiita access token}
|
22
|
+
```
|
23
|
+
|
24
|
+
How to get this
|
25
|
+
|
26
|
+
- organization neme -> your organization's URL
|
27
|
+
- ex) `https://foobar.qiita.com/` <- `foobar` is organization name.
|
28
|
+
- qiita access token -> see: https://qiita.com/api/v2/docs#認証認可
|
29
|
+
|
30
|
+
|
31
|
+
### Create article
|
32
|
+
|
33
|
+
`test_bot /create template (?<id>\d+) *(?<coediting>coediting)?/`
|
34
|
+
|
35
|
+
For example
|
36
|
+
|
37
|
+
```
|
38
|
+
@foobar create template 10
|
39
|
+
```
|
40
|
+
|
41
|
+
Created article using template id 10.
|
42
|
+
|
43
|
+
You can article by coediting mode also.
|
44
|
+
|
45
|
+
```
|
46
|
+
@foobar create template 10 coediting
|
47
|
+
```
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mizukmb/ruboty-qiitateam_template.
|
58
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ruboty/qiitateam_template"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Ruboty
|
6
|
+
module Handlers
|
7
|
+
class QiitateamTemplate < Base
|
8
|
+
on %r(create template (?<id>\d+) *(?<coediting>coediting)?), name: :create, description: "generate template on #{ENV['ORGANIZATION_NAME']}.qiita.com"
|
9
|
+
|
10
|
+
def create(message)
|
11
|
+
url = URI.parse("https://#{ENV['ORGANIZATION_NAME']}.qiita.com/api/v2/items")
|
12
|
+
req = Net::HTTP::Post.new(url.path)
|
13
|
+
req = set_headers(req)
|
14
|
+
|
15
|
+
template = template(message[:id])
|
16
|
+
coediting = message[:coediting] ? true : false
|
17
|
+
data = {
|
18
|
+
coediting: coediting,
|
19
|
+
gist: false,
|
20
|
+
tags: template[:tags],
|
21
|
+
title: template[:title],
|
22
|
+
body: template[:body]
|
23
|
+
}.to_json
|
24
|
+
|
25
|
+
req.body = data
|
26
|
+
|
27
|
+
http = Net::HTTP.new(url.host, url.port)
|
28
|
+
http.use_ssl = true
|
29
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
30
|
+
|
31
|
+
res = http.start do |http|
|
32
|
+
http.request(req)
|
33
|
+
end
|
34
|
+
|
35
|
+
created_url = JSON.load(res.body)['url']
|
36
|
+
message.reply("created #{created_url}")
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def template(id)
|
41
|
+
url = URI.parse("https://#{ENV['ORGANIZATION_NAME']}.qiita.com/api/v2/templates/#{id}")
|
42
|
+
req = Net::HTTP::Get.new(url.request_uri)
|
43
|
+
req = set_headers(req)
|
44
|
+
|
45
|
+
http = Net::HTTP.new(url.host, url.port)
|
46
|
+
http.use_ssl = true
|
47
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
48
|
+
|
49
|
+
res = http.start do |http|
|
50
|
+
http.request(req)
|
51
|
+
end
|
52
|
+
|
53
|
+
json = JSON.load(res.body)
|
54
|
+
|
55
|
+
{title: json["expanded_title"], body: json["expanded_body"], tags: json["tags"]}
|
56
|
+
end
|
57
|
+
|
58
|
+
def set_headers(req)
|
59
|
+
access_token = ENV['QIITA_ACCESS_TOKEN']
|
60
|
+
req['Accept'] = 'application/json'
|
61
|
+
req['Content-Type'] = 'application/json; charset=utf-8'
|
62
|
+
req['Authorization'] = "Bearer #{access_token}"
|
63
|
+
|
64
|
+
req
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruboty/qiitateam_template/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruboty-qiitateam_template"
|
8
|
+
spec.version = Ruboty::QiitateamTemplate::VERSION
|
9
|
+
spec.authors = ["mizukmb"]
|
10
|
+
spec.email = ["mizukmb6@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{}
|
13
|
+
spec.description = %q{}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-qiitateam_template
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mizukmb
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-13 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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
|
+
description: ''
|
42
|
+
email:
|
43
|
+
- mizukmb6@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- lib/ruboty/handlers/qiitateam_template.rb
|
56
|
+
- lib/ruboty/qiitateam_template.rb
|
57
|
+
- lib/ruboty/qiitateam_template/version.rb
|
58
|
+
- ruboty-qiitateam_template.gemspec
|
59
|
+
homepage: ''
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata:
|
63
|
+
allowed_push_host: https://rubygems.org
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.6.11
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: ''
|
84
|
+
test_files: []
|