kf5 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a3eb3a3fec42ed6f95a4a436ecaece42593d6edd
4
+ data.tar.gz: c7d1515809f053724790d54cca8c3e2b12cfdb28
5
+ SHA512:
6
+ metadata.gz: 5aa8979a24e1087d587f50ff52288bc520d3dab17ea589fc42b6e69eb346f28faf5de8fc903945960b39853ddd68f546c3ece1af85273201a409d68776e68e01
7
+ data.tar.gz: dab062f39fbdaa8dc5ba06b28c10f9d55ef1123ae1546582c5b467b28f91efdb52f7c73d06bc27ff0118383de023a0081532846118a3822e7a177aee5452ff22
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # v0.1.0 / 2015-09-03
2
+
3
+ Create project
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in presenters.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kf5 (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.4.2)
11
+ rspec (3.3.0)
12
+ rspec-core (~> 3.3.0)
13
+ rspec-expectations (~> 3.3.0)
14
+ rspec-mocks (~> 3.3.0)
15
+ rspec-core (3.3.2)
16
+ rspec-support (~> 3.3.0)
17
+ rspec-expectations (3.3.1)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.3.0)
20
+ rspec-its (1.2.0)
21
+ rspec-core (>= 3.0.0)
22
+ rspec-expectations (>= 3.0.0)
23
+ rspec-mocks (3.3.2)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.3.0)
26
+ rspec-support (3.3.0)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ bundler (~> 1.10)
33
+ kf5!
34
+ rake (~> 10.0)
35
+ rspec
36
+ rspec-its
37
+
38
+ BUNDLED WITH
39
+ 1.10.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Chen Yi-Cyuan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # KF5
2
+
3
+ A library to integrate with KF5 help desk.[逸創云客服](http://www.kf5.com/)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'kf5'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ gem install kf5
20
+
21
+ For rails, create config `config/initializers/kf5.rb`
22
+ ```ruby
23
+ KF5.configure do |config|
24
+ config.key = "your key of KF5 service"
25
+ config.domain = "your domain of KF5 service"
26
+
27
+ # if you use devise, it will fetch following information from current_user if exsit
28
+ # default is :username, this is identification
29
+ config.properties.username = :your_username_column
30
+
31
+ # default is :name, optional
32
+ config.properties.name = :your_name_column
33
+
34
+ # default is :phone, optional
35
+ config.properties.phone = :your_phone_column
36
+ end
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ In rails controllers, you can call `redirect_to_kf5` to redirect_to_kf5 for SSO. This will fetch information from `current_user` automatically if you use devise:
42
+ ```ruby
43
+ # ... my controller
44
+ def my_action
45
+ redirect_to_kf5
46
+ end
47
+ ```
48
+ Or you can assaign arguments manaully
49
+ ```ruby
50
+ redirect_to_kf5 :username => 'username' # others....
51
+ ```
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
56
+
57
+ ## Contact
58
+ The project's website is located at https://github.com/emn178/kf5
59
+ Author: emn178@gmail.com
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/kf5.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kf5/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kf5"
8
+ spec.version = KF5::VERSION
9
+ spec.authors = ["Chen Yi-Cyuan"]
10
+ spec.email = ["emn178@gmail.com"]
11
+
12
+ spec.summary = %q{A simple presenter pattern for ruby. It can work in rails.}
13
+ spec.description = %q{A simple presenter pattern for ruby. It can work in rails.}
14
+ spec.homepage = "https://github.com/emn178/kf5"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rspec-its"
26
+ end
@@ -0,0 +1,13 @@
1
+ module KF5
2
+ class Configuration
3
+ attr_reader :properties
4
+ attr_accessor :key, :domain
5
+
6
+ def initialize(options = {})
7
+ options.each { |key, value|
8
+ instance_variable_set("@#{key}", value)
9
+ }
10
+ @properties = Properties.new(options[:properties] || {})
11
+ end
12
+ end
13
+ end
data/lib/kf5/helper.rb ADDED
@@ -0,0 +1,52 @@
1
+ module KF5
2
+ module Helper
3
+ def kf5_url(options)
4
+ username = Helper.indifferent_access(options, :username)
5
+ time = Time.now.to_i
6
+ token = Digest::MD5.hexdigest "#{username}#{time}#{KF5.configuration.key}"
7
+
8
+ params = {
9
+ :username => username,
10
+ :time => time,
11
+ :token => token
12
+ }
13
+ Helper.copy_if_exist(options, params, :name)
14
+ Helper.copy_if_exist(options, params, :phone)
15
+ Helper.copy_if_exist(options, params, :return_to)
16
+
17
+ query = URI.encode_www_form(params)
18
+ "https://#{KF5.configuration.domain}.kf5.com/user/remote?#{query}"
19
+ end
20
+
21
+ def redirect_to_kf5(options = {})
22
+ redirect_to current_user_kf5_url(options)
23
+ end
24
+
25
+ private
26
+
27
+ def current_user_kf5_url(options = {})
28
+ kf5_url(current_user_kf5_options.merge(options))
29
+ end
30
+
31
+ def current_user_kf5_options
32
+ options = {}
33
+ return options unless respond_to? :current_user
34
+ [:username, :name, :phone].each { |key|
35
+ property = KF5.configuration.properties.send(key)
36
+ next if property.nil? || !current_user.respond_to?(property)
37
+ value = current_user.send(property)
38
+ options[key] = value unless value.nil?
39
+ }
40
+ options
41
+ end
42
+
43
+ def self.indifferent_access(hash, key)
44
+ hash[key.to_s] || hash[key.to_sym]
45
+ end
46
+
47
+ def self.copy_if_exist(from_hash, to_hash, key)
48
+ value = indifferent_access(from_hash, key)
49
+ to_hash[key] = value unless value.nil?
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,14 @@
1
+ module KF5
2
+ class Properties
3
+ attr_accessor :username, :name, :phone
4
+
5
+ def initialize(options = {})
6
+ @username = :username
7
+ @name = :name
8
+ @phone = :phone
9
+ options.each { |key, value|
10
+ instance_variable_set("@#{key}", value)
11
+ }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module KF5
2
+ VERSION = "0.1.0"
3
+ end
data/lib/kf5.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'digest'
2
+ require 'uri'
3
+
4
+ require "kf5/version"
5
+ require "kf5/configuration"
6
+ require "kf5/properties"
7
+ require "kf5/helper"
8
+
9
+ module KF5
10
+ def self.configure(&block)
11
+ yield configuration
12
+ end
13
+
14
+ def self.configuration
15
+ @configuration ||= Configuration.new
16
+ end
17
+
18
+ if defined?(::Rails::Engine)
19
+ class Engine < ::Rails::Engine
20
+ initializer "kf5" do
21
+ ActiveSupport.on_load :action_controller do
22
+ include KF5::Helper
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kf5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chen Yi-Cyuan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-03 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A simple presenter pattern for ruby. It can work in rails.
70
+ email:
71
+ - emn178@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - CHANGELOG.md
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - kf5.gemspec
85
+ - lib/kf5.rb
86
+ - lib/kf5/configuration.rb
87
+ - lib/kf5/helper.rb
88
+ - lib/kf5/properties.rb
89
+ - lib/kf5/version.rb
90
+ homepage: https://github.com/emn178/kf5
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.5
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: A simple presenter pattern for ruby. It can work in rails.
114
+ test_files: []