Git Product home page Git Product logo

alexdrone / amazons3requestmanager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from anthonymdev/amazons3requestmanager

4.0 3.0 0.0 336 KB

Carthage compatible fork. A request manager subclass of Alamofire's default manager that serializes requests to the AWS S3 (Amazon Simple Storage Solution). Based on AFAmazonS3Manager

License: MIT License

Ruby 2.60% Swift 78.54% Objective-C 18.85%

amazons3requestmanager's Introduction

AmazonS3RequestManager

Carthage compatible License Platform

An Alamofire based request manager that serializes requests to the AWS S3 (Amazon Simple Storage Solution).

AmazonS3RequestManager also includes a request serializer that creates NSURLRequest objects for use with any other networking methods.

Features

  • Request Serialization
  • Response Validation
  • Amazon S3 Response Error Parsing
  • Access Control List (ACL) Management
  • Support for Amazon S3 Subresources
  • Support for Amazon S3 Storage Classes
  • Comprehensive Unit Test Coverage
  • Complete Documentation

Installation

Carthage

To install Carthage, run (using Homebrew):

$ brew update
$ brew install carthage

Then add the following line to your Cartfile:

github "alexdrone/AmazonS3RequestManager" "master"    

Usage

First create an instance of the manager.

let amazonS3Manager = AmazonS3RequestManager(bucket: myAmazonS3Bucket,
    region: .USStandard,
    accessKey: myAmazonS3AccessKey,
    secret: myAmazonS3Secret)

Get Objects

Getting Objects as Response Objects:

amazonS3Manager.getObject("myFoler/fileName.jpg")

Saving Objects To File:

let destination: NSURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
amazonS3Manager.downloadObject("myFolder/fileName.jpg", saveToURL: destination)

Upload Objects

let fileURL: NSURL = NSURL(fileURLWithPath: "pathToMyObject")
amazonS3Manager.putObject(fileURL, destinationPath: "pathToSaveObjectTo/fileName.jpg")

Delete Objects

amazonS3Manager.deleteObject("myFolder/fileName.jpg")

Response Serialization

AmazonS3RequestManager includes a custom data response serializer that parses errors from the Amazon S3 Service.

amazonS3Manager.getObject("myFoler/fileName.jpg")
  .responseS3Data { (response) -> Void in
    // Handle Response Data or Error
}

Access Control Lists (ACL)

AmazonS3RequestManager provides simple APIs for getting and setting ACLs on buckets and objects.

Getting ACLs

You can retrieve the ACLs for the current bucket set on the request manager with a GET request:

amazonS3Manager.getBucketACL()

or for an object in the bucket with a GET request:

amazonS3Manager.getACL(forObjectAtPath: "myFolder/fileName.jpg")

Setting ACLs

You can set the ACLs on the current bucket with a PUT request:

amazonS3Manager.setBucketACL(AmazonS3PredefinedACL.Public)

or on an object in the bucket with a PUT request:

amazonS3Manager.setACL(forObjectAtPath: "myFolder/fileName.jpg", acl: AmazonS3PredefinedACL.Public)

The ACLs for an object can also be set while uploading by using the optional acl parameter.

Creating Custom ACLs

If the predefined ACLs that the Amazon S3 Service provides do not give you enough control, you may create custom ACLs using AmazonS3ACLPermissionGrant and AmazonS3CustomACL

AmazonS3ACLPermissionGrant grants multiple users/user groups a single permission. AmazonS3CustomACL is comprised of multiple AmazonS3ACLPermissionGrants to create any series of permissions you would like to create.

Examples

To give all users read access to the bucket:

let readPermission = AmazonS3ACLPermissionGrant(permission: .Read, grantee: .AllUsers)
amazonS3Manager.setBucketACL(readPermission)

To give all users read access to the bucket, authenticated users write access to the bucket, and two users with a given E-mail Address and given User ID full control:

let readPermission = AmazonS3ACLPermissionGrant(permission: .Read, grantee: .AllUsers)
let writePermission = AmazonS3ACLPermissionGrant(permission: .Write, grantee: .AuthenticatedUsers)
let fullControlPermission = AmazonS3ACLPermissionGrant(permission: .FullControl, grantees: [.EmailAddress("[email protected]"), .UserID("my-user-id")])
let customACL = AmazonS3CustomACL(grants: [readPermission, writePermission, fullControlPermission])
amazonS3Manager.setBucketACL(customACL)

amazons3requestmanager's People

Contributors

anthonymdev avatar danielrhammond avatar vortec4800 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.