Class: Nerdz
- Inherits:
-
Object
- Object
- Nerdz
- Defined in:
- lib/nerdz/structs.rb,
lib/nerdz.rb,
lib/nerdz/http.rb,
lib/nerdz/errors.rb,
lib/nerdz/version.rb
Overview
– Copyleft shura. [ [email protected] ]
This file is part of nerdz.
nerdz is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
nerdz is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with nerdz. If not, see <www.gnu.org/licenses/>. ++
Defined Under Namespace
Constant Summary collapse
- NotLoggedIn =
exception
- UserNotFound =
exception
- GETQueryNotFound =
exception
- POSTQueryNotFound =
exception
- UndefinedError =
exception
- LoginError =
exception
- InsertError =
exception
exception
- InvalidUrl =
exception
- InvalidAction =
exception
- NotOnline =
exception
- ERRORS =
Class.new { def initialize @errors = [nil, NotLoggedIn, UserNotFound, GETQueryNotFound, POSTQueryNotFound, UndefinedError, LoginError, InsertError, ShareError, InvalidUrl, InvalidAction, NotOnline].freeze end def [](x) x = x.to_s.to_i unless x.is_a?(Integer) @errors[x.to_i] end }.new
- VERSION =
'0.0.1'
Instance Method Summary collapse
-
#initialize ⇒ Nerdz
constructor
A new instance of Nerdz.
- #login(username, password) ⇒ Object
- #logout ⇒ Object
- #nerdz(message, to = nil) ⇒ Object
- #nerdzs(what, args = {}) ⇒ Object
- #request(*args) ⇒ Object
- #share(url, message = "", to = nil) ⇒ Object
- #user(id_or_name) ⇒ Object
Constructor Details
Instance Method Details
#login(username, password) ⇒ Object
38 39 40 41 |
# File 'lib/nerdz.rb', line 38 def login(username, password) request(:login, {username: username, password: password}) true end |
#logout ⇒ Object
43 44 45 46 |
# File 'lib/nerdz.rb', line 43 def logout request(:logout) true end |
#nerdz(message, to = nil) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/nerdz.rb', line 57 def nerdz(, to = nil) opts = {message: } opts[:to] = self.user(to).id if to request(:nerdz_it, opts) true end |
#nerdzs(what, args = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/nerdz.rb', line 71 def nerdzs(what, args = {}) opts = {what: what} opts[:limit] = args[:from] ? "#{args[:from]},#{args[:max]}" : args[:max].to_s if args[:max] opts[:id] = self.user(args[:user]).id if args[:user] opts[:pid] = args[:pid] if args[:pid] res = request(:nerdzs, opts) if res.values.first.is_a?(Hash) res.values.map {|nerdz| Post.new(nerdz) } else Post.new(res) end end |
#request(*args) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/nerdz.rb', line 30 def request(*args) res = JSON.parse(@http.request(*args).body) error = res['error'] error = ERRORS[error ? error.to_i : error] raise error if error res end |
#share(url, message = "", to = nil) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/nerdz.rb', line 64 def share(url, = "", to = nil) opts = {url: url, message: } opts[:to] = self.user(to).id if to request(:share_it, opts) true end |