Class: Gitlab::FogbugzImport::Interface
- Inherits:
-
Object
- Object
- Gitlab::FogbugzImport::Interface
- Defined in:
- lib/gitlab/fogbugz_import/interface.rb
Constant Summary collapse
- RequestError =
Class.new(StandardError)
- InitializationError =
Class.new(StandardError)
- AuthenticationError =
Class.new(StandardError)
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.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gitlab/fogbugz_import/interface.rb', line 12 def initialize( = {}) @options = {}.merge() raise InitializationError, 'Must supply URI (e.g. https://fogbugz.company.com)' unless [:uri] @token = [:token] if [:token] # Custom adapter to validate the URL before each request # This way we avoid DNS rebinds or other unsafe requests @http = HttpAdapter.new(uri: [:uri], ca_file: [:ca_file]) # Custom adapter to validate size of incoming XML before # attempting to parse it. @xml = XmlAdapter end |
Instance Attribute Details
#http ⇒ Object
Returns the value of attribute http.
10 11 12 |
# File 'lib/gitlab/fogbugz_import/interface.rb', line 10 def http @http end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/gitlab/fogbugz_import/interface.rb', line 10 def @options end |
#token ⇒ Object
Returns the value of attribute token.
10 11 12 |
# File 'lib/gitlab/fogbugz_import/interface.rb', line 10 def token @token end |
#xml ⇒ Object
Returns the value of attribute xml.
10 11 12 |
# File 'lib/gitlab/fogbugz_import/interface.rb', line 10 def xml @xml end |
Instance Method Details
#authenticate ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gitlab/fogbugz_import/interface.rb', line 25 def authenticate response = @http.request( :logon, params: { email: @options[:email], password: @options[:password] }) parsed_response = @xml.parse(response) @token ||= parsed_response['token'] raise AuthenticationError, parsed_response['error'] if @token.blank? @token end |
#command(action, parameters = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/gitlab/fogbugz_import/interface.rb', line 40 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 |