img_cloud 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/.travis.yml +15 -0
- data/Gemfile.lock +77 -40
- data/LICENSE.txt +1 -1
- data/README.md +30 -8
- data/Rakefile +6 -0
- data/img_cloud.gemspec +5 -4
- data/lib/img_cloud/configuration.rb +7 -7
- data/lib/img_cloud/helper.rb +17 -6
- data/lib/img_cloud/version.rb +1 -1
- data/lib/img_cloud.rb +21 -18
- metadata +26 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 775278098e694a47028a7c81bff7aebe52ed4f07
|
4
|
+
data.tar.gz: 459a135ceaa242c2c3540dbfe879d34aed10fb88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9029cbc0d074663d017bc92bf17ae62133a2d5835875ed8e7a9705b068d0d8713decb46c711139ee4696443e30a2af264ff5927f878d66c19953797d26dc2210
|
7
|
+
data.tar.gz: 5bd5d4bc8e2b37440e2ef5959a0d1b2d918c1c1e7c0d122ff079a48605edb78c27d0ec1d575a5cfd1e7c097674f35ab8e335588cc39a3fbd34244b9a8c76c32a
|
data/.gitignore
CHANGED
@@ -28,8 +28,8 @@ build/
|
|
28
28
|
# for a library or gem, you might want to ignore these files since the code is
|
29
29
|
# intended to run in multiple environments; otherwise, check them in:
|
30
30
|
# Gemfile.lock
|
31
|
-
|
32
|
-
|
31
|
+
.ruby-version
|
32
|
+
.ruby-gemset
|
33
33
|
|
34
34
|
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
35
|
.rvmrc
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -2,53 +2,71 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
img_cloud (0.1.0)
|
5
|
-
multipart-post
|
5
|
+
multipart-post (~> 2.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actionpack (
|
11
|
-
|
12
|
-
activesupport (=
|
13
|
-
|
14
|
-
rack-test (~> 0.6.2)
|
15
|
-
rails-dom-testing (~> 1.0, >= 1.0.5)
|
16
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
17
|
-
actionview (4.2.4)
|
18
|
-
activesupport (= 4.2.4)
|
19
|
-
builder (~> 3.1)
|
10
|
+
actionpack (3.2.22)
|
11
|
+
activemodel (= 3.2.22)
|
12
|
+
activesupport (= 3.2.22)
|
13
|
+
builder (~> 3.0.0)
|
20
14
|
erubis (~> 2.7.0)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
15
|
+
journey (~> 1.0.4)
|
16
|
+
rack (~> 1.4.5)
|
17
|
+
rack-cache (~> 1.2)
|
18
|
+
rack-test (~> 0.6.1)
|
19
|
+
sprockets (~> 2.2.1)
|
20
|
+
activemodel (3.2.22)
|
21
|
+
activesupport (= 3.2.22)
|
22
|
+
builder (~> 3.0.0)
|
23
|
+
activesupport (3.2.22)
|
24
|
+
i18n (~> 0.6, >= 0.6.4)
|
25
|
+
multi_json (~> 1.0)
|
26
|
+
addressable (2.3.8)
|
27
|
+
backports (3.6.6)
|
28
|
+
builder (3.0.4)
|
29
|
+
coderay (1.1.0)
|
30
30
|
diff-lcs (1.2.5)
|
31
31
|
erubis (2.7.0)
|
32
|
+
ethon (0.7.4)
|
33
|
+
ffi (>= 1.3.0)
|
34
|
+
faraday (0.9.1)
|
35
|
+
multipart-post (>= 1.2, < 3)
|
36
|
+
faraday_middleware (0.10.0)
|
37
|
+
faraday (>= 0.7.4, < 0.10)
|
38
|
+
ffi (1.9.10)
|
39
|
+
gh (0.14.0)
|
40
|
+
addressable
|
41
|
+
backports
|
42
|
+
faraday (~> 0.8)
|
43
|
+
multi_json (~> 1.0)
|
44
|
+
net-http-persistent (>= 2.7)
|
45
|
+
net-http-pipeline
|
46
|
+
highline (1.7.3)
|
47
|
+
hike (1.2.3)
|
32
48
|
i18n (0.7.0)
|
49
|
+
journey (1.0.4)
|
33
50
|
json (1.8.3)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
51
|
+
launchy (2.4.3)
|
52
|
+
addressable (~> 2.3)
|
53
|
+
method_source (0.8.2)
|
54
|
+
multi_json (1.11.2)
|
38
55
|
multipart-post (2.0.0)
|
39
|
-
|
40
|
-
|
41
|
-
|
56
|
+
net-http-persistent (2.9.4)
|
57
|
+
net-http-pipeline (1.0.1)
|
58
|
+
pry (0.9.12.6)
|
59
|
+
coderay (~> 1.0)
|
60
|
+
method_source (~> 0.8)
|
61
|
+
slop (~> 3.4)
|
62
|
+
pusher-client (0.6.2)
|
63
|
+
json
|
64
|
+
websocket (~> 1.0)
|
65
|
+
rack (1.4.7)
|
66
|
+
rack-cache (1.2)
|
67
|
+
rack (>= 0.4)
|
42
68
|
rack-test (0.6.3)
|
43
69
|
rack (>= 1.0)
|
44
|
-
rails-deprecated_sanitizer (1.0.3)
|
45
|
-
activesupport (>= 4.2.0.alpha)
|
46
|
-
rails-dom-testing (1.0.7)
|
47
|
-
activesupport (>= 4.2.0.beta, < 5.0)
|
48
|
-
nokogiri (~> 1.6.0)
|
49
|
-
rails-deprecated_sanitizer (>= 1.0.1)
|
50
|
-
rails-html-sanitizer (1.0.2)
|
51
|
-
loofah (~> 2.0)
|
52
70
|
rake (10.4.2)
|
53
71
|
rspec (3.3.0)
|
54
72
|
rspec-core (~> 3.3.0)
|
@@ -63,16 +81,35 @@ GEM
|
|
63
81
|
diff-lcs (>= 1.2.0, < 2.0)
|
64
82
|
rspec-support (~> 3.3.0)
|
65
83
|
rspec-support (3.3.0)
|
66
|
-
|
67
|
-
|
68
|
-
|
84
|
+
slop (3.6.0)
|
85
|
+
sprockets (2.2.3)
|
86
|
+
hike (~> 1.2)
|
87
|
+
multi_json (~> 1.0)
|
88
|
+
rack (~> 1.0)
|
89
|
+
tilt (~> 1.1, != 1.3.0)
|
90
|
+
tilt (1.4.1)
|
91
|
+
travis (1.8.0)
|
92
|
+
addressable (~> 2.3)
|
93
|
+
backports
|
94
|
+
faraday (~> 0.9)
|
95
|
+
faraday_middleware (~> 0.9, >= 0.9.1)
|
96
|
+
gh (~> 0.13)
|
97
|
+
highline (~> 1.6)
|
98
|
+
launchy (~> 2.1)
|
99
|
+
pry (~> 0.9, < 0.10)
|
100
|
+
pusher-client (~> 0.4)
|
101
|
+
typhoeus (~> 0.6, >= 0.6.8)
|
102
|
+
typhoeus (0.7.3)
|
103
|
+
ethon (>= 0.7.4)
|
104
|
+
websocket (1.2.2)
|
69
105
|
|
70
106
|
PLATFORMS
|
71
107
|
ruby
|
72
108
|
|
73
109
|
DEPENDENCIES
|
74
|
-
actionpack
|
110
|
+
actionpack (~> 3.2.0)
|
75
111
|
bundler (~> 1.8)
|
76
112
|
img_cloud!
|
77
113
|
rake (~> 10.0)
|
78
|
-
rspec
|
114
|
+
rspec (>= 3.2)
|
115
|
+
travis (~> 1.8.0)
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# ImgCloud
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
ruby gem for img cloud. Uploading images will return image path that can be then used in a helper tag to transform images.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -23,18 +21,42 @@ Or install it yourself as:
|
|
23
21
|
## Usage
|
24
22
|
you can configure api key and base uri for the gem like this in an initializer
|
25
23
|
|
24
|
+
```ruby
|
26
25
|
ImgCloud.configure do |config|
|
27
|
-
config.base_uri = 'http://
|
26
|
+
config.base_uri = 'http://www.imgcloud.io/' #optional
|
28
27
|
config.apiKey = 'f837dje0-4c99-11e5-a2ca-27ben7f17568' #required
|
29
28
|
end
|
29
|
+
```
|
30
|
+
|
31
|
+
### Uploading an Image
|
30
32
|
|
31
|
-
|
33
|
+
```ruby
|
34
|
+
ImgCloud.upload(image_path, tags, folder) # parameters => path(required), tags (optional, comma separated string) & folder (optional)
|
35
|
+
```
|
32
36
|
|
33
|
-
|
37
|
+
### Helper method for Image tag
|
34
38
|
|
35
|
-
|
39
|
+
```ruby
|
40
|
+
img_cloud_tag image_path, options
|
41
|
+
```
|
42
|
+
|
43
|
+
#### Options:
|
44
|
+
|
45
|
+
parameters | Type
|
46
|
+
---------------------------------------|------
|
47
|
+
height, width, borderWidth, blur | Integer
|
48
|
+
borderColor, class, style, alt, title | String
|
49
|
+
sepia, grayscale, crop, scale | Boolean
|
50
|
+
|
51
|
+
|
52
|
+
#### Example:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
img_cloud_tag "/ic_4e1756/1440667545769_1436524274_car1.jpg", :width => 100, :height => 100, :sepia => true, :borderWidth => 5, :borderColor => 'red', :class => 'img_class', :style => "margin:10px"
|
56
|
+
```
|
57
|
+
displays a transformed image, accepts a relative image path and optional parameters.
|
58
|
+
If the parameters are incorrect, it is not applied to the image.
|
36
59
|
|
37
|
-
helper method :
|
38
60
|
## Development
|
39
61
|
|
40
62
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
data/img_cloud.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
# end
|
15
15
|
|
16
16
|
spec.summary = %q{ruby gem for img cloud, upload/transform images}
|
17
|
-
|
17
|
+
spec.description = %q{ruby gem for img cloud, upload/transform images}
|
18
18
|
spec.homepage = "https://github.com/img-cloud/ruby_gem"
|
19
19
|
spec.license = "MIT"
|
20
20
|
|
@@ -25,8 +25,9 @@ Gem::Specification.new do |spec|
|
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.8"
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
-
spec.add_development_dependency 'rspec', '
|
28
|
+
spec.add_development_dependency 'rspec', '>= 3.2'
|
29
29
|
|
30
|
-
spec.add_runtime_dependency 'multipart-post', '~> 0'
|
31
|
-
spec.add_development_dependency "actionpack",
|
30
|
+
spec.add_runtime_dependency 'multipart-post', '~> 2.0.0'
|
31
|
+
spec.add_development_dependency "actionpack", "~> 3.2.0"
|
32
|
+
spec.add_development_dependency 'travis', '~> 1.8.0'
|
32
33
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module ImgCloud
|
2
|
-
|
3
|
-
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :base_uri, :apiKey, :upload_endpoint
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
def initialize
|
6
|
+
@base_uri = 'http://www.imgcloud.io'
|
7
|
+
@upload_endpoint = '/upload'
|
8
|
+
end
|
9
|
+
end
|
10
10
|
end
|
data/lib/img_cloud/helper.rb
CHANGED
@@ -1,8 +1,19 @@
|
|
1
1
|
module ImgCloudHelper
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
# displays a transformed image, accepts a relative image path and height width parameters. Additional parameters if any are ignored,
|
3
|
+
# and the original image is displayed if no or invalid height width parameters are provided.
|
4
|
+
|
5
|
+
# Example
|
6
|
+
#
|
7
|
+
# img_cloud_tag "/ic_4e1756/1440667545769_1436524274_car1.jpg", :width=>100, :height=>100
|
8
|
+
|
9
|
+
def img_cloud_tag(img_path, options = {})
|
10
|
+
height = "height=\"#{options[:height]}\"" if (options[:height].to_i > 0)
|
11
|
+
width = "width=\"#{options[:width]}\"" if (options[:width].to_i > 0)
|
12
|
+
dom_class = "class=\"#{options[:class]}\"" if options[:class]
|
13
|
+
alt = "alt=\"#{options[:alt]}\"" if options[:alt]
|
14
|
+
title = "title=\"#{options[:title]}\"" if options[:title]
|
15
|
+
style = "style=\"#{options[:style]}\"" if options[:style]
|
16
|
+
|
17
|
+
"<img src=\"#{ImgCloud.request_url(img_path, options)}\" #{height} #{width} #{dom_class} #{alt} #{title} #{style}>"
|
18
|
+
end
|
8
19
|
end
|
data/lib/img_cloud/version.rb
CHANGED
data/lib/img_cloud.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require "img_cloud/version"
|
2
2
|
require "img_cloud/configuration"
|
3
3
|
require 'net/http/post/multipart'
|
4
|
-
#require 'net/http'
|
5
4
|
require 'json'
|
6
5
|
|
7
6
|
module ImgCloud
|
@@ -17,38 +16,43 @@ module ImgCloud
|
|
17
16
|
def self.reset
|
18
17
|
@configuration = Configuration.new
|
19
18
|
end
|
20
|
-
|
21
|
-
#
|
22
|
-
#
|
23
|
-
# "Accept" => "application/json"}
|
24
|
-
# uri = URI.parse('http://img-cloud.herokuapp.com/users')
|
25
|
-
# http = Net::HTTP.new(uri.host, uri.port)
|
26
|
-
# res = http.post(uri.path, params.to_json, json_headers)
|
27
|
-
# res.body
|
28
|
-
# end
|
29
|
-
|
19
|
+
|
20
|
+
# Uploads the image, returns the image url and tags and folder in json format
|
21
|
+
# accepts image path as required parameter, and tags ( comma separated string ), folder ( string ) as optional parameters
|
30
22
|
def self.upload(path, tags, folder)
|
31
|
-
uri = URI.parse("#{ImgCloud.configuration.base_uri}
|
23
|
+
uri = URI.parse("#{ImgCloud.configuration.base_uri}#{ImgCloud.configuration.upload_endpoint}")
|
32
24
|
req = Net::HTTP::Post::Multipart.new uri.path,
|
33
|
-
"image" => UploadIO.new(File.new(path), "image/jpg",
|
25
|
+
"image" => UploadIO.new(File.new(path), "image/jpg", path.split('/').last),
|
34
26
|
"tags" => tags, "apiKey" => ImgCloud.configuration.apiKey, "folder" => folder
|
35
27
|
|
36
28
|
res = Net::HTTP.start(uri.host, uri.port) do |http|
|
37
29
|
http.request(req)
|
38
30
|
end
|
39
31
|
end
|
40
|
-
|
32
|
+
|
33
|
+
# return the image as byte data,
|
34
|
+
# accepts a relative image path and height width parameters.
|
41
35
|
def self.transform(image_path, options = {})
|
42
|
-
uri = URI.parse(
|
36
|
+
uri = URI.parse(request_url(image_path, options))
|
43
37
|
http = Net::HTTP.new(uri.host, uri.port)
|
44
38
|
http.get(uri.path)
|
45
39
|
end
|
46
40
|
|
47
|
-
|
41
|
+
# returns image url for img_cloud_tag helper
|
42
|
+
# accepts a relative image path and height width parameters.
|
43
|
+
def self.request_url(image_path, options = {})
|
48
44
|
transform_args = []
|
49
45
|
|
50
46
|
transform_args << "h_#{options[:height]}" if (options[:height].to_i > 0)
|
51
47
|
transform_args << "w_#{options[:width]}" if (options[:width].to_i > 0)
|
48
|
+
transform_args << "blur_#{options[:blur]}" if (options[:blur].to_i > 0)
|
49
|
+
transform_args << "sepia" if options[:sepia]
|
50
|
+
transform_args << "crop" if options[:crop]
|
51
|
+
transform_args << "scale" if options[:scale]
|
52
|
+
transform_args << "grayscale" if options[:grayscale]
|
53
|
+
if (options[:borderWidth].to_i > 0) or options[:borderColor]
|
54
|
+
transform_args << "bdr_#{options[:borderWidth]}-#{options[:borderColor]}"
|
55
|
+
end
|
52
56
|
|
53
57
|
args = transform_args.join(',')
|
54
58
|
|
@@ -58,8 +62,7 @@ module ImgCloud
|
|
58
62
|
parts.delete_at(1)
|
59
63
|
else
|
60
64
|
parts[1] = args
|
61
|
-
end
|
62
|
-
|
65
|
+
end
|
63
66
|
ImgCloud.configuration.base_uri + parts.join('/')
|
64
67
|
end
|
65
68
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: img_cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rahul Singh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,45 +42,59 @@ dependencies:
|
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.2'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: multipart-post
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 2.0.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 2.0.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: actionpack
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 3.2.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.2.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: travis
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.8.0
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
83
|
-
description:
|
96
|
+
version: 1.8.0
|
97
|
+
description: ruby gem for img cloud, upload/transform images
|
84
98
|
email:
|
85
99
|
- flytorahul00@gmail.com
|
86
100
|
executables: []
|
@@ -88,6 +102,7 @@ extensions: []
|
|
88
102
|
extra_rdoc_files: []
|
89
103
|
files:
|
90
104
|
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
91
106
|
- CODE_OF_CONDUCT.md
|
92
107
|
- Gemfile
|
93
108
|
- Gemfile.lock
|