Class: OwO::WhatsThis
- Inherits:
-
Object
- Object
- OwO::WhatsThis
- Defined in:
- lib/owo.rb
Overview
The main module for interaction
Instance Attribute Summary collapse
-
#api_url ⇒ String
The url being used to use the OwO API.
-
#token ⇒ String
The token used for OwO.
-
#url ⇒ String
The domain to use when returning URLs.
Instance Method Summary collapse
-
#initialize(token, url: 'owo.whats-th.is', api_url: 'https://api.awau.moe') ⇒ WhatsThis
constructor
Create a class to upload files and shorten URLs with OWO.
-
#shorten(*urls) ⇒ String+
Shortens a link with OwO.
-
#upload(*files) ⇒ String+
Upload a single file or multiple files to OwO.
Constructor Details
#initialize(token, url: 'owo.whats-th.is', api_url: 'https://api.awau.moe') ⇒ WhatsThis
Create a class to upload files and shorten URLs with OWO.
22 23 24 25 26 27 28 29 |
# File 'lib/owo.rb', line 22 def initialize(token, url: 'owo.whats-th.is', api_url: 'https://api.awau.moe') @token = token @url = url @api_url = api_url raise OwO::Err::BadToken, 'Token is empty!' if token.empty? raise OwO::Err::BadToken, 'Input your OwO token to test the client.' if token == 'TOKEN' end |
Instance Attribute Details
#api_url ⇒ String
Returns the url being used to use the OwO API.
16 17 18 |
# File 'lib/owo.rb', line 16 def api_url @api_url end |
#token ⇒ String
Returns the token used for OwO.
10 11 12 |
# File 'lib/owo.rb', line 10 def token @token end |
#url ⇒ String
Returns the domain to use when returning URLs.
13 14 15 |
# File 'lib/owo.rb', line 13 def url @url end |
Instance Method Details
#shorten(*urls) ⇒ String+
Shortens a link with OwO.
63 64 65 66 67 68 69 |
# File 'lib/owo.rb', line 63 def shorten(*urls) urls = urls.flatten raise OwO::Err::NoContent, 'There is a empty string in your arguments!' if urls.include? '' raise OwO::Err::NoContent, 'Theres no URLs provided!' if urls.empty? result = urls.flatten.map { |x| OwO::API.shorten(opts, x) } result[0] if urls.length == 1 || !urls.first.is_a?(Array) end |
#upload(*files) ⇒ String+
Upload a single file or multiple files to OwO.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/owo.rb', line 34 def upload(*files) ogfiles = files files = files.flatten raise OwO::Err::NoContent, 'There is a empty string in your arguments!' if files.include? '' raise OwO::Err::NoContent, 'Theres no files provided!' if files.empty? files = files.map do |x| return x if x.respond_to? :read begin File.new(File.absolute_path(x), 'rb') rescue Errno::ENOENT, Errno::EACCES, Errno::ENAMETOOLONG => e errstring = 'Unknown' case e.class.name when 'Errno::ENOENT' errstring = 'File Not Found' when 'Errno::EACCES' errstring = 'Permission Denied' when 'Errno::ENAMETOOLONG' errstring = 'Name Too Long' end raise OwO::Err::FileError, "Error initializing file '${x}' | #{errstring} | #{e.class.name}" end end result = OwO::API.upload(opts, files)['files'].map { |x| "https://#{@url}/#{x['url']}" } result[0] if ogfiles.length == 1 || !ogfiles.first.is_a?(Array) end |