get_pocket_send 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a3bd21a48f47bfcdcdb54ab4ac5a4d6c617df495
4
+ data.tar.gz: 887128d7bf0777137036f4b468ff16fea07d6e1f
5
+ SHA512:
6
+ metadata.gz: b43b7e3ce1492c66d39b648272af5e7d9df4f25cbdb7686916a6a25ad143e6bc3f92016a429728d485b0728e58dc31fbeae78e5975b66a10191e26b3a344c34b
7
+ data.tar.gz: 38287a7a81361780fe0b743552c465b6ad541f4da1a54cd550678cebe3b35eebbfbf9fc073347f159f548e2aadc4d1ec67e42ad6e2f116cb683eeaaeefb380c6
data/.gitignore ADDED
@@ -0,0 +1,15 @@
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
15
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create ruby-2.1.2@get_pocket_send
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in get_pocket_send.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Vasin Dmitriy
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,31 @@
1
+ # GetPocketSend
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'get_pocket_send'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install get_pocket_send
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/get_pocket_send/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require './lib/get_pocket_send'
4
+
5
+ begin
6
+ raise Interrupt unless ARGV.size == 2
7
+
8
+ pocket = GetPocketSend::CLI.new(ARGV[0], ARGV[1])
9
+ pocket.start
10
+ rescue Interrupt
11
+ $stderr.puts 'Quitting: Please insert all credentials...'
12
+ exit 1
13
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'get_pocket_send/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "get_pocket_send"
8
+ spec.version = GetPocketSend::VERSION
9
+ spec.authors = ["Vasin Dmitriy"]
10
+ spec.email = ["vasindima779@gmail.com"]
11
+ spec.summary = "This is a small aplication for turn get pocket from terminal"
12
+ spec.homepage = "https://github.com/DemitriyDN/SendToPocket"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = ["get_pocket_send"]
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'nokogiri', ['1.6.1']
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,22 @@
1
+ require 'net/smtp'
2
+
3
+ module GetPocketSend
4
+ module EmailSender
5
+ def send_email_with(opts={})
6
+ opts[:domain] ||= 'gmail.com'
7
+ opts[:pocket] ||= 'add@getpocket.com'
8
+
9
+ opts[:subject] ||= "You need to see this"
10
+ opts[:body] ||= "http://www.lostfilm.tv/"
11
+
12
+ msg = "Subject: #{opts[:subject]} \n\n #{opts[:body]}"
13
+ smtp = Net::SMTP.new 'smtp.gmail.com', 587
14
+ smtp.enable_starttls
15
+ smtp.start(opts[:domain], email, password, :login) do
16
+ smtp.send_message(msg, email, opts[:pocket])
17
+ end
18
+
19
+ message_sent
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,71 @@
1
+ module GetPocketSend
2
+ module Messages
3
+ def message_save_article
4
+ output.puts "Save this article? #{yes} / #{no} / #{close}"
5
+ end
6
+
7
+ def message_goodbie
8
+ show_message goodbie
9
+ end
10
+
11
+ def message_sent
12
+ show_message sent
13
+ end
14
+
15
+ def message_next
16
+ show_message the_next
17
+ end
18
+
19
+ def message_current_site site_name
20
+ output.puts "------- Site Name -------"
21
+ output.puts site_name
22
+ output.puts "------- Site Name -------"
23
+ end
24
+
25
+ def handling_permission?
26
+ permition = input.gets.chomp
27
+
28
+ case permition
29
+ when 'y', 'yes'
30
+ true
31
+ when 'n', 'no'
32
+ false
33
+ when 'c', 'close'
34
+ raise SystemExit
35
+ else
36
+ message_save_article
37
+ handling_permission?
38
+ end
39
+ end
40
+
41
+ private
42
+ def show_message msg
43
+ output.puts msg
44
+ output.puts "-------------------------"
45
+ end
46
+
47
+ def yes
48
+ "\033[32m[yes]y\033[0m"
49
+ end
50
+
51
+ def no
52
+ "\033[33m[no]n\033[0m"
53
+ end
54
+
55
+ def close
56
+ "\033[31m[close]c\033[0m"
57
+ end
58
+
59
+ def the_next
60
+ "\033[33mNext...\033[0m"
61
+ end
62
+
63
+ def goodbie
64
+ "\033[33mGoodbye...\033[0m"
65
+ end
66
+
67
+ def sent
68
+ "\033[32mSent...\033[0m"
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,42 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+
4
+ module GetPocketSend
5
+ class Parser
6
+ class << self
7
+ def get_title_and_link_by
8
+ a = Hash.new()
9
+
10
+ sites_and_selectors.map do |element|
11
+ name, url, block_selector, title_selector, link_selector = element
12
+
13
+ page = get_page_content(url)
14
+ title_with_link = page.css(block_selector).map do |block|
15
+ [
16
+ block.css(title_selector).children.first.text,
17
+ block.css(link_selector).first.attr('href'),
18
+ ]
19
+ end
20
+
21
+ a[name] = title_with_link
22
+ end
23
+
24
+ a
25
+ end
26
+
27
+ # private
28
+
29
+ def get_page_content remote_url
30
+ Nokogiri::HTML(open(remote_url))
31
+ end
32
+
33
+ # TODO: Should be grapping users file or somthing else..
34
+ def sites_and_selectors
35
+ [
36
+ ['ITC', 'http://itc.ua/', '.articles header', 'h1.post-title a', 'h1.post-title a'] #,
37
+ # ['livejournal', 'http://valerii.livejournal.com/feed', '.b-lenta-item', '.b-lenta-item-title a', '.b-lenta-item-title a']
38
+ ]
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module GetPocketSend
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+
3
+ require './lib/get_pocket_send/parser'
4
+ require './lib/get_pocket_send/messages'
5
+ require './lib/get_pocket_send/email_sender'
6
+
7
+ module GetPocketSend
8
+ class CLI
9
+ include Messages
10
+ include EmailSender
11
+
12
+ # [TODO] No needed declaration...
13
+ attr_accessor :input, :output, :email, :password
14
+ def initialize email, password
15
+ self.input = $stdin
16
+ self.output = $stdout
17
+
18
+ @email = email
19
+ @password = password
20
+ end
21
+
22
+
23
+ def start
24
+ error_handler do
25
+ hash = Parser.get_title_and_link_by
26
+
27
+ hash.each do |key, value|
28
+ message_current_site(key)
29
+
30
+ value.each_with_index do |title_and_link, index|
31
+ title = title_and_link[0]
32
+ link = title_and_link[1]
33
+
34
+ output.puts "#{index + 1}: #{title}"
35
+ output.puts "( #{link} )"
36
+
37
+ message_save_article
38
+
39
+ if handling_permission?
40
+ send_email_with({ body: link, subject: title })
41
+ else
42
+ message_next
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ private
50
+ def error_handler
51
+ begin
52
+ yield
53
+ rescue SystemExit
54
+ message_goodbie
55
+ exit 1
56
+ end
57
+ end
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: get_pocket_send
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Vasin Dmitriy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - vasindima779@gmail.com
58
+ executables:
59
+ - get_pocket_send
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".rvmrc"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/get_pocket_send
71
+ - get_pocket_send.gemspec
72
+ - lib/get_pocket_send.rb
73
+ - lib/get_pocket_send/email_sender.rb
74
+ - lib/get_pocket_send/messages.rb
75
+ - lib/get_pocket_send/parser.rb
76
+ - lib/get_pocket_send/version.rb
77
+ homepage: https://github.com/DemitriyDN/SendToPocket
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.4.1
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: This is a small aplication for turn get pocket from terminal
101
+ test_files: []