Module: ImgCloud
- Defined in:
- lib/img_cloud.rb,
lib/img_cloud/version.rb,
lib/img_cloud/configuration.rb
Defined Under Namespace
Classes: Configuration, Railtie
Constant Summary collapse
- VERSION =
"0.2.0"
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
- .configure {|configuration| ... } ⇒ Object
-
.request_url(image_path, options = {}) ⇒ Object
returns image url for img_cloud_tag helper accepts a relative image path and height width parameters.
- .reset ⇒ Object
-
.transform(image_path, options = {}) ⇒ Object
return the image as byte data, accepts a relative image path and height width parameters.
-
.upload(path, tags, folder) ⇒ Object
Uploads the image, returns the image url and tags and folder in json format accepts image path as required parameter, and tags ( comma separated string ), folder ( string ) as optional parameters.
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
9 10 11 |
# File 'lib/img_cloud.rb', line 9 def configuration @configuration end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
69 70 71 |
# File 'lib/img_cloud.rb', line 69 def self.configure yield(configuration) end |
.request_url(image_path, options = {}) ⇒ Object
returns image url for img_cloud_tag helper accepts a relative image path and height width parameters.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/img_cloud.rb', line 43 def self.request_url(image_path, = {}) transform_args = [] transform_args << "h_#{[:height]}" if ([:height].to_i > 0) transform_args << "w_#{[:width]}" if ([:width].to_i > 0) transform_args << "blur_#{[:blur]}" if ([:blur].to_i > 0) transform_args << "sepia" if [:sepia] transform_args << "crop" if [:crop] transform_args << "scale" if [:scale] transform_args << "grayscale" if [:grayscale] if ([:borderWidth].to_i > 0) or [:borderColor] transform_args << "bdr_#{[:borderWidth]}-#{[:borderColor]}" end args = transform_args.join(',') parts = image_path.rpartition('/') if args.empty? parts.delete_at(1) else parts[1] = args end ImgCloud.configuration.base_uri + parts.join('/') end |
.reset ⇒ Object
16 17 18 |
# File 'lib/img_cloud.rb', line 16 def self.reset @configuration = Configuration.new end |
.transform(image_path, options = {}) ⇒ Object
return the image as byte data, accepts a relative image path and height width parameters.
35 36 37 38 39 |
# File 'lib/img_cloud.rb', line 35 def self.transform(image_path, = {}) uri = URI.parse(request_url(image_path, )) http = Net::HTTP.new(uri.host, uri.port) http.get(uri.path) end |
.upload(path, tags, folder) ⇒ Object
Uploads the image, returns the image url and tags and folder in json format accepts image path as required parameter, and tags ( comma separated string ), folder ( string ) as optional parameters
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/img_cloud.rb', line 22 def self.upload(path, , folder) uri = URI.parse("#{ImgCloud.configuration.base_uri}#{ImgCloud.configuration.upload_endpoint}") req = Net::HTTP::Post::Multipart.new uri.path, "image" => UploadIO.new(File.new(path), "image/jpg", path.split('/').last), "tags" => , "apiKey" => ImgCloud.configuration.apiKey, "folder" => folder res = Net::HTTP.start(uri.host, uri.port) do |http| http.request(req) end end |