upyun-form 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/lib/upyun/form.rb +60 -0
- data/lib/upyun/form/version.rb +5 -0
- data/test.jpeg +0 -0
- data/test.rb +17 -0
- data/upyun-form.gemspec +26 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f749a77b40d41a02f59c1a9ebf4bd7bfd2b4554d
|
4
|
+
data.tar.gz: f768f7b900f4189041ea367b64aaf006843edbcf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f9c8c54f75013d2601abfecab212c9c47ee30b6f78bf94a1d3b1abbd4ef9fa3e32c1b6f82811eab3fadf4c87793d0a22fed4d4c91cbccb480a5e1549bbaf60f9
|
7
|
+
data.tar.gz: 780fde844b940a46a04899c24760221e3f47c361f8d28e502fc092db12c18562b9d6667559c57ba10c0178c4047488541db187268cb9b9f1a350a1e189594339
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
.DS_*
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 wikimo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Ruby Form For Upyun
|
2
|
+
|
3
|
+
upload photo to upyun with form
|
4
|
+
|
5
|
+
## Enviroment
|
6
|
+
ruby 2.1.1
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'upyun-form'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install upyun-form
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```
|
25
|
+
require 'upyun/form'
|
26
|
+
|
27
|
+
config = {:bucket => 'devel',
|
28
|
+
:secret => 'lRJmqjI19GxB80KJc7y7NOcI+8g=',
|
29
|
+
# :return_url => 'http://localhost/return_url',
|
30
|
+
:notify_url => 'http://dev.365jinbi.com/notify.php' }
|
31
|
+
|
32
|
+
uploader = Upyun::Form::Uploader.new config
|
33
|
+
|
34
|
+
```
|
35
|
+
|
36
|
+
when no return url,it will return a json obj contains http code, message and photo url
|
37
|
+
|
38
|
+
when you set return url,it will return a response_headers
|
39
|
+
|
40
|
+
when you set notify url,it will post the result to that url,in this demo,it will notify the url http://dev.365jinbi.com/notify.php, you can browser http://dev.365jinbi.com/upyun.log to see the result
|
data/Rakefile
ADDED
data/lib/upyun/form.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "upyun/form/version"
|
2
|
+
require 'faraday'
|
3
|
+
require 'securerandom'
|
4
|
+
require 'base64'
|
5
|
+
require 'json'
|
6
|
+
require 'mime/types'
|
7
|
+
|
8
|
+
module Upyun
|
9
|
+
module Form
|
10
|
+
|
11
|
+
class Uploader
|
12
|
+
|
13
|
+
def initialize(config)
|
14
|
+
@config = config
|
15
|
+
|
16
|
+
@bucket = @config[:bucket]
|
17
|
+
@form_api_secret = @config[:secret]
|
18
|
+
endpoint = @config[:endpoint] ? @config[:endpoint] : 0
|
19
|
+
@allow_file_types = ['jpg','jpeg','png','gif']
|
20
|
+
|
21
|
+
@url = "http://v#{endpoint}.api.upyun.com"
|
22
|
+
@conn = Faraday.new(@url) do |f|
|
23
|
+
f.request :multipart
|
24
|
+
f.request :url_encoded
|
25
|
+
f.adapter :net_http
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def put(file)
|
31
|
+
mime_type = MIME::Types.type_for(file).first
|
32
|
+
return false if !@allow_file_types.include? mime_type.sub_type
|
33
|
+
|
34
|
+
opt = {}
|
35
|
+
opt['bucket'] = @bucket
|
36
|
+
save_path = @config[:save_path] ? @config[:save_path] : Time.now.strftime("%Y-%m-%d")
|
37
|
+
opt['save-key'] = "/#{save_path}/#{SecureRandom.uuid}.#{mime_type.sub_type}"
|
38
|
+
opt['expiration'] = Time.now.to_i + 600
|
39
|
+
|
40
|
+
opt['return-url'] = @config[:return_url] if @config[:return_url] != ''
|
41
|
+
opt['notify-url'] = @config[:notify_url] if @config[:notify_url] != ''
|
42
|
+
|
43
|
+
policy = Base64.encode64(opt.to_json).gsub(/\n/,'')
|
44
|
+
sign = Digest::MD5.hexdigest("#{policy}&#{@form_api_secret}")
|
45
|
+
|
46
|
+
response = @conn.post("#{@bucket}", {:policy => policy,
|
47
|
+
:signature => sign,
|
48
|
+
:file => Faraday::UploadIO.new(file, mime_type.content_type) })
|
49
|
+
|
50
|
+
if @config[:return_url]
|
51
|
+
return response.env.response_headers
|
52
|
+
end
|
53
|
+
|
54
|
+
json = JSON.parse response.body
|
55
|
+
{code: json['code'], msg: json['message'], url: json['url']}
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/test.jpeg
ADDED
Binary file
|
data/test.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'upyun/form'
|
4
|
+
|
5
|
+
url = 'http://devel.b0.upaiyun.com'
|
6
|
+
|
7
|
+
config = {:bucket => 'devel',
|
8
|
+
:secret => 'lRJmqjI19GxB80KJc7y7NOcI+8g=',
|
9
|
+
# :return_url => 'http://localhost/return_url',
|
10
|
+
:notify_url => 'http://dev.365jinbi.com/notify.php' }
|
11
|
+
|
12
|
+
uploader = Upyun::Form::Uploader.new config
|
13
|
+
|
14
|
+
result = uploader.put './test.jpeg'
|
15
|
+
|
16
|
+
p result
|
17
|
+
# p "url ==> #{url}#{result[:url]}"
|
data/upyun-form.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'upyun/form/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "upyun-form"
|
8
|
+
spec.version = Upyun::Form::VERSION
|
9
|
+
spec.authors = ["wikimo"]
|
10
|
+
spec.email = ["gwikimo@gmail.com"]
|
11
|
+
spec.summary = %q{ruby-form-for-upyun}
|
12
|
+
spec.description = %q{upload picture to uppyun with form}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "faraday"
|
25
|
+
spec.add_dependency 'mime-types'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: upyun-form
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- wikimo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mime-types
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: upload picture to uppyun with form
|
70
|
+
email:
|
71
|
+
- gwikimo@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/upyun/form.rb
|
82
|
+
- lib/upyun/form/version.rb
|
83
|
+
- test.jpeg
|
84
|
+
- test.rb
|
85
|
+
- upyun-form.gemspec
|
86
|
+
homepage: ''
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.2.2
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: ruby-form-for-upyun
|
110
|
+
test_files: []
|