esapad 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e0bbd3c00d34bf625fe018c5ed27a7e15d0cf83
4
+ data.tar.gz: '018e97fad8ddd3cdc28c594b38cfa5a6cb0b0210'
5
+ SHA512:
6
+ metadata.gz: b901b17cd61061dad1818e3ab77656e1a9480fd8bdaab678724a320b6aa2d5cf6c4282e8ac46b4380e5948cc4942a05b98108a8e37209c564f70dd4578a6b9ba
7
+ data.tar.gz: 7a0db2c039df6fbfcd8c71f3330a45b4096f3517138844987fb84fe54ce52dc13f9fdb9cfb7c87791375416e6d5512266221075f9fdfa60748cbacf3df121d27
@@ -0,0 +1,3 @@
1
+ ESA_TEAM=
2
+ ESA_ACCESS_TOKEN=
3
+ ESA_TARGET_PAGE_ID=
@@ -0,0 +1 @@
1
+ .env
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in esapad.gemspec
4
+ gemspec
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ esapad (0.1.0)
5
+ denv
6
+ esa
7
+ json
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ byebug (9.0.6)
13
+ coderay (1.1.1)
14
+ denv (0.2.5)
15
+ esa (1.8.0)
16
+ faraday (~> 0.9)
17
+ faraday_middleware
18
+ mime-types (~> 2.6)
19
+ multi_xml (~> 0.5.5)
20
+ faraday (0.12.2)
21
+ multipart-post (>= 1.2, < 3)
22
+ faraday_middleware (0.12.0)
23
+ faraday (>= 0.7.4, < 1.0)
24
+ json (2.1.0)
25
+ method_source (0.8.2)
26
+ mime-types (2.99.3)
27
+ multi_xml (0.5.5)
28
+ multipart-post (2.0.0)
29
+ pry (0.10.4)
30
+ coderay (~> 1.1.0)
31
+ method_source (~> 0.8.1)
32
+ slop (~> 3.4)
33
+ pry-byebug (3.4.2)
34
+ byebug (~> 9.0)
35
+ pry (~> 0.10)
36
+ rake (12.0.0)
37
+ slop (3.6.0)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bundler (~> 1.15)
44
+ esapad!
45
+ pry
46
+ pry-byebug
47
+ rake (~> 12.0)
48
+
49
+ BUNDLED WITH
50
+ 1.15.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 hogelog
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,62 @@
1
+ # Esapad
2
+
3
+ Esapad update your esa page automatically.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'esapad'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install esapad
20
+
21
+ ## Usage
22
+ ### Edit target page
23
+ ```markdown
24
+ ## Blogs
25
+ <!-- RECENTLY-UPDATED-FLOW-POSTS-START -->
26
+ <!-- RECENTLY-UPDATED-FLOW-POSTS-END -->
27
+
28
+ ## Pages
29
+ <!-- RECENTLY-UPDATED-STOCK-POSTS-START -->
30
+ <!-- RECENTLY-UPDATED-STOCK-POSTS-END -->
31
+
32
+ ## Recently Popular Entries
33
+ <!-- RECENTLY-UPDATED-POSTS-UPDATED-START -->
34
+ <!-- RECENTLY-UPDATED-POSTS-UPDATED-END -->
35
+ ```
36
+
37
+ ### Update target page by esapad
38
+ ```
39
+ $ cp .env.sample .env
40
+ $ vim .env
41
+ ...
42
+ ESA_TEAM=yourteam
43
+ ESA_ACCESS_TOKEN=abcdefghijklmn
44
+ ESA_TARGET_PAGE_ID=1
45
+ $ bundle exec ./bin/update-pages-list
46
+ ```
47
+
48
+ ## Development
49
+
50
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
51
+
52
+ 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).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/esapad.
57
+
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
62
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "esapad"
5
+
6
+ require "pry"
7
+ pry
@@ -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,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+
5
+ require "esapad"
6
+
7
+ pad = Esapad.new
8
+ pad.update_pages_list(ENV["ESA_TARGET_PAGE_ID"])
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'esapad/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "esapad"
8
+ spec.version = Esapad::VERSION
9
+ spec.authors = ["hogelog"]
10
+ spec.email = ["konbu.komuro@gmail.com"]
11
+
12
+ spec.summary = %q{esa.io tools.}
13
+ spec.description = %q{esa.io tools.}
14
+ spec.homepage = "https://github.com/hogelog/esapad"
15
+ spec.license = "MIT"
16
+
17
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "esa"
25
+ spec.add_dependency "json"
26
+ spec.add_dependency "denv"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.15"
29
+ spec.add_development_dependency "rake", "~> 12.0"
30
+ spec.add_development_dependency "pry"
31
+ spec.add_development_dependency "pry-byebug"
32
+ end
@@ -0,0 +1,106 @@
1
+ require "esapad/version"
2
+
3
+ require "time"
4
+ require "esa"
5
+ require "denv"
6
+ require "pry"
7
+
8
+ Denv.load
9
+
10
+ class Esapad
11
+ def initialize
12
+ @client = Esa::Client.new(access_token: ENV["ESA_ACCESS_TOKEN"], current_team: ENV["ESA_TEAM"])
13
+ end
14
+
15
+ def update_pages_list(target_page_id)
16
+ flow_updated_md = generate_updated_md("flow")
17
+ stock_updated_md = generate_updated_md("stock")
18
+
19
+ recently_liked_md = generate_recently_liked_md
20
+
21
+ target_page = @client.post(ENV["ESA_TARGET_PAGE_ID"])
22
+ target_page_md = target_page.body["body_md"]
23
+
24
+ target_page_md = replace_pages_list_md(target_page_md, "flow", flow_updated_md)
25
+ target_page_md = replace_pages_list_md(target_page_md, "stock", stock_updated_md)
26
+ target_page_md = replace_liked_posts_md(target_page_md, recently_liked_md)
27
+
28
+ if target_page_md != target_page.body["body_md"]
29
+ target_page_md = replace_updated_time(target_page_md)
30
+ @client.update_post(target_page_id, body_md: target_page_md, updated_by: "esa_bot")
31
+ puts "Updated: #{ target_page.body["url"] }"
32
+ end
33
+ end
34
+
35
+ def blog_query
36
+ ENV["BLOG_CATEGORY"] || "category:日報/"
37
+ end
38
+
39
+ def fetch_updated_pages(kind)
40
+ query = case kind
41
+ when "flow"
42
+ "wip:false #{blog_query} -body:RECENTLY-UPDATED-POSTS"
43
+ when "stock"
44
+ "wip:false -#{blog_query} -body:RECENTLY-UPDATED-POSTS"
45
+ end
46
+ @client.posts(q: query).body["posts"]
47
+ end
48
+
49
+ def generate_updated_md(kind)
50
+ posts = fetch_updated_pages(kind)
51
+ posts.map {|post|
52
+ <<-MARKDOWN
53
+
54
+ <li>
55
+ <a href="#{ post["url"] }">#{ post["full_name"] }</a>
56
+ <div class="recently-updated-posts-metadata" style="font-size: 90%;">
57
+ <span class="post-list__date">#{ Time.parse(post["updated_at"]).strftime("%Y-%m-%d %H:%M") }</span>
58
+ by <img src="#{ post["updated_by"]["icon"] }" width="20px" height="20px" />
59
+ <a href="https://mwed.esa.io/users/#{ post["updated_by"]["screen_name"] }">#{ post["updated_by"]["screen_name"] }</a>
60
+ </div>
61
+ </li>
62
+ MARKDOWN
63
+ }.join
64
+ end
65
+
66
+ def generate_recently_liked_md
67
+ posts = (1..3).
68
+ map {|page| @client.posts(q: "wip:false created:>#{Date.today - 60} stars:>3", page: page).body["posts"] }.
69
+ flatten.
70
+ sort_by {|post| -post["stargazers_count"] }.
71
+ slice(0, 20).
72
+ sort_by {|post| -Time.parse(post["updated_at"]).to_i }.
73
+ map {|post|
74
+ <<-MARKDOWN
75
+
76
+ <li>
77
+ <a href="#{ post["url"] }">#{ post["full_name"] }</a>
78
+ <span class="recently-liked-posts-metadata" style="font-size: 90%;"> :star: #{ post["stargazers_count"] } </span>
79
+ </li>
80
+ MARKDOWN
81
+ }.join
82
+ end
83
+
84
+ private
85
+
86
+ def replace_pages_list_md(original_md, kind, updated_md)
87
+ original_md.gsub(
88
+ /<!-- RECENTLY-UPDATED-#{kind.upcase}-POSTS-START -->(.+)<!-- RECENTLY-UPDATED-#{kind.upcase}-POSTS-END -->/m,
89
+ "<!-- RECENTLY-UPDATED-#{kind.upcase}-POSTS-START -->#{updated_md}<!-- RECENTLY-UPDATED-#{kind.upcase}-POSTS-END -->"
90
+ )
91
+ end
92
+
93
+ def replace_updated_time(original_md)
94
+ original_md.gsub(
95
+ /<!-- RECENTLY-UPDATED-POSTS-UPDATED-START -->(.+)<!-- RECENTLY-UPDATED-POSTS-UPDATED-END -->/m,
96
+ "<!-- RECENTLY-UPDATED-POSTS-UPDATED-START -->\n更新日時: #{ Time.now.strftime("%Y-%m-%d %H:%M") }\n<!-- RECENTLY-UPDATED-POSTS-UPDATED-END -->",
97
+ )
98
+ end
99
+
100
+ def replace_liked_posts_md(original_md, updated_md)
101
+ original_md.gsub(
102
+ /<!-- RECENTLY-LIKED-POSTS-START -->(.+)<!-- RECENTLY-LIKED-POSTS-END -->/m,
103
+ "<!-- RECENTLY-LIKED-POSTS-START -->#{updated_md}<!-- RECENTLY-LIKED-POSTS-END -->"
104
+ )
105
+ end
106
+ end
@@ -0,0 +1,3 @@
1
+ class Esapad
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: esapad
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - hogelog
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: esa
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: json
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: denv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.15'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.15'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '12.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '12.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
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: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: esa.io tools.
112
+ email:
113
+ - konbu.komuro@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".env.sample"
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - bin/update-pages-list
128
+ - esapad.gemspec
129
+ - lib/esapad.rb
130
+ - lib/esapad/version.rb
131
+ homepage: https://github.com/hogelog/esapad
132
+ licenses:
133
+ - MIT
134
+ metadata:
135
+ allowed_push_host: https://rubygems.org
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.6.8
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: esa.io tools.
156
+ test_files: []