Class: Ruush::Api
- Inherits:
-
Object
- Object
- Ruush::Api
- Defined in:
- lib/ruush/auth.rb,
lib/ruush/delete.rb,
lib/ruush/upload.rb,
lib/ruush/history.rb
Constant Summary collapse
- AUTH_ENDPOINT =
Ruush::endpoint "/api/auth"
- DEL_ENDPOINT =
Ruush::endpoint "/api/del"
- UP_ENDPOINT =
Ruush::endpoint "/api/up"
- HIST_ENDPOINT =
Ruush::endpoint "/api/hist"
Class Method Summary collapse
- .auth_key(key) ⇒ Object
- .auth_password(email, password) ⇒ Object
- .delete(key, id) ⇒ Object
- .get_hist(key, number = 10, offset = 0) ⇒ Object
- .get_key(email, password) ⇒ Object
- .get_premium(key) ⇒ Object
- .get_usage(key) ⇒ Object
-
.upload_file(key, file) ⇒ Object
will fail silently if upload is too big.
Class Method Details
.auth_key(key) ⇒ Object
11 12 13 14 |
# File 'lib/ruush/auth.rb', line 11 def auth_key(key) response = RestClient.post AUTH_ENDPOINT, :k => key, :z => "poop" # pooping is necessary, email is not? Parser::parse_auth response.body end |
.auth_password(email, password) ⇒ Object
6 7 8 9 |
# File 'lib/ruush/auth.rb', line 6 def auth_password(email, password) response = RestClient.post AUTH_ENDPOINT, :e => email, :p => password, :z => "poop" # pooping is necessary Parser::parse_auth response.body end |
.delete(key, id) ⇒ Object
6 7 8 9 |
# File 'lib/ruush/delete.rb', line 6 def delete(key, id) response = RestClient.post DEL_ENDPOINT, :k => key, :i => id, :z => "poop" # pooping is necessary Parser::parse_hist response.body # same format as hist end |
.get_hist(key, number = 10, offset = 0) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/ruush/history.rb', line 6 def get_hist(key, number=10, offset=0) begin response = RestClient.post HIST_ENDPOINT, :k => key, :l => number, :o => offset # no pooping necessary here rescue RestClient::ServiceUnavailable return [] end Parser::parse_hist response.body end |
.get_key(email, password) ⇒ Object
16 17 18 19 |
# File 'lib/ruush/auth.rb', line 16 def get_key(email, password) auth_data = auth_password email, password auth_data.key end |
.get_premium(key) ⇒ Object
21 22 23 24 |
# File 'lib/ruush/auth.rb', line 21 def get_premium(key) auth_data = auth_key key auth_data.is_premium end |
.get_usage(key) ⇒ Object
26 27 28 29 |
# File 'lib/ruush/auth.rb', line 26 def get_usage(key) auth_data = auth_key key auth_data.usage_bytes end |
.upload_file(key, file) ⇒ Object
will fail silently if upload is too big.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ruush/upload.rb', line 8 def upload_file(key, file) # will fail silently if upload is too big. raise ArgumentError, "#{file.inspect} is not a File object" if !file.is_a? File hash = Digest::MD5.file(file).hexdigest # straight hash of the file begin response = RestClient.post UP_ENDPOINT, :k => key, :c => hash, :z => "poop", :f => file # pooping is necessary rescue => e upload_failure = Upload::UploadObject.new upload_failure.err = e return upload_failure end Parser::parse_upload response.body end |