Class: WP::HMAC::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/wp/hmac/client.rb

Overview

HMAC Client

This client uses EY::ApiHMAC to hash a request with a secret key in order to authenticate the client.

See here for the implementation details: github.com/engineyard/ey_api_hmac

Defined Under Namespace

Classes: UnsuccessfulResponse

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = nil) ⇒ Client

Returns a new instance of Client.



18
19
20
# File 'lib/wp/hmac/client.rb', line 18

def initialize(url = nil)
  build_rack_client(url)
end

Class Attribute Details

.rack_appObject

Returns the value of attribute rack_app.



15
16
17
# File 'lib/wp/hmac/client.rb', line 15

def rack_app
  @rack_app
end

Instance Method Details

#build_rack_client(url) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wp/hmac/client.rb', line 22

def build_rack_client(url)
  id = key_cabinet.id
  auth_key = key_cabinet.auth_key

  @client = Rack::Client.new(url) do
    use Rack::Config do |env|
      env['HTTP_DATE'] = Time.now.httpdate
    end
    use EY::ApiHMAC::ApiAuth::Client, id, auth_key
    run Client.rack_app
  end
  @client
end

#key_cabinetObject



36
37
38
# File 'lib/wp/hmac/client.rb', line 36

def key_cabinet
  @key_cabinet ||= HMAC::KeyCabinet.find_by_auth_id(HMAC.auth_id)
end