TheresNoBox 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 ADDED
@@ -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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in TheresNoBox.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Bill
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,20 @@
1
+ # TheresNoBox
2
+
3
+ There's No Box Utility Gem
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'TheresNoBox'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install TheresNoBox
18
+
19
+ ## Usage
20
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'TheresNoBox/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "TheresNoBox"
8
+ gem.version = TheresNoBox::VERSION
9
+ gem.authors = ["Bill"]
10
+ gem.email = ["bill@theresnobox.net"]
11
+ gem.description = %q{There's No Box utililty Library}
12
+ gem.summary = %q{There's No Box utililty Library}
13
+ gem.homepage = ""
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.require_paths = ["lib"]
19
+
20
+ gem.add_dependency('rest-client')
21
+ gem.add_dependency('fog')
22
+ end
@@ -0,0 +1,5 @@
1
+ require "TheresNoBox/version"
2
+
3
+
4
+ #require 'TheresNoBox/google'
5
+ require 'TheresNoBox/tnb'
@@ -0,0 +1,111 @@
1
+ module Google
2
+ def self.login(code)
3
+ token = Google::OAuth.get_token(code)
4
+ profile = Google::Profile.getProfile(token)
5
+
6
+ user = User.where(:provider=> 'Google', :email=> profile['email']).first
7
+
8
+ #User not currently in database...
9
+ if user.nil?
10
+ #Adding user as user.
11
+ user = User.new
12
+ user.email = profile['email']
13
+ user.provider = 'Google'
14
+ user.uid = profile['id']
15
+ user.name = profile['name']
16
+ user.imageUrl = profile['picture']
17
+ user.sites = {mySite => 'user'}
18
+ user.editable = true
19
+ user.save
20
+ end
21
+
22
+ #Found User, but name is nil / null
23
+ if user.name.nil?
24
+ user.email = profile['email']
25
+ user.provider = 'Google'
26
+ user.uid = profile['id']
27
+ user.name = profile['name']
28
+ user.imageUrl = profile['picture']
29
+ user.save
30
+ end
31
+
32
+ return user
33
+ end
34
+ module OAuth
35
+ def self.authentication_url( scopes = ['https://www.googleapis.com/auth/userinfo.profile',
36
+ 'https://www.googleapis.com/auth/userinfo.email',
37
+ 'https://www.googleapis.com/auth/analytics.readonly'])
38
+ url = 'https://accounts.google.com/o/oauth2/auth?'
39
+ url << 'access_type=online'
40
+ url << '&approval_prompt=auto'
41
+ url << "&client_id=#{Settings.googleClientId}"
42
+ url << "&redirect_uri=#{Settings.accountUrl}/auth/google/callback"
43
+ url << '&response_type=code'
44
+ url << "&scope=#{scopes.join('%20')}"
45
+ return url
46
+ end
47
+
48
+ def self.get_token(code)
49
+ data = {
50
+ :code=>code,
51
+ :client_id=>Settings.googleClientId,
52
+ :client_secret=>Settings.googleClientSecret,
53
+ :redirect_uri=>"#{Settings.accountUrl}/auth/google/callback",
54
+ :grant_type=>'authorization_code'
55
+ }
56
+ return JSON.parse( RestClient.post 'https://accounts.google.com/o/oauth2/token' , data)['access_token']
57
+ end
58
+ end
59
+
60
+ module Profile
61
+ def self.getProfile(token)
62
+ return JSON.parse(RestClient.get "https://www.googleapis.com/oauth2/v1/userinfo?access_token=#{token}")
63
+ end
64
+ end
65
+
66
+ module OpenId
67
+ def self.login(resp)
68
+ ax = OpenID::AX::FetchResponse.from_success_response(resp)
69
+ email = ax.get_single("http://axschema.org/contact/email")
70
+ user = User.where(:email => email).first
71
+ if user.nil?
72
+ user = User.create()
73
+ user.email = email.downcase
74
+ user.provider = 'Google'
75
+ user.name = ax.get_single("http://axschema.org/namePerson/first") << ' ' << ax.get_single("http://axschema.org/namePerson/last")
76
+ user.save
77
+ end
78
+
79
+ unless user.provider = 'Google'
80
+ raise 'User email already in use.'
81
+ end
82
+ return user
83
+ end
84
+
85
+ def self.header
86
+ return {:identifier => 'https://www.google.com/accounts/o8/id',
87
+ :required => ["http://axschema.org/contact/email",
88
+ "http://axschema.org/namePerson/first",
89
+ "http://axschema.org/namePerson/last"],
90
+ :method => 'post'}
91
+ end
92
+ end
93
+
94
+ module Recaptcha
95
+ def self.verify(params, ip)
96
+ data = {:privatekey=> Settings.recaptchaPriveKey,
97
+ :remoteip=> ip,
98
+ :challenge=> params[:recaptcha_challenge_field],
99
+ :response=> params[:recaptcha_response_field]
100
+ }
101
+ text = RestClient.post 'http://www.google.com/recaptcha/api/verify', data
102
+ text = text.split("\n\r")
103
+
104
+ if text[0] == 'true'
105
+ return true
106
+ else
107
+ return false
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,20 @@
1
+ module TNB
2
+ module Revisable
3
+ def createRevision
4
+ revision = Revision.new
5
+ revision.type = self.class.name
6
+ revision.data = self.attributes
7
+ revision.save
8
+ end
9
+ end
10
+
11
+ module Math
12
+ # amount is expected to be an integer.
13
+ def self.to_currency(amount)
14
+ amount = (amount + 0.5).floor
15
+ dollars = (amount / 100).floor
16
+ cents = sprintf('%02d', (amount - (dollars * 100)))
17
+ return '$' << dollars.to_s << '.' << cents
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module TheresNoBox
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: TheresNoBox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bill
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fog
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
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: There's No Box utililty Library
47
+ email:
48
+ - bill@theresnobox.net
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - TheresNoBox.gemspec
59
+ - lib/TheresNoBox.rb
60
+ - lib/TheresNoBox/google.rb
61
+ - lib/TheresNoBox/tnb.rb
62
+ - lib/TheresNoBox/version.rb
63
+ homepage: ''
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.23
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: There's No Box utililty Library
87
+ test_files: []