Class: Desviar::Client
- Inherits:
-
Object
- Object
- Desviar::Client
- Defined in:
- lib/desviar/client.rb
Instance Method Summary collapse
-
#clean ⇒ Object
Clean out expired entries.
-
#config ⇒ Object
Fetch configuration (as a hash).
-
#config_item(item) ⇒ Object
Fetch a single configuration item.
-
#create(uri, expiration = 900, opts = {}) ⇒ Object
Create a new redirect.
-
#fetch(temp_uri) ⇒ Object
Fetch content.
-
#initialize(user_name, private_key, server_uri = 'http://localhost:4567') ⇒ Client
constructor
Create new client.
-
#list ⇒ Object
Fetch list of stored redirects.
-
#list_item(id) ⇒ Object
Fetch meta information about a particular redirect.
-
#server_uri ⇒ Object
Return server’s URI.
-
#user_name ⇒ Object
Return username.
Constructor Details
#initialize(user_name, private_key, server_uri = 'http://localhost:4567') ⇒ Client
Create new client
22 23 24 25 26 |
# File 'lib/desviar/client.rb', line 22 def initialize(user_name, private_key, server_uri = 'http://localhost:4567') @server_uri = server_uri @user_name = user_name @private_key = private_key end |
Instance Method Details
#clean ⇒ Object
Clean out expired entries
61 62 63 |
# File 'lib/desviar/client.rb', line 61 def clean get("clean") end |
#config ⇒ Object
Fetch configuration (as a hash)
39 40 41 |
# File 'lib/desviar/client.rb', line 39 def config JSON.parse get("config/json") end |
#config_item(item) ⇒ Object
Fetch a single configuration item
44 45 46 47 48 |
# File 'lib/desviar/client.rb', line 44 def config_item(item) cfg = JSON.parse get("config/json") raise ArgumentError, "Invalid item #{item}" if !cfg.has_key?(item.to_s) cfg[item.to_s] end |
#create(uri, expiration = 900, opts = {}) ⇒ Object
Create a new redirect
66 67 68 69 70 |
# File 'lib/desviar/client.rb', line 66 def create(uri, expiration = 900, opts = {}) opts[:captcha_button] = "Proceed" if !opts.has_key?(:captcha_button) && !opts.has_key?("captcha_button") newlink = post("create", { :redir_uri => uri, :expiration => expiration.to_s }.merge(opts)) JSON.parse get("link/json/#{newlink.split('/').last}") end |
#fetch(temp_uri) ⇒ Object
Fetch content
73 74 75 |
# File 'lib/desviar/client.rb', line 73 def fetch(temp_uri) get("desviar/#{temp_uri}", false) end |
#list ⇒ Object
Fetch list of stored redirects
51 52 53 |
# File 'lib/desviar/client.rb', line 51 def list JSON.parse get("list/json") end |
#list_item(id) ⇒ Object
Fetch meta information about a particular redirect
56 57 58 |
# File 'lib/desviar/client.rb', line 56 def list_item(id) JSON.parse get("link/json/#{id}") end |
#server_uri ⇒ Object
Return server’s URI
29 30 31 |
# File 'lib/desviar/client.rb', line 29 def server_uri() @server_uri end |
#user_name ⇒ Object
Return username
34 35 36 |
# File 'lib/desviar/client.rb', line 34 def user_name() @user_name end |