dev_to 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 634c48b237c94fda45d5b012654767719130c24dfcb705d6c2017ecd26c9bfdb
4
- data.tar.gz: 49a4e5ea3ceeacf8139c46ec25388df50a7e81405382cb2254a8a5d85df5253d
3
+ metadata.gz: dcad7a42a07025c32e36148df95270a8171e4382ae084ced30f190ff66b680d0
4
+ data.tar.gz: 8dec72f52ed88d6f66ea9bb269aa0f66442d5b40cd4b019a3af7c7041f502b4a
5
5
  SHA512:
6
- metadata.gz: aedc5efc701c996d64d7ebba46ace75019d80cd51afa23155aab9ebaf3bb9b8270a883b1328dda1915cecae0138163bcccc1212fb3129ded46d776fc7551ccae
7
- data.tar.gz: 21db14182ebd0a3420226c3169bc10035978737936149d8c73dbe75bb8cfdf3092de69abba4da056c164aaf5a462dab407e1453ef2cd2fdba8e07b88c7ee99ef
6
+ metadata.gz: ac2d997c81905d89e40f62f286120cbc1fd12074a7c89ac8fe9566f9f769945d9a687d77e89cc8e57d8f1de0bcf8ad2697f3cfa614adc99da7d0e7696ce0989c
7
+ data.tar.gz: 91ee7ddbdab786e46ae30d789f73cb0ff79b89775eee637d92f2ed922a0d4ed4337d12da97a1ce07f9b2c8692bbbc66cc2a2426f4e9ec0e33fc7f3954296837a
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.16.0
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at https://github.com/PRbsas. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
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 dev_to.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 PRbsas
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,32 @@
1
+ # DevTo CLI GEM
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/dev_to.svg)](https://badge.fury.io/rb/dev_to)
4
+
5
+ This Ruby Gem provides a CLI to view posts from The DEV Community, [dev.to](https://dev.to/). It is published in [rubygems.org](https://rubygems.org/gems/dev_to).
6
+
7
+ ## Installation
8
+
9
+ $ gem install dev_to
10
+
11
+ ## Usage
12
+
13
+ After installing the gem run the command below:
14
+
15
+ $ devto
16
+
17
+ ## Development
18
+
19
+ To run the development version of the CLI run `bundle exec bin/devto`
20
+
21
+
22
+ ## Contributing
23
+
24
+ 1. Fork it ( https://github.com/PRbsas/devto-cli-gem/fork )
25
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
26
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
27
+ 4. Push to the branch (`git push origin my-new-feature`)
28
+ 5. Create new Pull Request
29
+
30
+ ## License
31
+
32
+ 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 "dev_to"
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,9 @@
1
+ require 'pry'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'colorize'
5
+
6
+ require_relative '../lib/dev_to/version'
7
+ require_relative '../lib/dev_to/cli'
8
+ require_relative '../lib/dev_to/post'
9
+ require_relative '../lib/dev_to/scraper'
data/dev_to-0.1.0.gem ADDED
Binary file
data/dev_to-0.1.1.gem ADDED
Binary file
data/dev_to.gemspec ADDED
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "dev_to/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dev_to"
8
+ spec.version = DevTo::VERSION
9
+ spec.authors = ["PRbsas"]
10
+ spec.email = ["paularamirez0316@gmail.com"]
11
+
12
+ spec.summary = %q{Get Posts in yout CLI from The DEV Community}
13
+ spec.description = %q{Application that provides a Command Line Interface (CLI) to read Posts from The DEV Community, https://dev.to/}
14
+ spec.homepage = "https://github.com/PRbsas/devto-cli-gem"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ spec.executables << 'devto'
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "nokogiri", "~> 1.6", ">= 1.6.8"
28
+ spec.add_development_dependency "pry", "~> 0.11.2"
29
+ spec.add_dependency "colorize", "~> 0.8.1"
30
+ end
data/lib/dev_to.rb ADDED
@@ -0,0 +1,4 @@
1
+ require_relative '../config/environment'
2
+
3
+ module DevTo
4
+ end
data/lib/dev_to/cli.rb ADDED
@@ -0,0 +1,60 @@
1
+ class DevTo::CLI
2
+
3
+ def call
4
+ DevTo::Scraper.new.make_posts
5
+ puts
6
+ puts "< Welcome to your DEV Community FEED >".colorize(:color => :light_white, :background => :red)
7
+ puts
8
+ list_posts
9
+ start
10
+ end
11
+
12
+ def list_posts
13
+ DevTo::Post.all.each.with_index(1) do |post, i|
14
+ puts
15
+ puts "#{i}. #{post.title} - #{post.author}"
16
+ puts " -------- #{post.tags.join(" · ")} \u{1F4AC} #{post.comments} \u{2764} #{post.likes}"
17
+ end
18
+ end
19
+
20
+ def print_post(post)
21
+ puts
22
+ puts
23
+ puts "#{post.title}".colorize(:color => :light_white, :background => :red)
24
+ puts " ---- #{post.author} ---- #{post.date}"
25
+ puts
26
+ puts "#{post.content}"
27
+ puts
28
+ puts " ---- #{post.tags.join(" · ")} \u{1F4AC} #{post.comments} \u{2764} #{post.likes}"
29
+ puts " ---- #{post.url}"
30
+ puts
31
+ end
32
+
33
+ def start
34
+ input = nil
35
+ post = nil
36
+ while input != "exit"
37
+ puts
38
+ puts "< Type post NUMBER to read it >"
39
+ puts "< Type LIST to see the posts again >"
40
+ puts "< Type EXIT to end program >"
41
+
42
+ input = gets.strip.downcase
43
+ if input == "list"
44
+ list_posts
45
+ elsif input.to_i.between?(1, DevTo::Post.all.size)
46
+ post = DevTo::Post.find(input)
47
+ DevTo::Scraper.new.make_content(post)
48
+ print_post(post)
49
+ puts "< Type OPEN to see it in the browser >"
50
+ post
51
+ elsif input.to_i > DevTo::Post.all.size
52
+ puts
53
+ puts " -------- Please select a valid option:"
54
+ elsif input == "open" && post != nil
55
+ system("open #{post.url}")
56
+ end
57
+ end
58
+ puts " -------- See you soon for more DEV Posts"
59
+ end
60
+ end
@@ -0,0 +1,17 @@
1
+ class DevTo::Post
2
+ attr_accessor :title, :author, :tags, :url, :comments, :likes, :date, :content
3
+
4
+ @@all = []
5
+
6
+ def initialize
7
+ self.class.all << self
8
+ end
9
+
10
+ def self.find(id)
11
+ self.all[id.to_i-1]
12
+ end
13
+
14
+ def self.all
15
+ @@all
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ class DevTo::Scraper
2
+
3
+ def get_page
4
+ Nokogiri::HTML(open("https://dev.to/"))
5
+ end
6
+
7
+ def get_posts
8
+ self.get_page.css(".articles-list .substories .single-article")
9
+ end
10
+
11
+ def make_posts
12
+ self.get_posts.each do |data|
13
+ post = DevTo::Post.new
14
+ post.title = data.search(".content h3 span").remove
15
+ post.title = data.search(".content h3").text.strip.gsub(/[[:space:]]+/," ")
16
+ post.author = data.search("h4").text.strip
17
+ post.tags = data.search(".tags .tag").collect { |tag| tag.text.strip}
18
+ post.url = "https://dev.to" + data.search("a").last.attr("href")
19
+ post.comments = data.search(".engagement-count-number").first.text.strip
20
+ post.likes = data.search(".engagement-count-number").last.text.strip
21
+ end
22
+ end
23
+
24
+ def make_content(post)
25
+ post_page = Nokogiri::HTML(open("#{post.url}"))
26
+ post.content = post_page.search("body #article-body").text.strip
27
+ post.date = post_page.search("#main-title .published-at").text.strip
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module DevTo
2
+ VERSION = "0.1.2"
3
+ end
data/spec.md ADDED
@@ -0,0 +1,13 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+
5
+ - [X] Have a CLI for interfacing with the application
6
+ The user interacts with the application through the CLI. Getting prompted for input from the start of the program.
7
+
8
+ - [X] Pull data from an external source
9
+ The data the CLI shows is scraped with Nokogiri and open-uri from [dev.to](https://dev.to/)
10
+
11
+ - [X] Implement both list and detail views
12
+ When the program runs, the Scraper class gets called with the method #make-posts that instantiates new instances of Post. The CLI method #list-posts then iterates through the instances of Post and prints them for the user.
13
+ When the user types in a post number to read, the CLI uses the Post #find method to find the Post. It then calls the Scraper method #make-content to scrape the content of the post and prints it for the user with the #print-post method.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev_to
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - PRbsas
@@ -109,7 +109,28 @@ executables:
109
109
  extensions: []
110
110
  extra_rdoc_files: []
111
111
  files:
112
+ - ".gitignore"
113
+ - ".rspec"
114
+ - ".travis.yml"
115
+ - CODE_OF_CONDUCT.md
116
+ - Gemfile
117
+ - Gemfile.lock
118
+ - LICENSE.txt
119
+ - README.md
120
+ - Rakefile
121
+ - bin/console
112
122
  - bin/devto
123
+ - bin/setup
124
+ - config/environment.rb
125
+ - dev_to-0.1.0.gem
126
+ - dev_to-0.1.1.gem
127
+ - dev_to.gemspec
128
+ - lib/dev_to.rb
129
+ - lib/dev_to/cli.rb
130
+ - lib/dev_to/post.rb
131
+ - lib/dev_to/scraper.rb
132
+ - lib/dev_to/version.rb
133
+ - spec.md
113
134
  homepage: https://github.com/PRbsas/devto-cli-gem
114
135
  licenses:
115
136
  - MIT
@@ -117,7 +138,7 @@ metadata: {}
117
138
  post_install_message:
118
139
  rdoc_options: []
119
140
  require_paths:
120
- - lib/dev_to.rb, config/environment.rb
141
+ - lib
121
142
  required_ruby_version: !ruby/object:Gem::Requirement
122
143
  requirements:
123
144
  - - ">="