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])
  @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
33
34
35
# 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.new(@xml.parse(response)["error"])
    end
  rescue REXML::ParseException => e
    # Probably an issue with the auth information
    # p response
    raise Fogbugz::AuthenticationException.new("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:



37
38
39
40
41
42
43
44
45
46
# File 'lib/ruby_fogbugz/interface.rb', line 37

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