Skip to content

Commit 385faa3

Browse files
author
Angela Guette
committed
content indexer app
0 parents  commit 385faa3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1297
-0
lines changed

.gitignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
2+
#
3+
# If you find yourself ignoring temporary files generated by your text editor
4+
# or operating system, you probably want to add a global ignore instead:
5+
# git config --global core.excludesfile '~/.gitignore_global'
6+
7+
# Ignore bundler config.
8+
/.bundle
9+
10+
# Ignore all logfiles and tempfiles.
11+
/log/*
12+
/tmp/*
13+
!/log/.keep
14+
!/tmp/.keep
15+
16+
.byebug_history

.rspec

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--require spec_helper

Gemfile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
source 'https://rubygems.org'
2+
ruby '2.4.0'
3+
4+
git_source(:github) do |repo_name|
5+
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
6+
"https://github.com/#{repo_name}.git"
7+
end
8+
9+
# Application
10+
gem 'rails', '~> 5.1.5'
11+
gem 'pg', '>= 0.18', '< 2.0'
12+
gem 'puma', '~> 3.7'
13+
gem 'jsonapi-resources'
14+
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
15+
16+
group :development, :test do
17+
gem 'rspec-rails', '~> 3.7'
18+
gem 'factory_bot_rails'
19+
gem 'faker'
20+
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
21+
end
22+
23+
group :development do
24+
gem 'listen', '>= 3.0.5', '< 3.2'
25+
gem 'spring'
26+
gem 'spring-watcher-listen', '~> 2.0.0'
27+
end
28+
29+
group :test do
30+
gem 'shoulda-matchers', '~> 3.1'
31+
gem 'rails-controller-testing'
32+
end

Gemfile.lock

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
actioncable (5.1.6)
5+
actionpack (= 5.1.6)
6+
nio4r (~> 2.0)
7+
websocket-driver (~> 0.6.1)
8+
actionmailer (5.1.6)
9+
actionpack (= 5.1.6)
10+
actionview (= 5.1.6)
11+
activejob (= 5.1.6)
12+
mail (~> 2.5, >= 2.5.4)
13+
rails-dom-testing (~> 2.0)
14+
actionpack (5.1.6)
15+
actionview (= 5.1.6)
16+
activesupport (= 5.1.6)
17+
rack (~> 2.0)
18+
rack-test (>= 0.6.3)
19+
rails-dom-testing (~> 2.0)
20+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
21+
actionview (5.1.6)
22+
activesupport (= 5.1.6)
23+
builder (~> 3.1)
24+
erubi (~> 1.4)
25+
rails-dom-testing (~> 2.0)
26+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
27+
activejob (5.1.6)
28+
activesupport (= 5.1.6)
29+
globalid (>= 0.3.6)
30+
activemodel (5.1.6)
31+
activesupport (= 5.1.6)
32+
activerecord (5.1.6)
33+
activemodel (= 5.1.6)
34+
activesupport (= 5.1.6)
35+
arel (~> 8.0)
36+
activesupport (5.1.6)
37+
concurrent-ruby (~> 1.0, >= 1.0.2)
38+
i18n (>= 0.7, < 2)
39+
minitest (~> 5.1)
40+
tzinfo (~> 1.1)
41+
arel (8.0.0)
42+
builder (3.2.3)
43+
byebug (10.0.2)
44+
concurrent-ruby (1.0.5)
45+
crass (1.0.4)
46+
diff-lcs (1.3)
47+
erubi (1.7.1)
48+
factory_bot (4.8.2)
49+
activesupport (>= 3.0.0)
50+
factory_bot_rails (4.8.2)
51+
factory_bot (~> 4.8.2)
52+
railties (>= 3.0.0)
53+
faker (1.8.7)
54+
i18n (>= 0.7)
55+
ffi (1.9.23)
56+
globalid (0.4.1)
57+
activesupport (>= 4.2.0)
58+
i18n (1.0.1)
59+
concurrent-ruby (~> 1.0)
60+
jsonapi-resources (0.9.0)
61+
activerecord (>= 4.1)
62+
concurrent-ruby
63+
railties (>= 4.1)
64+
listen (3.1.5)
65+
rb-fsevent (~> 0.9, >= 0.9.4)
66+
rb-inotify (~> 0.9, >= 0.9.7)
67+
ruby_dep (~> 1.2)
68+
loofah (2.2.2)
69+
crass (~> 1.0.2)
70+
nokogiri (>= 1.5.9)
71+
mail (2.7.0)
72+
mini_mime (>= 0.1.1)
73+
method_source (0.9.0)
74+
mini_mime (1.0.0)
75+
mini_portile2 (2.3.0)
76+
minitest (5.11.3)
77+
nio4r (2.3.1)
78+
nokogiri (1.8.2)
79+
mini_portile2 (~> 2.3.0)
80+
pg (1.0.0)
81+
puma (3.11.4)
82+
rack (2.0.5)
83+
rack-test (1.0.0)
84+
rack (>= 1.0, < 3)
85+
rails (5.1.6)
86+
actioncable (= 5.1.6)
87+
actionmailer (= 5.1.6)
88+
actionpack (= 5.1.6)
89+
actionview (= 5.1.6)
90+
activejob (= 5.1.6)
91+
activemodel (= 5.1.6)
92+
activerecord (= 5.1.6)
93+
activesupport (= 5.1.6)
94+
bundler (>= 1.3.0)
95+
railties (= 5.1.6)
96+
sprockets-rails (>= 2.0.0)
97+
rails-controller-testing (1.0.2)
98+
actionpack (~> 5.x, >= 5.0.1)
99+
actionview (~> 5.x, >= 5.0.1)
100+
activesupport (~> 5.x)
101+
rails-dom-testing (2.0.3)
102+
activesupport (>= 4.2.0)
103+
nokogiri (>= 1.6)
104+
rails-html-sanitizer (1.0.4)
105+
loofah (~> 2.2, >= 2.2.2)
106+
railties (5.1.6)
107+
actionpack (= 5.1.6)
108+
activesupport (= 5.1.6)
109+
method_source
110+
rake (>= 0.8.7)
111+
thor (>= 0.18.1, < 2.0)
112+
rake (12.3.1)
113+
rb-fsevent (0.10.3)
114+
rb-inotify (0.9.10)
115+
ffi (>= 0.5.0, < 2)
116+
rspec-core (3.7.1)
117+
rspec-support (~> 3.7.0)
118+
rspec-expectations (3.7.0)
119+
diff-lcs (>= 1.2.0, < 2.0)
120+
rspec-support (~> 3.7.0)
121+
rspec-mocks (3.7.0)
122+
diff-lcs (>= 1.2.0, < 2.0)
123+
rspec-support (~> 3.7.0)
124+
rspec-rails (3.7.2)
125+
actionpack (>= 3.0)
126+
activesupport (>= 3.0)
127+
railties (>= 3.0)
128+
rspec-core (~> 3.7.0)
129+
rspec-expectations (~> 3.7.0)
130+
rspec-mocks (~> 3.7.0)
131+
rspec-support (~> 3.7.0)
132+
rspec-support (3.7.1)
133+
ruby_dep (1.5.0)
134+
shoulda-matchers (3.1.2)
135+
activesupport (>= 4.0.0)
136+
spring (2.0.2)
137+
activesupport (>= 4.2)
138+
spring-watcher-listen (2.0.1)
139+
listen (>= 2.7, < 4.0)
140+
spring (>= 1.2, < 3.0)
141+
sprockets (3.7.1)
142+
concurrent-ruby (~> 1.0)
143+
rack (> 1, < 3)
144+
sprockets-rails (3.2.1)
145+
actionpack (>= 4.0)
146+
activesupport (>= 4.0)
147+
sprockets (>= 3.0.0)
148+
thor (0.20.0)
149+
thread_safe (0.3.6)
150+
tzinfo (1.2.5)
151+
thread_safe (~> 0.1)
152+
websocket-driver (0.6.5)
153+
websocket-extensions (>= 0.1.0)
154+
websocket-extensions (0.1.3)
155+
156+
PLATFORMS
157+
ruby
158+
159+
DEPENDENCIES
160+
byebug
161+
factory_bot_rails
162+
faker
163+
jsonapi-resources
164+
listen (>= 3.0.5, < 3.2)
165+
pg (>= 0.18, < 2.0)
166+
puma (~> 3.7)
167+
rails (~> 5.1.5)
168+
rails-controller-testing
169+
rspec-rails (~> 3.7)
170+
shoulda-matchers (~> 3.1)
171+
spring
172+
spring-watcher-listen (~> 2.0.0)
173+
tzinfo-data
174+
175+
RUBY VERSION
176+
ruby 2.4.0p0
177+
178+
BUNDLED WITH
179+
1.16.1

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# README
2+
3+
This README would normally document whatever steps are necessary to get the
4+
application up and running.
5+
6+
Things you may want to cover:
7+
8+
* Ruby version
9+
10+
* System dependencies
11+
12+
* Configuration
13+
14+
* Database creation
15+
16+
* Database initialization
17+
18+
* How to run the test suite
19+
20+
* Services (job queues, cache servers, search engines, etc.)
21+
22+
* Deployment instructions
23+
24+
* ...

Rakefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Add your own tasks in files placed in lib/tasks ending in .rake,
2+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3+
4+
require_relative 'config/application'
5+
6+
Rails.application.load_tasks
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module ApplicationCable
2+
class Channel < ActionCable::Channel::Base
3+
end
4+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module ApplicationCable
2+
class Connection < ActionCable::Connection::Base
3+
end
4+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module API
2+
module V1
3+
class ElementsController < ApplicationController
4+
end
5+
end
6+
end
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module API
2+
module V1
3+
class PagesController < ApplicationController
4+
def create
5+
super
6+
7+
if response.successful?
8+
response_body = JSON.parse(response.body)
9+
page_created = Page.find(response_body['data']['id'])
10+
11+
PageIndexCreator.call(page_created)
12+
end
13+
end
14+
end
15+
end
16+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ApplicationController < ActionController::API
2+
include JSONAPI::ActsAsResourceController
3+
end

app/controllers/concerns/.keep

Whitespace-only changes.

app/jobs/application_job.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class ApplicationJob < ActiveJob::Base
2+
end

app/mailers/application_mailer.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class ApplicationMailer < ActionMailer::Base
2+
default from: '[email protected]'
3+
layout 'mailer'
4+
end

app/models/application_record.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ApplicationRecord < ActiveRecord::Base
2+
self.abstract_class = true
3+
end

app/models/concerns/.keep

Whitespace-only changes.

app/models/element.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Element < ApplicationRecord
2+
belongs_to :page
3+
4+
validates :tag, :content, :page, presence: true
5+
end

app/models/page.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Page < ApplicationRecord
2+
has_many :elements
3+
4+
validates :url, presence: true
5+
end
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module API
2+
module V1
3+
class ElementResource < JSONAPI::Resource
4+
attributes :tag, :content
5+
6+
belongs_to :page
7+
end
8+
end
9+
end

app/resources/api/v1/page_resource.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module API
2+
module V1
3+
class PageResource < JSONAPI::Resource
4+
attributes :url
5+
6+
has_many :elements
7+
end
8+
end
9+
end

app/services/application_service.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class ApplicationService
2+
def self.call(*args, &block)
3+
new(*args, &block).call
4+
end
5+
end

app/services/page_index_creator.rb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'nokogiri'
2+
require 'open-uri'
3+
4+
class PageIndexCreator< ApplicationService
5+
attr_reader :page
6+
7+
def initialize(page)
8+
@page = page
9+
end
10+
11+
def call
12+
doc = Nokogiri::HTML(open(@page.url))
13+
14+
process_elements(doc, page)
15+
end
16+
17+
private
18+
19+
def process_elements(doc, page)
20+
%w[h1 h2 h3 a].each do |tag|
21+
process_element_content(page, doc, tag)
22+
end
23+
end
24+
25+
def process_element_content(page, doc, tag)
26+
doc.css(tag).each do |tag|
27+
page.elements.create(tag: tag.name, content: tag.content)
28+
end
29+
end
30+
end

app/views/layouts/mailer.html.erb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5+
<style>
6+
/* Email styles need to be inline */
7+
</style>
8+
</head>
9+
10+
<body>
11+
<%= yield %>
12+
</body>
13+
</html>

app/views/layouts/mailer.text.erb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= yield %>

0 commit comments

Comments
 (0)