bolso-furado 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9a146d368f7d8ad42c9e490220493b1b9632d6ae
4
+ data.tar.gz: 8080eadb91136bf1b34cba8cda6b478fef32674d
5
+ SHA512:
6
+ metadata.gz: 4f78546ec16b3d23d01c6dfd0f4f4dc341ea507307be2b38b9b93bdd564c2c41ce4f34c3a7fb12edd7c10892c6047a0aa80cd3e7e30fb9363f2f9b991ee515e8
7
+ data.tar.gz: a5a470c84c12e04e40276b533f05359ede3cc220c0188395d31fe1117507133e30fa795cfd640764de5bc725ecedb5f57c9279b032912923c0089d6463d6b179
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "pocket-ruby"
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ byebug (9.0.6)
5
+ faraday (0.12.1)
6
+ multipart-post (>= 1.2, < 3)
7
+ faraday_middleware (0.11.0.1)
8
+ faraday (>= 0.7.4, < 1.0)
9
+ hashie (3.5.5)
10
+ multi_json (1.12.1)
11
+ multipart-post (2.0.0)
12
+ pocket-ruby (0.0.6)
13
+ faraday (>= 0.7)
14
+ faraday_middleware (~> 0.9)
15
+ hashie (>= 0.4.0)
16
+ multi_json (~> 1.0, >= 1.0.3)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ byebug
23
+ pocket-ruby
24
+
25
+ BUNDLED WITH
26
+ 1.14.6
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # bolso-furado
2
+
3
+ Tag your old articles on Pocket as "bolso-furado"
4
+
5
+ # How to use
6
+
7
+ Install the gem:
8
+
9
+ $ gem install bolso-furado
10
+
11
+ Create a Pocket application.
12
+
13
+ Get consumer key and token.
14
+
15
+ Run script with consumer key and token:
16
+
17
+ $ bolso-furado -k 68583-ceb7f902cac956bc671bd299 -t 91142ba0-acfb-373c-735c-8e072b -d 20
18
+ 21 item(s) untagged
19
+ 17 recent item(s) untagged
20
+ 4 item(s) tagged as bolso-furado
21
+
22
+ Day parameter is optional. Default will be 30 days.
data/bin/bolso-furado ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require './lib/bolso_furado'
4
+ require './lib/cli_options'
5
+
6
+ CliOptions.parse! do |opts|
7
+ result = BolsoFurado.new(opts).execute!
8
+ puts "#{result.all.size} item(s) untagged"
9
+ puts "#{result.new_articles.size} recent item(s) untagged"
10
+ puts "#{result.old_articles.size} item(s) tagged as bolso-furado"
11
+ end
@@ -0,0 +1,17 @@
1
+ require "./lib/version"
2
+
3
+ Gem::Specification.new do |s|
4
+ s.required_ruby_version = ">= 2.0"
5
+ s.name = 'bolso-furado'
6
+ s.version = VERSION
7
+ s.summary = 'Tag your old articles on Pocket as "bolso-furado"'
8
+ s.description = s.summary
9
+ s.authors = ['Hercules Lemke Merscher']
10
+ s.email = 'hlmerscher@gmail.com'
11
+ s.files = `git ls-files`.split("\n")
12
+ .delete_if { |entry| entry.start_with?(".", "bin") }
13
+ s.executables = `git ls-files -- bin/*`.split("\n")
14
+ .map {|f| File.basename(f) }
15
+ s.homepage = 'http://github.com/hlmerscher/bolso-furado'
16
+ s.license = 'MIT'
17
+ end
@@ -0,0 +1,27 @@
1
+ require "date"
2
+ require "./lib/pocket_client"
3
+
4
+ class BolsoFurado
5
+ def initialize(opts)
6
+ @opts = opts
7
+ @opts[:days] ||= 30
8
+ @pocket = PocketClient.new(opts[:key], opts[:token])
9
+ end
10
+
11
+ def execute!
12
+ build_result(@pocket.retrieve_untagged).tap(&method(:tag_items!))
13
+ end
14
+
15
+ private
16
+
17
+ def build_result(items)
18
+ days_ago = Date.today - @opts[:days]
19
+ OpenStruct.new(all: items,
20
+ old_articles: items.select { |item| item[:added_at] <= days_ago },
21
+ new_articles: items.select { |item| item[:added_at] > days_ago })
22
+ end
23
+
24
+ def tag_items!(result)
25
+ @pocket.tag_as_bolso_furado(result.old_articles)
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'optparse'
2
+ require './lib/version'
3
+
4
+ class CliOptions
5
+ def self.parse!
6
+ options = {}
7
+ OptionParser.new do |opts|
8
+ opts.banner = 'Usage options:'
9
+ opts.on('-k', '--key CONSUMER-KEY', 'Consumer key') { |key| options[:key] = key }
10
+ opts.on('-t', '--token CONSUMER-TOKEN', 'Consumer token') { |token| options[:token] = token }
11
+ opts.on('-d', '--days 30', Integer, 'How many days (default to 30)') { |days| options[:days] = days }
12
+ opts.on('-v', '--version', "Current version") { puts VERSION }
13
+ end.parse!
14
+ errors = check_required_params(options)
15
+ errors.each { |msg| puts msg }
16
+ yield(options) if errors.empty?
17
+ end
18
+
19
+ private
20
+
21
+ def self.check_required_params(opts)
22
+ errors = []
23
+ errors << "Consumer key required!" if opts[:key].nil? || opts[:key].empty?
24
+ errors << "Consumer token required!" if opts[:token].nil? || opts[:token].empty?
25
+ errors
26
+ end
27
+ end
@@ -0,0 +1,45 @@
1
+ require "pocket-ruby"
2
+
3
+ class PocketClient
4
+ def initialize(consumer_key, consumer_token)
5
+ Pocket.configure do |config|
6
+ config.consumer_key = consumer_key
7
+ end
8
+ @consumer_token = consumer_token
9
+ end
10
+
11
+ def retrieve_untagged
12
+ info = client.retrieve(detailType: "simple", tag: "_untagged_")
13
+ info["list"].map { |(item_id, value)| build_item(value) }
14
+ end
15
+
16
+ def tag_as_bolso_furado(old_items)
17
+ old_items
18
+ .map(&method(:build_item_to_modify))
19
+ .tap(&method(:modify_items!))
20
+ end
21
+
22
+ private
23
+
24
+ def client
25
+ @client ||= Pocket.client(access_token: @consumer_token)
26
+ end
27
+
28
+ def build_item(hash)
29
+ timestamp = hash["time_added"].to_i
30
+ OpenStruct.new(title: hash["given_title"],
31
+ added_at: Time.at(timestamp).to_date,
32
+ item_id: hash["item_id"])
33
+ end
34
+
35
+ def build_item_to_modify(item)
36
+ { "action" => "tags_add",
37
+ "item_id" => item.item_id,
38
+ "tags" => "bolso-furado",
39
+ "time" => Time.now.to_i }
40
+ end
41
+
42
+ def modify_items!(items_to_tag)
43
+ client.modify(items_to_tag) if items_to_tag.size > 0
44
+ end
45
+ end
data/lib/version.rb ADDED
@@ -0,0 +1 @@
1
+ VERSION = '1.0.0'
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bolso-furado
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Hercules Lemke Merscher
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Tag your old articles on Pocket as "bolso-furado"
14
+ email: hlmerscher@gmail.com
15
+ executables:
16
+ - bolso-furado
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Gemfile
21
+ - Gemfile.lock
22
+ - README.md
23
+ - bin/bolso-furado
24
+ - bolso_furado.gemspec
25
+ - lib/bolso_furado.rb
26
+ - lib/cli_options.rb
27
+ - lib/pocket_client.rb
28
+ - lib/version.rb
29
+ homepage: http://github.com/hlmerscher/bolso-furado
30
+ licenses:
31
+ - MIT
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '2.0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.6.11
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Tag your old articles on Pocket as "bolso-furado"
53
+ test_files: []