batchtapaper 1.0.0 → 1.1.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/batchtapaper +14 -94
  3. metadata +36 -9
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 129911756a75e4e94c28fd70553e5279609fd0a6
4
+ data.tar.gz: 2bae666e6c96eb1632dcd7b23e8fec696e4f1b18
5
+ SHA512:
6
+ metadata.gz: 5a09b32b3dab434ec03d469e4f10637fc6a4e7ec4bf79a665747f3e89962b52b9fc23641ed54c1d6f786e859282a4e23ad17c211169551520c3717d81a760ebb
7
+ data.tar.gz: eb81ddf220e61063e2ecd96a49dbf24e999516ea485f20df4d0505b3fdb7d826a29b24cf1627bf7f5afdda8f07148c2e51101ea6f472454ed3b15a4f8c391760
data/bin/batchtapaper CHANGED
@@ -1,102 +1,22 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "net/http"
4
- require "net/https"
5
- require "uri"
6
-
7
- API_URL = URI.parse("https://www.instapaper.com/api/add")
3
+ require "bundler/setup"
4
+ require "batchtapaper"
5
+ require "faraday"
8
6
 
9
7
  # Fetch our URLs; either from the files given in the arguments, or from
10
8
  # STDIN.
11
9
  lines = ARGF.read
12
10
 
13
- unless lines
14
- puts "No URLs specified."
15
- exit
16
- end
17
-
18
- lines = lines.split("\n")
19
-
20
- # First, attempt to read usernames and passwords from the
21
- # ~/.instapaperrc file.
22
- rcfile = File.expand_path("~/.instapaperrc")
23
- if File.exists? rcfile
24
- username, password = IO.read(rcfile).split("\n")
25
- end
26
-
27
- if !username && !STDIN.tty?
28
- # If we haven't got a username from the rc file, and we're reading input
29
- # from STDIN, then we're out of luck; we can't proceed.
30
- puts "When passing URLs via STDIN, you must have an ~/.instapaperrc file containing your auth details."
31
- exit
32
- elsif !username && STDIN.tty?
33
- # If we do have a TTY (if the URLs are in a file), then we can prompt
34
- # the user for their auth details.
35
- begin
36
- print "Email or username: "
37
- username = STDIN.gets.chomp
38
-
39
- print "Password (if you have one): "
40
- # We don't want to echo input when the user is entering their
41
- # password, to prevent shoulder surfing; so, we disable the
42
- # terminal's echo temporarily.
43
- system 'stty -echo'
44
- password = STDIN.gets.chomp
45
- system 'stty echo'
46
- rescue NoMethodError, Interrupt
47
- # In case the user interrupts when typing their password, we don't
48
- # want to leave them with a terminal that isn't echoing.
49
- system 'stty echo'
50
- exit
51
- end
52
-
53
- puts "\n\n"
54
- end
55
-
56
- # Grab the lines of the file
57
- lines.each do |line|
58
- line.strip!
59
-
60
- # If the line contains a tab, then assume it's in "URL[tab]title" format
61
- if line =~ /\t/
62
- url, title = line.split("\t")
63
- else
64
- url = line
65
- end
66
-
67
- # Attempt to parse the URL that we've been given.
68
- begin
69
- url = URI.parse(url)
70
- rescue
71
- puts "#{url} doesn't seem to be a valid URL. Moving on..."
72
- continue
73
- end
74
-
75
- print "Processing URL: #{url}..."
76
-
77
- post = { 'username' => username, 'password' => password, 'url' => url.to_s }
78
- if title
79
- post['title'] = title
80
- end
81
-
82
- # We need to use this slightly more verbose syntax, rather than just
83
- # Net::HTTP::post_form, because the Instapaper API uses SSL.
84
- request = Net::HTTP::Post.new(API_URL.path)
85
- request.set_form_data(post)
86
-
87
- sock = Net::HTTP.new(API_URL.host, API_URL.port)
88
- sock.use_ssl = true
89
- response = sock.start { |http| http.request(request) }
90
-
91
- # The Instapaper API will return a 403 error for any request if the
92
- # given username and password are wrong.
93
- if response.code == 403
94
- puts "Username/password incorrect."
95
- exit
96
- end
97
-
98
- # We can fairly reasonably assume that any other request is valid.
99
- print " Got response #{response.code}\n"
100
-
101
- sleep 1
11
+ begin
12
+ batchtapaper = Batchtapaper.from_string(lines)
13
+ batchtapaper.process do |request|
14
+ if request.successful?
15
+ puts "Successfully added #{request.url} (#{request.title})."
16
+ else
17
+ puts "Failed to add #{request.url}."
18
+ end
19
+ end
20
+ rescue Batchtapaper::NoAuthError => e
21
+ $stderr.puts e.message
102
22
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: batchtapaper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Rob Miller
@@ -10,7 +9,35 @@ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
  date: 2013-03-19 00:00:00.000000000 Z
13
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
14
41
  description: Easily add multiple URLs to Instapaper, either from a file or from STDIN.
15
42
  email: rob@bigfish.co.uk
16
43
  executables:
@@ -21,26 +48,26 @@ files:
21
48
  - bin/batchtapaper
22
49
  homepage: https://github.com/robmiller/batchtapaper
23
50
  licenses: []
51
+ metadata: {}
24
52
  post_install_message:
25
53
  rdoc_options: []
26
54
  require_paths:
27
55
  - lib
28
56
  required_ruby_version: !ruby/object:Gem::Requirement
29
- none: false
30
57
  requirements:
31
- - - ! '>='
58
+ - - '>='
32
59
  - !ruby/object:Gem::Version
33
60
  version: '0'
34
61
  required_rubygems_version: !ruby/object:Gem::Requirement
35
- none: false
36
62
  requirements:
37
- - - ! '>='
63
+ - - '>='
38
64
  - !ruby/object:Gem::Version
39
65
  version: '0'
40
66
  requirements: []
41
67
  rubyforge_project:
42
- rubygems_version: 1.8.25
68
+ rubygems_version: 2.0.3
43
69
  signing_key:
44
- specification_version: 3
70
+ specification_version: 4
45
71
  summary: Bulk-add URLs to Instapaper
46
72
  test_files: []
73
+ has_rdoc: