peepshot 0.0.2

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "rspec", "~> 2.6.0"
5
+ gem "bundler", "~> 1.0.0"
6
+ gem "jeweler", "~> 1.5.2"
7
+ gem "rcov", ">= 0"
8
+ gem "rdoc"
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Anders Toxboe
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ PeepShot
2
+ ===========
3
+
4
+ Provides rails helpers for interfacing with [PeepShot](http://peepshot.com).
5
+
6
+ Example
7
+ -------
8
+
9
+ 0- Prerequisite: You need a peepshot.com account. Have your API Key and API Secret handy.
10
+
11
+ 1- Install peepshot as a gem in your rails app.
12
+
13
+ 2- Create `config/peepshot.yml` with the appropriate environment.
14
+
15
+ production:
16
+ api_key: <your API key>
17
+ api_secret: <your API secret>
18
+
19
+ 3- Create `config/initializers/peepshot.rb` and place the following line in it
20
+
21
+ PeepShot.load_peepshot_yaml
22
+
23
+ Contributing
24
+ ------------
25
+
26
+ Unit tests use rspec and require the following environment configuration to run:
27
+ rails 2.3.10
28
+ rspec 1.3.1
29
+ rspec-rails 1.3.3
30
+ json 1.4.0
31
+
32
+ Invoke tests on Mac/Linux by running `rake spec` from this directory
33
+
34
+ Invoke tests on Windows by running `spec spec/` from this directory
35
+
36
+ Copyright (c) 2012 Anders Toxboe, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "peepshot"
18
+ gem.homepage = "https://github.com/PeepShot/peepshot"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{PeepShot URL and view helpers}
21
+ gem.description = %Q{Use this gem in your rails applications to capture thumbnail screenshots through the PeepShot API}
22
+ gem.email = "info@ui-patterns.com"
23
+ gem.authors = ["Anders Toxboe"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "peepshot #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,13 @@
1
+ module PeepShot
2
+ module Rails
3
+ module Helpers
4
+ module ImageTags
5
+ def peepshot_image_tag(url, options)
6
+ width = find_width(options).to_s.downcase == 'original' ? 1024 : find_width(options)
7
+ height = find_height(options)
8
+ image_tag(peepshot_url(url, options), :width => width, :height => height)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,56 @@
1
+ require 'uri'
2
+ require 'cgi'
3
+ require 'digest'
4
+
5
+ module PeepShot
6
+ module Rails
7
+ module Helpers
8
+ class InvalidDimensions < Exception; end
9
+ include ImageTags
10
+
11
+ def peepshot_url(url, options)
12
+ options = {:width => 200,
13
+ :height => nil
14
+ }.merge(options)
15
+
16
+ host = 'api.peepshot.com'
17
+ token = Digest::MD5.hexdigest(PeepShot.api_secret + url)
18
+ dimensions = build_dimensions_string(options)
19
+
20
+ URI.escape("http://#{host}/v1/#{PeepShot.api_key}/#{token}/#{dimensions}?url=#{url}")
21
+ end
22
+
23
+ def build_dimensions_string(options)
24
+ width = find_width(options)
25
+ height = find_height(options)
26
+
27
+ dimensions_string = height ? "#{width}x#{height}" : "#{width}"
28
+ /[\dx]+|original/i =~ dimensions_string ? dimensions_string : raise_invalid_dimensions
29
+ end
30
+
31
+ def find_width(options)
32
+ if options[:width].to_s.downcase == 'original'
33
+ 'original'
34
+ elsif options[:width].to_i < 10
35
+ raise_invalid_dimensions
36
+ elsif options[:width].to_i > 1024
37
+ raise_invalid_dimensions
38
+ else
39
+ options[:width].to_i
40
+ end
41
+ end
42
+
43
+ def find_height(options)
44
+ if options[:height] && options[:height].to_i > 10 && options[:height].to_i < 2000
45
+ options[:height].to_i
46
+ else
47
+ nil
48
+ end
49
+ end
50
+
51
+ def raise_invalid_dimensions
52
+ raise InvalidDimensions.new("The dimensions you provided was not valid. The width must be a number between 10 and 1024 or the string 'original'. Height must be a number.")
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,4 @@
1
+ module PeepShot
2
+ module Rails
3
+ end
4
+ end
data/lib/peepshot.rb ADDED
@@ -0,0 +1,35 @@
1
+ module PeepShot
2
+ class NotConfigured < Exception; end
3
+ class << self
4
+ attr_accessor :api_key, :api_secret
5
+ end
6
+
7
+ def self.api_key
8
+ @api_key || raise_unconfigured_exception
9
+ end
10
+
11
+ def self.api_secret
12
+ @api_secret || raise_unconfigured_exception
13
+ end
14
+
15
+ def self.raise_unconfigured_exception
16
+ raise NotConfigured.new("No configuration provided for PeepShot. Either set the api_key and api_secret or call PeepShot.load_peepshot_yaml in an initializer")
17
+ end
18
+
19
+ def self.configuration=(hash)
20
+ self.api_key = hash[:api_key]
21
+ self.api_secret = hash[:api_secret]
22
+ end
23
+
24
+ def self.load_peepshot_yaml
25
+ config = (YAML.load(ERB.new(File.read(File.join(::Rails.root,"config","peepshot.yml"))).result)[::Rails.env])
26
+ raise NotConfigured.new("Unable to load configuration for #{::Rails.env} from peepshot.yml. Is it set up?") if config.nil?
27
+ self.configuration = config.with_indifferent_access
28
+ end
29
+ end
30
+
31
+ require "peepshot/rails/helpers/image_tags"
32
+ require "peepshot/rails/helpers"
33
+ require "peepshot/rails"
34
+
35
+ ActionView::Base.send :include, PeepShot::Rails::Helpers if defined? ActionView
data/peepshot.gemspec ADDED
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "peepshot"
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Anders Toxboe"]
12
+ s.date = "2012-02-14"
13
+ s.description = "Use this gem in your rails applications to capture thumbnail screenshots through the PeepShot API"
14
+ s.email = "info@ui-patterns.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "LICENSE.txt",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/peepshot.rb",
27
+ "lib/peepshot/rails.rb",
28
+ "lib/peepshot/rails/helpers.rb",
29
+ "lib/peepshot/rails/helpers/image_tags.rb",
30
+ "peepshot.gemspec",
31
+ "test/helper.rb",
32
+ "test/test_peepshot.rb"
33
+ ]
34
+ s.homepage = "https://github.com/PeepShot/peepshot"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.15"
38
+ s.summary = "PeepShot URL and view helpers"
39
+ s.test_files = [
40
+ "test/helper.rb",
41
+ "test/test_peepshot.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
49
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
51
+ s.add_development_dependency(%q<rcov>, [">= 0"])
52
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<rspec>, ["~> 2.6.0"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
57
+ s.add_dependency(%q<rcov>, [">= 0"])
58
+ s.add_dependency(%q<rdoc>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<rspec>, ["~> 2.6.0"])
62
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
64
+ s.add_dependency(%q<rcov>, [">= 0"])
65
+ s.add_dependency(%q<rdoc>, [">= 0"])
66
+ end
67
+ end
68
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'peepshot'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestPeepshot < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peepshot
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Anders Toxboe
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-14 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ hash: 23
27
+ segments:
28
+ - 2
29
+ - 6
30
+ - 0
31
+ version: 2.6.0
32
+ name: rspec
33
+ prerelease: false
34
+ type: :development
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 23
43
+ segments:
44
+ - 1
45
+ - 0
46
+ - 0
47
+ version: 1.0.0
48
+ name: bundler
49
+ prerelease: false
50
+ type: :development
51
+ requirement: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 7
59
+ segments:
60
+ - 1
61
+ - 5
62
+ - 2
63
+ version: 1.5.2
64
+ name: jeweler
65
+ prerelease: false
66
+ type: :development
67
+ requirement: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ name: rcov
79
+ prerelease: false
80
+ type: :development
81
+ requirement: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ version_requirements: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ name: rdoc
93
+ prerelease: false
94
+ type: :development
95
+ requirement: *id005
96
+ description: Use this gem in your rails applications to capture thumbnail screenshots through the PeepShot API
97
+ email: info@ui-patterns.com
98
+ executables: []
99
+
100
+ extensions: []
101
+
102
+ extra_rdoc_files:
103
+ - LICENSE.txt
104
+ - README.md
105
+ files:
106
+ - .document
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - VERSION
112
+ - lib/peepshot.rb
113
+ - lib/peepshot/rails.rb
114
+ - lib/peepshot/rails/helpers.rb
115
+ - lib/peepshot/rails/helpers/image_tags.rb
116
+ - peepshot.gemspec
117
+ - test/helper.rb
118
+ - test/test_peepshot.rb
119
+ homepage: https://github.com/PeepShot/peepshot
120
+ licenses:
121
+ - MIT
122
+ post_install_message:
123
+ rdoc_options: []
124
+
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ hash: 3
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ hash: 3
142
+ segments:
143
+ - 0
144
+ version: "0"
145
+ requirements: []
146
+
147
+ rubyforge_project:
148
+ rubygems_version: 1.8.15
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: PeepShot URL and view helpers
152
+ test_files:
153
+ - test/helper.rb
154
+ - test/test_peepshot.rb