[rzz] test-gym

pull/30/head
Alpha Chen 5 years ago
parent 0407213908
commit d710726d55

@ -0,0 +1,13 @@
FROM arm32v7/ruby:2.7
# throw errors if Gemfile has been modified since Gemfile.lock
RUN bundle config --global frozen 1
WORKDIR /usr/src/app
COPY Gemfile Gemfile.lock ./
RUN bundle install
COPY . .
CMD ["rackup", "--host", "0.0.0.0"]

@ -0,0 +1,14 @@
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "nokogiri"
gem "roda"
group :development do
gem "pry"
gem "rake"
gem "rerun"
end

@ -0,0 +1,37 @@
GEM
remote: https://rubygems.org/
specs:
coderay (1.1.2)
ffi (1.12.1)
listen (3.2.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
method_source (0.9.2)
mini_portile2 (2.4.0)
nokogiri (1.10.7)
mini_portile2 (~> 2.4.0)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rack (2.1.1)
rake (13.0.1)
rb-fsevent (0.10.3)
rb-inotify (0.10.1)
ffi (~> 1.0)
rerun (0.13.0)
listen (~> 3.0)
roda (3.28.0)
rack
PLATFORMS
ruby
DEPENDENCIES
nokogiri
pry
rake
rerun
roda
BUNDLED WITH
2.1.2

@ -0,0 +1,17 @@
desc "Run RZZ in development mode"
task :dev do
sh "rerun -- rackup"
end
namespace :docker do
TAG = "kejadlen/rzz"
task :build do
sh "docker build --tag #{TAG} ."
end
task push: :build do
sh "docker push #{TAG}"
end
end

@ -0,0 +1,3 @@
require_relative "rzz"
run Rzz::App.freeze.app

@ -0,0 +1,44 @@
require "digest/sha1"
require "open-uri"
require "nokogiri"
require "roda"
module Rzz
class App < Roda
plugin :caching
route do |r|
r.get do
r.is "test-gym" do
url = "https://elemental.medium.com/feed/"
xml = URI.open(url).read
r.etag Digest::SHA1.hexdigest(xml)
doc = Nokogiri::XML(xml)
doc
.xpath("/rss/channel/item")
.select {|item| item.xpath("./category[text()='test-gym']").empty? }
.each(&:remove)
doc
.xpath("/rss/channel/item")
.each do |item|
link = item.at_xpath("./link/text()").content
item.at_xpath("./description/text()").content = URI.open(link).read
end
response.headers["Content-Type"] = "text/xml"
doc.to_xml
end
end
end
end
end
if __FILE__ == $0
require "pry"
binding.pry
end
Loading…
Cancel
Save