Class: Github::S3Uploader
- Inherits:
-
Object
- Object
- Github::S3Uploader
- Defined in:
- lib/github_api/s3_uploader.rb
Constant Summary collapse
- REQUIRED_S3_PARAMS =
%w[ path acl name accesskeyid policy signature mime_type ].freeze
- SUCCESS_STATUS =
Status code for successful upload to Amazon S3 service
201
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
-
#initialize(resource, filename) ⇒ S3Uploader
constructor
A new instance of S3Uploader.
- #send ⇒ Object
Constructor Details
#initialize(resource, filename) ⇒ S3Uploader
Returns a new instance of S3Uploader.
23 24 25 26 |
# File 'lib/github_api/s3_uploader.rb', line 23 def initialize(resource, filename) @resource = resource @filename = filename end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
21 22 23 |
# File 'lib/github_api/s3_uploader.rb', line 21 def filename @filename end |
#resource ⇒ Object
Returns the value of attribute resource.
21 22 23 |
# File 'lib/github_api/s3_uploader.rb', line 21 def resource @resource end |
Instance Method Details
#send ⇒ Object
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 |
# File 'lib/github_api/s3_uploader.rb', line 28 def send REQUIRED_S3_PARAMS.each do |key| unless resource.respond_to?(key) raise ArgumentError, "Expected following key: #{key}" end end mapped_params = Github::CoreExt::OrderedHash[ 'key', resource.path, 'acl', resource.acl, 'success_action_status', SUCCESS_STATUS, 'Filename', resource.name, 'AWSAccessKeyId', resource.accesskeyid, 'Policy', resource.policy, 'Signature', resource.signature, 'Content-Type', resource.mime_type, 'file', Faraday::UploadIO.new(filename, 'application/octet-stream') ] http = Faraday.new do |builder| builder.request :multipart builder.use Github::Response::Xmlize builder.adapter :net_http end http.post resource.s3_url, mapped_params end |