stashboxr 0.1.2 → 0.1.3
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.
- data/VERSION +1 -1
- data/lib/stashboxr.rb +24 -10
- data/stashboxr.gemspec +4 -4
- metadata +3 -14
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/stashboxr.rb
CHANGED
@@ -44,6 +44,14 @@ class Stashboxr
|
|
44
44
|
@@username
|
45
45
|
end
|
46
46
|
|
47
|
+
def self.autosave=(pref)
|
48
|
+
@@autosave = (pref == true)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.autosave?
|
52
|
+
@@autosave rescue true
|
53
|
+
end
|
54
|
+
|
47
55
|
# Search stashbox.org - the site has this advice for formatting searches:
|
48
56
|
#
|
49
57
|
# You can use any number of terms in your search, all of which will be required in the results. You can also use the following search types (using "type:*the_type*" format): archives, audio, code, documents, images, movies
|
@@ -78,30 +86,32 @@ class Stashboxr
|
|
78
86
|
# Upload the file
|
79
87
|
res = Agent.post('http://stashbox.org/upload.php',{
|
80
88
|
:upload_type => "local_file",
|
81
|
-
:wants_rss => 1,
|
82
89
|
:file => open(local_file),
|
83
90
|
:is_public => is_public
|
84
91
|
})
|
85
|
-
body = Nokogiri::XML(res.body)
|
86
92
|
|
87
|
-
reason =
|
93
|
+
reason = res.search('//div[@class=\'error\']').inner_text
|
88
94
|
|
89
|
-
if reason.
|
90
|
-
new(
|
95
|
+
if reason.empty?
|
96
|
+
new(res)
|
91
97
|
else
|
92
98
|
raise RuntimeError, "The upload wasn't allowed"<<((reason.nil?) ? "" : " because '#{reason}'")
|
93
99
|
end
|
94
100
|
end
|
95
101
|
|
96
102
|
def initialize(url)
|
97
|
-
|
103
|
+
|
104
|
+
if (url.is_a? Mechanize::Page)
|
105
|
+
# We're being initialized with an information page (ie. an upload) make use of it!
|
106
|
+
refresh(url)
|
107
|
+
elsif (url =~ /(?:http:\/\/)?(?:stashbox\.org)?(?:\/v)?\/?([0-9]+\/(.+))$/)
|
98
108
|
@stashboxid = $1
|
99
109
|
@filename = $2
|
100
110
|
else
|
101
111
|
raise RuntimeError, "That isn't a valid stashbox URL"
|
102
112
|
end
|
103
113
|
|
104
|
-
@autosave =
|
114
|
+
@autosave = Stashboxr.autosave?
|
105
115
|
@saved = true
|
106
116
|
end
|
107
117
|
|
@@ -208,13 +218,16 @@ class Stashboxr
|
|
208
218
|
end
|
209
219
|
|
210
220
|
# Grab metadata from stashbox.org
|
211
|
-
def refresh
|
221
|
+
def refresh(doc = nil)
|
212
222
|
# Get extended information
|
213
|
-
doc
|
223
|
+
doc ||= Agent.get "http://stashbox.org/v/"<<@stashboxid
|
214
224
|
|
215
225
|
doc.search("//div[@class='subsection']").each do |sub|
|
216
226
|
value = sub.search("div[@class='value']").inner_text.strip
|
217
227
|
case sub.search("div[@class='label']").inner_text
|
228
|
+
when "Filename"
|
229
|
+
@filename = value
|
230
|
+
@stashboxid = URI.parse(sub.search("div[@class='value']/a")[0]['href']).path[1..-1]
|
218
231
|
when "Size"
|
219
232
|
@size = value[/^(\d+\.\d+)\ ([K|M]?)B$/,1].to_f * SIZES[$2]
|
220
233
|
when "Uploaded On"
|
@@ -252,8 +265,9 @@ class Stashboxr
|
|
252
265
|
private
|
253
266
|
def parse_tags(new_tags)
|
254
267
|
[new_tags].flatten.collect do |tag|
|
255
|
-
tag.downcase.gsub(/[^a-z0-9_-]+/,"_")
|
268
|
+
tag = tag.downcase.gsub(/[^a-z0-9_-]+/,"_")
|
256
269
|
tag = nil if tag.empty?
|
270
|
+
tag
|
257
271
|
end.compact.uniq
|
258
272
|
end
|
259
273
|
end
|
data/stashboxr.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{stashboxr}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["JP Hastings-Spital"]
|
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.homepage = %q{http://github.com/jphastings/StashboxR}
|
26
26
|
s.rdoc_options = ["--charset=UTF-8"]
|
27
27
|
s.require_paths = ["lib"]
|
28
|
-
s.rubygems_version = %q{1.3.
|
28
|
+
s.rubygems_version = %q{1.3.6}
|
29
29
|
s.summary = %q{A ruby api for the stashbox.org website}
|
30
30
|
s.test_files = [
|
31
31
|
"test/helper.rb",
|
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
|
|
36
36
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
37
37
|
s.specification_version = 3
|
38
38
|
|
39
|
-
if Gem::Version.new(Gem::
|
39
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
40
40
|
s.add_runtime_dependency(%q<mechanize>, [">= 1.0.0"])
|
41
41
|
s.add_development_dependency(%q<Shoulda>, [">= 0"])
|
42
42
|
else
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stashboxr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 31
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- JP Hastings-Spital
|
@@ -22,11 +21,9 @@ dependencies:
|
|
22
21
|
name: mechanize
|
23
22
|
prerelease: false
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
24
|
requirements:
|
27
25
|
- - ">="
|
28
26
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 23
|
30
27
|
segments:
|
31
28
|
- 1
|
32
29
|
- 0
|
@@ -38,11 +35,9 @@ dependencies:
|
|
38
35
|
name: Shoulda
|
39
36
|
prerelease: false
|
40
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
38
|
requirements:
|
43
39
|
- - ">="
|
44
40
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 3
|
46
41
|
segments:
|
47
42
|
- 0
|
48
43
|
version: "0"
|
@@ -62,8 +57,6 @@ files:
|
|
62
57
|
- VERSION
|
63
58
|
- lib/stashboxr.rb
|
64
59
|
- stashboxr.gemspec
|
65
|
-
- test/helper.rb
|
66
|
-
- test/test_stashboxr.rb
|
67
60
|
has_rdoc: true
|
68
61
|
homepage: http://github.com/jphastings/StashboxR
|
69
62
|
licenses: []
|
@@ -74,27 +67,23 @@ rdoc_options:
|
|
74
67
|
require_paths:
|
75
68
|
- lib
|
76
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
-
none: false
|
78
70
|
requirements:
|
79
71
|
- - ">="
|
80
72
|
- !ruby/object:Gem::Version
|
81
|
-
hash: 3
|
82
73
|
segments:
|
83
74
|
- 0
|
84
75
|
version: "0"
|
85
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
-
none: false
|
87
77
|
requirements:
|
88
78
|
- - ">="
|
89
79
|
- !ruby/object:Gem::Version
|
90
|
-
hash: 3
|
91
80
|
segments:
|
92
81
|
- 0
|
93
82
|
version: "0"
|
94
83
|
requirements: []
|
95
84
|
|
96
85
|
rubyforge_project:
|
97
|
-
rubygems_version: 1.3.
|
86
|
+
rubygems_version: 1.3.6
|
98
87
|
signing_key:
|
99
88
|
specification_version: 3
|
100
89
|
summary: A ruby api for the stashbox.org website
|