Class: Desviar::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/desviar/client.rb

Instance Method Summary collapse

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

#cleanObject

Clean out expired entries



61
62
63
# File 'lib/desviar/client.rb', line 61

def clean
  get("clean")
end

#configObject

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

Raises:

  • (ArgumentError)


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

#listObject

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_uriObject

Return server’s URI



29
30
31
# File 'lib/desviar/client.rb', line 29

def server_uri()
  @server_uri
end

#user_nameObject

Return username



34
35
36
# File 'lib/desviar/client.rb', line 34

def user_name()
  @user_name
end