owrb 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/owrb.rb +227 -5
  3. data/lib/owrb/version.rb +1 -1
  4. data/owrb.gemspec +4 -0
  5. metadata +58 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87ef90e379f05340df4f5e0bb581496cb040e377
4
- data.tar.gz: 5b2c2318d241c9517a7b6dafe96f774d2aad7903
3
+ metadata.gz: f9b4c84322ef3d8955747446526977a13c4b6a45
4
+ data.tar.gz: 93ce894e8f3b4730a652f0ff99c75fdd6890fb87
5
5
  SHA512:
6
- metadata.gz: cbf2c75fa072c9a65f053973942b14b1ff4052532b384140cba382a802ee7f4f1a0ffc2436e58be13a29c5892fe7edb7c4b69f25bbc5d4e49e297bf5c7c5b9db
7
- data.tar.gz: 47f3ccf1a0081e2182b5f0ac30b48ba38704482dfee5e88119787503b7a101e400e7bd1da520eced4c3c7ceb6838be6846e9c8da3863e1d73d2d972796d1da4f
6
+ metadata.gz: a1466cac9cc81a58d76800e0d6f0a0359bf800afd905a109abbee023f80e686f97fd94a12b2deb9df32064028cdb57ef5cbc92d2619b7394e434ef46902c9558
7
+ data.tar.gz: 97834bcfab4cf50a1260f41d8b4b23bc0342f31485eaf970cbb24aca253ec95215d187167e5a2704c6bf396d8d7bffa79bfb99a2afbebef953cbd09f2f296f8b
@@ -4,12 +4,26 @@ require "uri"
4
4
  require "json"
5
5
  require "nokogiri"
6
6
  require "watir-webdriver"
7
+ require "omniauth"
8
+ require "omniauth-twitter"
9
+ require "omniauth-facebook"
10
+ require "omniauth-github"
11
+ require "openssl"
12
+ require "base64"
7
13
 
8
14
  module Owrb
9
15
  module URL
10
16
  def self.parse( url )
11
17
  URI.parse( url )
12
18
  end
19
+
20
+ def self.encode( url )
21
+ URI.encode( url )
22
+ end
23
+
24
+ def self.decode( url )
25
+ URI.decode( url )
26
+ end
13
27
  end
14
28
 
15
29
  module JSON
@@ -64,6 +78,61 @@ module Owrb
64
78
  def self.parse( code )
65
79
  Document.new( Nokogiri::HTML.parse( code ) )
66
80
  end
81
+
82
+ module Style
83
+ def self.css( name, *args )
84
+ <<EOS
85
+ #{name} {
86
+ #{args.collect{|styles| styles.join( ";\n " )}.join( ";\n " )}
87
+ }
88
+ EOS
89
+ end
90
+
91
+ def self.border( styles )
92
+ result = []
93
+ result.push "border: #{styles[ :border ]}" if styles.key?( :border )
94
+ if styles.key?( :radius )
95
+ result.push "border-radius: #{styles[ :radius ]}"
96
+ result.push "-webkit-border-radius: #{styles[ :radius ]}"
97
+ result.push "-moz-border-radius: #{styles[ :radius ]}"
98
+ end
99
+ result
100
+ end
101
+
102
+ def self.font( styles )
103
+ result = []
104
+ result.push "font-size: #{styles[ :size ]}" if styles.key?( :size )
105
+ result.push "font-weight: #{styles[ :style ]}" if styles.key?( :style )
106
+ result.push "font-family: #{styles[ :family ]}" if styles.key?( :family )
107
+ result
108
+ end
109
+
110
+ def self.text( styles )
111
+ result = []
112
+ result.push "text-decoration: #{styles[ :decoration ]}" if styles.key?( :decoration )
113
+ result.push "text-shadow: #{styles[ :shadow ]}" if styles.key?( :shadow )
114
+ result.push "text-align: #{styles[ :align ]}" if styles.key?( :align )
115
+ result.push "color: #{styles[ :color ]}" if styles.key?( :color )
116
+ result
117
+ end
118
+
119
+ def self.background( styles )
120
+ result = []
121
+ result.push "background-color: #{styles[ :color ]}" if styles.key?( :color )
122
+ result.push "background-image: #{styles[ :image ]}" if styles.key?( :image )
123
+ if styles.key?( :linear_gradient )
124
+ color = styles[ :linear_gradient ][ :color ]
125
+ result.push "background-color: #{color[ 0 ]}"
126
+ result.push "background-image: -webkit-gradient(linear, left top, left bottom, from(#{color[ 0 ]}), to(#{color[ 1 ]}))"
127
+ result.push "background-image: -webkit-linear-gradient(top, #{color[ 0 ]}, #{color[ 1 ]})"
128
+ result.push "background-image: -moz-linear-gradient(top, #{color[ 0 ]}, #{color[ 1 ]})"
129
+ result.push "background-image: -ms-linear-gradient(top, #{color[ 0 ]}, #{color[ 1 ]})"
130
+ result.push "background-image: -o-linear-gradient(top, #{color[ 0 ]}, #{color[ 1 ]})"
131
+ result.push "background-image: linear-gradient(to bottom, #{color[ 0 ]}, #{color[ 1 ]})"
132
+ end
133
+ result
134
+ end
135
+ end
67
136
  end
68
137
 
69
138
  class Browser
@@ -94,15 +163,168 @@ module Owrb
94
163
  end
95
164
  end
96
165
 
97
- =begin
98
- class Cipher
99
- def encode
166
+ module Rails
167
+ module Auth
168
+ def self.provider( type, key, secret )
169
+ key = key.to_s
170
+ key = ENV[ key ] if ENV.key?( key )
171
+
172
+ secret = secret.to_s
173
+ secret = ENV[ secret ] if ENV.key?( secret )
174
+
175
+ [ type, key, secret ]
176
+ end
177
+
178
+ def self.set( providers )
179
+ ::Rails.application.config.middleware.use ::OmniAuth::Builder do
180
+ providers.each{|args|
181
+ provider *Auth.provider( *args )
182
+ }
183
+ end
184
+ end
185
+ end
186
+
187
+ class Cookie
188
+ attr_reader :cookies
189
+
190
+ def initialize( cookies )
191
+ @cookies = cookies
192
+ end
193
+
194
+ def get( key, default_value )
195
+ value = @cookies.signed[ key ]
196
+ value.nil? ? default_value : value
197
+ end
198
+
199
+ def set( key, value, expires = 1.years.from_now( ::Time.now ) )
200
+ @cookies.signed[ key ] = { :value => value, :expires => expires }
201
+ end
202
+
203
+ def delete( key )
204
+ @cookies.delete key
205
+ end
206
+ end
207
+ end
208
+
209
+ module Data
210
+ def self.hash( data )
211
+ Digest::SHA512::hexdigest( data )
212
+ end
213
+
214
+ class Cipher
215
+ attr_reader :cipher
216
+ attr_accessor :key, :iv
217
+
218
+ def initialize( cipher )
219
+ @cipher = cipher
220
+ @key = ""
221
+ @iv = ""
222
+ end
100
223
 
224
+ def key_iv( pass, salt, count = 2000 )
225
+ result = OpenSSL::PKCS5.pbkdf2_hmac_sha1( pass, salt, count, @cipher.key_len + @cipher.iv_len )
226
+ @key = result[ 0, @cipher.key_len ]
227
+ @iv = result[ @cipher.key_len, @cipher.iv_len ]
228
+ [ @key, @iv ]
229
+ end
230
+
231
+ def encrypt( data )
232
+ @cipher.encrypt
233
+ @cipher.key = @key
234
+ @cipher.iv = @iv
235
+ "#{@cipher.update( data )}#{@cipher.final}"
236
+ end
237
+
238
+ def decrypt( data )
239
+ @cipher.decrypt
240
+ @cipher.key = @key
241
+ @cipher.iv = @iv
242
+ "#{@cipher.update( data )}#{@cipher.final}"
243
+ end
101
244
  end
102
245
 
103
- def decode
246
+ def self.cipher( name = "AES-256-CBC" )
247
+ Cipher.new( OpenSSL::Cipher.new( name ) )
248
+ end
249
+
250
+ module Base64
251
+ def self.encode( data )
252
+ ::Base64.urlsafe_encode64( data )
253
+ end
104
254
 
255
+ def self.decode( data )
256
+ ::Base64.urlsafe_decode64( data )
257
+ end
258
+ end
259
+ end
260
+
261
+ class Time
262
+ DAY_SECONDS = 24 * 60 * 60
263
+ HOUR_SECONDS = 60 * 60
264
+ MINUTE_SECONDS = 60
265
+
266
+ def self.format( type, value = ::Time.now )
267
+ case type
268
+ when :all
269
+ value.strftime( "%Y/%m/%d %H:%M:%S.%6N" )
270
+ when :ymdhms
271
+ value.strftime( "%Y/%m/%d %H:%M:%S" )
272
+ else
273
+ ""
274
+ end
275
+ end
276
+
277
+ attr_reader :value
278
+
279
+ def initialize( value = ::Time.now )
280
+ @value = value
281
+ end
282
+
283
+ def to_s
284
+ Time::format( :all, @value )
285
+ end
286
+
287
+ def add_days( value )
288
+ @value + value * DAY_SECONDS
289
+ end
290
+
291
+ def add_hours( value )
292
+ @value + value * HOUR_SECONDS
293
+ end
294
+
295
+ def add_minutes( value )
296
+ @value + value * MINUTE_SECONDS
297
+ end
298
+
299
+ def add_seconds( value )
300
+ @value + value
301
+ end
302
+
303
+ def diff_days( seconds )
304
+ [ seconds / DAY_SECONDS, seconds % DAY_SECONDS ]
305
+ end
306
+
307
+ def diff_hours( seconds )
308
+ [ seconds / HOUR_SECONDS, seconds % HOUR_SECONDS ]
309
+ end
310
+
311
+ def diff_minutes( seconds )
312
+ [ seconds / MINUTE_SECONDS, seconds % MINUTE_SECONDS ]
313
+ end
314
+
315
+ def diff( value )
316
+ total_seconds = ( value < @value ) ? @value - value : value - @value
317
+ total_seconds = total_seconds.to_i
318
+ days = diff_days( total_seconds )
319
+ hours = diff_hours( days[ 1 ] )
320
+ minutes = diff_minutes( hours[ 1 ] )
321
+ {
322
+ :total_seconds => total_seconds,
323
+ :days => days[ 0 ],
324
+ :hours => hours[ 0 ],
325
+ :minutes => minutes[ 0 ],
326
+ :seconds => minutes[ 1 ],
327
+ }
105
328
  end
106
329
  end
107
- =end
108
330
  end
@@ -1,3 +1,3 @@
1
1
  module Owrb
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -23,4 +23,8 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_dependency "nokogiri"
25
25
  spec.add_dependency "watir"
26
+ spec.add_dependency "omniauth"
27
+ spec.add_dependency "omniauth-twitter"
28
+ spec.add_dependency "omniauth-facebook"
29
+ spec.add_dependency "omniauth-github"
26
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: owrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - liveralmask
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-29 00:00:00.000000000 Z
11
+ date: 2016-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,62 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: omniauth
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: omniauth-twitter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: omniauth-facebook
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: omniauth-github
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
69
125
  description: Web scripts.
70
126
  email:
71
127
  - liveralmask.lisk@gmail.com