visdiff 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: a3b703ac4b86840342144cd9c2ea5723c7e30855
4
+ data.tar.gz: 9dcb1dc54d2e02fb266db0c0d44d8d342f57bc83
5
+ SHA512:
6
+ metadata.gz: 83527b27d32b0277986c369f692a95d73416762a2b32f2896ba484209e35653406120a4c4116a69a5312461f47e7361ed8a9025c5353eb7903ab4e1a15a779be
7
+ data.tar.gz: cde83f73d53fb5ff44fdbcd125950dfe6039fd8d6c69f0aa7c32a51b23fd1a4ff33e05c6d33e49b4b78227618c6c3fc29ffb549d73ac36d9e0bab3a3fa9410ad
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in visdiff.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 John Hawthorn
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,31 @@
1
+ # Visdiff
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'visdiff'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install visdiff
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/jhawthorn/visdiff-ruby/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,57 @@
1
+ require 'visdiff/config'
2
+
3
+ module Visdiff
4
+ class Client
5
+ attr_reader :config
6
+
7
+ def initialize(config=Visdiff.config)
8
+ @config = config
9
+ end
10
+
11
+ def revision identifier, images=[]
12
+ revision = Revision.new(identifier, images)
13
+ revision.client = self
14
+ yield revision if block_given?
15
+ revision
16
+ end
17
+
18
+ def submit_revision revision
19
+ post('revisions', revision: revision.attributes)
20
+ end
21
+
22
+ def submit_image image
23
+ put("images/#{image.signature}", image: image.attributes)
24
+ end
25
+
26
+ private
27
+
28
+ def post path, data
29
+ parse(conn.post(path, request_data(data)))
30
+ end
31
+
32
+ def put path, data
33
+ parse(conn.put(path, request_data(data)))
34
+ end
35
+
36
+ def request_data data
37
+ {api_key: api_key}.merge(data)
38
+ end
39
+
40
+ def api_key
41
+ config.api_key || raise("visdiff api key not configured")
42
+ end
43
+
44
+ def base_url
45
+ "#{config.base_url}/api"
46
+ end
47
+
48
+ def conn
49
+ config.connection
50
+ end
51
+
52
+ def parse response
53
+ raise response.body unless response.success?
54
+ JSON.parse(response.body)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,20 @@
1
+ require 'faraday'
2
+
3
+ module Visdiff
4
+ class Config
5
+ attr_accessor :base_url, :api_key
6
+
7
+ def initialize
8
+ end
9
+
10
+ attr_writer :connection
11
+ def connection
12
+ @connection ||= Faraday.new(:url => base_url) do |faraday|
13
+ faraday.request :multipart
14
+ faraday.request :url_encoded
15
+ faraday.response :logger
16
+ faraday.adapter Faraday.default_adapter
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,33 @@
1
+ module Visdiff
2
+ class Image
3
+ attr_reader :identifier, :fullpath
4
+ attr_accessor :client
5
+
6
+ def initialize identifier, fullpath
7
+ @identifier = identifier
8
+ @fullpath = fullpath
9
+ end
10
+
11
+ def basename
12
+ File.basename(fullpath)
13
+ end
14
+
15
+ def signature
16
+ @signature ||= IO.popen(["identify", "-format", "%#", '--', fullpath]) do |f|
17
+ f.read
18
+ end
19
+ end
20
+
21
+ def submit!
22
+ @client.submit_image self
23
+ end
24
+
25
+ def attributes
26
+ {image: upload_io}
27
+ end
28
+
29
+ def upload_io
30
+ Faraday::UploadIO.new(fullpath, 'image/png')
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,41 @@
1
+ module Visdiff
2
+ class Revision
3
+ attr_reader :identifier, :images
4
+ attr_accessor :client
5
+
6
+ def initialize identifier, images=[]
7
+ @identifier = identifier
8
+ @images = images
9
+ end
10
+
11
+ def add_image identifier, filename
12
+ image = Image.new(identifier, filename)
13
+ image.client = client
14
+ @images << image
15
+ end
16
+
17
+ def submit!
18
+ response = client.submit_revision(self)
19
+
20
+ missing_images = []
21
+ response['images'].each do |rimg|
22
+ missing_images << rimg['signature'] unless rimg['url']
23
+ end
24
+ puts "Uploading #{missing_images.length} new images (#{response['images'].length} total)"
25
+
26
+ images.each do |image|
27
+ next unless missing_images.include?(image.signature)
28
+ client.submit_image(image)
29
+ end
30
+ end
31
+
32
+ def attributes
33
+ {
34
+ identifier: identifier,
35
+ image_attributes: images.map do |image|
36
+ {identifier: identifier, signature: image.signature}
37
+ end
38
+ }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Visdiff
2
+ VERSION = "0.0.1"
3
+ end
data/lib/visdiff.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "visdiff/version"
2
+
3
+ require 'visdiff/client'
4
+ require 'visdiff/config'
5
+ require 'visdiff/image'
6
+ require 'visdiff/revision'
7
+
8
+ module Visdiff
9
+ def self.config
10
+ @config ||= Config.new
11
+ yield(@config) if block_given?
12
+ @config
13
+ end
14
+
15
+ config.base_url = "http://www.visdiff.com/"
16
+ end
data/visdiff.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'visdiff/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "visdiff"
8
+ spec.version = Visdiff::VERSION
9
+ spec.authors = ["John Hawthorn"]
10
+ spec.email = ["john.hawthorn@gmail.com"]
11
+ spec.summary = %q{Visual diff tool - visdiff.com}
12
+ spec.description = %q{Visual diff tool - visdiff.com}
13
+ spec.homepage = "http://visdiff.com/"
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_dependency "faraday"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: visdiff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - John Hawthorn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
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.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Visual diff tool - visdiff.com
56
+ email:
57
+ - john.hawthorn@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
+ - lib/visdiff.rb
68
+ - lib/visdiff/client.rb
69
+ - lib/visdiff/config.rb
70
+ - lib/visdiff/image.rb
71
+ - lib/visdiff/revision.rb
72
+ - lib/visdiff/version.rb
73
+ - visdiff.gemspec
74
+ homepage: http://visdiff.com/
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.5
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Visual diff tool - visdiff.com
98
+ test_files: []