Class: Fogbugz::Interface

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_fogbugz/interface.rb

Defined Under Namespace

Classes: InitializationError, RequestError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Interface

Returns a new instance of Interface.



8
9
10
11
12
13
14
15
# File 'lib/ruby_fogbugz/interface.rb', line 8

def initialize(options = {})
  @options = {}.merge(options)

  raise InitializationError, 'Must supply URI (e.g. https://fogbugz.company.com)' unless options[:uri]
  @token = options[:token] if options[:token]
  @http = Fogbugz.adapter[:http].new(uri: options[:uri], ca_file: options[:ca_file])
  @xml = Fogbugz.adapter[:xml]
end

Instance Attribute Details

#httpObject

Returns the value of attribute http.



6
7
8
# File 'lib/ruby_fogbugz/interface.rb', line 6

def http
  @http
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/ruby_fogbugz/interface.rb', line 6

def options
  @options
end

#tokenObject

Returns the value of attribute token.



6
7
8
# File 'lib/ruby_fogbugz/interface.rb', line 6

def token
  @token
end

#xmlObject

Returns the value of attribute xml.



6
7
8
# File 'lib/ruby_fogbugz/interface.rb', line 6

def xml
  @xml
end

Instance Method Details

#authenticateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruby_fogbugz/interface.rb', line 17

def authenticate
  response = @http.request :logon,
                           params: {
                             email: @options[:email],
                             password: @options[:password]
                           }
  begin
    @token ||= @xml.parse(response)['token']
    if @token.nil? || @token == ''
      raise Fogbugz::AuthenticationException, @xml.parse(response)['error']
    end
  rescue REXML::ParseException
    raise Fogbugz::AuthenticationException, "Looks like there was an issue with authentication (to #{@options[:uri]} as #{@options[:email]}) - probably the host/url."
  end
  @token
end

#command(action, parameters = {}) ⇒ Object

Raises:



34
35
36
37
38
39
40
41
# File 'lib/ruby_fogbugz/interface.rb', line 34

def command(action, parameters = {})
  raise RequestError, 'No token available, #authenticate first' unless @token
  parameters[:token] = @token

  response = @http.request action, params: parameters.merge(options[:params] || {})

  @xml.parse(response)
end