syobocalite 0.1.0

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
+ SHA256:
3
+ metadata.gz: f8dcc7caf5e785e5db9e1a125e3a6ae293649e8e1d8b1147f02be88765a37603
4
+ data.tar.gz: ec89b3bc62616e1410eef439ab5618bd1bb4a6bd60d738cf02dba81a99e8eb44
5
+ SHA512:
6
+ metadata.gz: 4bffe23133dbd2af590cc510e9853e2c24ed082bc58b8627a27134fbd1caac3e83197b0efeb4d628e363bc699fc5509cd63eacd675e025437e8dff0ff5498e9d
7
+ data.tar.gz: 7e35926344c57137a133463649dc2285b64ee85fd1aa051a32fb4c4e2d2fa1ee99a88c83703d7a7201de4b0a32405ed9f3f617b1b6cee1550cf3cbc1dbc86472
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ repo_token: 2UFIIAxPxVPLjinaP0ZRXnY4SARkXc7PP
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,26 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3
4
+ - 2.4
5
+ - 2.5
6
+ - ruby-head
7
+ bundler_args: "--jobs=4"
8
+ cache: bundler
9
+ before_install:
10
+ - gem update --system --no-document
11
+ - gem install bundler --no-document
12
+ before_script:
13
+ - export CODECLIMATE_REPO_TOKEN=82d5b98775f7517294816845556790951867aba59db59a59178f0bed50a44216
14
+ script:
15
+ - bundle exec rspec
16
+ # - bundle exec codeclimate-test-reporter || true
17
+ branches:
18
+ only:
19
+ - master
20
+ matrix:
21
+ allow_failures:
22
+ - rvm: ruby-head
23
+ sudo: false
24
+ notifications:
25
+ slack:
26
+ secure: GZZkyEmKBlwECsm47m+8XOcQhNcXciPsUhXfrAFBfTRxwCCy7myUBXL7aSV9T10N+QQX1rVilkD1zHRgX3U2S/S8xQfafrYiv5ZNDXp6xrNqGPC3WNGGY9PzvhJxpacp05qXxWXR5ml3Uk+1IZIoWJIPNtUVAgVO2gg6eLegHMiR2DwFmylW3nbfY6ozb6lo00rBih/k8KFqKZwo7odbdWN5LMPPH5vzO2f3sTF/3F8KsgxhESoA9hBLymDlcofEJ0gThXIH0T1WQGRmPpjJu5CSt5DAgDJxoJ/DjHy02ZJi/2vy8WnM2TGNI0sGInp/0GYb8AntpnyDw57UF2MCW4pYBqVgGfUxRHunzhLTtUI870BrQN0UHzHvnMgyxXCLZYN7rMqBuptQXRseWXzWovDHBEeGtYaEf41aOCX9bi/KC+k4FEeK6eJIXW5FXBC6TOnQTYvCx1V2BDdqH2jzxfSEtyA7rJlzDr+CajfsT25H+izqUQF7s5JxtcPuYoHXfxN420Qpfylvmje312WnccKXQKqdX4K/MWy+PM2VsU74EWCUy52flMonqKblyPWGn+Eo4LxGGRkq68lzVH02fwlF9QiIX0jjFkLPyHrw2+kxDK4g2S5+VxIOsKq2IYssXuEfGlXHuv3TRLb3Z8taqgS1zqZ5U1pVfQhLkCDSikM=
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --markup markdown
2
+ --no-private
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## master
2
+ [full changelog](https://github.com/sue445/syobocalite/compare/v0.1.0...master)
3
+
4
+ ## 0.1.0
5
+ * first release
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in syobocalite.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 sue445
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # Syobocalite
2
+
3
+ Lite client for [Syoboi calendar](http://cal.syoboi.jp/) API.
4
+
5
+ [![Build Status](https://travis-ci.org/sue445/syobocalite.svg?branch=master)](https://travis-ci.org/sue445/syobocalite)
6
+ [![Coverage Status](https://coveralls.io/repos/github/sue445/syobocalite/badge.svg?branch=master)](https://coveralls.io/github/sue445/syobocalite?branch=master)
7
+ [![Maintainability](https://api.codeclimate.com/v1/badges/9f77793acf8d5c24886e/maintainability)](https://codeclimate.com/github/sue445/syobocalite/maintainability)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'syobocalite'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install syobocalite
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require "syobocalite"
29
+ require "time"
30
+
31
+ start_at = Time.parse("2018-10-07 08:30:00")
32
+ end_at = Time.parse("2018-10-07 09:00:00")
33
+
34
+ # or
35
+
36
+ Time.zone = "Tokyo"
37
+ start_at = Time.zone.parse("2018-10-07 08:30:00")
38
+ end_at = Time.zone.parse("2018-10-07 09:00:00")
39
+
40
+ # Get programs that start between 8:30 and 9:00
41
+ Syobocalite.search(start_at: start_at, end_at: end_at)
42
+ ```
43
+
44
+ `Syobocalite.search` returns `Array` of [`Syobocalite::Program`](lib/syobocalite/program.rb)
45
+
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+
50
+ 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).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sue445/syobocalite.
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "syobocalite"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,81 @@
1
+ module Syobocalite
2
+ class Program
3
+ # @!attribute pid
4
+ # @return [Integer]
5
+ attr_accessor :pid
6
+
7
+ # @!attribute tid
8
+ # @return [Integer]
9
+ attr_accessor :tid
10
+
11
+ # @!attribute st_time
12
+ # @return [TimeWithZone]
13
+ attr_accessor :st_time
14
+
15
+ # @!attribute ed_time
16
+ # @return [TimeWithZone]
17
+ attr_accessor :ed_time
18
+
19
+ # @!attribute ch_name
20
+ # @return [String]
21
+ attr_accessor :ch_name
22
+
23
+ # @!attribute ch_id
24
+ # @return [Integer]
25
+ attr_accessor :ch_id
26
+
27
+ # @!attribute count
28
+ # @return [Integer]
29
+ attr_accessor :count
30
+
31
+ # @!attribute st_offset
32
+ # @return [Integer]
33
+ attr_accessor :st_offset
34
+
35
+ # @!attribute sub_title
36
+ # @return [String]
37
+ attr_accessor :sub_title
38
+
39
+ # @!attribute title
40
+ # @return [String]
41
+ attr_accessor :title
42
+
43
+ # @!attribute prog_comment
44
+ # @return [String]
45
+ attr_accessor :prog_comment
46
+
47
+ # @param attrs [Hash]
48
+ def initialize(attrs = {})
49
+ @pid = attrs["PID"]&.to_i
50
+ @tid = attrs["TID"]&.to_i
51
+ @st_time = to_time(attrs["StTime"])
52
+ @ed_time = to_time(attrs["EdTime"])
53
+ @ch_name = attrs["ChName"]
54
+ @ch_id = attrs["ChID"]&.to_i
55
+ @count = attrs["Count"]&.to_i
56
+ @st_offset = attrs["StOffset"]&.to_i
57
+ @sub_title = sanitize_text(attrs["SubTitle"])
58
+ @title = sanitize_text(attrs["Title"])
59
+ @prog_comment = attrs["ProgComment"]&.gsub(/^!/, "")
60
+ end
61
+
62
+ alias_method :story_number, :count
63
+ alias_method :story_number=, :count=
64
+
65
+ private
66
+
67
+ def to_time(str)
68
+ return nil unless str
69
+
70
+ Time.use_zone("Tokyo") do
71
+ Time.zone.parse(str)
72
+ end
73
+ end
74
+
75
+ def sanitize_text(str)
76
+ return nil unless str
77
+
78
+ CGI.unescapeHTML(str)
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,3 @@
1
+ module Syobocalite
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,47 @@
1
+ require "syobocalite/version"
2
+ require "syobocalite/program"
3
+ require "active_support/all"
4
+ require "multi_xml"
5
+ require "open-uri"
6
+
7
+ module Syobocalite
8
+ # Search programs between `start_at` and `end_at`
9
+ #
10
+ # @param start_at [Time]
11
+ # @param end_at [Time]
12
+ #
13
+ # @return [Array<Program>]
14
+ #
15
+ # @see https://sites.google.com/site/syobocal/spec/cal_chk-php
16
+ def self.search(start_at:, end_at:)
17
+ xml = fetch(start_at: start_at, end_at: end_at)
18
+ response = MultiXml.parse(xml)
19
+ prog_items = response["syobocal"]["ProgItems"]["ProgItem"]
20
+
21
+ programs = prog_items.map { |prog_item| Syobocalite::Program.new(prog_item) }
22
+
23
+ programs.select do |program|
24
+ (start_at...end_at).cover?(program.st_time)
25
+ end
26
+ end
27
+
28
+ def self.fetch(start_at:, end_at:)
29
+ params = {}
30
+
31
+ if start_at.hour >= 5
32
+ params[:days] = (end_at.to_date - start_at.to_date).to_i + 1
33
+ params[:start] = start_at.strftime("%Y-%m-%d")
34
+ else
35
+ # NOTE: If start_at is 2018/4/7, returns 2018/4/7 05:00 - 28:59(2018/4/8 04:59)
36
+ params[:days] = (end_at.to_date - start_at.to_date).to_i + 2
37
+ params[:start] = (start_at - 1.day).strftime("%Y-%m-%d")
38
+ end
39
+
40
+ headers = {
41
+ "User-Agent" => "Syobocalite v#{Syobocalite::VERSION}",
42
+ }
43
+
44
+ open("http://cal.syoboi.jp/cal_chk.php?#{params.to_param}", headers).read
45
+ end
46
+ private_class_method :fetch
47
+ end
@@ -0,0 +1,49 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "syobocalite/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "syobocalite"
8
+ spec.version = Syobocalite::VERSION
9
+ spec.authors = ["sue445"]
10
+ spec.email = ["sue445@sue445.net"]
11
+
12
+ spec.summary = %q{Lite client for Syoboi calendar}
13
+ spec.description = %q{Lite client for Syoboi calendar}
14
+ spec.homepage = "https://github.com/sue445/syobocalite"
15
+ spec.license = "MIT"
16
+
17
+ spec.required_ruby_version = ">= 2.3.0"
18
+
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = spec.homepage
22
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_dependency "activesupport"
38
+ spec.add_dependency "multi_xml"
39
+
40
+ spec.add_development_dependency "bundler", "~> 1.16"
41
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
42
+ spec.add_development_dependency "coveralls"
43
+ spec.add_development_dependency "pry-byebug"
44
+ spec.add_development_dependency "rake", "~> 10.0"
45
+ spec.add_development_dependency "rspec", "~> 3.0"
46
+ spec.add_development_dependency "rspec-its"
47
+ spec.add_development_dependency "webmock"
48
+ spec.add_development_dependency "yard"
49
+ end
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: syobocalite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - sue445
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
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
+ - !ruby/object:Gem::Dependency
28
+ name: multi_xml
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codeclimate-test-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec-its
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: yard
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Lite client for Syoboi calendar
168
+ email:
169
+ - sue445@sue445.net
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".coveralls.yml"
175
+ - ".gitignore"
176
+ - ".rspec"
177
+ - ".travis.yml"
178
+ - ".yardopts"
179
+ - CHANGELOG.md
180
+ - Gemfile
181
+ - LICENSE.txt
182
+ - README.md
183
+ - Rakefile
184
+ - bin/console
185
+ - bin/setup
186
+ - lib/syobocalite.rb
187
+ - lib/syobocalite/program.rb
188
+ - lib/syobocalite/version.rb
189
+ - syobocalite.gemspec
190
+ homepage: https://github.com/sue445/syobocalite
191
+ licenses:
192
+ - MIT
193
+ metadata:
194
+ homepage_uri: https://github.com/sue445/syobocalite
195
+ source_code_uri: https://github.com/sue445/syobocalite
196
+ changelog_uri: https://github.com/sue445/syobocalite/blob/master/CHANGELOG.md
197
+ post_install_message:
198
+ rdoc_options: []
199
+ require_paths:
200
+ - lib
201
+ required_ruby_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: 2.3.0
206
+ required_rubygems_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ requirements: []
212
+ rubyforge_project:
213
+ rubygems_version: 2.7.7
214
+ signing_key:
215
+ specification_version: 4
216
+ summary: Lite client for Syoboi calendar
217
+ test_files: []