dropscreen 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a6ff227d7feac29321e3e3e1457b585ff4791622
4
+ data.tar.gz: 8060fa6bb984ccf9528e928457a9c1a258c68538
5
+ SHA512:
6
+ metadata.gz: e8c8471e4dde06177aba33bd8ffe1ec94e1fa4b129b5442b2dede548f4b3b6fd0ae4da623dc000d340e7820542c7b44d91a1271ec37c64d9ba756f2ca97aeb26
7
+ data.tar.gz: 784ad40fc8bf3c3b80c91e9dfca192ccb66fad31ce35ed550457c62c59f4f46864fdececff285b8f1ac77d944ea53c84a24abf6b04f252916205bef717ac76f7
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 dropscreen.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2014, BSkyB
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of the {organization} nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Sky Haiku Team
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,64 @@
1
+ # Dropscreen
2
+
3
+ A gem to sync screenshot files with Dropbox
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'dropscreen'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install dropscreen
18
+
19
+
20
+ ## Authentication
21
+
22
+ You need to setup an app in dropbox and get a dropbox access token. Instructions are here:
23
+ https://www.dropbox.com/developers/core/start/ruby
24
+
25
+ ## Usage
26
+
27
+ export the dropbox access token as an environment variable:
28
+ export DROPBOX_ACCESS_TOKEN=**insert dropbox access token here**
29
+
30
+ ### In your code
31
+ require 'dropscreen'
32
+
33
+ This uses the token from the environment variable and sets the root dir local and remote to be the local app dir and the permitted dropbox dir respectively.
34
+ dropscreen_client = Dropscreen::Client.new
35
+
36
+ Alternatively, you can pass in a hash with one or more of these options:
37
+
38
+ client = Dropscreen::Client.new(
39
+ remote_base_dir: 'remote_base_dir',
40
+ local_base_dir: 'local_base_dir'
41
+ )
42
+
43
+ #### Pulling files from dropbox
44
+
45
+ client.pull('some_folder'[, 'dest_folder'])
46
+
47
+ The destination folder will by default be the same name as the source folder, alternatively you can pass in a destination folder as the second param.
48
+
49
+
50
+ #### Pushing files to dropbox
51
+
52
+ client.push('some_folder'[, 'dest_folder'])
53
+
54
+ The destination folder will by default be the same name as the source folder, alternatively you can pass in a destination folder as the second param.
55
+
56
+
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it ( http://github.com/<my-github-username>/dropscreen/fork )
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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 'dropscreen/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dropscreen"
8
+ spec.version = Dropscreen::VERSION
9
+ spec.authors = ["Sky Haiku Team"]
10
+ spec.email = ["skyhaikuteam@gmail.com"]
11
+ spec.summary = %q{Push and pull files to dropbox}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "dropbox-sdk"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "pry"
26
+ end
@@ -0,0 +1,3 @@
1
+ module Dropscreen
2
+ VERSION = "0.0.1"
3
+ end
data/lib/dropscreen.rb ADDED
@@ -0,0 +1,51 @@
1
+ require "dropscreen/version"
2
+ require "dropbox_sdk"
3
+
4
+ module Dropscreen
5
+ class Client
6
+
7
+ attr_accessor :client
8
+
9
+ def initialize opts
10
+ @token = ENV['DROPBOX_ACCESS_TOKEN']
11
+ @remote_base_dir = opts[:remote_base_dir] || '/'
12
+ @local_base_dir = opts[:local_base_dir] || '/'
13
+ @client = DropboxClient.new @token
14
+ end
15
+
16
+ def push(src, dest=src)
17
+ @client.file_create_folder(File.join(@remote_base_dir, dest)) unless exists? dest
18
+ Dir.foreach(File.join(@local_base_dir, src)) do |filename|
19
+ next if filename == '.' or filename == '..' or filename == '.DS_Store'
20
+ file = open(File.join(@local_base_dir, src, filename))
21
+ dropbox_file_name = File.basename(filename)
22
+ @client.put_file(File.join(@remote_base_dir, dest, dropbox_file_name), file, true)
23
+ end
24
+ end
25
+
26
+ def exists? path
27
+ fullpath = File.join(@remote_base_dir,path)
28
+ @client.metadata(fullpath)
29
+ return true
30
+ rescue DropboxError => e
31
+ if e.message.include? 'not found'
32
+ return false
33
+ else
34
+ raise e
35
+ end
36
+ end
37
+
38
+ def pull(src, dest=src)
39
+ dest = File.join(@local_base_dir, dest)
40
+ FileUtils.mkdir_p(dest) unless File.exists?(dest)
41
+ files = @client.metadata(File.join(@remote_base_dir, src))['contents']
42
+ files.each do |file|
43
+ basename = File.basename(file['path'])
44
+ destination_filename = File.join(dest, basename)
45
+ contents = @client.get_file(file['path'])
46
+ open(destination_filename, 'wb') {|f| f.puts contents }
47
+ end
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'pry'
3
+ require 'dropbox_sdk'
4
+
5
+ describe Dropscreen do
6
+
7
+ describe Dropscreen::Client do
8
+
9
+ before do
10
+ `rm -rf artifacts/reference_screenshots`
11
+ @client = Dropscreen::Client.new(
12
+ remote_base_dir: 'dropscreen',
13
+ local_base_dir: 'artifacts'
14
+ )
15
+ end
16
+
17
+ describe '#pull' do
18
+
19
+ it 'should pull down all the files in a given directory' do
20
+ @client.pull('reference_screenshots')
21
+ File.exists?('artifacts/reference_screenshots/advisor_page_firefox.gif').should be_true
22
+ File.exists?('artifacts/reference_screenshots/advisor_page_ie9.gif').should be_true
23
+ end
24
+
25
+ end
26
+
27
+ describe '#exists?' do
28
+ it 'should be false if it doesnt exist' do
29
+ @client.exists?('flibble').should be_false
30
+ end
31
+ it 'should be true if it exists' do
32
+ @client.exists?('reference_screenshots').should be_true
33
+ end
34
+ end
35
+
36
+
37
+ describe '#push' do
38
+
39
+ it 'should create the destination folder if it doesnt already exist' do
40
+ @client.push('screenshots_generated_this_run')
41
+ new_folder = @client.client.metadata('dropscreen/screenshots_generated_this_run/')
42
+ fail "Folder wasn't created" unless new_folder['is_dir']
43
+ end
44
+
45
+ it 'should not create the destination folder if it already exists' do
46
+ @client.push('screenshots_generated_this_run')
47
+ @client.push('screenshots_generated_this_run')
48
+ end
49
+
50
+
51
+ it 'should push up all the files in a given directory' do
52
+ @client.push('screenshots_generated_this_run')
53
+ contents = @client.client.metadata('dropscreen/screenshots_generated_this_run/')['contents']
54
+ end
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,6 @@
1
+ require 'dropscreen'
2
+
3
+
4
+ RSpec.configure do |config|
5
+
6
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dropscreen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sky Haiku Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dropbox-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - skyhaikuteam@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - artifacts/screenshots_generated_this_run/advisor_page_firefox.gif
97
+ - artifacts/screenshots_generated_this_run/advisor_page_ie9.gif
98
+ - dropscreen.gemspec
99
+ - lib/dropscreen.rb
100
+ - lib/dropscreen/version.rb
101
+ - spec/dropscreen_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: ''
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.0
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Push and pull files to dropbox
127
+ test_files:
128
+ - spec/dropscreen_spec.rb
129
+ - spec/spec_helper.rb