stashboxr 0.1.0 → 0.1.1
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/README.rdoc +32 -0
- data/VERSION +1 -1
- data/lib/stashboxr.rb +15 -8
- data/stashboxr.gemspec +51 -0
- metadata +7 -5
data/README.rdoc
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
= StashboxR
|
2
|
+
|
3
|
+
Original name, I know. This gem will let you communicate with http://stashbox.org via Ruby.
|
4
|
+
|
5
|
+
You can upload files and edit their metadata with either an anonymous or registered account. You can even delete files you own, should you so desire!
|
6
|
+
|
7
|
+
== Usage
|
8
|
+
|
9
|
+
s = Stashboxr::File.new("http://stashbox.org/922233/5.jpg")
|
10
|
+
# => <Stash: 5.jpg (public)>
|
11
|
+
s.title
|
12
|
+
# => nil
|
13
|
+
s.title = "Not my file"
|
14
|
+
# RuntimeError: You don't have permission to edit this file
|
15
|
+
s = Stashboxr::File.upload("a textfile.txt")
|
16
|
+
# RuntimeError: The upload wasn't allowed because 'Anonymous users are restricted to image uploads..'
|
17
|
+
Stashboxr.login("myusername","mypassword")
|
18
|
+
# => true
|
19
|
+
s = Stashboxr::File.upload("textfile.txt")
|
20
|
+
# => <Stash: textfile.txt>
|
21
|
+
s.tags = ["one","spaces won't go thru","a4"]
|
22
|
+
# => ["one","spaces_won_t_go_thru","a4"]
|
23
|
+
s.add_tag("hello")
|
24
|
+
# => ["one","spaces_won_t_go_thru","a4","hello"]
|
25
|
+
|
26
|
+
Stashboxr.search("a4")
|
27
|
+
# => [<Stash: textfile.txt>]
|
28
|
+
|
29
|
+
== Todo
|
30
|
+
|
31
|
+
* Add the feature to input a know code for a specific file so it can be edited at a later date
|
32
|
+
* Figure out why the know code isn't returned when the API is used to upload a file
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/stashboxr.rb
CHANGED
@@ -84,11 +84,11 @@ class Stashboxr
|
|
84
84
|
})
|
85
85
|
body = Nokogiri::XML(res.body)
|
86
86
|
|
87
|
-
|
88
|
-
|
87
|
+
reason = body.search('//error').inner_text rescue nil
|
88
|
+
|
89
|
+
if reason.nil?
|
89
90
|
new(body.search('//url').inner_text)
|
90
91
|
else
|
91
|
-
reason = body.search('//error').inner_text rescue nil
|
92
92
|
raise RuntimeError, "The upload wasn't allowed"<<((reason.nil?) ? "" : " because '#{reason}'")
|
93
93
|
end
|
94
94
|
end
|
@@ -128,6 +128,7 @@ class Stashboxr
|
|
128
128
|
@tags = (tags + parse_tags(new_tags)).uniq
|
129
129
|
@saved = false
|
130
130
|
save if @autosave
|
131
|
+
@tags
|
131
132
|
end
|
132
133
|
alias :add_tags :add_tag
|
133
134
|
|
@@ -136,14 +137,16 @@ class Stashboxr
|
|
136
137
|
@tags = (tags - parse_tags(new_tags)).uniq
|
137
138
|
@saved = false
|
138
139
|
save if @autosave
|
140
|
+
@tags
|
139
141
|
end
|
140
142
|
alias :remove_tags :remove_tag
|
141
143
|
|
142
144
|
# Reset the tags for this file to the ones in the given array
|
143
|
-
def
|
145
|
+
def tags=(new_tags)
|
144
146
|
@tags = parse_tags(new_tags)
|
145
147
|
@saved = false
|
146
148
|
save if @autosave
|
149
|
+
@tags
|
147
150
|
end
|
148
151
|
|
149
152
|
def title=(title)
|
@@ -195,9 +198,13 @@ class Stashboxr
|
|
195
198
|
end
|
196
199
|
|
197
200
|
def inspect
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
+
if @metadata
|
202
|
+
keys = [@public ? "public" : "private"]
|
203
|
+
keys.push("nsfw") if !@sfw
|
204
|
+
"<Stash: #{@filename} (#{keys * ", "})>"
|
205
|
+
else
|
206
|
+
"<Stash: #{@filename}>"
|
207
|
+
end
|
201
208
|
end
|
202
209
|
|
203
210
|
# Grab metadata from stashbox.org
|
@@ -245,7 +252,7 @@ class Stashboxr
|
|
245
252
|
private
|
246
253
|
def parse_tags(new_tags)
|
247
254
|
[new_tags].flatten.collect do |tag|
|
248
|
-
tag.downcase.gsub(/[^a-z0-9_-]
|
255
|
+
tag.downcase.gsub(/[^a-z0-9_-]+/,"_")
|
249
256
|
tag = nil if tag.empty?
|
250
257
|
end.compact.uniq
|
251
258
|
end
|
data/stashboxr.gemspec
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{stashboxr}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["JP Hastings-Spital"]
|
12
|
+
s.date = %q{2010-06-08}
|
13
|
+
s.description = %q{Upload files to stashbox.org and manage their metadata. User accounts or anonymous uploads!}
|
14
|
+
s.email = %q{jphastings@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"lib/stashboxr.rb",
|
23
|
+
"stashboxr.gemspec"
|
24
|
+
]
|
25
|
+
s.homepage = %q{http://github.com/jphastings/StashboxR}
|
26
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
s.rubygems_version = %q{1.3.7}
|
29
|
+
s.summary = %q{A ruby api for the stashbox.org website}
|
30
|
+
s.test_files = [
|
31
|
+
"test/helper.rb",
|
32
|
+
"test/test_stashboxr.rb"
|
33
|
+
]
|
34
|
+
|
35
|
+
if s.respond_to? :specification_version then
|
36
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
37
|
+
s.specification_version = 3
|
38
|
+
|
39
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
40
|
+
s.add_runtime_dependency(%q<mechanize>, [">= 1.0.0"])
|
41
|
+
s.add_development_dependency(%q<Shoulda>, [">= 0"])
|
42
|
+
else
|
43
|
+
s.add_dependency(%q<mechanize>, [">= 1.0.0"])
|
44
|
+
s.add_dependency(%q<Shoulda>, [">= 0"])
|
45
|
+
end
|
46
|
+
else
|
47
|
+
s.add_dependency(%q<mechanize>, [">= 1.0.0"])
|
48
|
+
s.add_dependency(%q<Shoulda>, [">= 0"])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stashboxr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- JP Hastings-Spital
|
@@ -54,12 +54,14 @@ executables: []
|
|
54
54
|
|
55
55
|
extensions: []
|
56
56
|
|
57
|
-
extra_rdoc_files:
|
58
|
-
|
57
|
+
extra_rdoc_files:
|
58
|
+
- README.rdoc
|
59
59
|
files:
|
60
|
+
- README.rdoc
|
60
61
|
- Rakefile
|
61
62
|
- VERSION
|
62
63
|
- lib/stashboxr.rb
|
64
|
+
- stashboxr.gemspec
|
63
65
|
- test/helper.rb
|
64
66
|
- test/test_stashboxr.rb
|
65
67
|
has_rdoc: true
|