ruush 0.93.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 +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +31 -0
- data/Rakefile +7 -0
- data/bin/ruush +24 -0
- data/lib/ruush.rb +28 -0
- data/lib/ruush/auth.rb +32 -0
- data/lib/ruush/cli.rb +180 -0
- data/lib/ruush/config.rb +31 -0
- data/lib/ruush/delete.rb +12 -0
- data/lib/ruush/endpoint.rb +6 -0
- data/lib/ruush/errors.rb +7 -0
- data/lib/ruush/history.rb +16 -0
- data/lib/ruush/parser.rb +66 -0
- data/lib/ruush/upload.rb +22 -0
- data/lib/ruush/version.rb +4 -0
- data/ruush.gemspec +32 -0
- data/spec/auth_spec.rb +70 -0
- data/spec/delete_spec.rb +25 -0
- data/spec/endpoint_spec.rb +14 -0
- data/spec/history_spec.rb +25 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/upload_spec.rb +14 -0
- metadata +174 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 15e43140695a06b4bdb488ae30cdf0b70154d4d9
|
4
|
+
data.tar.gz: 9fe21329935c57d6b6dccd40cd62bc76e0e96c9b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a080a06d2f4143fc918ad737df6697499b4a00591152432c8b63d5f6ec5d11636170a3e353e44d5519c773153e50abf63f862c73515ef7341243f2a614a8377
|
7
|
+
data.tar.gz: e77a72f53277e18f55fcbb14aa6a9d660dd89239106f056357c0832cb9e5fb013baa4998e5a2d75d46db34d542aceec7ca5de6e14e3db5fe864e191e456f1994
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Mark Old
|
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
|
+
# ruush [](https://travis-ci.org/Dlom/ruush)
|
2
|
+
|
3
|
+
Command-line access to [puush](https://puush.me) via ruby
|
4
|
+
|
5
|
+
`ruush` is compatible with puush r93
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'ruush'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ruush
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
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 new Pull Request
|
data/Rakefile
ADDED
data/bin/ruush
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
bin_file = Pathname.new(__FILE__).realpath # thanks heroku
|
6
|
+
$:.unshift File.expand_path("../../lib", bin_file)
|
7
|
+
|
8
|
+
require "ruush"
|
9
|
+
write_config = true
|
10
|
+
|
11
|
+
begin
|
12
|
+
Ruush::CLI::run!
|
13
|
+
rescue Interrupt
|
14
|
+
warn "Aborting"
|
15
|
+
write_config = false
|
16
|
+
rescue Slop::Error => e
|
17
|
+
warn e
|
18
|
+
rescue Ruush::Error => e
|
19
|
+
warn e
|
20
|
+
rescue ArgumentError, Errno::ENOENT => e
|
21
|
+
warn e
|
22
|
+
end
|
23
|
+
|
24
|
+
Ruush::write_config if write_config # update .ruush with new info from this run
|
data/lib/ruush.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "ruush/version"
|
2
|
+
|
3
|
+
require "rest-client"
|
4
|
+
|
5
|
+
require "ruush/endpoint"
|
6
|
+
require "ruush/errors"
|
7
|
+
require "ruush/config"
|
8
|
+
|
9
|
+
require "ruush/parser"
|
10
|
+
require "ruush/auth"
|
11
|
+
require "ruush/history"
|
12
|
+
require "ruush/upload"
|
13
|
+
require "ruush/delete"
|
14
|
+
|
15
|
+
require "ruush/cli"
|
16
|
+
|
17
|
+
module Ruush
|
18
|
+
@config_file = "#{Dir.home}/.ruush"
|
19
|
+
@config = Config.new @config_file
|
20
|
+
|
21
|
+
def self.config
|
22
|
+
@config
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.write_config
|
26
|
+
@config.write "#{Dir.home}/.ruush"
|
27
|
+
end
|
28
|
+
end
|
data/lib/ruush/auth.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Ruush
|
2
|
+
class Api
|
3
|
+
AUTH_ENDPOINT = Ruush::endpoint "/api/auth"
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def auth_password(email, password)
|
7
|
+
response = RestClient.post AUTH_ENDPOINT, :e => email, :p => password, :z => "poop" # pooping is necessary
|
8
|
+
Parser::parse_auth response.body
|
9
|
+
end
|
10
|
+
|
11
|
+
def auth_key(key)
|
12
|
+
response = RestClient.post AUTH_ENDPOINT, :k => key, :z => "poop" # pooping is necessary, email is not?
|
13
|
+
Parser::parse_auth response.body
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_key(email, password)
|
17
|
+
auth_data = auth_password email, password
|
18
|
+
auth_data.key
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_premium(key)
|
22
|
+
auth_data = auth_key key
|
23
|
+
auth_data.is_premium
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_usage(key)
|
27
|
+
auth_data = auth_key key
|
28
|
+
auth_data.usage_bytes
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/ruush/cli.rb
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
require "slop"
|
2
|
+
require "io/console"
|
3
|
+
|
4
|
+
module Ruush
|
5
|
+
class CLI
|
6
|
+
class << self
|
7
|
+
def die(message)
|
8
|
+
warn message
|
9
|
+
exit
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup # this whole thing will (hopefully) be cleaned up at a later date
|
13
|
+
slop = Slop.new :strict => true, :help => true do |s|
|
14
|
+
s.banner "Usage: ruush <command> [options] [<args>]"
|
15
|
+
s.on :v, :version, "Print version and exit", :tail => true do puts "ruush v#{Ruush::VERSION} based on puush #{Ruush::PUUSH_VERSION}"; end
|
16
|
+
|
17
|
+
s.command "setup", :help => true do
|
18
|
+
description "Interactively set up ~/.ruush"
|
19
|
+
banner "Usage: ruush setup [options]"
|
20
|
+
|
21
|
+
run do |opts, args|
|
22
|
+
raise Slop::InvalidArgumentError, "Too many arguments (expected zero)" if args.length > 0
|
23
|
+
exit if opts.to_h[:help]
|
24
|
+
|
25
|
+
print "Email: "
|
26
|
+
email = ($stdin.gets || "").chomp
|
27
|
+
exit if email == ""
|
28
|
+
print "Password: "
|
29
|
+
password = ($stdin.noecho(&:gets) || "").chomp
|
30
|
+
print "\n"
|
31
|
+
|
32
|
+
begin
|
33
|
+
result = Api::auth_password email, password
|
34
|
+
Ruush::config["key"] = result.key
|
35
|
+
Ruush::config["email"] = email
|
36
|
+
Ruush::config["is_premium"] = result.is_premium
|
37
|
+
Ruush::config["usage_bytes"] = result.usage_bytes
|
38
|
+
puts "Successfully authenticated with puush"
|
39
|
+
rescue BadAuth
|
40
|
+
warn "Email or password is incorrect"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
s.command "auth", :help => true do
|
46
|
+
description "Authenticate with API key in ~/.ruush"
|
47
|
+
banner "Usage: ruush auth [options]"
|
48
|
+
|
49
|
+
run do |opts, args|
|
50
|
+
raise Slop::InvalidArgumentError, "Too many arguments (expected zero)" if args.length > 0
|
51
|
+
exit if opts.to_h[:help]
|
52
|
+
|
53
|
+
begin
|
54
|
+
result = Api::auth_key Ruush::config["key"]
|
55
|
+
Ruush::config["is_premium"] = result.is_premium
|
56
|
+
Ruush::config["usage_bytes"] = result.usage_bytes
|
57
|
+
puts "Successfully authenticated with puush"
|
58
|
+
rescue BadAuth
|
59
|
+
CLI::die "API key is invalid"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
s.command "upload", :help => true do
|
65
|
+
description "Upload a file to puush"
|
66
|
+
banner "Usage: ruush upload [options] [<file>]"
|
67
|
+
on :s, :silent, "Do not print url"
|
68
|
+
|
69
|
+
run do |opts, args|
|
70
|
+
raise Slop::MissingArgumentError, "Missing file argument" if args.length < 1
|
71
|
+
raise Slop::InvalidArgumentError, "Too many files (expected one)" if args.length > 1
|
72
|
+
exit if opts.to_h[:help]
|
73
|
+
CLI::die "Please run `ruush setup` or place your API key in ~/.ruush" if Ruush::config["key"] == ""
|
74
|
+
|
75
|
+
begin
|
76
|
+
key = Ruush::config[:key]
|
77
|
+
result = Api::upload_file key, File.open(args[0])
|
78
|
+
Ruush::config["usage_bytes"] = result.usage_bytes
|
79
|
+
puts result.url if !opts.to_h[:silent]
|
80
|
+
rescue Error => e
|
81
|
+
CLI::die e
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
s.command "list", :help => true do
|
87
|
+
description "List most recent puushes"
|
88
|
+
banner "Usage: ruush list [options]"
|
89
|
+
on :f, :files, "Only print filenames"
|
90
|
+
on :u, :urls, "Only print URLs"
|
91
|
+
on :n=, :number=, "Number of puushes to list (defaults 10)", :as => Integer
|
92
|
+
on :o=, :offset=, "How many puushes to skip before listing (defaults 0)", :as => Integer # confusing
|
93
|
+
|
94
|
+
run do |opts, args|
|
95
|
+
raise Slop::InvalidArgumentError, "Too many arguments (expected zero)" if args.length > 0
|
96
|
+
exit if opts.to_h[:help]
|
97
|
+
CLI::die "Please run `ruush setup` or place your API key in ~/.ruush" if Ruush::config["key"] == ""
|
98
|
+
|
99
|
+
begin
|
100
|
+
history = Api::get_hist Ruush::config["key"], (opts.to_h[:number] || 10), (opts.to_h[:offset] || 0)
|
101
|
+
if history.length == 0
|
102
|
+
puts "You have no puushes!"
|
103
|
+
else
|
104
|
+
history.each do |h|
|
105
|
+
if opts.to_h[:files]
|
106
|
+
puts h.filename
|
107
|
+
elsif opts.to_h[:urls]
|
108
|
+
puts h.url
|
109
|
+
else
|
110
|
+
puts "#{h.url} - #{h.filename}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
rescue BadKey => e
|
115
|
+
CLI::die "API key is invalid"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
s.command "usage", :help => true do
|
121
|
+
description "Display current storage usage"
|
122
|
+
banner "Usage: ruush usage [options]"
|
123
|
+
on :b, :bytes, "Print usage in bytes"
|
124
|
+
on :r, :raw, "Only print byte information (implies --bytes)"
|
125
|
+
|
126
|
+
run do |opts, args|
|
127
|
+
raise Slop::InvalidArgumentError, "Too many arguments (expected zero)" if args.length > 0
|
128
|
+
exit if opts.to_h[:help]
|
129
|
+
CLI::die "Please run `ruush setup` or place your API key in ~/.ruush" if Ruush::config["key"] == ""
|
130
|
+
|
131
|
+
begin
|
132
|
+
bytes = Api::get_usage Ruush::config["key"]
|
133
|
+
Ruush::config["usage_bytes"] = bytes
|
134
|
+
if opts.to_h[:raw]
|
135
|
+
puts bytes
|
136
|
+
elsif opts.to_h[:bytes]
|
137
|
+
puts "Current usage: %d bytes" % bytes
|
138
|
+
else
|
139
|
+
puts "Current usage: %.2fMB" % (bytes / 1048576.0) # bytes in a megabyte
|
140
|
+
end
|
141
|
+
rescue BadKey => e
|
142
|
+
CLI::die "API key is invalid"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
s.command "help", :help => true do
|
148
|
+
description "Alias for `<command> --help`"
|
149
|
+
banner "Usage: ruush help <command>"
|
150
|
+
|
151
|
+
run do |opts, args|
|
152
|
+
exit if opts.to_h[:help]
|
153
|
+
|
154
|
+
if args.length != 0 and s.commands.has_key? args[0]
|
155
|
+
s.commands[args[0]].options.detect { |opt| opt.long == "help" }.call
|
156
|
+
else
|
157
|
+
s.options.detect { |opt| opt.long == "help" }.call
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
s.run do |opts, args|
|
163
|
+
if args.length == 0
|
164
|
+
if opts.to_hash.values.all? { |x| x.nil? }
|
165
|
+
s.options.detect { |opt| opt.long == "help" }.call
|
166
|
+
end
|
167
|
+
else
|
168
|
+
raise Slop::InvalidCommandError, "Unknown command #{args[0]}"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def run!(argv = ARGV.dup)
|
175
|
+
slop = setup
|
176
|
+
slop.parse! argv
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
data/lib/ruush/config.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "settingslogic"
|
2
|
+
|
3
|
+
module Ruush
|
4
|
+
class Config < Settingslogic
|
5
|
+
DEFAULTS = {
|
6
|
+
"key" => "",
|
7
|
+
"email" => "",
|
8
|
+
"is_premium" => false,
|
9
|
+
"usage_bytes" => -1
|
10
|
+
}
|
11
|
+
|
12
|
+
def initialize(filename, section = nil)
|
13
|
+
if !File.exists? filename
|
14
|
+
write_defaults filename
|
15
|
+
end
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def write(filename)
|
20
|
+
File.open filename, "w" do |f|
|
21
|
+
f.write self.to_h.to_yaml
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def write_defaults(filename)
|
26
|
+
File.open filename, "w" do |f|
|
27
|
+
f.write DEFAULTS.to_yaml
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/ruush/delete.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Ruush
|
2
|
+
class Api
|
3
|
+
DEL_ENDPOINT = Ruush::endpoint "/api/del"
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def delete(key, id)
|
7
|
+
response = RestClient.post DEL_ENDPOINT, :k => key, :i => id, :z => "poop" # pooping is necessary
|
8
|
+
Parser::parse_hist response.body # same format as hist
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/ruush/errors.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Ruush
|
2
|
+
class Api
|
3
|
+
HIST_ENDPOINT = Ruush::endpoint "/api/hist"
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def get_hist(key, number=10, offset=0)
|
7
|
+
begin
|
8
|
+
response = RestClient.post HIST_ENDPOINT, :k => key, :l => number, :o => offset # no pooping necessary here
|
9
|
+
rescue RestClient::ServiceUnavailable
|
10
|
+
return []
|
11
|
+
end
|
12
|
+
Parser::parse_hist response.body
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/ruush/parser.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
module Ruush
|
2
|
+
class Parser
|
3
|
+
AuthObject = Struct.new(:premium_string, :key, :expiry, :usage_string) do # order is important here, expiry is always blank? (means never)
|
4
|
+
def is_premium
|
5
|
+
premium_string != "0"
|
6
|
+
end
|
7
|
+
|
8
|
+
def usage_bytes
|
9
|
+
usage_string.to_i
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# /api/del returns the same object structure as /api/hist, so we don't need a new struct
|
14
|
+
|
15
|
+
HistoryObject = Struct.new(:id, :time_string, :url, :filename, :view_count_string) do # order is important here
|
16
|
+
def timestamp
|
17
|
+
DateTime.parse time_string
|
18
|
+
end
|
19
|
+
|
20
|
+
def view_count
|
21
|
+
view_count_string.to_i
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
UploadObject = Struct.new(:url, :id, :usage_string) do # order is important here
|
26
|
+
def usage_bytes
|
27
|
+
usage_string.to_i
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class << self
|
32
|
+
def parse_hist(body)
|
33
|
+
hist_objects = []
|
34
|
+
if body == "-1" # only (known) error code
|
35
|
+
raise BadKey, "API key is invalid"
|
36
|
+
else
|
37
|
+
body.split("0\n")[1..-1].each do |hist_data| # we have to split on "0\n", and the first element is always blank
|
38
|
+
hist_objects.push HistoryObject.new *hist_data.split(",") # magic
|
39
|
+
end
|
40
|
+
end
|
41
|
+
hist_objects
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_auth(body)
|
45
|
+
if body == "-1" # only (known) error code
|
46
|
+
raise BadAuth, "Credentials are invalid"
|
47
|
+
end
|
48
|
+
AuthObject.new *body.split(",")
|
49
|
+
end
|
50
|
+
|
51
|
+
def parse_upload(body)
|
52
|
+
error_codes = {
|
53
|
+
"-1" => [BadKey, "API key is invalid"],
|
54
|
+
"-2" => [BadData, "Data sent is invalid"],
|
55
|
+
"-3" => [BadHash, "Data hash is invalid"]
|
56
|
+
# "-?" => [Errors::QuotaExceded, "Quota exceded"] (needs more research)
|
57
|
+
}
|
58
|
+
upload_data = body.split ","
|
59
|
+
if error_codes.has_key? upload_data[0] # account for multiple error codes
|
60
|
+
raise error_codes[upload_data[0]][0], error_codes[upload_data[0]][1]
|
61
|
+
end
|
62
|
+
UploadObject.new *upload_data[1..-1] # first element is always "0"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/ruush/upload.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "digest"
|
2
|
+
|
3
|
+
module Ruush
|
4
|
+
class Api
|
5
|
+
UP_ENDPOINT = Ruush::endpoint "/api/up"
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def upload_file(key, file) # will fail silently if upload is too big.
|
9
|
+
raise ArgumentError, "#{file.inspect} is not a File object" if !file.is_a? File
|
10
|
+
hash = Digest::MD5.file(file).hexdigest # straight hash of the file
|
11
|
+
begin
|
12
|
+
response = RestClient.post UP_ENDPOINT, :k => key, :c => hash, :z => "poop", :f => file # pooping is necessary
|
13
|
+
rescue => e
|
14
|
+
upload_failure = Upload::UploadObject.new
|
15
|
+
upload_failure.err = e
|
16
|
+
return upload_failure
|
17
|
+
end
|
18
|
+
Parser::parse_upload response.body
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/ruush.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruush/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruush"
|
8
|
+
spec.version = Ruush::VERSION
|
9
|
+
spec.authors = ["Mark Old"]
|
10
|
+
spec.email = ["dlom234@gmail.com"]
|
11
|
+
spec.description = %q{puush client in ruby}
|
12
|
+
spec.summary = %q{Command-line access to puush via ruby}
|
13
|
+
spec.homepage = "https://github.com/Dlom/ruush"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.required_ruby_version = ">= 2.0.0"
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
# todo lock versions
|
24
|
+
spec.add_dependency "rest-client"
|
25
|
+
spec.add_dependency "slop"
|
26
|
+
spec.add_dependency "settingslogic"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
spec.add_development_dependency "rspec"
|
31
|
+
spec.add_development_dependency "webmock"
|
32
|
+
end
|
data/spec/auth_spec.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Authentication" do
|
4
|
+
let(:email) { "example@example.com" }
|
5
|
+
let(:password) { "verysecurepassword123" }
|
6
|
+
let(:key) { "A1B2C3" }
|
7
|
+
|
8
|
+
describe "endpoint" do
|
9
|
+
it "should be /api/auth" do
|
10
|
+
Ruush::Api::AUTH_ENDPOINT.should eq "http://puush.me/api/auth"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "password auth" do
|
15
|
+
it "should retrieve the correct information" do
|
16
|
+
stub = mock_password_auth(email, password, key, true, 10000)
|
17
|
+
|
18
|
+
result = Ruush::Api::auth_password email, password
|
19
|
+
|
20
|
+
result.key.should eq key
|
21
|
+
result.expiry.should eq ""
|
22
|
+
result.is_premium.should eq true
|
23
|
+
result.usage_bytes.should eq 10000
|
24
|
+
stub.should have_been_requested
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "key auth" do
|
29
|
+
it "should retrieve the correct information" do
|
30
|
+
stub = mock_key_auth(key, false, 100)
|
31
|
+
|
32
|
+
result = Ruush::Api::auth_key key
|
33
|
+
|
34
|
+
result.key.should eq key
|
35
|
+
result.expiry.should eq ""
|
36
|
+
result.is_premium.should eq false
|
37
|
+
result.usage_bytes.should eq 100
|
38
|
+
stub.should have_been_requested
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "getting specifics" do
|
43
|
+
it "should get the key" do
|
44
|
+
stub = mock_password_auth(email, password, key, false, 100)
|
45
|
+
|
46
|
+
result = Ruush::Api::get_key email, password
|
47
|
+
|
48
|
+
result.should eq key
|
49
|
+
stub.should have_been_requested
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should get premium status" do
|
53
|
+
stub = mock_key_auth(key, true, 100)
|
54
|
+
|
55
|
+
result = Ruush::Api::get_premium key
|
56
|
+
|
57
|
+
result.should eq true
|
58
|
+
stub.should have_been_requested
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should get the usage in bytes" do
|
62
|
+
stub = mock_key_auth(key, false, 12345678)
|
63
|
+
|
64
|
+
result = Ruush::Api::get_usage key
|
65
|
+
|
66
|
+
result.should eq 12345678
|
67
|
+
stub.should have_been_requested
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/delete_spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Delete" do
|
4
|
+
let(:key) { "A1B2C3" }
|
5
|
+
describe "endpoint" do
|
6
|
+
it "should be /api/del" do
|
7
|
+
Ruush::Api::DEL_ENDPOINT.should eq "http://puush.me/api/del"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should get the 10 most recent history items" do
|
12
|
+
stub = mock_delete(key, "3")
|
13
|
+
|
14
|
+
result = Ruush::Api::delete key, "3"
|
15
|
+
|
16
|
+
result.length.should eq 10
|
17
|
+
10.times do |i|
|
18
|
+
result[i].id.should eq "#{i}"
|
19
|
+
result[i].time_string.should eq "1970-#{i}-1 12:34:56"
|
20
|
+
result[i].url.should eq "http://puu.sh/#{i}.png"
|
21
|
+
result[i].filename.should eq "#{i}.gif"
|
22
|
+
result[i].view_count.should eq i
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Endpoint" do
|
4
|
+
it "should have the correct base url" do
|
5
|
+
Ruush::BASE_URL.should eq "http://puush.me"
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should concatenate the base url with the endpoint" do
|
9
|
+
Ruush::endpoint("/api/auth").should eq "#{Ruush::BASE_URL}/api/auth"
|
10
|
+
Ruush::endpoint("/api/del").should eq "#{Ruush::BASE_URL}/api/del"
|
11
|
+
Ruush::endpoint("/api/hist").should eq "#{Ruush::BASE_URL}/api/hist"
|
12
|
+
Ruush::endpoint("/api/up").should eq "#{Ruush::BASE_URL}/api/up"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "History" do
|
4
|
+
let(:key) { "A1B2C3" }
|
5
|
+
describe "endpoint" do
|
6
|
+
it "should be /api/hist" do
|
7
|
+
Ruush::Api::HIST_ENDPOINT.should eq "http://puush.me/api/hist"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should get the 10 most recent history items" do
|
12
|
+
stub = mock_history(key)
|
13
|
+
|
14
|
+
result = Ruush::Api::get_hist key
|
15
|
+
|
16
|
+
result.length.should eq 10
|
17
|
+
10.times do |i|
|
18
|
+
result[i].id.should eq "#{i}"
|
19
|
+
result[i].time_string.should eq "1970-#{i}-1 12:34:56"
|
20
|
+
result[i].url.should eq "http://puu.sh/#{i}.png"
|
21
|
+
result[i].filename.should eq "#{i}.gif"
|
22
|
+
result[i].view_count.should eq i
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "webmock/rspec"
|
3
|
+
require "ruush"
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.color_enabled = true
|
7
|
+
config.tty = true
|
8
|
+
end
|
9
|
+
|
10
|
+
def mock_password_auth(email, password, key, is_premium, usage_bytes)
|
11
|
+
body = "#{is_premium ? 1 : 0},#{key},,#{usage_bytes}"
|
12
|
+
stub_request(:post, Ruush::endpoint("/api/auth")).with(:body => {:e => email, :p => password, :z => "poop"}).to_return :body => body
|
13
|
+
end
|
14
|
+
|
15
|
+
def mock_key_auth(key, is_premium, usage_bytes)
|
16
|
+
body = "#{is_premium ? 1 : 0},#{key},,#{usage_bytes}"
|
17
|
+
stub_request(:post, Ruush::endpoint("/api/auth")).with(:body => {:k => key, :z => "poop"}).to_return :body => body
|
18
|
+
end
|
19
|
+
|
20
|
+
def mock_history(key)
|
21
|
+
things = []
|
22
|
+
10.times do |i|
|
23
|
+
things.push "#{i},1970-#{i}-1 12:34:56,http://puu.sh/#{i}.png,#{i}.gif,#{i}"
|
24
|
+
end
|
25
|
+
body = "0\n#{things.join(",0\n")},0\n"
|
26
|
+
stub_request(:post, Ruush::endpoint("/api/hist")).with(:body => {:k => key, :l => 10.to_s, :o => 0.to_s}).to_return :body => body
|
27
|
+
end
|
28
|
+
|
29
|
+
def mock_delete(key, id)
|
30
|
+
things = []
|
31
|
+
10.times do |i|
|
32
|
+
things.push "#{i},1970-#{i}-1 12:34:56,http://puu.sh/#{i}.png,#{i}.gif,#{i}"
|
33
|
+
end
|
34
|
+
body = "0\n#{things.join(",0\n")},0\n"
|
35
|
+
stub_request(:post, Ruush::endpoint("/api/del")).with(:body => {:k => key, :i => id, :z => "poop"}).to_return :body => body
|
36
|
+
end
|
data/spec/upload_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Upload" do
|
4
|
+
let(:key) { "A1B2C3" }
|
5
|
+
describe "endpoint" do
|
6
|
+
it "should be /api/up" do
|
7
|
+
Ruush::Api::UP_ENDPOINT.should eq "http://puush.me/api/up"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should upload a file" do
|
12
|
+
# TODO webmock can't handle uploads
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruush
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.93.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Old
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: slop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: settingslogic
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: puush client in ruby
|
112
|
+
email:
|
113
|
+
- dlom234@gmail.com
|
114
|
+
executables:
|
115
|
+
- ruush
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- .travis.yml
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/ruush
|
126
|
+
- lib/ruush.rb
|
127
|
+
- lib/ruush/auth.rb
|
128
|
+
- lib/ruush/cli.rb
|
129
|
+
- lib/ruush/config.rb
|
130
|
+
- lib/ruush/delete.rb
|
131
|
+
- lib/ruush/endpoint.rb
|
132
|
+
- lib/ruush/errors.rb
|
133
|
+
- lib/ruush/history.rb
|
134
|
+
- lib/ruush/parser.rb
|
135
|
+
- lib/ruush/upload.rb
|
136
|
+
- lib/ruush/version.rb
|
137
|
+
- ruush.gemspec
|
138
|
+
- spec/auth_spec.rb
|
139
|
+
- spec/delete_spec.rb
|
140
|
+
- spec/endpoint_spec.rb
|
141
|
+
- spec/history_spec.rb
|
142
|
+
- spec/spec_helper.rb
|
143
|
+
- spec/upload_spec.rb
|
144
|
+
homepage: https://github.com/Dlom/ruush
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
metadata: {}
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: 2.0.0
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - '>='
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
requirements: []
|
163
|
+
rubyforge_project:
|
164
|
+
rubygems_version: 2.0.3
|
165
|
+
signing_key:
|
166
|
+
specification_version: 4
|
167
|
+
summary: Command-line access to puush via ruby
|
168
|
+
test_files:
|
169
|
+
- spec/auth_spec.rb
|
170
|
+
- spec/delete_spec.rb
|
171
|
+
- spec/endpoint_spec.rb
|
172
|
+
- spec/history_spec.rb
|
173
|
+
- spec/spec_helper.rb
|
174
|
+
- spec/upload_spec.rb
|