pinterest-share 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.
@@ -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
@@ -0,0 +1 @@
1
+ 1.9.3-p125
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pinterest-share.gemspec
4
+ gemspec
@@ -0,0 +1,6 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Maurizio De Magnis
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.
@@ -0,0 +1,51 @@
1
+ # Pinterest Share
2
+
3
+ Create a share url for Pinterest.
4
+
5
+ ## Pinterest documentation
6
+
7
+ [Pin It Button for Web Sites](http://pinterest.com/about/goodies/)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'pinterest-share'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install pinterest-share
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'pinterest_share'
27
+ options = {
28
+ url: 'http://red-object.net',
29
+ media: 'http://a1.twimg.com/profile_images/1288708278/2010_tron_legacy-wide_normal.jpg'
30
+ }
31
+ PinterestShare::Generation.new(options).to_s
32
+ => "http://pinterest.com/pin/create/button/?url=http%3A%2F%2Fred-object.net&media=http%3A%2F%2Fa1.twimg.com%2Fprofile_images%2F1288708278%2F2010_tron_legacy-wide_normal.jpg"
33
+ ```
34
+
35
+ ## Test
36
+
37
+ ```shell
38
+ $ guard
39
+ ```
40
+
41
+ ## Support
42
+
43
+ At the moment it only supports Ruby >= 1.9.
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ require 'uri'
2
+ require "pinterest_share/version"
3
+ require "pinterest_share/generation"
4
+ require "pinterest_share/errors"
5
+ require 'pinterest_share/configuration'
6
+
7
+ module PinterestShare
8
+ end
@@ -0,0 +1,16 @@
1
+ module PinterestShare
2
+
3
+ ALLOWED_FIELDS = %w[
4
+ description
5
+ media
6
+ url
7
+ ].map(&:to_sym)
8
+
9
+ REQUIRED_FIELDS = %w[
10
+ media
11
+ url
12
+ ].map(&:to_sym)
13
+
14
+ BASE_PATH = 'http://pinterest.com/pin/create/button/?'
15
+
16
+ end
@@ -0,0 +1,4 @@
1
+ module PinterestShare
2
+ class InvalidHttpUrl < Exception
3
+ end
4
+ end
@@ -0,0 +1,48 @@
1
+ module PinterestShare
2
+ class Generation
3
+ def initialize(options)
4
+ @options = options
5
+ @url = url_for
6
+ end
7
+
8
+ def to_s
9
+ @url
10
+ end
11
+
12
+ private
13
+ def url_for
14
+ filter!
15
+ validate
16
+ generate
17
+ end
18
+
19
+ def generate
20
+ BASE_PATH + URI.encode_www_form(@options)
21
+ end
22
+
23
+ def filter!
24
+ @options.select! do |key|
25
+ ALLOWED_FIELDS.include? key
26
+ end
27
+ end
28
+
29
+ def validate
30
+ validate_required
31
+ validate_format
32
+ end
33
+
34
+ def validate_required
35
+ required_fields_missing = REQUIRED_FIELDS - @options.keys
36
+ if required_fields_missing.size > 0
37
+ raise ArgumentError, "Required fields not specified: #{required_fields_missing.join(', ')}"
38
+ end
39
+ end
40
+
41
+ def validate_format
42
+ REQUIRED_FIELDS.each do |field|
43
+ raise InvalidHttpUrl unless @options[field] =~ URI.regexp(['http'])
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module PinterestShare
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/pinterest_share/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Maurizio De Magnis"]
6
+ gem.email = ["maurizio.demagnis@gmail.com"]
7
+ gem.description = %q{Sharing url for Pinterest}
8
+ gem.summary = %q{It creates sharing url given the necessary attributes.}
9
+ gem.homepage = ""
10
+
11
+ gem.add_development_dependency 'rspec'
12
+ gem.add_development_dependency 'guard-rspec'
13
+ gem.add_development_dependency 'growl'
14
+
15
+ gem.files = `git ls-files`.split($\)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.name = "pinterest-share"
19
+ gem.require_paths = ["lib"]
20
+ gem.version = PinterestShare::VERSION
21
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ module PinterestShare
4
+ describe Generation do
5
+ describe '.new' do
6
+
7
+ it "should require the necessary fields" do
8
+ expect { Generation.new }.to raise_error(ArgumentError)
9
+ expect { Generation.new(foo: 'bar') }.to raise_error(ArgumentError)
10
+ end
11
+
12
+ context "when passing the necessary fields" do
13
+ it 'should require them to be valid HTTP URLs' do
14
+ options = REQUIRED_FIELDS.each_with_object({}) do |field, memo|
15
+ memo[field] = 'foo'
16
+ end
17
+ expect { Generation.new(options) }.to raise_error(InvalidHttpUrl)
18
+ end
19
+ end
20
+
21
+ it "should use only the allowed fields" do
22
+ options = REQUIRED_FIELDS.each_with_object({}) do |field, memo|
23
+ memo[field] = 'http://www.foo.com'
24
+ end
25
+ options[:foo] = 'bar'
26
+ generated_url = Generation.new(options).to_s
27
+ generated_query = URI.parse(generated_url).query
28
+ generated_parameters = URI.decode_www_form(generated_query).map do |item|
29
+ item.first.to_sym
30
+ end
31
+ (generated_parameters - ALLOWED_FIELDS).should eq([])
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ module PinterestShare
4
+ end
@@ -0,0 +1 @@
1
+ require 'pinterest_share'
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pinterest-share
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Maurizio De Magnis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70126017908180 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70126017908180
25
+ - !ruby/object:Gem::Dependency
26
+ name: guard-rspec
27
+ requirement: &70126017907760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70126017907760
36
+ - !ruby/object:Gem::Dependency
37
+ name: growl
38
+ requirement: &70126017907340 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70126017907340
47
+ description: Sharing url for Pinterest
48
+ email:
49
+ - maurizio.demagnis@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rbenv-version
56
+ - Gemfile
57
+ - Guardfile
58
+ - LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ - lib/pinterest_share.rb
62
+ - lib/pinterest_share/configuration.rb
63
+ - lib/pinterest_share/errors.rb
64
+ - lib/pinterest_share/generation.rb
65
+ - lib/pinterest_share/version.rb
66
+ - pinterest_share.gemspec
67
+ - spec/pinterest_share/generation_spec.rb
68
+ - spec/pinterest_share_spec.rb
69
+ - spec/spec_helper.rb
70
+ homepage: ''
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.11
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: It creates sharing url given the necessary attributes.
94
+ test_files:
95
+ - spec/pinterest_share/generation_spec.rb
96
+ - spec/pinterest_share_spec.rb
97
+ - spec/spec_helper.rb