token_postman 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: f66564f9234d0b90cc463a7c800318412dc3c798
4
+ data.tar.gz: 4220d89073cb104c2869ee2e4e16412b8d8a064c
5
+ SHA512:
6
+ metadata.gz: 9a5a09ec1a51a0d62003e6a664bfa0405a56013e7cd89d1a69fc1ff6bde25620586ed04cacfd174370a2d1c9dcec768cc80e9165946886a8dc784981cad0933e
7
+ data.tar.gz: d121b144b42bea990a0f9c7d5a8bbf5114278ac1f91a3274ca3cc27cde600a18e72a91d3c9fb52afab6251ae8bdb5a577599510ce2e279c2f609f80055509e3a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'TokenPostman'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :token_postman do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,82 @@
1
+ module TokenPostman
2
+ class MethodNotImplementedException < Exception; end
3
+ def self.included base
4
+
5
+ base.class_eval do
6
+
7
+ def _postman_login user
8
+ if params[:cookie]
9
+ ensure_method_exists(user, :generate_web_access_token)
10
+ cookies['TOKEN_POSTMAN'] = user.generate_web_access_token
11
+ render :json => user
12
+ else
13
+ ensure_method_exists(user, :generate_access_token)
14
+ user_hash = user.as_json.merge(
15
+ :access_token => user.generate_access_token)
16
+ render :json => user_hash
17
+ end
18
+ end
19
+ private :_postman_login
20
+
21
+ def ensure_method_exists(user, method_name)
22
+ unless user.respond_to?(method_name)
23
+ raise MethodNotImplementedException,
24
+ "#{user.class} should have `##{method_name}` method"
25
+ end
26
+ end
27
+ private :ensure_method_exists
28
+
29
+ def _postman_conflict
30
+ render :json => { :reason => 'login failed' },
31
+ :status => 409
32
+ end
33
+ private :_postman_conflict
34
+
35
+ def _postman_bad_request e
36
+ render :json => { :reason => e.message },
37
+ :status => 400
38
+ end
39
+ private :_postman_bad_request
40
+
41
+ end
42
+
43
+ class << base
44
+ # usage:
45
+ # class UsersController
46
+ # login FacebookUser, :with => :facebook_login
47
+ # end
48
+ #
49
+ # # route.rb
50
+ # post '/users/fb_login' => 'users#facebook_login'
51
+ def login user_class, options
52
+ ensure_login_method_exists(user_class)
53
+
54
+ instance_method_name = options[:with]
55
+
56
+ define_method instance_method_name do
57
+ begin
58
+ user = user_class.login(params.require(:account), params.require(:validator))
59
+
60
+ if user
61
+ _postman_login(user)
62
+ else
63
+ _postman_conflict
64
+ end
65
+ rescue ActionController::ParameterMissing => e
66
+ _postman_bad_request(e)
67
+ end
68
+ end
69
+ end
70
+
71
+ def ensure_login_method_exists user_class
72
+ unless user_class.respond_to?(:login)
73
+ raise MethodNotImplementedException,
74
+ "#{user_class} should have `::login` method"
75
+ end
76
+ end
77
+ private :ensure_login_method_exists
78
+
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ module TokenPostman
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: token_postman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yang-Hsing Lin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.10
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
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
+ description: A rails plugin handling login stuff in controller
56
+ email:
57
+ - yanghsing.lin@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/token_postman/version.rb
63
+ - lib/tasks/token_postman_tasks.rake
64
+ - lib/token_postman.rb
65
+ - MIT-LICENSE
66
+ - Rakefile
67
+ homepage: https://github.com/mz026/token_postman
68
+ licenses: []
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.0.3
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: A rails plugin handling login stuff in controller
90
+ test_files: []