ruboty-hatena_hotentry 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f5235b7f615abcde6b5862fab1f03d5fc4bcfc47
4
+ data.tar.gz: 1058ed0b2286731f41112453be73cc6d22968eb4
5
+ SHA512:
6
+ metadata.gz: 39f3e8b847a401c9a5a27714fda48c5c47f9f5de6510307463ebf92dabe852ce69c2ec781b96ae6f4b1ee4a308bfb64c60246c699aae9fbcbc3e6d6868ece763
7
+ data.tar.gz: bf9444ed67ad99cd8c14060b24b128c4faa66e68cc294eb95c45c13b4c2116391964b1c6155eee4d926bcf287f0812243527da018af5fdfbd1903fcc4d89c4ad
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-hatena_hotentry.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 fukuiretu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ Ruboty::HatenaHotentry
2
+ ==========
3
+
4
+ ## Overview
5
+
6
+
7
+
8
+ ## Usage
9
+
10
+ ```bash
11
+ ruboty hotentry {all|social|economics|life|knowledge|it|fun|entertainment|game}
12
+ ```
13
+
14
+ ## Demo
15
+
16
+ ここにgifあにめ
17
+
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'ruboty-hatena_hotentry'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install ruboty-hatena_hotentry
34
+
35
+
36
+
37
+ ### TODO
38
+ * spec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,30 @@
1
+ module Ruboty
2
+ module Handlers
3
+ class HatenaHotentry < Base
4
+ ARTICLE_FORMAT = "%{title} (%{bookmarkcount}ブクマ)\n%{link}\n"
5
+
6
+ on /hotentry( me)? (?<keyword>all|social|economics|life|knowledge|it|fun|entertainment|game)/,
7
+ name: "hotentry",
8
+ description: "Reference Hotentry from HatenaBookmark"
9
+
10
+ def hotentry(message)
11
+ hotentry = ref(message[:keyword])
12
+ message.reply(layout(hotentry)) unless hotentry.nil?
13
+ end
14
+
15
+ private
16
+
17
+ def ref(category)
18
+ Ruboty::HatenaHotentry::Client.new(category: category).get
19
+ end
20
+
21
+ def layout(hotentry)
22
+ String.new.tap do |s|
23
+ s << "```\n"
24
+ s << hotentry.collect { |v| sprintf(ARTICLE_FORMAT, v) }.join("\n")
25
+ s << "```"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,58 @@
1
+ require "nokogiri"
2
+ require "open-uri"
3
+
4
+ module Ruboty
5
+ module HatenaHotentry
6
+ class Client
7
+ URL_FOR_ALL = "http://b.hatena.ne.jp/hotentry?mode=rss&sort=popular"
8
+ URL_FOR_CATEGORY = "http://b.hatena.ne.jp/hotentry/%{category}.rss&sort=popular"
9
+
10
+ NAMESPACES = {
11
+ "rss" => "http://purl.org/rss/1.0/",
12
+ "rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
13
+ "content" => "http://purl.org/rss/1.0/modules/content/",
14
+ "dc" => "http://purl.org/dc/elements/1.1/",
15
+ "feedburner" => "http://rssnamespace.org/feedburner/ext/1.0",
16
+ "hatena" => "http://www.hatena.ne.jp/info/xmlns#"
17
+ }
18
+
19
+ attr_reader :options
20
+
21
+ def initialize(options)
22
+ @options = options
23
+ end
24
+
25
+ def get
26
+ begin
27
+ url = url(@options[:category])
28
+ parse(open(url).read)
29
+ rescue => exception
30
+ Ruboty.logger.error("Error: #{self}##{__method__} - #{exception}")
31
+ nil
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def url(category)
38
+ category == "all" ? URL_FOR_ALL : sprintf(URL_FOR_CATEGORY, category: category)
39
+ end
40
+
41
+ def namespaces
42
+ NAMESPACES
43
+ end
44
+
45
+ def parse(doc)
46
+ [].tap do |arr|
47
+ Nokogiri::XML(doc).xpath('//xmlns:item').each do |node|
48
+ arr << {
49
+ title: node.xpath('rss:title', namespaces).text,
50
+ link: node.xpath('rss:link', namespaces).text,
51
+ bookmarkcount: node.xpath('hatena:bookmarkcount', namespaces).text
52
+ }
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module HatenaHotentry
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require "ruboty"
2
+ require "ruboty/hatena_hotentry/client"
3
+ require "ruboty/hatena_hotentry/version"
4
+ require "ruboty/handlers/hatena_hotentry"
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'ruboty/hatena_hotentry/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruboty-hatena_hotentry"
7
+ spec.version = Ruboty::HatenaHotentry::VERSION
8
+ spec.authors = ["Fukui ReTu"]
9
+ spec.email = ["s0232101@gmail.com"]
10
+ spec.summary = "An ruboty handler to reference hotentry from HatenaBookmark"
11
+ spec.homepage = "https://github.com/fukuiretu/ruboty-hatena_hotentry"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "ruboty"
20
+ spec.add_dependency "nokogiri"
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-hatena_hotentry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Fukui ReTu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
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: nokogiri
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.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - s0232101@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/ruboty/handlers/hatena_hotentry.rb
82
+ - lib/ruboty/hatena_hotentry.rb
83
+ - lib/ruboty/hatena_hotentry/client.rb
84
+ - lib/ruboty/hatena_hotentry/version.rb
85
+ - ruboty-hatena_hotentry.gemspec
86
+ homepage: https://github.com/fukuiretu/ruboty-hatena_hotentry
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: An ruboty handler to reference hotentry from HatenaBookmark
110
+ test_files: []