platformx 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca7b6d2a7aac9298fc0c65283a38577ab965ba3c
4
- data.tar.gz: 314d8db2ddb3a20ea50cfa92be604defb054cc93
3
+ metadata.gz: 571b39d3d6f2ebe74e27e2ac3254f32e62ac6beb
4
+ data.tar.gz: b834abaae3f5d33e7fcea76ca31bc5b5ba914023
5
5
  SHA512:
6
- metadata.gz: 09aa0f8de9e457a5b7ab97657ba9d9261fe53bf67e7f51d88318a9068b48ec5c1894e1544a2fb0d1c417aab7e46932e72b2a6f8e1f773fb25c66379b15c4cdef
7
- data.tar.gz: 322765572b038cb0c168a53fa788028b74dc5b055ab470a154545229b7880fcef371e3bcd3a12246f802a0ea215ff6e00abd8166c4fc117b1adb1ce75640acff
6
+ metadata.gz: d25f9bbcfd02967b288729cac8db60e17ecdf348fa81eec54bdfb7924ab646daf64df6afeab4b3e534cdf3985b828f12b0e027537c499de5a2c8704f73e65320
7
+ data.tar.gz: af66a07ab362239195187cc6d174c71df9606059f4a717e5b8a6cc4781ad8b3e9ef94bef73a9fff17375488728a077cdfa242b8cea9391a488e757650337e414
data/.gitignore CHANGED
@@ -20,3 +20,6 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+
24
+ .ruby-version
25
+ .ruby-gemset
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in platformx.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'yard'
8
+ end
data/README.md CHANGED
@@ -28,4 +28,23 @@ To use in Sinatra add
28
28
  config.bugsnag_api_key = "string"
29
29
  end
30
30
 
31
- ## Contributing
31
+ ## Documentation
32
+
33
+ The gem is documented with YARD. You can run yard documentation using its inbuilt
34
+ server. Following git clone...
35
+
36
+ ~# cd platformx-gem
37
+ ~# bundle install
38
+ ~# yard server --reload
39
+
40
+ and visit localhost:8808.
41
+
42
+ If you prefer to compile it to html (ex: to host)..
43
+
44
+ ~# yard
45
+
46
+ For more information visit [yardoc website](http://yardoc.org/) or use...
47
+
48
+ ~# yard --help
49
+
50
+ ## Contributing
@@ -1,74 +1,81 @@
1
1
  module Platformx
2
- module AuthHelpers
3
- ########################################################
4
- #
5
- # Start Helpers
6
- #
7
- ########################################################
2
+ module AuthHelpers
8
3
 
9
- ########################################################
10
- #
11
- # Admin Login
12
- #
13
- ########################################################
4
+ # Admin session helpers
14
5
 
15
- def x_admin_authorized?
16
- session[:admin_authorized]
17
- end
6
+ # Checks if the current user authorizes as an admin
7
+ #
8
+ # @return [Boolean] if current user authorizes as an admin
9
+ def x_admin_authorized?
10
+ session[:admin_authorized]
11
+ end
18
12
 
19
- def x_admin_authorize!
20
- redirect '/admin/login' unless x_admin_authorized? || request.url.include?("/admin/login")
21
- end
13
+ # Authorizes the current user as an admin or redirects the user to the admin login page.
14
+ def x_admin_authorize!
15
+ redirect '/admin/login' unless x_admin_authorized? || request.url.include?("/admin/login")
16
+ end
22
17
 
23
- def x_admin_logout!
24
- session[:admin_authorized] = false
25
- session.clear
26
- end
18
+ # Logs out the amdin
19
+ def x_admin_logout!
20
+ session[:admin_authorized] = false
21
+ session.clear
22
+ end
27
23
 
28
- ########################################################
29
- #
30
- # Login
31
- #
32
- ########################################################
24
+ # User session helpers
33
25
 
34
- def x_authorized?
35
- session[:authorized]
36
- end
26
+ # Checks if the user is logged in
27
+ #
28
+ # @return [Boolean] if uesr logged in
29
+ def x_authorized?
30
+ session[:authorized]
31
+ end
37
32
 
38
- def x_authorize!
39
- redirect '/login' unless x_authorized? || request.url.include?("/login") || request.url.include?("/auth")
40
- end
33
+ # Authorizes the user and redirects the user to the registration page.
34
+ def x_authorize!
35
+ redirect '/login' unless x_authorized? || request.url.include?("/login") || request.url.include?("/auth")
36
+ end
41
37
 
42
- def x_logout!
43
- session[:authorized] = false
44
- session.clear
45
- end
38
+ # Logs out the currenly logged in user
39
+ def x_logout!
40
+ session[:authorized] = false
41
+ session.clear
42
+ end
46
43
 
47
- ########################################################
48
- #
49
- # Encyrption
50
- #
51
- ########################################################
52
- def x_encrypt(int = "")
53
- str = int.to_s
54
- #encrypted_value = Encryptor.encrypt(:value => str, :key => "=PeuMX7B4LQ#@jG*s;tYGdF")
55
- return Base64.urlsafe_encode64(str)
56
- end
44
+ # Encyrption helprs
45
+
46
+ # Encodes a value to a base 64 string.
47
+ #
48
+ # @note The provided object should respond to `#to_s` to obtain a string representation of the object.
49
+ #
50
+ # @param int [Object] the value required to be encrypted
51
+ #
52
+ # @return [String] encoded string
53
+ def x_encrypt(int = "")
54
+ str = int.to_s
55
+ #encrypted_value = Encryptor.encrypt(:value => str, :key => "=PeuMX7B4LQ#@jG*s;tYGdF")
56
+ return Base64.urlsafe_encode64(str)
57
+ end
57
58
 
58
- def x_decrypt(str = "")
59
- str = Base64.urlsafe_decode64(str)
60
- #decrypted_value = Encryptor.decrypt(:value => str, :key => '=PeuMX7B4LQ#@jG*s;tYGdF')
61
- return str.to_i
62
- end
59
+ # Decodes an encoded string
60
+ #
61
+ # @param str [String] the encoded string
62
+ #
63
+ # @return [String] decoded string
64
+ def x_decrypt(str = "")
65
+ str = Base64.urlsafe_decode64(str)
66
+ #decrypted_value = Encryptor.decrypt(:value => str, :key => '=PeuMX7B4LQ#@jG*s;tYGdF')
67
+ return str.to_i
68
+ end
69
+
70
+ # Generate a random password
71
+ #
72
+ # @param len [Integer] the length of the password
73
+ #
74
+ # @return [String] random generated password
75
+ def x_generate_password(len = "10")
76
+ random_password = Array.new(len).map { (65 + rand(58)).chr }.join
77
+ return random_password
78
+ end
63
79
 
64
- def x_generate_password(len = "10")
65
- random_password = Array.new(len).map { (65 + rand(58)).chr }.join
66
- return random_password
67
- end
68
- ########################################################
69
- #
70
- # End
71
- #
72
- ########################################################
73
80
  end
74
- end
81
+ end
data/lib/platformx/aws.rb CHANGED
@@ -1,71 +1,71 @@
1
1
  module Platformx
2
- module S3Helpers
3
- ########################################################
4
- #
5
- # Set Up Connection
6
- #
7
- ########################################################
8
- def x_s3_init()
9
-
10
- connection = Fog::Storage.new({
11
- :provider => 'AWS',
12
- :region => Platformx.configuration.aws_region,
13
- :aws_access_key_id => Platformx.configuration.aws_access_key_id,
14
- :aws_secret_access_key => Platformx.configuration.aws_secret_access_key
15
- })
16
- return connection
17
-
18
- end
19
-
20
- ########################################################
21
- #
22
- # Upload to S3
23
- #
24
- ########################################################
25
- def x_s3_upload(new_filename: "", file: "", bucket: "#{Platformx.configuration.aws_bucket}", path: "")
26
-
27
-
28
- ################# Init S3 #################
29
- connection = x_s3_init
30
2
 
3
+ #
4
+ # Amazon S3 helpers
5
+ #
6
+ # @author Tim Mushen
7
+ #
8
+ module S3Helpers
9
+
10
+ # Set up Amazon S3 connection
11
+ #
12
+ # @return [Fog::Storage] S3 storage connection
13
+ def x_s3_init()
14
+ connection = Fog::Storage.new({
15
+ :provider => 'AWS',
16
+ :region => Platformx.configuration.aws_region,
17
+ :aws_access_key_id => Platformx.configuration.aws_access_key_id,
18
+ :aws_secret_access_key => Platformx.configuration.aws_secret_access_key
19
+ })
20
+ return connection
21
+ end
31
22
 
32
- ################# Set Bucket #################
33
- bucket = connection.directories.create(key: "#{bucket}/#{path}", public: false)
23
+ # Upload file to S3 with the given parameters
24
+ #
25
+ # @param new_filename [String] new name of the file
26
+ # @param file [String] file to be uploaded
27
+ # @param bucket [String] bucket to upload the file to
28
+ # @param path [String] path of the final file
29
+ #
30
+ # @return S3 bucket file
31
+ def x_s3_upload(new_filename: "", file: "", bucket: "#{Platformx.configuration.aws_bucket}", path: "")
32
+ # Obtaining an S3 connection
33
+ connection = x_s3_init
34
34
 
35
- # upload that resume
36
- file = bucket.files.create(
37
- :key => "#{new_filename}",
38
- :body => open(file),
39
- :public => false
40
- )
35
+ # Creating the directory to upload the file to
36
+ bucket = connection.directories.create(key: "#{bucket}/#{path}", public: false)
41
37
 
42
- end
38
+ # upload that resume
39
+ file = bucket.files.create(
40
+ :key => "#{new_filename}",
41
+ :body => open(file),
42
+ :public => false
43
+ )
44
+ end
43
45
 
46
+ # Download link from S3 asset
47
+ #
48
+ # @param key [String] key or the file name
49
+ # @param bucket [String] the bucket name
50
+ # @param bucket_path [String] the bucket path
51
+ # @param verbose [Boolean] make operation verborse
52
+ #
53
+ # @return [String] a public URL for the file
54
+ #
55
+ # @note The returned public URL will expire in 7 days
56
+ def x_s3_get_link(key: "", bucket: "", bucket_path: "", verbose: false)
57
+
58
+ connection = x_s3_init
59
+ expiry = Time.now.to_i + 604800
60
+ connection.directories.new(:key => "#{bucket}").files.new(:key => "#{bucket_path}/#{key}").url(expiry)
61
+
62
+ if verbose == true
63
+ # returns more information about file from s3
64
+ # directory = connection.directories.get("files.myclocktower.com")
65
+ # file = directory.files.get("support/#{support_id}/#{key}")
66
+ #return file.url(expiry)
67
+ end
68
+ end
44
69
 
45
- ########################################################
46
- #
47
- # Download from S3
48
- #
49
- ########################################################
50
- def x_s3_get_link(key: "", bucket:"", bucket_path:"", verbose: false)
51
-
52
- connection = x_s3_init
53
- expiry = Time.now.to_i + 604800
54
- connection.directories.new(:key => "#{bucket}").files.new(:key => "#{bucket_path}/#{key}").url(expiry)
55
-
56
- if verbose == true
57
- # returns more information about file from s3
58
- # directory = connection.directories.get("files.myclocktower.com")
59
- # file = directory.files.get("support/#{support_id}/#{key}")
60
- #return file.url(expiry)
61
- end
62
-
70
+ end
63
71
  end
64
-
65
- ########################################################
66
- #
67
- # End
68
- #
69
- ########################################################
70
- end
71
- end
@@ -1,96 +1,99 @@
1
1
  module Platformx
2
- module DateHelpers
3
- ########################################################
4
- #
5
- # Start Helpers
6
- #
7
- ########################################################
8
2
 
9
- ########################################################
10
- #
11
- # Time in words
12
- #
13
- ########################################################
14
- def x_time_in_words(date: "")
15
- date = date.to_date
16
- date = Date.parse(date, true) unless /Date.*/ =~ date.class.to_s
17
- days = (date - Date.today).to_i
18
- return 'Today' if days >= 0 and days < 1
19
- return 'Tomorrow' if days >= 1 and days < 2
20
- return 'Yesterday' if days >= -1 and days < 0
21
- return "In #{days} days" if days.abs < 60 and days > 0
22
- return "#{days.abs} days ago" if days.abs < 60 and days < 0
23
- return date.strftime('%A, %B %e, %Y') if days.abs < 182
24
- return date.strftime('%A, %B %e, %Y')
25
- end
3
+ #
4
+ # Date helpers module
5
+ # @author Tim Mushen
6
+ #
7
+ module DateHelpers
26
8
 
27
- ########################################################
28
- #
29
- # Returns relative time in words referencing the given date
30
- # relative_time_ago(Time.now) => 'about a minute ago'
31
- #
32
- ########################################################
33
- def x_relative_time_ago(from_time: "")
34
- distance_in_minutes = (((Time.now - from_time.to_time).abs)/60).round
35
- case distance_in_minutes
36
- when 0..1 then 'A minute ago'
37
- when 2..44 then "#{distance_in_minutes} minutes ago"
38
- when 45..89 then '1 hour ago'
39
- when 90..1439 then "#{(distance_in_minutes.to_f / 60.0).round} hours ago"
40
- when 1440..2439 then '1 day ago'
41
- when 2440..2879 then '2 days ago'
42
- when 2880..43199 then "#{(distance_in_minutes / 1440).round} days ago"
43
- when 43200..86399 then 'About 1 month ago'
44
- when 86400..525599 then "#{(distance_in_minutes / 43200).round} months ago"
45
- when 525600..1051199 then 'About 1 year ago'
46
- else "Over #{(distance_in_minutes / 525600).round} years ago"
9
+ # Get the time in words
10
+ # @param date [String] a string representation of the date
11
+ # @return [String] time in words
12
+ def x_time_in_words(date: "")
13
+ date = date.to_date
14
+ date = Date.parse(date, true) unless /Date.*/ =~ date.class.to_s
15
+ days = (date - Date.today).to_i
16
+ return 'Today' if days >= 0 and days < 1
17
+ return 'Tomorrow' if days >= 1 and days < 2
18
+ return 'Yesterday' if days >= -1 and days < 0
19
+ return "In #{days} days" if days.abs < 60 and days > 0
20
+ return "#{days.abs} days ago" if days.abs < 60 and days < 0
21
+ return date.strftime('%A, %B %e, %Y') if days.abs < 182
22
+ return date.strftime('%A, %B %e, %Y')
47
23
  end
48
- end
49
24
 
50
- def x_format_date(date: "", show_time: false, show_month: true)
51
-
52
-
53
- if date.nil?
25
+ # Returns relative time in words referencing the given date
26
+ # @param from_time [Time] the from time
27
+ # @return [String] a 'time ago' representation for the given time
28
+ # @example
29
+ # relative_time_ago(Time.now) # => 'about a minute ago'
30
+ def x_relative_time_ago(from_time: "")
31
+ distance_in_minutes = (((Time.now - from_time.to_time).abs)/60).round
32
+
33
+ case distance_in_minutes
34
+ when 0..1 then 'A minute ago'
35
+ when 2..44 then "#{distance_in_minutes} minutes ago"
36
+ when 45..89 then '1 hour ago'
37
+ when 90..1439 then "#{(distance_in_minutes.to_f / 60.0).round} hours ago"
38
+ when 1440..2439 then '1 day ago'
39
+ when 2440..2879 then '2 days ago'
40
+ when 2880..43199 then "#{(distance_in_minutes / 1440).round} days ago"
41
+ when 43200..86399 then 'About 1 month ago'
42
+ when 86400..525599 then "#{(distance_in_minutes / 43200).round} months ago"
43
+ when 525600..1051199 then 'About 1 year ago'
44
+ else "Over #{(distance_in_minutes / 525600).round} years ago"
45
+ end
46
+ end
47
+
48
+ # Formats the date
49
+ # @param date [Time] date representation in the format %A, %B %d, %Y
50
+ # @param show_time [Boolean] if the timme should be incldued
51
+ # @param show_month [Boolean] if teh month should be included
52
+ # @return [String] formated representation of the given date
53
+ def x_format_date(date: "", show_time: false, show_month: true)
54
+ if date.nil?
54
55
  return ""
55
- else
56
+ else
56
57
  time = date.strftime("%A, %B %d, %Y")
57
58
 
58
59
  if show_time == true
59
- time = time + date.strftime(" %l:%M %p")
60
+ time = time + date.strftime(" %l:%M %p")
60
61
  end
61
62
 
62
63
  return time
64
+ end
63
65
  end
64
- end
65
66
 
66
- def x_format_datetime(date: "")
67
-
68
- if date.nil?
67
+ # Format date time
68
+ # @param date [Time] the date-time to be formatted
69
+ # @return [String] the formatted date
70
+ def x_format_datetime(date: "")
71
+ if date.nil?
69
72
  return ""
70
- else
73
+ else
71
74
  time = date.strftime("%A, %B %d, %Y %l:%M %p")
72
75
  return time
76
+ end
73
77
  end
74
- end
75
78
 
76
- def x_format_time(time: "")
77
-
78
- if time.nil?
79
+ # Format time
80
+ # @param time [Time] the time to be formatted
81
+ # @return [String] formatted time
82
+ def x_format_time(time: "")
83
+ if time.nil?
79
84
  return ""
80
- else
85
+ else
81
86
  time = time.strftime("%l:%M %p")
82
87
  return time
88
+ end
83
89
  end
84
- end
85
90
 
86
- def x_short_date(datevar: "")
87
- return datevar.strftime("%A, %-m-%d-%y") unless datevar.nil?
88
- end
91
+ # Short date with format %A, %-m-%d-%y
92
+ # @param datevar [Time | Date] date or time to be formatted
93
+ # @return [String] formatted date/time
94
+ def x_short_date(datevar: "")
95
+ return datevar.strftime("%A, %-m-%d-%y") unless datevar.nil?
96
+ end
89
97
 
90
- ########################################################
91
- #
92
- # End
93
- #
94
- ########################################################
95
98
  end
96
- end
99
+ end