github_markdown_api 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/LICENSE.md +27 -28
- data/bin/github_markdown_api +2 -0
- data/github_markdown_api.gemspec +2 -3
- data/lib/github_markdown_api.rb +6 -4
- data/lib/github_markdown_api/api_client.rb +45 -43
- data/lib/github_markdown_api/raw.rb +6 -9
- data/lib/github_markdown_api/version.rb +1 -1
- metadata +5 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5737fe7e4af01198fac341d2a3b476d3039f6d62
|
|
4
|
+
data.tar.gz: b7796252fd4bf0bc846f023755d929a727283269
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 04475cda8d9dd4770736c5f7d7f4452535551fdf7581d8ed831c34d28c8ce8801a4fafc7c565fb7b74bb7ba3072c4b9f2a25cb1ab4a342aa17726757fdb0a4b7
|
|
7
|
+
data.tar.gz: 857ed5d1dd898e319c3c9ba6dde801f2e43e15859b2a2fed81f4a0c78786e32b223b2f3a00b4f06ef111e85782e292cbe4facf9e80e8ab828fce949115c06dbc
|
data/LICENSE.md
CHANGED
|
@@ -3,25 +3,42 @@ Github_Markdown_API
|
|
|
3
3
|
|
|
4
4
|
Github Markdown API client and command-line tool.
|
|
5
5
|
|
|
6
|
-
You can redistribute it and/or modify it under either the terms of the
|
|
6
|
+
You can redistribute it and/or modify it under either the terms of the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0) or [NYSL Version 0.9982](http://www.kmonos.net/nysl/).
|
|
7
|
+
|
|
8
|
+
Apache-2.0
|
|
9
|
+
----------
|
|
10
|
+
|
|
11
|
+
> Copyright 2013 USAMI Kenta <tadsan@zonu.me>
|
|
12
|
+
>
|
|
13
|
+
> Licensed under the Apache License, Version 2.0 (the "License");
|
|
14
|
+
> you may not use this file except in compliance with the License.
|
|
15
|
+
> You may obtain a copy of the License at
|
|
16
|
+
>
|
|
17
|
+
> http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
+
>
|
|
19
|
+
> Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
> distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
> WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
> See the License for the specific language governing permissions and
|
|
23
|
+
> limitations under the License.
|
|
7
24
|
|
|
8
25
|
NYSL(ja)
|
|
9
26
|
--------
|
|
10
27
|
|
|
11
28
|
> A. 本ソフトウェアは Everyone'sWare です。このソフトを手にした一人一人が、
|
|
12
29
|
> ご自分の作ったものを扱うのと同じように、自由に利用することが出来ます。
|
|
13
|
-
>
|
|
30
|
+
>
|
|
14
31
|
> A-1. フリーウェアです。作者からは使用料等を要求しません。
|
|
15
32
|
> A-2. 有料無料や媒体の如何を問わず、自由に転載・再配布できます。
|
|
16
33
|
> A-3. いかなる種類の 改変・他プログラムでの利用 を行っても構いません。
|
|
17
34
|
> A-4. 変更したものや部分的に使用したものは、あなたのものになります。
|
|
18
35
|
> 公開する場合は、あなたの名前の下で行って下さい。
|
|
19
|
-
>
|
|
36
|
+
>
|
|
20
37
|
> B. このソフトを利用することによって生じた損害等について、作者は
|
|
21
38
|
> 責任を負わないものとします。各自の責任においてご利用下さい。
|
|
22
|
-
>
|
|
23
|
-
> C. 著作者人格権は
|
|
24
|
-
|
|
39
|
+
>
|
|
40
|
+
> C. 著作者人格権は USAMI Kenta <tadsan@zonu.me> に帰属します。著作権は放棄します。
|
|
41
|
+
>
|
|
25
42
|
> D. 以上の3項は、ソース・実行バイナリの双方に適用されます。
|
|
26
43
|
|
|
27
44
|
NYSL(en, Unofficial)
|
|
@@ -30,38 +47,20 @@ NYSL(en, Unofficial)
|
|
|
30
47
|
> A. This software is "Everyone'sWare". It means:
|
|
31
48
|
> Anybody who has this software can use it as if he/she is
|
|
32
49
|
> the author.
|
|
33
|
-
>
|
|
50
|
+
>
|
|
34
51
|
> A-1. Freeware. No fee is required.
|
|
35
52
|
> A-2. You can freely redistribute this software.
|
|
36
53
|
> A-3. You can freely modify this software. And the source
|
|
37
54
|
> may be used in any software with no limitation.
|
|
38
55
|
> A-4. When you release a modified version to public, you
|
|
39
56
|
> must publish it with your name.
|
|
40
|
-
>
|
|
57
|
+
>
|
|
41
58
|
> B. The author is not responsible for any kind of damages or loss
|
|
42
59
|
> while using or misusing this software, which is distributed
|
|
43
60
|
> "AS IS". No warranty of any kind is expressed or implied.
|
|
44
61
|
> You use AT YOUR OWN RISK.
|
|
45
|
-
>
|
|
62
|
+
>
|
|
46
63
|
> C. Copyrighted to USAMI Kenta <tadsan@zonu.me>
|
|
47
|
-
>
|
|
64
|
+
>
|
|
48
65
|
> D. Above three clauses are applied both to source and binary
|
|
49
66
|
> form of this software.
|
|
50
|
-
|
|
51
|
-
GPLv3
|
|
52
|
-
-----
|
|
53
|
-
|
|
54
|
-
> Copyright (C) 2012 Kusami, USAMI Kenta <<tadsan@zonu.me>>
|
|
55
|
-
>
|
|
56
|
-
> This program is free software: you can redistribute it and/or modify
|
|
57
|
-
> it under the terms of the GNU General Public License as published by
|
|
58
|
-
> the Free Software Foundation, either version 3 of the License, or
|
|
59
|
-
> (at your option) any later version.
|
|
60
|
-
>
|
|
61
|
-
> This program is distributed in the hope that it will be useful,
|
|
62
|
-
> but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
63
|
-
> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
64
|
-
> GNU General Public License for more details.
|
|
65
|
-
>
|
|
66
|
-
> You should have received a copy of the GNU General Public License
|
|
67
|
-
> along with this program. If not, see <http://www.gnu.org/licenses/>.
|
data/bin/github_markdown_api
CHANGED
data/github_markdown_api.gemspec
CHANGED
|
@@ -10,15 +10,14 @@ Gem::Specification.new do |spec|
|
|
|
10
10
|
spec.email = ["tadsan@zonu.me"]
|
|
11
11
|
spec.description = %q{GitHub Markdown API client and command-line tool}
|
|
12
12
|
spec.summary = %q{}
|
|
13
|
-
spec.homepage = "
|
|
14
|
-
spec.licenses = %w[
|
|
13
|
+
spec.homepage = "https://github.com/zonuexe/ruby-github_markdown_api"
|
|
14
|
+
spec.licenses = %w[Apache-2.0 NYSL]
|
|
15
15
|
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
19
|
spec.require_paths = ["lib"]
|
|
20
20
|
|
|
21
|
-
spec.add_dependency 'hashize'
|
|
22
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
|
23
22
|
spec.add_development_dependency "rake"
|
|
24
23
|
end
|
data/lib/github_markdown_api.rb
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
require 'github_markdown_api/version'
|
|
2
|
-
require 'github_markdown_api/raw'
|
|
3
2
|
|
|
4
3
|
module GitHubMarkdownAPI
|
|
5
4
|
DEFAULT_SCHEME = :https
|
|
6
|
-
DEFAULT_HOST = 'api.github.com'
|
|
5
|
+
DEFAULT_HOST = 'api.github.com'.freeze
|
|
7
6
|
DEFAULT_PORT = nil
|
|
8
7
|
DEFAULT_ENDPOINTS = {
|
|
9
8
|
raw: '/markdown/raw',
|
|
10
9
|
attr: '/markdown',
|
|
11
|
-
}
|
|
10
|
+
}.freeze
|
|
12
11
|
DEFAULT_AUTH = nil
|
|
13
|
-
DEFAULT_CONTENT_TYPE = 'text/plain'
|
|
12
|
+
DEFAULT_CONTENT_TYPE = 'text/plain'.freeze
|
|
13
|
+
|
|
14
|
+
autoload :APIClient, 'github_markdown_api/api_client'
|
|
15
|
+
autoload :Raw, 'github_markdown_api/raw'
|
|
14
16
|
end
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
require 'uri'
|
|
2
2
|
require 'net/https'
|
|
3
|
-
require 'github_markdown_api/version'
|
|
4
3
|
|
|
5
4
|
# Abstract class of API Clients
|
|
6
5
|
# @abstract
|
|
7
6
|
class GitHubMarkdownAPI::APIClient
|
|
7
|
+
def self.render(markdown)
|
|
8
|
+
new.render(markdown)
|
|
9
|
+
end
|
|
10
|
+
|
|
8
11
|
# @param [Hash,String] args
|
|
9
|
-
def initialize
|
|
12
|
+
def initialize(args = {}, sub_args = {})
|
|
10
13
|
case args
|
|
11
14
|
when Hash
|
|
12
|
-
set_option
|
|
15
|
+
set_option(args)
|
|
13
16
|
when String
|
|
14
17
|
# pending
|
|
15
18
|
end
|
|
@@ -35,77 +38,76 @@ class GitHubMarkdownAPI::APIClient
|
|
|
35
38
|
|
|
36
39
|
# @param [Hash] args
|
|
37
40
|
# @return [self]
|
|
38
|
-
def set_option
|
|
41
|
+
def set_option(args)
|
|
39
42
|
option = default_options.merge(args)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
|
|
44
|
+
self.scheme = option[:scheme].to_sym
|
|
45
|
+
self.host = option[:host].to_s
|
|
46
|
+
self.port = option[:port]
|
|
47
|
+
self.endpoints = option[:endpoints].to_h
|
|
48
|
+
self.content_type = option[:content_type].to_s
|
|
49
|
+
|
|
50
|
+
self
|
|
46
51
|
end
|
|
47
52
|
|
|
48
|
-
#
|
|
49
|
-
# @
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
host: GitHubMarkdownAPI::DEFAULT_HOST,
|
|
54
|
-
port: GitHubMarkdownAPI::DEFAULT_PORT,
|
|
55
|
-
endpoints: GitHubMarkdownAPI::DEFAULT_ENDPOINTS,
|
|
56
|
-
auth: GitHubMarkdownAPI::DEFAULT_AUTH,
|
|
57
|
-
content_type: GitHubMarkdownAPI::DEFAULT_CONTENT_TYPE,
|
|
58
|
-
}
|
|
53
|
+
# Renders HTML from Markdown
|
|
54
|
+
# @param [String] markdown
|
|
55
|
+
# @abstract
|
|
56
|
+
def render(markdown)
|
|
57
|
+
raise NotImplementedError, "#{__method__} is a abstract method."
|
|
59
58
|
end
|
|
60
59
|
|
|
60
|
+
private
|
|
61
|
+
|
|
61
62
|
# Requests API
|
|
62
63
|
# @param [URI] raw_uri
|
|
63
64
|
# @param [Hash] request
|
|
64
65
|
# @return [String]
|
|
65
|
-
def request
|
|
66
|
+
def request(raw_uri, post)
|
|
66
67
|
http = Net::HTTP.new(raw_uri.host, raw_uri.port)
|
|
67
|
-
|
|
68
|
+
|
|
69
|
+
if scheme == :https
|
|
68
70
|
http.use_ssl = true
|
|
69
71
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
70
72
|
end
|
|
71
73
|
|
|
72
|
-
response = http.start{ http.request
|
|
74
|
+
response = http.start { http.request(post) }
|
|
73
75
|
@last_response = response
|
|
74
76
|
|
|
75
77
|
case response
|
|
76
78
|
when Net::HTTPSuccess
|
|
77
|
-
|
|
79
|
+
response.body
|
|
78
80
|
else
|
|
79
81
|
raise RuntimeError, response
|
|
80
82
|
end
|
|
81
83
|
end
|
|
82
84
|
|
|
83
|
-
# Renders HTML from Markdown
|
|
84
|
-
# @param [String] markdown
|
|
85
|
-
# @abstract
|
|
86
|
-
def render (markdown)
|
|
87
|
-
raise NotImplementedError, "#{__method__} is a abstract method."
|
|
88
|
-
end
|
|
89
|
-
|
|
90
85
|
# Returns endpoint of API type
|
|
91
86
|
# @param [Symbol,#to_sym] type
|
|
92
87
|
# @return [URI]
|
|
93
|
-
def endpoint
|
|
94
|
-
path
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
when :https; URI::HTTPS
|
|
98
|
-
end
|
|
88
|
+
def endpoint(type)
|
|
89
|
+
path = endpoints[type.to_sym]
|
|
90
|
+
scheme_class = URI.scheme_list.fetch(scheme.to_s.upcase)
|
|
91
|
+
|
|
99
92
|
param = {
|
|
100
|
-
host:
|
|
93
|
+
host: host,
|
|
101
94
|
path: path,
|
|
95
|
+
port: (port || 443)
|
|
102
96
|
}
|
|
103
|
-
param[:port] = @port || 443
|
|
104
97
|
|
|
105
|
-
|
|
98
|
+
scheme_class.build(param)
|
|
106
99
|
end
|
|
107
100
|
|
|
108
|
-
|
|
109
|
-
|
|
101
|
+
# Returns hash of default options
|
|
102
|
+
# @return [Hash]
|
|
103
|
+
def default_options
|
|
104
|
+
{
|
|
105
|
+
scheme: GitHubMarkdownAPI::DEFAULT_SCHEME,
|
|
106
|
+
host: GitHubMarkdownAPI::DEFAULT_HOST,
|
|
107
|
+
port: GitHubMarkdownAPI::DEFAULT_PORT,
|
|
108
|
+
endpoints: GitHubMarkdownAPI::DEFAULT_ENDPOINTS,
|
|
109
|
+
auth: GitHubMarkdownAPI::DEFAULT_AUTH,
|
|
110
|
+
content_type: GitHubMarkdownAPI::DEFAULT_CONTENT_TYPE,
|
|
111
|
+
}
|
|
110
112
|
end
|
|
111
113
|
end
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
require 'uri'
|
|
2
|
-
require 'net/https'
|
|
3
|
-
require 'github_markdown_api/version'
|
|
4
|
-
require 'github_markdown_api/api_client'
|
|
5
|
-
|
|
6
1
|
# Client implementation of Markdown Raw API
|
|
7
2
|
class GitHubMarkdownAPI::Raw < GitHubMarkdownAPI::APIClient
|
|
8
3
|
# @param [String] markdown
|
|
9
4
|
# @return [String]
|
|
10
|
-
def render
|
|
5
|
+
def render(markdown)
|
|
11
6
|
raw_uri = endpoint(:raw)
|
|
12
|
-
|
|
7
|
+
|
|
8
|
+
headers = {
|
|
13
9
|
'Content-Type' => @content_type
|
|
14
10
|
}
|
|
15
|
-
|
|
11
|
+
|
|
12
|
+
post = Net::HTTP::Post.new(raw_uri, headers)
|
|
16
13
|
post.body = markdown
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
request(raw_uri, post)
|
|
19
16
|
end
|
|
20
17
|
end
|
metadata
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: github_markdown_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- USAMI Kenta
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-12-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: hashize
|
|
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
13
|
- !ruby/object:Gem::Dependency
|
|
28
14
|
name: bundler
|
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -72,9 +58,9 @@ files:
|
|
|
72
58
|
- lib/github_markdown_api/api_client.rb
|
|
73
59
|
- lib/github_markdown_api/raw.rb
|
|
74
60
|
- lib/github_markdown_api/version.rb
|
|
75
|
-
homepage:
|
|
61
|
+
homepage: https://github.com/zonuexe/ruby-github_markdown_api
|
|
76
62
|
licenses:
|
|
77
|
-
-
|
|
63
|
+
- Apache-2.0
|
|
78
64
|
- NYSL
|
|
79
65
|
metadata: {}
|
|
80
66
|
post_install_message:
|
|
@@ -93,9 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
93
79
|
version: '0'
|
|
94
80
|
requirements: []
|
|
95
81
|
rubyforge_project:
|
|
96
|
-
rubygems_version: 2.2
|
|
82
|
+
rubygems_version: 2.5.2
|
|
97
83
|
signing_key:
|
|
98
84
|
specification_version: 4
|
|
99
85
|
summary: ''
|
|
100
86
|
test_files: []
|
|
101
|
-
has_rdoc:
|