Class: Roust
- Inherits:
-
Object
- Object
- Roust
- Defined in:
- lib/roust.rb,
lib/roust/user.rb,
lib/roust/queue.rb,
lib/roust/ticket.rb,
lib/roust/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
'1.8.5'
Instance Method Summary collapse
- #authenticate! ⇒ Object
- #authenticated? ⇒ Boolean
-
#initialize(credentials) ⇒ Roust
constructor
A new instance of Roust.
Methods included from User
#user_create, #user_show, #user_update
Methods included from Queue
Methods included from Ticket
#ticket_comment, #ticket_create, #ticket_history, #ticket_links_add, #ticket_links_remove, #ticket_links_show, #ticket_search, #ticket_show, #ticket_update
Constructor Details
#initialize(credentials) ⇒ Roust
Returns a new instance of Roust.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/roust.rb', line 15 def initialize(credentials) @server = credentials[:server] @username = credentials[:username] @password = credentials[:password] if @server =~ /REST\/1\.0/ raise ArgumentError, 'The supplied :server has REST in the URL. You only need to specify the base, e.g. http://rt.example.org/' end authenticate! end |
Instance Method Details
#authenticate! ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/roust.rb', line 27 def authenticate! # - There is no way to authenticate against the API. The only way to log # in is to fill out the same HTML form humans fill in, cache the cookies # returned, and send them on every subsequent request. # - RT does not provide *any* indication that the authentication request # has succeeded or failed. RT will always return a HTTP 200. self.class.base_uri(@server) response = self.class.post( '/index.html', :body => { :user => @username, :pass => @password } ) = response.headers['set-cookie'] self.class.headers['Cookie'] = if # Switch the base uri over to the actual REST API base uri. self.class.base_uri "#{@server}/REST/1.0" # - The easiest way to programatically check if an authentication request # succeeded is by doing a request for a ticket, and seeing if the API # responds with some specific text ("401 Credentials required") that # indicates authentication has previously failed. # - The authenticated? method will return false if an Unauthenticated # exception bubbles up from response handling. We (dirtily) rethrow the # exception. raise Unauthenticated unless authenticated? end |
#authenticated? ⇒ Boolean
60 61 62 63 64 |
# File 'lib/roust.rb', line 60 def authenticated? return true if show('1') rescue Unauthenticated return false end |