github_markdown_api 0.0.1 → 0.0.2
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/.yardopts +1 -0
- data/README.md +10 -4
- data/bin/github_markdown_api +1 -1
- data/github_markdown_api.gemspec +2 -1
- data/lib/github_markdown_api/api_client.rb +111 -0
- data/lib/github_markdown_api/raw.rb +20 -0
- data/lib/github_markdown_api/version.rb +3 -1
- data/lib/github_markdown_api.rb +1 -1
- metadata +28 -12
- data/lib/github_markdown_api/client.rb +0 -79
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0f51deadfe6eb8a74ec96e94c26032aa15e4732
|
4
|
+
data.tar.gz: 9de0644d7834a2a2543e54ebc34c8386bc8e5704
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 397ef2cdb9b4a14cc48aefc52c97399cfd8182b9fbbf481139b8cfa6f645fe4e2e9bb23b59a6e85f92aaa7776bbbb483fa82bafcd484fc716818c56d3f245bd6
|
7
|
+
data.tar.gz: f0e18d25d97014f59a7967d3145c13f39b2eb78190e12a6c7c3e19be52b21d17af58db8f11cb9eda0ff88a8d63863bf459298179e2cc9e224b79c8a7393db9c0
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown
|
data/README.md
CHANGED
@@ -21,6 +21,8 @@ Or install it yourself as:
|
|
21
21
|
Usage
|
22
22
|
-----
|
23
23
|
|
24
|
+
### Raw API
|
25
|
+
|
24
26
|
In ruby script:
|
25
27
|
|
26
28
|
```ruby
|
@@ -30,7 +32,7 @@ md = <<EOM
|
|
30
32
|
AWESOME SCRIPT
|
31
33
|
==============
|
32
34
|
|
33
|
-
It's a wonderful markup
|
35
|
+
It's a wonderful markup language!
|
34
36
|
|
35
37
|
* Markdown
|
36
38
|
* reStructuredText
|
@@ -44,7 +46,7 @@ puts html
|
|
44
46
|
# <h1>
|
45
47
|
# <a name="awesome-script" class="anchor" href="#awesome-script"><span class="octicon octicon-link"></span></a>AWESOME SCRIPT</h1>
|
46
48
|
#
|
47
|
-
# <p>It's a wonderful markup
|
49
|
+
# <p>It's a wonderful markup language!</p>
|
48
50
|
#
|
49
51
|
# <ul>
|
50
52
|
# <li>Markdown</li>
|
@@ -59,7 +61,7 @@ In command-line:
|
|
59
61
|
AWESOME SCRIPT
|
60
62
|
==============
|
61
63
|
|
62
|
-
It's a wonderful markup
|
64
|
+
It's a wonderful markup language!
|
63
65
|
|
64
66
|
* Markdown
|
65
67
|
* reStructuredText
|
@@ -69,7 +71,7 @@ It's a wonderful markup languages!
|
|
69
71
|
<h1>
|
70
72
|
<a name="awesome-script" class="anchor" href="#awesome-script"><span class="octicon octicon-link"></span></a>AWESOME SCRIPT</h1>
|
71
73
|
|
72
|
-
<p>It's a wonderful markup
|
74
|
+
<p>It's a wonderful markup language!</p>
|
73
75
|
|
74
76
|
<ul>
|
75
77
|
<li>Markdown</li>
|
@@ -77,6 +79,10 @@ It's a wonderful markup languages!
|
|
77
79
|
</ul>
|
78
80
|
```
|
79
81
|
|
82
|
+
### Attr API
|
83
|
+
|
84
|
+
|
85
|
+
|
80
86
|
### Advansed
|
81
87
|
|
82
88
|
```
|
data/bin/github_markdown_api
CHANGED
data/github_markdown_api.gemspec
CHANGED
@@ -11,13 +11,14 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.description = %q{GitHub Markdown API client and command-line tool}
|
12
12
|
spec.summary = %q{}
|
13
13
|
spec.homepage = "http://dt.zonu.me/"
|
14
|
-
spec.licenses = %w[
|
14
|
+
spec.licenses = %w[LGPLv3 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'
|
21
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
23
|
spec.add_development_dependency "rake"
|
23
24
|
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/https'
|
3
|
+
require 'github_markdown_api/version'
|
4
|
+
|
5
|
+
# Abstract class of API Clients
|
6
|
+
# @abstract
|
7
|
+
class GitHubMarkdownAPI::APIClient
|
8
|
+
# @param [Hash,String] args
|
9
|
+
def initialize (args = {}, sub_args = {})
|
10
|
+
case args
|
11
|
+
when Hash
|
12
|
+
set_option args
|
13
|
+
when String
|
14
|
+
# pending
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :last_response
|
19
|
+
|
20
|
+
# @return [Symbol] Scheme of API
|
21
|
+
# @note `:http` of `:https`
|
22
|
+
attr_accessor :scheme
|
23
|
+
|
24
|
+
# @return [String] Hostname
|
25
|
+
attr_accessor :host
|
26
|
+
|
27
|
+
# @return [Fixnum] Port number
|
28
|
+
attr_accessor :port
|
29
|
+
|
30
|
+
# @return [Hash] Endpoint (Server path of API)
|
31
|
+
attr_accessor :endpoints
|
32
|
+
|
33
|
+
# @return [String] HTTP ContentType
|
34
|
+
attr_accessor :content_type
|
35
|
+
|
36
|
+
# @param [Hash] args
|
37
|
+
# @return [self]
|
38
|
+
def set_option (args)
|
39
|
+
option = default_options.merge(args)
|
40
|
+
@scheme = option[:scheme].intern
|
41
|
+
@host = option[:host].to_s
|
42
|
+
@port = option[:port]
|
43
|
+
@endpoints = option[:endpoints].to_hash
|
44
|
+
@content_type = option[:content_type].to_s
|
45
|
+
return self
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns hash of default options
|
49
|
+
# @return [Hash]
|
50
|
+
def default_options
|
51
|
+
return {
|
52
|
+
scheme: GitHubMarkdownAPI::DEFAULT_SCHEME,
|
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
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
# Requests API
|
62
|
+
# @param [URI] raw_uri
|
63
|
+
# @param [Hash] request
|
64
|
+
# @return [String]
|
65
|
+
def request (raw_uri, post)
|
66
|
+
http = Net::HTTP.new(raw_uri.host, raw_uri.port)
|
67
|
+
if @scheme == :https
|
68
|
+
http.use_ssl = true
|
69
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
70
|
+
end
|
71
|
+
|
72
|
+
response = http.start{ http.request post }
|
73
|
+
@last_response = response
|
74
|
+
|
75
|
+
case response
|
76
|
+
when Net::HTTPSuccess
|
77
|
+
return response.body
|
78
|
+
else
|
79
|
+
raise RuntimeError, response
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
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
|
+
# Returns endpoint of API type
|
91
|
+
# @param [Symbol,#to_sym] type
|
92
|
+
# @return [URI]
|
93
|
+
def endpoint (type)
|
94
|
+
path = @endpoints[type.to_sym]
|
95
|
+
klass = case @scheme
|
96
|
+
when :http; URI::HTTP
|
97
|
+
when :https; URI::HTTPS
|
98
|
+
end
|
99
|
+
param = {
|
100
|
+
host: @host,
|
101
|
+
path: path,
|
102
|
+
}
|
103
|
+
param[:port] = @port || 443
|
104
|
+
|
105
|
+
return klass.build(param)
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.render (markdown)
|
109
|
+
return self.new.render markdown
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/https'
|
3
|
+
require 'github_markdown_api/version'
|
4
|
+
require 'github_markdown_api/api_client'
|
5
|
+
|
6
|
+
# Client implementation of Markdown Raw API
|
7
|
+
class GitHubMarkdownAPI::Raw < GitHubMarkdownAPI::APIClient
|
8
|
+
# @param [String] markdown
|
9
|
+
# @return [String]
|
10
|
+
def render (markdown)
|
11
|
+
raw_uri = endpoint(:raw)
|
12
|
+
header = {
|
13
|
+
'Content-Type' => @content_type
|
14
|
+
}
|
15
|
+
post = Net::HTTP::Post.new(raw_uri, header)
|
16
|
+
post.body = markdown
|
17
|
+
|
18
|
+
return request(raw_uri, post)
|
19
|
+
end
|
20
|
+
end
|
data/lib/github_markdown_api.rb
CHANGED
metadata
CHANGED
@@ -1,41 +1,55 @@
|
|
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.2
|
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: 2014-01-25 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'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- - ~>
|
31
|
+
- - "~>"
|
18
32
|
- !ruby/object:Gem::Version
|
19
33
|
version: '1.3'
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
|
-
- - ~>
|
38
|
+
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '1.3'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- -
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- -
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
description: GitHub Markdown API client and command-line tool
|
@@ -46,7 +60,8 @@ executables:
|
|
46
60
|
extensions: []
|
47
61
|
extra_rdoc_files: []
|
48
62
|
files:
|
49
|
-
- .gitignore
|
63
|
+
- ".gitignore"
|
64
|
+
- ".yardopts"
|
50
65
|
- Gemfile
|
51
66
|
- LICENSE.md
|
52
67
|
- README.md
|
@@ -54,11 +69,12 @@ files:
|
|
54
69
|
- bin/github_markdown_api
|
55
70
|
- github_markdown_api.gemspec
|
56
71
|
- lib/github_markdown_api.rb
|
57
|
-
- lib/github_markdown_api/
|
72
|
+
- lib/github_markdown_api/api_client.rb
|
73
|
+
- lib/github_markdown_api/raw.rb
|
58
74
|
- lib/github_markdown_api/version.rb
|
59
75
|
homepage: http://dt.zonu.me/
|
60
76
|
licenses:
|
61
|
-
-
|
77
|
+
- LGPLv3
|
62
78
|
- NYSL
|
63
79
|
metadata: {}
|
64
80
|
post_install_message:
|
@@ -67,17 +83,17 @@ require_paths:
|
|
67
83
|
- lib
|
68
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
69
85
|
requirements:
|
70
|
-
- -
|
86
|
+
- - ">="
|
71
87
|
- !ruby/object:Gem::Version
|
72
88
|
version: '0'
|
73
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
90
|
requirements:
|
75
|
-
- -
|
91
|
+
- - ">="
|
76
92
|
- !ruby/object:Gem::Version
|
77
93
|
version: '0'
|
78
94
|
requirements: []
|
79
95
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.2.1
|
81
97
|
signing_key:
|
82
98
|
specification_version: 4
|
83
99
|
summary: ''
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'net/https'
|
3
|
-
require 'github_markdown_api/version'
|
4
|
-
|
5
|
-
class GitHubMarkdownAPI::Client
|
6
|
-
# @param [Hash] args
|
7
|
-
def initialize (args = {})
|
8
|
-
set_option args
|
9
|
-
end
|
10
|
-
|
11
|
-
attr_reader :last_response
|
12
|
-
|
13
|
-
def render
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
# @param [Hash] args
|
18
|
-
# @return []
|
19
|
-
def set_option (args)
|
20
|
-
option = default_options.merge(args)
|
21
|
-
@scheme = option[:scheme].intern
|
22
|
-
@host = option[:host].to_s
|
23
|
-
@port = option[:port].to_i
|
24
|
-
@endpoints = option[:endpoints].to_hash
|
25
|
-
@content_type = option[:content_type].to_s
|
26
|
-
return self
|
27
|
-
end
|
28
|
-
|
29
|
-
# @return [Hash]
|
30
|
-
def default_options
|
31
|
-
return {
|
32
|
-
scheme: GitHubMarkdownAPI::DEFAULT_SCHEME,
|
33
|
-
host: GitHubMarkdownAPI::DEFAULT_HOST,
|
34
|
-
port: GitHubMarkdownAPI::DEFAULT_PORT,
|
35
|
-
endpoints: GitHubMarkdownAPI::DEFAULT_ENDPOINTS,
|
36
|
-
auth: GitHubMarkdownAPI::DEFAULT_AUTH,
|
37
|
-
content_type: GitHubMarkdownAPI::DEFAULT_CONTENT_TYPE,
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
# @param [String] markdown
|
42
|
-
# @return [String]
|
43
|
-
def raw (markdown)
|
44
|
-
raw_uri = endpoint(:raw)
|
45
|
-
header = {
|
46
|
-
'Content-Type' => @content_type
|
47
|
-
}
|
48
|
-
post = Net::HTTP::Post.new(raw_uri, header)
|
49
|
-
post.body = markdown
|
50
|
-
|
51
|
-
request = Net::HTTP.new(raw_uri.host, raw_uri.port)
|
52
|
-
if @scheme == :https
|
53
|
-
request.use_ssl = true
|
54
|
-
request.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
55
|
-
end
|
56
|
-
|
57
|
-
response = request.start{|http| http.request(post) }
|
58
|
-
@last_response = response
|
59
|
-
|
60
|
-
case response
|
61
|
-
when Net::HTTPSuccess
|
62
|
-
return response.body
|
63
|
-
else
|
64
|
-
raise RuntimeError, response
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
# @param [Symbol,#to_sym]
|
69
|
-
# @return [URI]
|
70
|
-
def endpoint(type)
|
71
|
-
path = @endpoints[type.to_sym]
|
72
|
-
klass = case @scheme
|
73
|
-
when :http; URI::HTTP
|
74
|
-
when :https; URI::HTTPS
|
75
|
-
end
|
76
|
-
uri = klass.build(host: @host, path: path, port: @port)
|
77
|
-
return uri
|
78
|
-
end
|
79
|
-
end
|