ucenter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2085195cc8047d6bb067e0ff9afe2ef2dc69bb5c
4
+ data.tar.gz: 297ad4445d166b63c8399fe23892e5e09f9c520d
5
+ SHA512:
6
+ metadata.gz: a6fb212133e70230a00cb5cdde1ce6891a7e555048ea92f8ced63aa7178afcf1b4bebfd23a91d278cccf1eb0413f2500936342cb1d8545c782c9a546cc0d6440
7
+ data.tar.gz: 9259bc21437a6a62eaa0ec302563bbebea89c01827d9098d9431344d13e896f306291211f6894522fe9a6afc223c475c3ee8bffdb30ae6b95426c70a2bf6a885
data/.gitignore ADDED
@@ -0,0 +1,23 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ucenter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Willin Wang
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,29 @@
1
+ # Ucenter
2
+
3
+ ruby version uc_client
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ucenter'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ucenter
18
+
19
+ ## Usage
20
+
21
+ U Know De.
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/willin/ucenter/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/ucenter.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'ucenter/config'
2
+ require 'ucenter/client'
3
+ require 'ucenter/interface/base'
4
+ require 'ucenter/interface/authcode'
5
+ require 'ucenter/interface/utility'
@@ -0,0 +1,11 @@
1
+ module Ucenter
2
+ class Client
3
+ def authcode
4
+ @authcode ||= Ucenter::Interface::Authcode.new(self)
5
+ end
6
+
7
+ def utility
8
+ @utility ||= Ucenter::Interface::Utility.new(self)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ module Ucenter
2
+ module Config
3
+
4
+ def self.uc_key=(val)
5
+ @@uc_key = val
6
+ end
7
+
8
+ def self.uc_key
9
+ @@uc_key
10
+ end
11
+
12
+ def self.app_id=(val)
13
+ @@app_id = val
14
+ end
15
+
16
+ def self.app_id
17
+ @@app_id
18
+ end
19
+
20
+ def self.uc_api=(val)
21
+ @@uc_api = val
22
+ end
23
+
24
+ def self.uc_api
25
+ @@uc_api
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,68 @@
1
+ module Ucenter
2
+ module Interface
3
+ class Authcode < Base
4
+
5
+ KeyLength = 4
6
+ # 参考 https://github.com/daxingplay/dokuwiki_ucenter/blob/master/api/uc.php#L295
7
+ def decode string
8
+ string = '' if string.nil?
9
+ # 拆分key,并各自做md5
10
+ key = md5(Ucenter::Config.uc_key)
11
+ key_left, key_right = md5(key[0, 16]), md5(key[16, 16])
12
+ # 拆分string auth和content部分
13
+ string_auth, string_content = string[0, KeyLength], string[KeyLength..-1]
14
+ # 从key_crypt抽取box
15
+ key_crypt = key_left + md5(key_left + string_auth)
16
+ key_crypt_length = key_crypt.length
17
+ rndkey = []
18
+ 0.upto(255) do |i|
19
+ rndkey[i] = (key_crypt[i % key_crypt_length]).ord
20
+ end
21
+ a = b = 0
22
+ box = (0..255).to_a
23
+ while b < 256 do
24
+ a = (a + box[b] + rndkey[b]) % 256
25
+ box[b], box[a] = box[a], box[b]
26
+ b +=1
27
+ end
28
+ # 联合key_crypt和key_content解密出result
29
+ string_content_ords = base64_url_decode(string_content).bytes.to_a
30
+ string_content_ords_length = string_content_ords.length
31
+ a = b = string_idx = 0
32
+ result = ""
33
+ while string_idx < string_content_ords_length
34
+ a = (a + 1) % 256
35
+ b = (b + box[a]) % 256
36
+ box[a], box[b] = box[b], box[a]
37
+ result << (string_content_ords[string_idx] ^ (box[(box[a] + box[b]) % 256])).chr
38
+ string_idx +=1
39
+ end
40
+ result_time_valided = (result[0, 10] == '0'*10) || (result[0, 10].to_i - Time.now.to_i > 0)
41
+ result_string_valided = result[10, 16] == md5("#{result[26..-1]}#{key_right}")[0, 16] # 重新加密和string对比验证
42
+ if (result_time_valided && result_string_valided)
43
+ return result[26..-1]
44
+ else
45
+ return ''
46
+ end
47
+ end
48
+
49
+ def microtime
50
+ epoch_mirco = Time.now.to_f
51
+ epoch_full = Time.now.to_i
52
+ epoch_fraction = epoch_mirco - epoch_full
53
+ epoch_fraction.to_s + ' ' + epoch_full.to_s
54
+ end
55
+
56
+ private
57
+ def md5 str; Digest::MD5.hexdigest str.to_s end
58
+
59
+ def base64_url_decode str
60
+ mod = str.to_s.length.modulo(4)
61
+ str2 = "#{str}#{'=' * (4 - mod)}".tr('-_','+/')
62
+ Base64.decode64 str2
63
+ end
64
+
65
+ end
66
+ end
67
+ end
68
+
@@ -0,0 +1,12 @@
1
+ module Ucenter
2
+ module Interface
3
+ # The Base class of API
4
+ class Base
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ module Ucenter
2
+ module Interface
3
+ class Utility < Base
4
+ def explain_query(query_params)
5
+ query_params = '' if query_params === {}
6
+ # systemname=cets&responsible=sj ==> {"systemname"=>"cets","responsible"=>"sj"}
7
+ # only very sample explain,
8
+ # have not care about special char ,e.g. & = ...
9
+ re = {}
10
+ if query_params.nil? or query_params == ""
11
+ return re # empty ,need not explain
12
+ end
13
+ querys = query_params.split("&")
14
+ querys.each do | query |
15
+ query_arr = query.split("=")
16
+ re[query_arr[0]]=query_arr[1]
17
+ end
18
+ return re
19
+ end
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,3 @@
1
+ module Ucenter
2
+ VERSION = "0.0.1"
3
+ end
data/ucenter.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ucenter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ucenter"
8
+ spec.version = Ucenter::VERSION
9
+ spec.authors = "Willin Wang"
10
+ spec.email = "willin@willin.org"
11
+ spec.summary = %q{Ruby uc_client for Ucenter Sever.}
12
+ spec.description = %q{http://willin.wang visit for more info.}
13
+ spec.homepage = "https://github.com/willin/ucenter"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~>0"
23
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ucenter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Willin Wang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: http://willin.wang visit for more info.
42
+ email: willin@willin.org
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".gitignore"
48
+ - Gemfile
49
+ - LICENSE.txt
50
+ - README.md
51
+ - Rakefile
52
+ - lib/ucenter.rb
53
+ - lib/ucenter/client.rb
54
+ - lib/ucenter/config.rb
55
+ - lib/ucenter/interface/authcode.rb
56
+ - lib/ucenter/interface/base.rb
57
+ - lib/ucenter/interface/utility.rb
58
+ - lib/ucenter/version.rb
59
+ - ucenter.gemspec
60
+ homepage: https://github.com/willin/ucenter
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.2.2
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Ruby uc_client for Ucenter Sever.
84
+ test_files: []