appoxy_api 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/api/api_controller.rb +27 -14
- data/lib/api/client.rb +3 -3
- data/lib/api/client_helper.rb +1 -0
- data/lib/api/signatures.rb +0 -4
- data/lib/appoxy_api.rb +6 -1
- metadata +2 -2
data/lib/api/api_controller.rb
CHANGED
@@ -9,11 +9,24 @@ module Appoxy
|
|
9
9
|
# rescue_from Api::ApiError, :with => :send_error
|
10
10
|
# before_filter :verify_signature(params)
|
11
11
|
|
12
|
-
# Your Controller must define a
|
12
|
+
# Your Controller must define a secret_key_for_signature method which will return the secret key to use to generate signature.
|
13
13
|
|
14
14
|
module ApiController
|
15
15
|
|
16
|
-
def verify_signature
|
16
|
+
def verify_signature
|
17
|
+
|
18
|
+
if request.put?
|
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
|
+
|
28
|
+
operation = "#{controller_name}/#{action_name}"
|
29
|
+
puts "XXX " + operation
|
17
30
|
|
18
31
|
# puts 'params in base=' + params.inspect
|
19
32
|
|
@@ -22,15 +35,15 @@ module Appoxy
|
|
22
35
|
timestamp = params["timestamp"]
|
23
36
|
sig = params["sig"]
|
24
37
|
|
25
|
-
raise Api::
|
26
|
-
raise Api::
|
27
|
-
raise Api::
|
28
|
-
raise Api::
|
38
|
+
raise Appoxy::Api::ApiError, "No access_key" if access_key.nil?
|
39
|
+
raise Appoxy::Api::ApiError, "No sigv" if sigv.nil?
|
40
|
+
raise Appoxy::Api::ApiError, "No timestamp" if timestamp.nil?
|
41
|
+
raise Appoxy::Api::ApiError, "No sig" if sig.nil?
|
29
42
|
|
30
|
-
|
31
|
-
|
43
|
+
sig2 = Appoxy::Api::Signatures.generate_signature(operation, timestamp, secret_key_for_signature(access_key))
|
44
|
+
raise Appoxy::Api::ApiError, "Invalid signature!" unless sig == sig2
|
32
45
|
|
33
|
-
|
46
|
+
puts 'Verified OK'
|
34
47
|
|
35
48
|
end
|
36
49
|
|
@@ -41,11 +54,11 @@ module Appoxy
|
|
41
54
|
|
42
55
|
def send_ok(msg={})
|
43
56
|
response_as_string = '' # in case we want to add debugging or something
|
44
|
-
respond_to do |format|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
57
|
+
# respond_to do |format|
|
58
|
+
# format.json { render :json=>msg }
|
59
|
+
response_as_string = render_to_string :json => msg
|
60
|
+
render :json => response_as_string
|
61
|
+
# end
|
49
62
|
true
|
50
63
|
end
|
51
64
|
|
data/lib/api/client.rb
CHANGED
@@ -5,12 +5,12 @@ module Appoxy
|
|
5
5
|
# host: endpoint url for service
|
6
6
|
class Client
|
7
7
|
|
8
|
-
attr_accessor :access_key, :secret_key
|
8
|
+
attr_accessor :host, :access_key, :secret_key
|
9
9
|
|
10
10
|
def initialize(host, access_key, secret_key, options={})
|
11
|
+
@host = host
|
11
12
|
@access_key = access_key
|
12
13
|
@secret_key = secret_key
|
13
|
-
|
14
14
|
end
|
15
15
|
|
16
16
|
def get(method, params={}, options={})
|
@@ -36,6 +36,6 @@ module Appoxy
|
|
36
36
|
|
37
37
|
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
end
|
41
41
|
end
|
data/lib/api/client_helper.rb
CHANGED
data/lib/api/signatures.rb
CHANGED
@@ -8,11 +8,7 @@ module Appoxy
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.generate_signature(operation, timestamp, secret_key)
|
11
|
-
# if USE_EMBEDDED_HMAC
|
12
|
-
# my_sha_hmac = HMAC::SHA1.digest(secret_key, operation + timestamp)
|
13
|
-
# else
|
14
11
|
my_sha_hmac = Digest::HMAC.digest(operation + timestamp, secret_key, Digest::SHA1)
|
15
|
-
# end
|
16
12
|
my_b64_hmac_digest = Base64.encode64(my_sha_hmac).strip
|
17
13
|
return my_b64_hmac_digest
|
18
14
|
end
|
data/lib/appoxy_api.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
-
|
1
|
+
require 'active_support'
|
2
|
+
require 'digest/hmac'
|
3
|
+
require 'net/http'
|
4
|
+
require 'base64'
|
5
|
+
|
2
6
|
require File.join(File.dirname(__FILE__), "api", "api_controller")
|
3
7
|
require File.join(File.dirname(__FILE__), "api", "client_helper")
|
4
8
|
require File.join(File.dirname(__FILE__), "api", "signatures")
|
9
|
+
require File.join(File.dirname(__FILE__), "api", "client")
|
5
10
|
|