-
Notifications
You must be signed in to change notification settings - Fork 7
/
ConnectionDelegate.rb
55 lines (45 loc) · 1.28 KB
/
ConnectionDelegate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
#
# ConnectionDelegate.rb
# gisteditor
#
# Created by Greg Borenstein on 6/3/09.
# Copyright (c) 2009 __MyCompanyName__. All rights reserved.
#
# Originally from the peepcode via Unfollowbot
require "base64"
require "cgi"
class ConnectionDelegate
def initialize(parent, message, &block)
@parent = parent
@message = message
@block = block
@parent.startProgressIndicator(message)
end
def connectionDidFinishLoading(connection)
NSLog(@receivedData.inspect)
doc = NSXMLDocument.alloc.initWithData(@receivedData,
options:NSXMLDocumentValidate,
error:nil)
@parent.endProgressIndicator
if doc
@block.call(doc)
else
@block.call("Invalid response")
end
end
def connection(connection, didReceiveResponse:response)
case response.statusCode
when 401
@block.call("Invalid username and password")
when (400..500)
@block.call("Unable to complete your request")
end
end
def connection(connection, didReceiveData:data)
@receivedData ||= NSMutableData.new
@receivedData.appendData(data)
end
def connection(conn, didFailWithError:error)
@parent.status_label.stringValue = "Error communicating with GitHub"
end
end