github_markdown_api 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: d914dac7a1db4e9a8d926e7786f7b555ca81613a
4
+ data.tar.gz: 2f8a4a7e1333fcc78f27890875dc80f1853d44fd
5
+ SHA512:
6
+ metadata.gz: d30dd29cc4fb70bbff25dfb8de2f96cffefb30b983cdc0b3234cf9b0360627f3f7cd4f9fd5200bc42ebd9b5418e63d63fa19cfe172c396206d16bb94523034ea
7
+ data.tar.gz: 559747ada9b2946fa967a1cdb26e26e6a93ac05f97c569812423d64a9182448d4c21cf89fd6b0c8245b92d56409bf5616eb9b98675a08f9a9b96979109e6c4b0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in github_markdown_api.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,67 @@
1
+ Github_Markdown_API
2
+ ===================
3
+
4
+ Github Markdown API client and command-line tool.
5
+
6
+ You can redistribute it and/or modify it under either the terms of the GPL Version 3 or NYSL(0.9982).
7
+
8
+ NYSL(ja)
9
+ --------
10
+
11
+ > A. 本ソフトウェアは Everyone'sWare です。このソフトを手にした一人一人が、
12
+ > ご自分の作ったものを扱うのと同じように、自由に利用することが出来ます。
13
+ >
14
+ > A-1. フリーウェアです。作者からは使用料等を要求しません。
15
+ > A-2. 有料無料や媒体の如何を問わず、自由に転載・再配布できます。
16
+ > A-3. いかなる種類の 改変・他プログラムでの利用 を行っても構いません。
17
+ > A-4. 変更したものや部分的に使用したものは、あなたのものになります。
18
+ > 公開する場合は、あなたの名前の下で行って下さい。
19
+ >
20
+ > B. このソフトを利用することによって生じた損害等について、作者は
21
+ > 責任を負わないものとします。各自の責任においてご利用下さい。
22
+ >
23
+ > C. 著作者人格権は ZonuEXE(Kusami, tadsan@zonu.me) に帰属します。著作権は放棄します。
24
+
25
+ > D. 以上の3項は、ソース・実行バイナリの双方に適用されます。
26
+
27
+ NYSL(en, Unofficial)
28
+ --------------------
29
+
30
+ > A. This software is "Everyone'sWare". It means:
31
+ > Anybody who has this software can use it as if he/she is
32
+ > the author.
33
+ >
34
+ > A-1. Freeware. No fee is required.
35
+ > A-2. You can freely redistribute this software.
36
+ > A-3. You can freely modify this software. And the source
37
+ > may be used in any software with no limitation.
38
+ > A-4. When you release a modified version to public, you
39
+ > must publish it with your name.
40
+ >
41
+ > B. The author is not responsible for any kind of damages or loss
42
+ > while using or misusing this software, which is distributed
43
+ > "AS IS". No warranty of any kind is expressed or implied.
44
+ > You use AT YOUR OWN RISK.
45
+ >
46
+ > C. Copyrighted to USAMI Kenta <tadsan@zonu.me>
47
+ >
48
+ > D. Above three clauses are applied both to source and binary
49
+ > 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/README.md ADDED
@@ -0,0 +1,100 @@
1
+ GitHubMarkdownAPI
2
+ =================
3
+
4
+ GitHub's [Markdown Rendering API](http://developer.github.com/v3/markdown/) client and command-line tool.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'github_markdown_api'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install github_markdown_api
20
+
21
+ Usage
22
+ -----
23
+
24
+ In ruby script:
25
+
26
+ ```ruby
27
+ require 'github_markdown_api'
28
+
29
+ md = <<EOM
30
+ AWESOME SCRIPT
31
+ ==============
32
+
33
+ It's a wonderful markup languages!
34
+
35
+ * Markdown
36
+ * reStructuredText
37
+ EOM
38
+
39
+ github_md = GitHubMarkdownAPI::Client.new
40
+ html = github_md.raw(md)
41
+
42
+ puts html
43
+ #=>
44
+ # <h1>
45
+ # <a name="awesome-script" class="anchor" href="#awesome-script"><span class="octicon octicon-link"></span></a>AWESOME SCRIPT</h1>
46
+ #
47
+ # <p>It's a wonderful markup languages!</p>
48
+ #
49
+ # <ul>
50
+ # <li>Markdown</li>
51
+ # <li>reStructuredText</li>
52
+ # </ul>
53
+ ```
54
+
55
+ In command-line:
56
+
57
+ ```sh
58
+ % cat ./awesome.md
59
+ AWESOME SCRIPT
60
+ ==============
61
+
62
+ It's a wonderful markup languages!
63
+
64
+ * Markdown
65
+ * reStructuredText
66
+
67
+ % github_markdown_api ./awesome.md > ./awesome.html
68
+ % cat ./awesome.html
69
+ <h1>
70
+ <a name="awesome-script" class="anchor" href="#awesome-script"><span class="octicon octicon-link"></span></a>AWESOME SCRIPT</h1>
71
+
72
+ <p>It's a wonderful markup languages!</p>
73
+
74
+ <ul>
75
+ <li>Markdown</li>
76
+ <li>reStructuredText</li>
77
+ </ul>
78
+ ```
79
+
80
+ ### Advansed
81
+
82
+ ```
83
+ my_md_api = GitHubMarkdownAPI::Client.new(
84
+ scheme: 'http',
85
+ host: 'your.markdown.serv',
86
+ port: 3939,
87
+ endpoints: {raw: '/md/raw'},
88
+ )
89
+
90
+ puts my_md_api(markdown)
91
+ ```
92
+
93
+ Contributing
94
+ ------------
95
+
96
+ 1. Fork it
97
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
98
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
99
+ 4. Push to the branch (`git push origin my-new-feature`)
100
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'github_markdown_api'
4
+
5
+ puts GitHubMarkdownAPI::Client.new.raw(ARGF.read)
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'github_markdown_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "github_markdown_api"
8
+ spec.version = GitHubMarkdownAPI::VERSION
9
+ spec.authors = ["USAMI Kenta"]
10
+ spec.email = ["tadsan@zonu.me"]
11
+ spec.description = %q{GitHub Markdown API client and command-line tool}
12
+ spec.summary = %q{}
13
+ spec.homepage = "http://dt.zonu.me/"
14
+ spec.licenses = %w[GPLv3 NYSL]
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,79 @@
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
@@ -0,0 +1,3 @@
1
+ module GitHubMarkdownAPI
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,14 @@
1
+ require 'github_markdown_api/version'
2
+ require 'github_markdown_api/client'
3
+
4
+ module GitHubMarkdownAPI
5
+ DEFAULT_SCHEME = :https
6
+ DEFAULT_HOST = 'api.github.com'
7
+ DEFAULT_PORT = nil
8
+ DEFAULT_ENDPOINTS = {
9
+ raw: '/markdown/raw',
10
+ attr: '/markdown',
11
+ }
12
+ DEFAULT_AUTH = nil
13
+ DEFAULT_CONTENT_TYPE = 'text/plain'
14
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github_markdown_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - USAMI Kenta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-27 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: GitHub Markdown API client and command-line tool
42
+ email:
43
+ - tadsan@zonu.me
44
+ executables:
45
+ - github_markdown_api
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.md
52
+ - README.md
53
+ - Rakefile
54
+ - bin/github_markdown_api
55
+ - github_markdown_api.gemspec
56
+ - lib/github_markdown_api.rb
57
+ - lib/github_markdown_api/client.rb
58
+ - lib/github_markdown_api/version.rb
59
+ homepage: http://dt.zonu.me/
60
+ licenses:
61
+ - GPLv3
62
+ - NYSL
63
+ metadata: {}
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.0.6
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: ''
84
+ test_files: []
85
+ has_rdoc: