owo 1.1.1 → 1.2.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 +4 -4
- data/lib/owo.rb +14 -17
- data/lib/owo/api.rb +7 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7ea7249271b04538e746273c02f31900772f4db
|
4
|
+
data.tar.gz: 13d193c9b9da46c37039da7b19cf83bb5dbf1696
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ed821d013f84b4b9dbfa96fbf69177087d024521d5dc6263ccee4b6e2c3b61df0183aad88d0c5d24421deaae31a43fdc21be88b89a79289aaeb1c249d714f59
|
7
|
+
data.tar.gz: c9201ecd0b74a21b14717a8cc3386ebdbc7bb278033a4d3c7a1675ceba6c2ece70309f8044e8b0bfc6d83c3db4b50a18af36afde3102f227c6c5a3be9a7494a3
|
data/lib/owo.rb
CHANGED
@@ -15,25 +15,24 @@ module OwO
|
|
15
15
|
# The domain to use when returning shortener URLs
|
16
16
|
attr_accessor :shorten_url
|
17
17
|
|
18
|
-
def initialize(token, upload_url:
|
18
|
+
def initialize(token, upload_url: 'owo.whats-th.is', shorten_url: 'uwu.whats-th.is')
|
19
19
|
@token = token
|
20
20
|
@upload_url = upload_url
|
21
21
|
@shorten_url = shorten_url
|
22
22
|
end
|
23
23
|
|
24
|
-
def opts
|
25
|
-
{'t' => @token, 'u' => @upload_url, 's' => @shorten_url}
|
24
|
+
def opts
|
25
|
+
{ 't' => @token, 'u' => @upload_url, 's' => @shorten_url }
|
26
26
|
end
|
27
27
|
|
28
28
|
# Upload a single file or multiple files to OwO.
|
29
29
|
# @param files [File, String, Array<File, String>] Files to upload, can be either String or File
|
30
30
|
# @return [String, Array<String>] Returns the URLs of the uploaded files
|
31
31
|
def upload(files)
|
32
|
-
|
33
|
-
|
32
|
+
ogfiles = files
|
33
|
+
if not files.empty?
|
34
34
|
if files.is_a?(String)
|
35
|
-
files = [
|
36
|
-
was_string = true
|
35
|
+
files = [files]
|
37
36
|
end
|
38
37
|
files = files.map do |x|
|
39
38
|
if x.is_a?(String)
|
@@ -42,17 +41,15 @@ module OwO
|
|
42
41
|
x
|
43
42
|
end
|
44
43
|
end
|
45
|
-
result = OwO::API.upload(opts
|
44
|
+
result = OwO::API.upload(opts, files)
|
46
45
|
result.shift
|
47
|
-
result = result[
|
46
|
+
result = result['files'].map do |x|
|
48
47
|
"https://#{@upload_url}/#{x['url']}"
|
49
48
|
end
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
return result
|
49
|
+
result = result[0] unless ogfiles.is_a?(Array)
|
50
|
+
result
|
54
51
|
else
|
55
|
-
raise OwO::Err::NoContent,
|
52
|
+
raise OwO::Err::NoContent, 'Theres no files provided!'
|
56
53
|
end
|
57
54
|
end
|
58
55
|
|
@@ -62,12 +59,12 @@ module OwO
|
|
62
59
|
def shorten(urls)
|
63
60
|
if not urls.length == 0
|
64
61
|
if urls.is_a?(Array)
|
65
|
-
|
62
|
+
urls.map { |x| OwO::API.shorten(opts(), x) }
|
66
63
|
else
|
67
|
-
|
64
|
+
OwO::API.shorten(opts, urls)
|
68
65
|
end
|
69
66
|
else
|
70
|
-
raise OwO::Err::NoContent,
|
67
|
+
raise OwO::Err::NoContent, 'Theres no URL provided!'
|
71
68
|
end
|
72
69
|
end
|
73
70
|
end
|
data/lib/owo/api.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'owo/err'
|
2
|
+
require 'owo/ver'
|
2
3
|
require 'uri'
|
3
4
|
require 'rest-client'
|
4
5
|
|
@@ -11,23 +12,23 @@ module OwO
|
|
11
12
|
module_function
|
12
13
|
|
13
14
|
def request(type, *attributes)
|
14
|
-
raw = RestClient.send(type, *attributes, :'User-Agent' => "OwO.rb (https://github.com/whats-this/owo.rb)")
|
15
|
+
raw = RestClient.send(type, *attributes, :'User-Agent' => "OwO.rb v#{OwO::VERSION} (https://github.com/whats-this/owo.rb)")
|
15
16
|
json = parse_json(raw);
|
16
17
|
return json
|
17
18
|
rescue RestClient::RequestEntityTooLarge
|
18
|
-
raise OwO::Err::TooLarge,
|
19
|
+
raise OwO::Err::TooLarge, 'Requested files are too large!'
|
19
20
|
rescue RestClient::Unauthorized
|
20
|
-
raise OwO::Err::BadToken,
|
21
|
+
raise OwO::Err::BadToken, 'Token is invalid!'
|
21
22
|
rescue RestClient::BadRequest => e
|
22
23
|
raw = e.response
|
23
24
|
json = parse_json(raw)
|
24
25
|
if json.is_a?(Hash)
|
25
26
|
if json['description'] == 'too many files'
|
26
|
-
raise OwO::Err::TooManyFiles,
|
27
|
+
raise OwO::Err::TooManyFiles, 'You requested too many files!'
|
27
28
|
end
|
28
29
|
else
|
29
30
|
if raw == 'invalid URL'
|
30
|
-
raise OwO::Err::BadURL,
|
31
|
+
raise OwO::Err::BadURL, 'Your URL is invalid!'
|
31
32
|
end
|
32
33
|
end
|
33
34
|
err = if json.is_a?(Hash)
|
@@ -38,7 +39,7 @@ module OwO
|
|
38
39
|
|
39
40
|
raise err
|
40
41
|
rescue RestClient::InternalServerError
|
41
|
-
raise OwO::Err::ServerFail,
|
42
|
+
raise OwO::Err::ServerFail, 'Server Error!'
|
42
43
|
rescue RuntimeError => e
|
43
44
|
raise e
|
44
45
|
end
|