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
# File 'lib/ruby_fogbugz/interface.rb', line 8

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

  raise InitializationError, "Must supply URI (e.g. http://fogbugz.company.com)" unless options[:uri]
  @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



16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby_fogbugz/interface.rb', line 16

def authenticate
  response = @http.request :logon, { 
    :params => {
      :email    => @options[:email],
      :password => @options[:password]
    }
  }

  @token ||= @xml.parse(response)["token"]
end

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

Raises:



27
28
29
30
31
32
33
34
35
36
# File 'lib/ruby_fogbugz/interface.rb', line 27

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