Toggle navigation
Toggle navigation
This project
Loading...
Sign in
iOS
/
asi-http-request
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Tom Andersen
2010-04-08 08:31:35 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
Ben Copsey
2010-04-12 11:57:09 +0100
Commit
34b1600b0a9941e06f5560a1e03d902b8ad4bb94
34b1600b
1 parent
def80797
Added 'folder' support and fix bugs with S3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
8 deletions
Classes/S3/ASIS3BucketRequest.h
Classes/S3/ASIS3BucketRequest.m
Classes/S3/ASIS3ObjectRequest.m
Classes/S3/ASIS3BucketRequest.h
View file @
34b1600
...
...
@@ -33,6 +33,9 @@
NSString
*
currentElement
;
ASIS3BucketObject
*
currentObject
;
NSMutableArray
*
objects
;
NSMutableArray
*
foundFolders
;
BOOL
isTruncated
;
}
// Fetch a bucket
...
...
@@ -57,6 +60,9 @@
// Returns an array of ASIS3BucketObjects created from the XML response
-
(
NSArray
*
)
bucketObjects
;
// prefixes are like folders - get them by setting a delimiter string (usually always @"/")
-
(
NSArray
*
)
commonPrefixes
;
//Builds a query string out of the list parameters we supplied
-
(
void
)
createQueryString
;
...
...
@@ -66,4 +72,5 @@
@property
(
retain
)
NSString
*
marker
;
@property
(
assign
)
int
maxResultCount
;
@property
(
retain
)
NSString
*
delimiter
;
@property
(
readonly
)
BOOL
isTruncated
;
@end
...
...
Classes/S3/ASIS3BucketRequest.m
View file @
34b1600
...
...
@@ -16,6 +16,8 @@
@property
(
retain
,
nonatomic
)
NSString
*
currentElement
;
@property
(
retain
,
nonatomic
)
ASIS3BucketObject
*
currentObject
;
@property
(
retain
,
nonatomic
)
NSMutableArray
*
objects
;
@property
(
retain
,
nonatomic
)
NSMutableArray
*
foundFolders
;
@property
(
readwrite
)
BOOL
isTruncated
;
@end
@implementation
ASIS3BucketRequest
...
...
@@ -57,6 +59,7 @@
[
currentElement
release
];
[
currentContent
release
];
[
objects
release
];
[
foundFolders
release
];
[
prefix
release
];
[
marker
release
];
[
delimiter
release
];
...
...
@@ -88,8 +91,12 @@
if
([
self
maxResultCount
]
>
0
)
{
[
queryParts
addObject
:[
NSString
stringWithFormat
:
@"delimiter=%hi"
,[
self
maxResultCount
]]];
}
if
([
queryParts
count
])
{
[
self
setURL
:[
NSURL
URLWithString
:[
NSString
stringWithFormat
:
@"%@?%@"
,[[
self
url
]
absoluteString
],[
queryParts
componentsJoinedByString
:
@"&"
]]]];
if
([
queryParts
count
])
{
NSString
*
template
=
@"%@?%@"
;
if
([
self
.
subResource
length
]
>
0
)
template
=
@"%@&%@"
;
[
self
setURL
:[
NSURL
URLWithString
:[
NSString
stringWithFormat
:
template
,[[
self
url
]
absoluteString
],[
queryParts
componentsJoinedByString
:
@"&"
]]]];
}
}
...
...
@@ -99,21 +106,36 @@
[
super
main
];
}
-
(
NSArray
*
)
bucketObjects
-
(
void
)
makeBucketsAndPrefixes
;
{
if
([
self
objects
])
{
return
[
self
objects
];
}
[
self
setObjects
:[[[
NSMutableArray
alloc
]
init
]
autorelease
]];
[
self
setFoundFolders
:[[[
NSMutableArray
alloc
]
init
]
autorelease
]];
NSXMLParser
*
parser
=
[[[
NSXMLParser
alloc
]
initWithData
:[
self
responseData
]]
autorelease
];
[
parser
setDelegate
:
self
];
[
parser
setShouldProcessNamespaces
:
NO
];
[
parser
setShouldReportNamespacePrefixes
:
NO
];
[
parser
setShouldResolveExternalEntities
:
NO
];
[
parser
parse
];
}
-
(
NSArray
*
)
bucketObjects
{
if
([
self
objects
])
{
return
[
self
objects
];
}
[
self
makeBucketsAndPrefixes
];
return
[
self
objects
];
}
-
(
NSArray
*
)
commonPrefixes
;
{
if
([
self
foundFolders
])
{
return
[
self
foundFolders
];
}
[
self
makeBucketsAndPrefixes
];
return
[
self
foundFolders
];
}
-
(
void
)
parser
:
(
NSXMLParser
*
)
parser
didStartElement
:
(
NSString
*
)
elementName
namespaceURI
:
(
NSString
*
)
namespaceURI
qualifiedName
:
(
NSString
*
)
qName
attributes
:
(
NSDictionary
*
)
attributeDict
{
[
self
setCurrentElement
:
elementName
];
...
...
@@ -141,9 +163,12 @@
[[
self
currentObject
]
setOwnerID
:[
self
currentContent
]];
}
else
if
([
elementName
isEqualToString
:
@"DisplayName"
])
{
[[
self
currentObject
]
setOwnerName
:[
self
currentContent
]];
}
else
if
([
elementName
isEqualToString
:
@"Prefix"
])
{
[
foundFolders
addObject
:[
NSString
stringWithString
:[
self
currentContent
]]];
}
else
if
([
elementName
isEqualToString
:
@"IsTruncated"
])
{
self
.
isTruncated
=
[[
NSString
stringWithString
:[
self
currentContent
]]
boolValue
];
}
}
-
(
void
)
parser
:
(
NSXMLParser
*
)
parser
foundCharacters
:
(
NSString
*
)
string
{
[
self
setCurrentContent
:[[
self
currentContent
]
stringByAppendingString
:
string
]];
...
...
@@ -169,8 +194,11 @@
@synthesize
currentElement
;
@synthesize
currentObject
;
@synthesize
objects
;
@synthesize
foundFolders
;
@synthesize
prefix
;
@synthesize
marker
;
@synthesize
maxResultCount
;
@synthesize
delimiter
;
@synthesize
isTruncated
;
@end
...
...
Classes/S3/ASIS3ObjectRequest.m
View file @
34b1600
...
...
@@ -31,7 +31,7 @@
+
(
id
)
requestWithBucket
:
(
NSString
*
)
bucket
key
:
(
NSString
*
)
key
subResource
:
(
NSString
*
)
subResource
{
NSString
*
path
=
[
ASIS3Request
stringByURLEncodingForS3Path
:
key
];
ASIS3ObjectRequest
*
request
=
[[[
self
alloc
]
initWithURL
:[
NSURL
URLWithString
:[
NSString
stringWithFormat
:
@"http://%@.s3.amazonaws.com%@?"
,
bucket
,
path
,
subResource
]]]
autorelease
];
ASIS3ObjectRequest
*
request
=
[[[
self
alloc
]
initWithURL
:[
NSURL
URLWithString
:[
NSString
stringWithFormat
:
@"http://%@.s3.amazonaws.com%@?
%@
"
,
bucket
,
path
,
subResource
]]]
autorelease
];
[
request
setBucket
:
bucket
];
[
request
setKey
:
key
];
return
request
;
...
...
Please
register
or
login
to post a comment