appoxy_api 0.0.1 → 0.0.2

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.
@@ -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 sig_should method which will return the signature to compare against.
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(params, operation)
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::SigError, "No access_key" if access_key.nil?
26
- raise Api::SigError, "No sigv" if sigv.nil?
27
- raise Api::SigError, "No timestamp" if timestamp.nil?
28
- raise Api::SigError, "No sig" if sig.nil?
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
- # todo: verify sig! Use SimpleWorker::HttpEnabled signature methods
31
- sig2 = Appoxy::Api::Signatures.generate_signature(operation, timestamp, @project.secret_key)
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
- raise Api::ApiError, "Invalid signature!" unless sig_should == sig2
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
- # format.json { render :json=>msg }
46
- response_as_string = render_to_string :json => msg
47
- render :json => response_as_string
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
@@ -76,6 +76,7 @@ module Appoxy
76
76
  raise ClientError.new(res.class.name, ActiveSupport::JSON.decode(res.body))
77
77
  else
78
78
  #res.error
79
+ puts 'ERROR BODY=' + res.body
79
80
  raise ServiceError.new(res.class.name, res.body)
80
81
  end
81
82
  return ret
@@ -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
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Travis Reeder