thumbs_yup 0.1.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: 1adab547f4675b1dd8da06175ff6013a9dbac7fe
4
+ data.tar.gz: fe8d9a8815a43c696ed42c8e505796af5e6c8aab
5
+ SHA512:
6
+ metadata.gz: fd39d1e16f3262f8aa10a7d97ed7dfd0f003319dc487f08333d06e0556d0619d0e1cdd87d0f9416dd866f777e1d33b6264b2ac6dec7bec52ce2d01ebc55bb7cd
7
+ data.tar.gz: 982da90fe7d1e4bae2653ab5995e24451e5581ea918e535ae88d078649d86929883630f642a8139b39d7e9811cdd7f1c3d10632a76a0671c8de35ea2b97c70e7
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.14.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in thumbs_yup.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 ThumbsYup, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # ThumbsYup
2
+
3
+ Tools for integrating with the thumbsyup.com web services.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'thumbs_yup'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install thumbs_yup
20
+
21
+ ## Usage
22
+
23
+ Create an initializer: `config/initializers/thumbs_yup_init.rb`
24
+
25
+ ```
26
+ ThumbsYup.configure do |config|
27
+ config.user_identifier = "your-thumbsyup-website-identifier"
28
+
29
+ #INFO: The rest of these are defaults
30
+ #config.thumbs_yup_url = "http://www.thumbsyup.com"
31
+ #config.review_style = "bubble"
32
+ #config.review_color = "blue"
33
+ #config.review_background = "hollow"
34
+ #config.review_size = "med"
35
+ end
36
+ ```
37
+
38
+ Place in your template:
39
+
40
+ ```
41
+ <%= ThumbsYup::ServerEmbed.render_public_reviews(page: params[:page]) %>
42
+ ```
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "thumbs_yup"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ module ThumbsYup
2
+ class Configuration
3
+ attr_accessor :user_identifier
4
+ attr_accessor :review_style
5
+ attr_accessor :review_color
6
+ attr_accessor :review_background
7
+ attr_accessor :review_size
8
+ attr_accessor :thumbs_yup_url
9
+
10
+ def initialize
11
+ @review_style = 'bubble'
12
+ @review_color = 'blue'
13
+ @review_background = 'hollow'
14
+ @review_size = 'med'
15
+ @thumbs_yup_url = 'http://www.thumbsyup.com'
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ <script type='text/javascript'>
2
+ window.thumbsYup = {
3
+ settings: {
4
+ reviewStyle: <%= "'#{settings[:review_style]}'" %>,
5
+ reviewColor: <%= "'#{settings[:review_color]}'" %>,
6
+ reviewBackground: <%= "'#{settings[:review_background]}'" %>,
7
+ reviewSize: <%= "'#{settings[:review_size]}'" %>,
8
+ thumbsYupUrl: <%= "'#{settings[:thumbs_yup_url]}'" %>
9
+ },
10
+ pagination: {
11
+ currentPage: <%= "#{pagination[:current_page]}" %>,
12
+ totalCount: <%= "#{pagination[:total_count]}" %>,
13
+ perPage: <%= "#{pagination[:per_page]}" %>
14
+ }
15
+ }
16
+ </script>
17
+ <div class="thumbsYup">
18
+ <div class="pagination">
19
+ </div>
20
+ <%= reviews_html %>
21
+ </div>
22
+ <script type='text/javascript' src=<%= "'#{settings[:thumbs_yup_url]}" %>/assets/thumbs-yup-client.js'></script>
@@ -0,0 +1,82 @@
1
+ module ThumbsYup
2
+ module ServerEmbed
3
+ class << self
4
+ require 'net/http'
5
+ require 'json'
6
+ require_relative 'template_renderer'
7
+
8
+ def render_public_reviews(page: nil)
9
+ check_user_identifer!
10
+
11
+ reviews_html = ""
12
+
13
+ review_data = json_review_data(page: page)
14
+ reviews = review_data["reviews"]
15
+ metadata = review_data["metadata"]
16
+
17
+ reviews.each do |review|
18
+ reviews_html += decorate(review)
19
+ end
20
+
21
+ html = TemplateRenderer::render_page(
22
+ settings: settings,
23
+ pagination: pagination(metadata),
24
+ reviews_html: reviews_html
25
+ )
26
+
27
+ html.html_safe
28
+ end
29
+
30
+ private
31
+
32
+ def check_user_identifer!
33
+ if ThumbsYup.configuration.user_identifier.nil?
34
+ raise <<-EOS
35
+ Create your user_identifier in: config/initializers/thumbs_yup_init.rb
36
+ ThumbsYup.configure do |config|
37
+ config.user_identifier = "your-website-identifier"
38
+ end
39
+ EOS
40
+ end
41
+ end
42
+
43
+ def json_review_data(page:)
44
+ url = ThumbsYup.configuration.thumbs_yup_url + '/site/' + ThumbsYup.configuration.user_identifier
45
+
46
+ uri = URI.parse(url)
47
+ params = { :page => page }
48
+ uri.query = URI.encode_www_form(params)
49
+
50
+ request = Net::HTTP::Get.new(uri.request_uri)
51
+ request["User-Agent"] = "My User Agent"
52
+ request["Accept"] = "application/json"
53
+
54
+ http = Net::HTTP.new(uri.host, uri.port)
55
+ response = http.request(request)
56
+ JSON.parse(response.body)
57
+ end
58
+
59
+ def decorate(json_review)
60
+ TemplateRenderer::render_review(json_review)
61
+ end
62
+
63
+ def settings
64
+ {
65
+ review_style: ThumbsYup.configuration.review_style,
66
+ review_color: ThumbsYup.configuration.review_color,
67
+ review_background: ThumbsYup.configuration.review_background,
68
+ review_size: ThumbsYup.configuration.review_size,
69
+ thumbs_yup_url: ThumbsYup.configuration.thumbs_yup_url
70
+ }
71
+ end
72
+
73
+ def pagination(metadata)
74
+ {
75
+ current_page: metadata["current_page"],
76
+ total_count: metadata["total_count"],
77
+ per_page: metadata["per_page"]
78
+ }
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,26 @@
1
+ require 'erb'
2
+ require 'ostruct'
3
+
4
+ class TemplateRenderer < OpenStruct
5
+ def self.render_review(vars)
6
+ style = ThumbsYup.configuration.review_style
7
+ background = ThumbsYup.configuration.review_background
8
+ template_file = style + "_" + background + ".erb"
9
+
10
+ template = File.read(
11
+ File.join(File.dirname(__FILE__), 'templates', template_file)
12
+ )
13
+ TemplateRenderer.new(vars).render(template)
14
+ end
15
+
16
+ def self.render_page(vars)
17
+ template = File.read(
18
+ File.join(File.dirname(__FILE__), 'reviews.erb')
19
+ )
20
+ TemplateRenderer.new(vars).render(template)
21
+ end
22
+
23
+ def render(template)
24
+ ERB.new(template).result(binding)
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ <div class="review<%= ThumbsYup.configuration.review_size.capitalize %>">
2
+ <div class="rstyle<%= ThumbsYup.configuration.review_color.capitalize + ThumbsYup.configuration.review_style.capitalize + ThumbsYup.configuration.review_background.capitalize %>">
3
+ <%= CGI::escapeHTML(body) %>
4
+ </div>
5
+ <p class="signature">
6
+ <%= CGI::escapeHTML(first_name) %>
7
+ </p>
8
+ </div>
@@ -0,0 +1,3 @@
1
+ module ThumbsYup
2
+ VERSION = "0.1.1"
3
+ end
data/lib/thumbs_yup.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "thumbs_yup/version"
2
+ require 'thumbs_yup/configuration'
3
+ require 'thumbs_yup/server_embed'
4
+
5
+ module ThumbsYup
6
+ class << self
7
+ def configure(&block)
8
+ yield(configuration)
9
+ configuration
10
+ end
11
+
12
+ def configuration
13
+ @_configuration ||= Configuration.new
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'thumbs_yup/version'
6
+ require 'thumbs_yup/configuration'
7
+ require 'thumbs_yup'
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.name = "thumbs_yup"
11
+ spec.version = ThumbsYup::VERSION
12
+ spec.authors = ["Jomana Malone", "Scott Malone"]
13
+ spec.email = ["jomana.malone@gmail.com", "scottmalone101@gmail.com"]
14
+
15
+ spec.summary = %q{ThumbsYup review integration.}
16
+ spec.description = %q{Creates the HTML, styling, javascript and review data necessary to embed reviews in a website.}
17
+ spec.homepage = "https://github.com/jojomalone/thumbs_yup"
18
+ spec.license = "MIT"
19
+
20
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
21
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
22
+ if spec.respond_to?(:metadata)
23
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
30
+ f.match(%r{^(test|spec|features)/})
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.14"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thumbs_yup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jomana Malone
8
+ - Scott Malone
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2017-04-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.14'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.14'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ description: Creates the HTML, styling, javascript and review data necessary to embed
57
+ reviews in a website.
58
+ email:
59
+ - jomana.malone@gmail.com
60
+ - scottmalone101@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".rspec"
67
+ - ".travis.yml"
68
+ - Gemfile
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - lib/thumbs_yup.rb
75
+ - lib/thumbs_yup/configuration.rb
76
+ - lib/thumbs_yup/reviews.erb
77
+ - lib/thumbs_yup/server_embed.rb
78
+ - lib/thumbs_yup/template_renderer.rb
79
+ - lib/thumbs_yup/templates/bubble_hollow.erb
80
+ - lib/thumbs_yup/version.rb
81
+ - thumbs_yup.gemspec
82
+ homepage: https://github.com/jojomalone/thumbs_yup
83
+ licenses:
84
+ - MIT
85
+ metadata:
86
+ allowed_push_host: https://rubygems.org
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.8
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: ThumbsYup review integration.
107
+ test_files: []