Class: ZammadAPI::Transport

Inherits:
Object
  • Object
show all
Defined in:
lib/zammad_api/transport.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, logger) ⇒ Transport

Returns a new instance of Transport.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/zammad_api/transport.rb', line 9

def initialize(config, logger)
  @logger = logger
  @logger.debug "Transport to #{config[:url]} with #{config[:user]}:#{config[:password]}"
  @conn = Faraday.new(url: config[:url]) do |faraday|
    #faraday.request  :url_encoded             # form-encode POST params
    #faraday.response :logger                  # log requests to STDOUT
    faraday.adapter Faraday.default_adapter  # make requests with Net::HTTP
  end
  @conn.headers[:user_agent] = 'Zammad API Ruby'
  if config[:http_token] && !config[:http_token].empty?
    @conn.request :authorization, 'Token', config[:http_token]
  elsif config[:oauth2_token] && !config[:oauth2_token].empty?
    @conn.request :authorization, 'Bearer', config[:oauth2_token]
  else
    @conn.request :authorization, :basic, config[:user], config[:password]
  end
end

Instance Attribute Details

#on_behalf_ofObject

Returns the value of attribute on_behalf_of.



7
8
9
# File 'lib/zammad_api/transport.rb', line 7

def on_behalf_of
  @on_behalf_of
end

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/zammad_api/transport.rb', line 7

def password
  @password
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/zammad_api/transport.rb', line 7

def url
  @url
end

#userObject

Returns the value of attribute user.



7
8
9
# File 'lib/zammad_api/transport.rb', line 7

def user
  @user
end