Class: Unresponsys::Client

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

Defined Under Namespace

Classes: Folders, Lists

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/unresponsys/client.rb', line 5

def initialize(options = {})
  raise Unresponsys::ArgumentError unless options[:username] && options[:password]
  raise Unresponsys::ArgumentError unless [nil, 2, 5].include?(options[:interact])
  @username = options[:username]
  @password = options[:password]
  @interact = options.fetch(:interact, 2)
  @debug    = options[:debug]
  @logger   = Logger.new(STDOUT) if @debug
  @log_opts = { logger: @logger, log_level: :debug, log_format: :curl }
  authenticate
end

Instance Method Details

#delete(path, options = {}, &block) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/unresponsys/client.rb', line 33

def delete(path, options = {}, &block)
  path      = "#{@base_uri}#{path}"
  options   = @options.merge(options)
  options   = options.merge(@log_opts) if @debug
  response  = HTTParty.delete(path, options, &block)
  handle_error(response)
end

#foldersObject



41
42
43
# File 'lib/unresponsys/client.rb', line 41

def folders
  @folders ||= Folders.new(self)
end

#get(path, options = {}, &block) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/unresponsys/client.rb', line 17

def get(path, options = {}, &block)
  path      = "#{@base_uri}#{path}"
  options   = @options.merge(options)
  options   = options.merge(@log_opts) if @debug
  response  = HTTParty.get(path, options, &block)
  handle_error(response)
end

#listsObject



45
46
47
# File 'lib/unresponsys/client.rb', line 45

def lists
  @lists ||= Lists.new(self)
end

#post(path, options = {}, &block) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/unresponsys/client.rb', line 25

def post(path, options = {}, &block)
  path      = "#{@base_uri}#{path}"
  options   = @options.merge(options)
  options   = options.merge(@log_opts) if @debug
  response  = HTTParty.post(path, options, &block)
  handle_error(response)
end