settlebox 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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +94 -0
- data/Rakefile +11 -0
- data/lib/settlebox.rb +29 -0
- data/lib/settlebox/crypt.rb +23 -0
- data/lib/settlebox/railtie.rb +7 -0
- data/lib/settlebox/version.rb +4 -0
- data/lib/settlebox/view_helpers.rb +68 -0
- data/settlebox.gemspec +22 -0
- data/test/lib/settlebox/config_test.rb +49 -0
- data/test/lib/settlebox/crypt_test.rb +10 -0
- data/test/lib/settlebox/version_test.rb +7 -0
- data/test/lib/settlebox/view_helper_test.rb +37 -0
- data/test/test_helper.rb +3 -0
- metadata +98 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Johan Gyllenspetz
|
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,94 @@
|
|
1
|
+
# Settlebox
|
2
|
+
|
3
|
+
Rails view helpers for easy integration with the SettleBox API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your Gemfile:
|
8
|
+
|
9
|
+
gem 'settlebox'
|
10
|
+
|
11
|
+
The run:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
## Configuration
|
16
|
+
|
17
|
+
When you signup for SettleBox you will recieve an API_KEY and an API_SECRET. Put these in an initializer for your application.
|
18
|
+
|
19
|
+
#config/initializers/settlebox.rb
|
20
|
+
require 'settlebox'
|
21
|
+
Settlebox.config do |config|
|
22
|
+
config.api_key = "API_KEY"
|
23
|
+
config.api_secret = "API_SECRET"
|
24
|
+
config.lang = :en # This optional currently :en and :sv are supported, :en is default
|
25
|
+
end
|
26
|
+
|
27
|
+
After this you are ready to go.
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
The gem comes with a couple of helpers that helps you include the SettleBox widget.
|
32
|
+
For a more fancy description of the API with interactive guides see [SettleBox homepage](https://settlebox.com/partner/api).
|
33
|
+
|
34
|
+
### Javascript
|
35
|
+
|
36
|
+
Include the javascript tag on any page that you want to make use of the SettleBox profile.
|
37
|
+
|
38
|
+
= settlebox_include_tag
|
39
|
+
|
40
|
+
### View helpers
|
41
|
+
|
42
|
+
|
43
|
+
#### Signup
|
44
|
+
|
45
|
+
Include this on the users settings profile page.
|
46
|
+
|
47
|
+
= settlebox_card_tag('demo_full@settlebox.com')
|
48
|
+
|
49
|
+
#### Reputation
|
50
|
+
|
51
|
+
Include this where you have more space and want to show the complete SettleBox profile of the user.
|
52
|
+
|
53
|
+
= settlebox_reputation_tag('demo_full@settlebox.com')
|
54
|
+
|
55
|
+
#### Listing (Cube)
|
56
|
+
|
57
|
+
This is the SettleBox cube which has an hoovering effect. Use this where you have alot of items in a list.
|
58
|
+
|
59
|
+
# href tells SettleBox where to go if the cube is clicked
|
60
|
+
= settlebox_listing_tag('demo_full@settlebox.com', href="https://settlebox.com)
|
61
|
+
|
62
|
+
## Debugging
|
63
|
+
|
64
|
+
To easily try out the SettleBox gem and API. There exists a demo user. The demo user has the following email address
|
65
|
+
|
66
|
+
# Replace the * depending on how much information you want the profile to show
|
67
|
+
demo_*@settlebox.com
|
68
|
+
|
69
|
+
# Examples
|
70
|
+
|
71
|
+
# Will show a profile of a user that has connected everything there is to connect.
|
72
|
+
demo_full@settlebox.com
|
73
|
+
|
74
|
+
# Will show a user that only has connected facebook
|
75
|
+
demo_fb@settlebox.com
|
76
|
+
|
77
|
+
# Will show a user with an avatar, ebay and twitter
|
78
|
+
demo_av_eb_tw@settlebox.com
|
79
|
+
|
80
|
+
Supported options for the demo user are.
|
81
|
+
|
82
|
+
* av = Avatar
|
83
|
+
* fb = Facebook
|
84
|
+
* tw = Twitter
|
85
|
+
* li = LinkedIn
|
86
|
+
* eb = Ebay
|
87
|
+
* tr = Tradera
|
88
|
+
* pe = Percent of good ratings
|
89
|
+
* to = Total number of ratings
|
90
|
+
* aa = Total number of listings the user have
|
91
|
+
|
92
|
+
## More on SettleBox
|
93
|
+
|
94
|
+
For more information about SettleBox please refer to our homepage [SettleBox homepage](https://settlebox.com/partner).
|
data/Rakefile
ADDED
data/lib/settlebox.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "settlebox/version"
|
2
|
+
require "settlebox/crypt"
|
3
|
+
require "settlebox/view_helpers"
|
4
|
+
require 'settlebox/railtie' if defined?(Rails::Railtie)
|
5
|
+
|
6
|
+
module Settlebox
|
7
|
+
class SettleboxError < StandardError;end
|
8
|
+
class SettleboxConfigError < SettleboxError;end
|
9
|
+
|
10
|
+
class Configuration
|
11
|
+
attr_accessor :api_key, :api_secret, :language, :url
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
self.language = 'en'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configuration
|
19
|
+
@configuration ||= Configuration.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.config
|
23
|
+
yield(configuration) if block_given?
|
24
|
+
|
25
|
+
raise SettleboxConfigError.new("api_key can't be blank") if @configuration.api_key == nil
|
26
|
+
raise SettleboxConfigError.new("api_secret needs to be 64 charachters long") if @configuration.api_secret.length != 64
|
27
|
+
raise SettleboxConfigError.new("language not supported") unless [:en, :sv].include?(@configuration.language)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'digest/md5'
|
3
|
+
require 'openssl'
|
4
|
+
|
5
|
+
module Settlebox
|
6
|
+
module Crypt
|
7
|
+
# http://jdwyah.blogspot.se/2009/12/decrypting-ruby-aes-encryption.html
|
8
|
+
def self.encrypt(string, key)
|
9
|
+
Base64.encode64(aes(key, string)).gsub /\s/, ''
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.aes(key, string)
|
13
|
+
key = Array(key).pack 'H*'
|
14
|
+
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
15
|
+
cipher.encrypt
|
16
|
+
cipher.key = key
|
17
|
+
cipher.iv = initialization_vector = cipher.random_iv
|
18
|
+
cipher_text = cipher.update(string)
|
19
|
+
cipher_text << cipher.final
|
20
|
+
return initialization_vector + cipher_text
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
unless defined?(Rails)
|
2
|
+
class String
|
3
|
+
def html_safe
|
4
|
+
self
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module Settlebox
|
10
|
+
module ViewHelpers
|
11
|
+
def settlebox_include_tag(async=true)
|
12
|
+
ret = ""
|
13
|
+
|
14
|
+
api_key = Settlebox.configuration.api_key
|
15
|
+
language = Settlebox.configuration.language
|
16
|
+
api_version = Settlebox::API_VERSION
|
17
|
+
|
18
|
+
url = Settlebox.configuration.url ? Settlebox.configuration.url : "https://settlebox.com"
|
19
|
+
src = "#{url}/assets/widgets/reputation.js";
|
20
|
+
|
21
|
+
ret += "\n<script>\n";
|
22
|
+
ret += "(function(w,d,t,u,o,k,l,v,e,p){";
|
23
|
+
ret += "w[o]=w[o]||{};";
|
24
|
+
ret += "w[o].key=k;";
|
25
|
+
ret += "w[o].lang=l;";
|
26
|
+
ret += "w[o].ver=v;";
|
27
|
+
ret += "e=d.createElement(t);";
|
28
|
+
ret += "p=d.getElementsByTagName(t)[0];";
|
29
|
+
if async
|
30
|
+
ret += "e.async=1;";
|
31
|
+
else
|
32
|
+
ret += "w[o].sync=!0;";
|
33
|
+
end
|
34
|
+
ret += "e.src=u;";
|
35
|
+
ret += "p.parentNode.insertBefore(e,p);";
|
36
|
+
ret += "}(window,document,'script','#{src}','SB','#{api_key}', '#{language}', '#{api_version}'));";
|
37
|
+
ret += "\n</script>\n";
|
38
|
+
|
39
|
+
ret.html_safe
|
40
|
+
end
|
41
|
+
|
42
|
+
def settlebox_reputation_tag(email)
|
43
|
+
demail = crypt_email(email)
|
44
|
+
"<div id='settlebox-reputation' data-sb-email='#{demail}'></div>".html_safe
|
45
|
+
end
|
46
|
+
|
47
|
+
def settlebox_listing_tag(email, href = false)
|
48
|
+
demail = crypt_email(email)
|
49
|
+
href = href ? href : "https://settlebox.com"
|
50
|
+
"<div class='settlebox-listing' data-sb-email='#{demail}' data-sb-href='#{href}'></div>".html_safe
|
51
|
+
end
|
52
|
+
|
53
|
+
def settlebox_card_tag(email)
|
54
|
+
demail = crypt_email(email)
|
55
|
+
|
56
|
+
unless email =~ /^demo_.*@settlebox.com$/
|
57
|
+
"<div class='settlebox-card' data-sb-email='#{demail}' data-sb-email-plain=#{email}></div>".html_safe
|
58
|
+
else
|
59
|
+
"<div class='settlebox-card' data-sb-demo='true'></div>".html_safe
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
def crypt_email(email)
|
65
|
+
Settlebox::Crypt.encrypt(email, Settlebox.configuration.api_secret)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/settlebox.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'settlebox/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "settlebox"
|
8
|
+
spec.version = Settlebox::VERSION
|
9
|
+
spec.authors = ["Johan Gyllenspetz"]
|
10
|
+
spec.email = ["johan.gyllenspetz@gmail.com"]
|
11
|
+
spec.description = %q{SettleBox}
|
12
|
+
spec.summary = %q{Easy integration with the SettleBox API}
|
13
|
+
spec.homepage = "https://github.com/popgiro/settlebox-rails"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
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_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Settlebox do
|
4
|
+
let(:api_key) {"api_key"}
|
5
|
+
let(:api_secret) {"0123456789012345678901234567890123456789012345678901234567891234"}
|
6
|
+
let(:language) {:en}
|
7
|
+
|
8
|
+
it "shoulde be able to configure" do
|
9
|
+
Settlebox.config do |config|
|
10
|
+
config.api_key = api_key
|
11
|
+
config.api_secret = api_secret
|
12
|
+
config.language = language
|
13
|
+
end
|
14
|
+
|
15
|
+
assert_equal Settlebox.configuration.api_key, api_key
|
16
|
+
assert_equal Settlebox.configuration.api_secret, api_secret
|
17
|
+
assert_equal Settlebox.configuration.language, language
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise error if no api key" do
|
21
|
+
assert_raises Settlebox::SettleboxConfigError do
|
22
|
+
Settlebox.config do |config|
|
23
|
+
config.api_secret = api_secret
|
24
|
+
config.api_key = nil
|
25
|
+
config.language = language
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should raise error if api_secret is to short" do
|
31
|
+
assert_raises Settlebox::SettleboxConfigError do
|
32
|
+
Settlebox.config do |config|
|
33
|
+
config.api_secret = "7005h0r7"
|
34
|
+
config.api_key = api_key
|
35
|
+
config.language = language
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should raise error if language not supported" do
|
41
|
+
assert_raises Settlebox::SettleboxConfigError do
|
42
|
+
Settlebox.config do |config|
|
43
|
+
config.api_secret = api_secret
|
44
|
+
config.api_key = api_key
|
45
|
+
config.language = :xx
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Settlebox do
|
4
|
+
let(:key) {"B374A26A71490437AA024E4FADD5B497FDFF1A8EA6FF12F6FB65AF2720B59CCF"}
|
5
|
+
let(:string) {"settlebox@example.com"}
|
6
|
+
|
7
|
+
it "be able to crypt" do
|
8
|
+
Settlebox::Crypt.encrypt(string, key).wont_be_nil
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
class SBHelper
|
4
|
+
include Settlebox::ViewHelpers
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Settlebox do
|
8
|
+
let(:email) {"settlebox@example.com"}
|
9
|
+
let(:sb) {SBHelper.new}
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
Settlebox.config do |config|
|
13
|
+
config.api_key = "7569373564584bc684648202838737"
|
14
|
+
config.api_secret = "B374A26A71490437AA024E4FADD5B497FDFF1A8EA6FF12F6FB65AF2720B59CCF"
|
15
|
+
config.language = :en
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should generate card tag" do
|
20
|
+
sb.settlebox_card_tag(email)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should generate reputation tag" do
|
24
|
+
sb.settlebox_reputation_tag(email)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should generate listing tag" do
|
28
|
+
sb.settlebox_listing_tag(email)
|
29
|
+
sb.settlebox_listing_tag(email, "/test")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should generate include tag" do
|
33
|
+
sb.settlebox_include_tag
|
34
|
+
sb.settlebox_include_tag(false)
|
35
|
+
sb.settlebox_include_tag(true)
|
36
|
+
end
|
37
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: settlebox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Johan Gyllenspetz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: SettleBox
|
47
|
+
email:
|
48
|
+
- johan.gyllenspetz@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/settlebox.rb
|
59
|
+
- lib/settlebox/crypt.rb
|
60
|
+
- lib/settlebox/railtie.rb
|
61
|
+
- lib/settlebox/version.rb
|
62
|
+
- lib/settlebox/view_helpers.rb
|
63
|
+
- settlebox.gemspec
|
64
|
+
- test/lib/settlebox/config_test.rb
|
65
|
+
- test/lib/settlebox/crypt_test.rb
|
66
|
+
- test/lib/settlebox/version_test.rb
|
67
|
+
- test/lib/settlebox/view_helper_test.rb
|
68
|
+
- test/test_helper.rb
|
69
|
+
homepage: https://github.com/popgiro/settlebox-rails
|
70
|
+
licenses: []
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.8.24
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Easy integration with the SettleBox API
|
93
|
+
test_files:
|
94
|
+
- test/lib/settlebox/config_test.rb
|
95
|
+
- test/lib/settlebox/crypt_test.rb
|
96
|
+
- test/lib/settlebox/version_test.rb
|
97
|
+
- test/lib/settlebox/view_helper_test.rb
|
98
|
+
- test/test_helper.rb
|