Class: Fogbugz::Interface
- Inherits:
-
Object
- Object
- Fogbugz::Interface
- Defined in:
- lib/ruby_fogbugz/interface.rb
Defined Under Namespace
Classes: InitializationError, RequestError
Instance Attribute Summary collapse
-
#http ⇒ Object
Returns the value of attribute http.
-
#options ⇒ Object
Returns the value of attribute options.
-
#token ⇒ Object
Returns the value of attribute token.
-
#xml ⇒ Object
Returns the value of attribute xml.
Instance Method Summary collapse
- #authenticate ⇒ Object
- #command(action, parameters = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Interface
constructor
A new instance of Interface.
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 = {}.merge() raise InitializationError, 'Must supply URI (e.g. https://fogbugz.company.com)' unless [:uri] @token = [:token] if [:token] @http = Fogbugz.adapter[:http].new(uri: [:uri], ca_file: [:ca_file]) @xml = Fogbugz.adapter[:xml] end |
Instance Attribute Details
#http ⇒ Object
Returns the value of attribute http.
6 7 8 |
# File 'lib/ruby_fogbugz/interface.rb', line 6 def http @http end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/ruby_fogbugz/interface.rb', line 6 def @options end |
#token ⇒ Object
Returns the value of attribute token.
6 7 8 |
# File 'lib/ruby_fogbugz/interface.rb', line 6 def token @token end |
#xml ⇒ Object
Returns the value of attribute xml.
6 7 8 |
# File 'lib/ruby_fogbugz/interface.rb', line 6 def xml @xml end |
Instance Method Details
#authenticate ⇒ Object
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
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([:params] || {}) @xml.parse(response) end |