shioruby 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: 078ab6d07d1953d758721c8351f9729b550a1c3a
4
+ data.tar.gz: 00a5cd0cc1feda1aa3021e02ea90d18bbeb5d2fb
5
+ SHA512:
6
+ metadata.gz: 49201063aea6f898d290ecb9ca167c673b1613b02abeecd0de7a2b685b1ae2eaa761bf8a5fa3434cdf6a087f42d132e2bfaa7d31015d644a5660d502ee59c2bd
7
+ data.tar.gz: d32e731c36169883b9332a383d5fcafb69cd54f0f20bc6285b81e0662275f5fc3646e46fa18c2e47f23be082965654e5a6dec3424cdfb92b5f0450337f408640
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .*.sw?
data/.gitmodules ADDED
@@ -0,0 +1,4 @@
1
+ [submodule "doc"]
2
+ path = doc
3
+ url = https://github.com/Narazaka/shioruby.git
4
+ branch = gh-pages
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format doc
3
+ --require ./spec/spec_helper.rb
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ script: bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shioruby.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # [Shioruby](https://github.com/Narazaka/shioruby)
2
+
3
+ [![Gem](https://img.shields.io/gem/v/shioruby.svg)](https://rubygems.org/gems/shioruby)
4
+ [![Gem](https://img.shields.io/gem/dtv/shioruby.svg)](https://rubygems.org/gems/shioruby)
5
+ [![Build Status](https://travis-ci.org/Narazaka/shioruby.svg)](https://travis-ci.org/Narazaka/shioruby)
6
+ [![codecov.io](https://codecov.io/github/Narazaka/shioruby/coverage.svg?branch=master)](https://codecov.io/github/Narazaka/shioruby?branch=master)
7
+ [![Code Climate](https://codeclimate.com/github/Narazaka/shioruby/badges/gpa.svg)](https://codeclimate.com/github/Narazaka/shioruby)
8
+
9
+ SHIORI Protocol Parser / Builder for Ruby
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'shioruby'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install shioruby
26
+
27
+ ## Usage
28
+
29
+ ```ruby
30
+ require 'shioruby'
31
+
32
+ p Shioruby.parse_request(<<-EOS
33
+ GET SHIORI/3.0
34
+ Charset: UTF-8
35
+ Sender: ikagaka
36
+ ID: OnClose
37
+ Reference0: user
38
+
39
+ EOS
40
+ )
41
+ #<OpenStruct method="GET", version="3.0", Charset="UTF-8", Sender="ikagaka", ID="OnClose", Reference0="user">
42
+
43
+ p Shioruby.build_response(OpenStruct.new({
44
+ code: 200,
45
+ version: '3.0',
46
+ Value: '\h\s[0]\e',
47
+ Charset: 'UTF-8',
48
+ Sender: 'shioruby',
49
+ }))
50
+ #"SHIORI/3.0 200 OK\nValue: \\h\\s[0]\\e\nCharset: UTF-8\nSender: shioruby\n\n"
51
+
52
+ request = Shioruby.parse_request(<<-EOS
53
+ GET SHIORI/3.0
54
+ Charset: UTF-8
55
+ Sender: ikagaka
56
+ ID: otherghostname
57
+ Reference0: sakura\x010\x0110
58
+
59
+ EOS
60
+ )
61
+ p request.Reference0.separated
62
+ #["sakura", "0", "10"]
63
+
64
+ # sakura.recommendsites etc.
65
+ sites = [
66
+ ['Shioruby', 'https://github.com/Narazaka/shioruby', '', '\h\s[0]This is Shioruby site.\e'],
67
+ ['ShioriJK', 'https://github.com/Narazaka/shiorijk', '', '\h\s[0]This is ShioriJK site.\e'],
68
+ ]
69
+ response_str = Shioruby.build_response(OpenStruct.new({
70
+ code: 200,
71
+ version: '3.0',
72
+ Value: sites.combined2,
73
+ Charset: 'UTF-8',
74
+ Sender: 'shioruby',
75
+ }))
76
+ p response_str
77
+ #"SHIORI/3.0 200 OK\nValue: Shioruby\u0001https://github.com/Narazaka/shioruby\u0001\u0001\\h\\s[0]This is Shioruby site.\\e\u0002ShioriJK\u0001https://github.com/Narazaka/shiorijk\u0001\u0001\\h\\s[0]This is ShioriJK site.\\e\nCharset: UTF-8\nSender: shioruby\n\n"
78
+ ```
79
+
80
+ ## API
81
+
82
+ [API Document](https://narazaka.github.io/shioruby/index.html)
83
+
84
+ ## License
85
+
86
+ This is released under [MIT License](http://narazaka.net/license/MIT?2016).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'yard'
4
+ require 'yard/rake/yardoc_task'
5
+
6
+ task :default => :spec
7
+
8
+ RSpec::Core::RakeTask.new
9
+ YARD::Rake::YardocTask.new
data/lib/shioruby.rb ADDED
@@ -0,0 +1,96 @@
1
+ require 'ostruct'
2
+
3
+ # SHIORI Protocol Parser / Builder
4
+ module Shioruby
5
+
6
+ # response messages for status codes
7
+ @@response_message = {
8
+ 200 => 'OK',
9
+ 204 => 'No Content',
10
+ 310 => 'Communicate',
11
+ 311 => 'Not Enough',
12
+ 312 => 'Advice',
13
+ 400 => 'Bad Request',
14
+ 418 => "I'm a tea pot",
15
+ 451 => 'Unavailable For Legal Reasons',
16
+ 500 => 'Internal Server Error',
17
+ }
18
+
19
+ class << self
20
+
21
+ # parse SHIORI/3.x Request
22
+ # @param [String] request_str SHIORI/3.x Request string
23
+ # @return [OpenStruct] SHIORI/3.x Request object
24
+ def parse_request(request_str)
25
+ lines = request_str.each_line.map(&:chomp).reject(&:empty?)
26
+ request_line = lines.shift
27
+ unless request_line_result = request_line.match(/^(.+) SHIORI\/([\d.]+)$/)
28
+ raise ParseError.new("invalid request line")
29
+ end
30
+ request = OpenStruct.new
31
+ request.method = request_line_result[1]
32
+ request.version = request_line_result[2]
33
+ lines.each do |line|
34
+ unless header_result = line.match(/^(.+?): (.*)$/)
35
+ raise ParseError.new("invalid header")
36
+ end
37
+ request[header_result[1]] = header_result[2]
38
+ end
39
+ request
40
+ end
41
+
42
+ # build SHIORI/3.x Response
43
+ # @param [OpenStruct] response SHIORI/3.x Response object
44
+ # @return [String] SHIORI/3.x Response string
45
+ def build_response(response)
46
+ message = response.message || @@response_message[response.code]
47
+ response.version
48
+ lines = ["SHIORI/#{response.version} #{response.code} #{message}"]
49
+ response.each_pair.reject {|key, _| ['code', 'message', 'version', :code, :message, :version].include?(key)}.each do |key, value|
50
+ lines << "#{key}: #{value}"
51
+ end
52
+ lines.join("\n") + "\n\n"
53
+ end
54
+
55
+ end
56
+
57
+ # parse error
58
+ class ParseError < RuntimeError
59
+ end
60
+ end
61
+
62
+ # convenient for SHIORI Request treatment
63
+ class String
64
+ # split \\x01 separated Reference* value like "arg1\\x01arg2\\x01arg3" into Array
65
+ # @param [String] separator separator
66
+ # @return [Array<String>] separated strings
67
+ def separated(separator = "\x01")
68
+ self.split(separator)
69
+ end
70
+
71
+ # split \\x01, \\x02 separated Reference* value like "arg1-1\\x01arg1-2\\x02arg2-1\\x01arg2-2" into Array of Array
72
+ # @param [String] separator1 1st level separator
73
+ # @param [String] separator2 2nd level separator
74
+ # @return [Array<Array<String>>] separated strings
75
+ def separated2(separator1 = "\x02", separator2 = "\x01")
76
+ self.split(separator1).map {|element| element.split(separator2)}
77
+ end
78
+ end
79
+
80
+ # convenient for SHIORI Response treatment
81
+ class Array
82
+ # join \\x01 separated value like "arg1\\x01arg2\\x01arg3" from Array
83
+ # @param [String] separator separator
84
+ # @return [String] combined strings
85
+ def combined(separator = "\x01")
86
+ self.join(separator)
87
+ end
88
+
89
+ # join \\x01, \\x02 separated value like "arg1-1\\x01arg1-2\\x02arg2-1\\x01arg2-2" from Array of Array
90
+ # @param [String] separator1 1st level separator
91
+ # @param [String] separator2 2nd level separator
92
+ # @return [String] combined strings
93
+ def combined2(separator1 = "\x02", separator2 = "\x01")
94
+ self.map {|element| element.join(separator2)}.join(separator1)
95
+ end
96
+ end
data/shioruby.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "shioruby"
6
+ spec.version = "0.0.1"
7
+ spec.authors = ["Narazaka"]
8
+ spec.email = ["info@narazaka.net"]
9
+
10
+ spec.summary = %q{SHIORI Protocol Parser / Builder}
11
+ spec.description = %q{Ukagaka SHIORI Protocol Request Parser / Response Builder}
12
+ spec.homepage = "https://github.com/Narazaka/shioruby"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_development_dependency "bundler", ">= 1.7.9"
18
+ spec.add_development_dependency "rake", "~> 10.0"
19
+ spec.add_development_dependency "rspec", "~> 3.4"
20
+ spec.add_development_dependency "yard", "~> 0.8.7"
21
+ spec.add_development_dependency "simplecov", "~> 0.11"
22
+ spec.add_development_dependency "codecov", "~>0.1"
23
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shioruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Narazaka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-24 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.7.9
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.9
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.7
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.7
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.11'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.11'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.1'
97
+ description: Ukagaka SHIORI Protocol Request Parser / Response Builder
98
+ email:
99
+ - info@narazaka.net
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".gitmodules"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - README.md
110
+ - Rakefile
111
+ - lib/shioruby.rb
112
+ - shioruby.gemspec
113
+ homepage: https://github.com/Narazaka/shioruby
114
+ licenses: []
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.4.5.1
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: SHIORI Protocol Parser / Builder
136
+ test_files: []
137
+ has_rdoc: