appoxy_rails 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,32 +1,32 @@
1
1
  module Appoxy
2
2
 
3
- module Rails
3
+ module Rails
4
4
 
5
- # The rails controllers that use this should set:
5
+ # The rails controllers that use this should set:
6
6
  # protect_from_forgery :only => [] # can add methods to here, eg: :create, :update, :destroy
7
7
 
8
8
  # rescue_from SigError, :with => :send_error
9
9
  # rescue_from Api::ApiError, :with => :send_error
10
- # before_filter :verify_signature(params)
11
-
12
- # Your Controller must define a secret_key_for_signature method which will return the secret key to use to generate signature.
13
-
14
- module ApiController
15
-
16
- def verify_signature
17
- params2 = nil
18
- if request.put? || request.post?
19
- # We'll extract params from body instead here
20
- # todo: maybe check for json format first in case this is a file or something?
21
- body = request.body.read
22
- puts 'body=' + body.inspect
23
- params2 = ActiveSupport::JSON.decode(body)
24
- puts 'params2=' + params2.inspect
25
- params.merge! params2
26
- end
10
+ # before_filter :verify_signature(params)
11
+
12
+ # Your Controller must define a secret_key_for_signature method which will return the secret key to use to generate signature.
13
+
14
+ module ApiController
15
+
16
+ def verify_signature
17
+ params2 = nil
18
+ if request.put? || request.post?
19
+ # We'll extract params from body instead here
20
+ # todo: maybe check for json format first in case this is a file or something?
21
+ body = request.body.read
22
+ puts 'body=' + body.inspect
23
+ params2 = ActiveSupport::JSON.decode(body)
24
+ puts 'params2=' + params2.inspect
25
+ params.merge! params2
26
+ end
27
27
 
28
- #operation = "#{controller_name}/#{action_name}"
29
- #operation = request.env["PATH_INFO"].gsub(/\/rails\//, "")# here we're getting original request url'
28
+ #operation = "#{controller_name}/#{action_name}"
29
+ #operation = request.env["PATH_INFO"].gsub(/\/rails\//, "")# here we're getting original request url'
30
30
 
31
31
  # #getting clean params (without parsed via routes)
32
32
  # params_for_signature = params2||request.query_parameters
@@ -34,80 +34,81 @@ module Appoxy
34
34
  # params_for_signature = params_for_signature.delete_if {|key, value| ["access_key", "sigv", "sig", "timestamp"].include? key}
35
35
 
36
36
 
37
- #puts "params " +operation+Appoxy::Api::Signatures.hash_to_s(params_for_signature)
38
- access_key = params["access_key"]
39
- sigv = params["sigv"]
40
- timestamp = params["timestamp"]
41
- sig = params["sig"]
42
- signature = ""
43
- case sigv
44
- when "0.1"
45
- puts "outdated version of client"
46
- signature = "#{controller_name}/#{action_name}"
47
- when "0.2"
48
- puts "new version of client"
49
- operation = request.env["PATH_INFO"].gsub(/\/rails\//, "")# here we're getting original request url'
50
- params_for_signature = params2||request.query_parameters
51
- params_for_signature = params_for_signature.delete_if {|key, value| ["access_key", "sigv", "sig", "timestamp"].include? key}
52
- signature = operation+Appoxy::Api::Signatures.hash_to_s(params_for_signature)
53
- end
37
+ #puts "params " +operation+Appoxy::Api::Signatures.hash_to_s(params_for_signature)
38
+ access_key = params["access_key"]
39
+ sigv = params["sigv"]
40
+ timestamp = params["timestamp"]
41
+ sig = params["sig"]
42
+ signature = ""
43
+ case sigv
44
+ when "0.1"
45
+ puts "outdated version of client"
46
+ signature = "#{controller_name}/#{action_name}"
47
+ when "0.2"
48
+ puts "new version of client"
49
+ operation = request.env["PATH_INFO"].gsub(/\/rails\//, "") # here we're getting original request url'
50
+ params_for_signature = params2||request.query_parameters
51
+ params_for_signature = params_for_signature.delete_if { |key, value| ["access_key", "sigv", "sig", "timestamp"].include? key }
52
+ signature = operation+Appoxy::Api::Signatures.hash_to_s(params_for_signature)
53
+ end
54
54
  # puts "signature " + signature
55
- raise Appoxy::Api::ApiError, "No access_key" if access_key.nil?
56
- raise Appoxy::Api::ApiError, "No sigv" if sigv.nil?
57
- raise Appoxy::Api::ApiError, "No timestamp" if timestamp.nil?
58
- raise Appoxy::Api::ApiError, "No sig" if sig.nil?
59
- timestamp2 = Appoxy::Api::Signatures.generate_timestamp(Time.now.gmtime)
60
- raise Appoxy::Api::ApiError, "Request timed out!" unless (Time.parse(timestamp2)-Time.parse(timestamp))<60 # deny all requests older than 60 seconds
61
- sig2 = Appoxy::Api::Signatures.generate_signature(signature, timestamp, secret_key_for_signature(access_key))
62
- raise Appoxy::Api::ApiError, "Invalid signature!" unless sig == sig2
55
+ raise Appoxy::Api::ApiError, "No access_key" if access_key.nil?
56
+ raise Appoxy::Api::ApiError, "No sigv" if sigv.nil?
57
+ raise Appoxy::Api::ApiError, "No timestamp" if timestamp.nil?
58
+ raise Appoxy::Api::ApiError, "No sig" if sig.nil?
59
+ gmtime = Time.now.gmtime
60
+ # timestamp2 = Appoxy::Api::Signatures.generate_timestamp(gmtime)
61
+ raise Appoxy::Api::ApiError, "Request timed out!" unless (gmtime - Time.parse(timestamp)) < 60 # deny all requests older than 60 seconds
62
+ sig2 = Appoxy::Api::Signatures.generate_signature(signature, timestamp, secret_key_for_signature(access_key))
63
+ raise Appoxy::Api::ApiError, "Invalid signature!" unless sig == sig2
63
64
 
64
- puts 'Signature OK'
65
+ puts 'Signature OK'
65
66
 
66
- end
67
+ end
67
68
 
68
69
 
69
- def sig_should
70
- raise "You didn't define a sig_should method in your controller!"
71
- end
70
+ def sig_should
71
+ raise "You didn't define a sig_should method in your controller!"
72
+ end
72
73
 
73
74
 
74
- def send_ok(msg={})
75
- response_as_string = '' # in case we want to add debugging or something
75
+ def send_ok(msg={})
76
+ response_as_string = '' # in case we want to add debugging or something
76
77
  # respond_to do |format|
77
- # format.json { render :json=>msg }
78
+ # format.json { render :json=>msg }
78
79
  # response_as_string = render_to_string :json => msg
79
- render :json => msg
80
+ render :json => msg
80
81
  # end
81
- true
82
- end
83
-
84
-
85
- def send_error(statuscode_or_error, msg=nil)
86
- exc = nil
87
- if statuscode_or_error.is_a? Exception
88
- exc = statuscode_or_error
89
- statuscode_or_error = 400
90
- msg = exc.message
91
- end
92
- # deprecate status, should use status_code
93
- json_msg = {"status_code"=>statuscode_or_error, "msg"=>msg}
94
- render :json=>json_msg, :status=>statuscode_or_error
95
- true
96
- end
82
+ true
83
+ end
97
84
 
98
85
 
86
+ def send_error(statuscode_or_error, msg=nil)
87
+ exc = nil
88
+ if statuscode_or_error.is_a? Exception
89
+ exc = statuscode_or_error
90
+ statuscode_or_error = 400
91
+ msg = exc.message
99
92
  end
93
+ # deprecate status, should use status_code
94
+ json_msg = {"status_code"=>statuscode_or_error, "msg"=>msg}
95
+ render :json=>json_msg, :status=>statuscode_or_error
96
+ true
97
+ end
100
98
 
101
99
 
102
- class ApiError < StandardError
100
+ end
103
101
 
104
- def initialize(msg=nil)
105
- super(msg)
106
102
 
107
- end
103
+ class ApiError < StandardError
108
104
 
109
- end
105
+ def initialize(msg=nil)
106
+ super(msg)
107
+
108
+ end
110
109
 
111
110
  end
112
111
 
112
+ end
113
+
113
114
  end
@@ -430,6 +430,10 @@ module Appoxy
430
430
 
431
431
  end
432
432
 
433
+ def google_oauth
434
+
435
+ end
436
+
433
437
  private
434
438
 
435
439
  def after_save_setup(user)
@@ -70,7 +70,7 @@ module Appoxy
70
70
  end
71
71
 
72
72
  if ::Rails.env == "development"
73
- ret += '<div style="margin-top: 10px;">' + ERB::Util.html_escape(SimpleRecord.stats.inspect) + '</div>'
73
+ ret += '<div class="debug">' + ERB::Util.html_escape(SimpleRecord.stats.inspect) + '</div>'
74
74
  end
75
75
  ret.html_safe
76
76
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appoxy_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.0.25
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-03-03 00:00:00.000000000 -08:00
12
+ date: 2011-03-10 00:00:00.000000000 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
17
- requirement: &22818252 !ruby/object:Gem::Requirement
17
+ requirement: &26331156 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *22818252
25
+ version_requirements: *26331156
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: oauth
28
- requirement: &22817964 !ruby/object:Gem::Requirement
28
+ requirement: &26330856 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *22817964
36
+ version_requirements: *26330856
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: ruby-openid
39
- requirement: &22817676 !ruby/object:Gem::Requirement
39
+ requirement: &26330520 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *22817676
47
+ version_requirements: *26330520
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: appoxy_api
50
- requirement: &22817388 !ruby/object:Gem::Requirement
50
+ requirement: &26330220 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *22817388
58
+ version_requirements: *26330220
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: mini_fb
61
- requirement: &22817100 !ruby/object:Gem::Requirement
61
+ requirement: &26329932 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *22817100
69
+ version_requirements: *26329932
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: simple_record
72
- requirement: &22816812 !ruby/object:Gem::Requirement
72
+ requirement: &26329644 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: '0'
78
78
  type: :runtime
79
79
  prerelease: false
80
- version_requirements: *22816812
80
+ version_requirements: *26329644
81
81
  description: Appoxy API Helper gem description...
82
82
  email: travis@appoxy.com
83
83
  executables: []
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  requirements: []
128
128
  rubyforge_project:
129
- rubygems_version: 1.6.0
129
+ rubygems_version: 1.6.2
130
130
  signing_key:
131
131
  specification_version: 3
132
132
  summary: Appoxy Rails Helper gem