cloutree 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2da2c1b9a2c65fdd748206dc1cc6d4f2ff4da7cb
4
+ data.tar.gz: 26ae53559296c208ee253de6a4eda4dd869ace89
5
+ SHA512:
6
+ metadata.gz: cc8b957dd869e00e7383990857c3bfab0b43bec1546884061f4ac335515c7f670987bf3a367d8883e930fa2eb2ba7029f67a6817b06c518742825612189af7f1
7
+ data.tar.gz: 6d5c42d25639d317f46e24e3795ba85fe9a54be698396d9ef06e4fae0fee7c3b10fb05f588023c3f7e1aef224f37f62004ec10d0da4ba0d274d44bdd8772da4d
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cloutree.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ivan Shamatov
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,22 @@
1
+ # Cloutree
2
+
3
+ Add this line to your application's Gemfile:
4
+
5
+ gem 'cloutree'
6
+
7
+ And then execute:
8
+
9
+ $ bundle
10
+
11
+ Or install it yourself as:
12
+
13
+ $ gem install cloutree
14
+
15
+ ## Usage
16
+
17
+ CC.configure(
18
+ app_key: YOUR_APP_KEY,
19
+ app_secret: YOUR_APP_SECRET
20
+ )
21
+ CC.upload(filename) #=> will return link for uploaded file
22
+ CC.result #=> will return link for last uploaded file
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/cloutree.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cloutree/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cloutree"
8
+ spec.version = Cloutree::VERSION
9
+ spec.authors = ["Ivan Shamatov"]
10
+ spec.email = ["status.enable@gmail.com"]
11
+ spec.summary = %q{Gem to upload files to Cloutree CDN}
12
+ spec.description = %q{}
13
+ spec.homepage = "https://github.com/IvanShamatov/cloutree"
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.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest"
24
+ end
data/lib/cloutree.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'digest/sha1'
2
+ require 'singleton'
3
+ require 'json'
4
+
5
+ require_relative "cloutree/version"
6
+
7
+
8
+
9
+ module Cloutree
10
+ class Error < StandardError; ; end
11
+
12
+ class Client
13
+ include Singleton
14
+ attr_accessor :app_key, :app_secret
15
+ attr_reader :result
16
+
17
+ def self.configure(hash)
18
+ raise Cloutree::Error, "Specify :app_key" unless instance.app_key = hash[:app_key]
19
+ raise Cloutree::Error, "Specify :app_secret" unless instance.app_secret = hash[:app_secret]
20
+ instance
21
+ end
22
+
23
+
24
+ def self.upload(file)
25
+ raise Cloutree::Error, "Configure Cloutree::Client before uploading:
26
+ CC.configure(app_key: YOUR_KEY, app_secret: YOUR_SECRET)" unless instance.app_key && instance.app_secret
27
+ instance.upload(file)
28
+ end
29
+
30
+
31
+ def self.result
32
+ unless instance.result
33
+ raise Cloutree::Error, "Try to upload something first. CC.upload(filepath)"
34
+ end
35
+ instance.result
36
+ end
37
+
38
+
39
+ def upload(file)
40
+ filename = File.basename(file)
41
+ time = Time.now.to_i
42
+ string_to_sha = [app_key, time, filename, app_secret].join(":")
43
+ checksum = Digest::SHA1.hexdigest(string_to_sha)
44
+
45
+ command = "curl 'https://cloutr.ee/upload' "
46
+ command += "--data-binary '@#{file}' "
47
+ command += "-H 'KEY: #{app_key}' "
48
+ command += "-H 'CHECKSUM: #{checksum}' "
49
+ command += "-H 'FILENAME: #{filename}' "
50
+ command += "-H 'TIMESTAMP: #{time}'"
51
+ @result = JSON.parse(`#{command}`)
52
+ @result["success"]
53
+ end
54
+
55
+ end
56
+ end
57
+ CC = Cloutree::Client
@@ -0,0 +1,3 @@
1
+ module Cloutree
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/spec'
3
+ require File.expand_path('../../lib/cloutree.rb', __FILE__)
4
+
5
+
6
+ describe Cloutree do
7
+ it "should check configuration" do
8
+ -> { CC.upload("spec/logo.jpg") }.must_raise Cloutree::Error
9
+ end
10
+
11
+ it "should check app_key while configuration" do
12
+ -> { CC.configure(a: 1) }.must_raise Cloutree::Error
13
+ end
14
+
15
+ it "should check app_secret while configuration" do
16
+ -> { CC.configure(app_key: 1) }.must_raise Cloutree::Error
17
+ end
18
+ end
data/spec/logo.jpg ADDED
Binary file
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloutree
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Shamatov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-01 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ''
56
+ email:
57
+ - status.enable@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - cloutree.gemspec
68
+ - lib/cloutree.rb
69
+ - lib/cloutree/version.rb
70
+ - spec/cloutree_spec.rb
71
+ - spec/logo.jpg
72
+ homepage: https://github.com/IvanShamatov/cloutree
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Gem to upload files to Cloutree CDN
96
+ test_files:
97
+ - spec/cloutree_spec.rb
98
+ - spec/logo.jpg
99
+ has_rdoc: