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
# File 'lib/unresponsys/client.rb', line 5

def initialize(options = {})
  raise Unresponsys::ArgumentError unless options[:username] && options[:password]
  @username = options[:username]
  @password = options[:password]
  @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



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

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



39
40
41
# File 'lib/unresponsys/client.rb', line 39

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

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



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

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



43
44
45
# File 'lib/unresponsys/client.rb', line 43

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

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



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

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