Class: Smaak::Client

Inherits:
Associate show all
Defined in:
lib/smaak/client.rb

Instance Attribute Summary collapse

Attributes inherited from Associate

#association_store, #key, #token_life

Instance Method Summary collapse

Methods inherited from Associate

#add_association, #set_key, #set_token_life

Constructor Details

#initializeClient

Returns a new instance of Client.



11
12
13
14
# File 'lib/smaak/client.rb', line 11

def initialize
  super
  set_route_info("")
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



8
9
10
# File 'lib/smaak/client.rb', line 8

def identifier
  @identifier
end

#route_infoObject (readonly)

Returns the value of attribute route_info.



9
10
11
# File 'lib/smaak/client.rb', line 9

def route_info
  @route_info
end

Instance Method Details

#get(identifier, uri, body, ssl = false, ssl_verify = OpenSSL::SSL::VERIFY_PEER) ⇒ Object



39
40
41
# File 'lib/smaak/client.rb', line 39

def get(identifier, uri, body, ssl = false, ssl_verify = OpenSSL::SSL::VERIFY_PEER)
  connect(Net::HTTP::Get, identifier, uri, body, ssl, ssl_verify)
end

#post(identifier, uri, body, ssl = false, ssl_verify = OpenSSL::SSL::VERIFY_PEER) ⇒ Object



43
44
45
# File 'lib/smaak/client.rb', line 43

def post(identifier, uri, body, ssl = false, ssl_verify = OpenSSL::SSL::VERIFY_PEER)
  connect(Net::HTTP::Post, identifier, uri, body, ssl, ssl_verify)
end

#set_identifier(identifier) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
# File 'lib/smaak/client.rb', line 20

def set_identifier(identifier)
  raise ArgumentError.new("Invalid identifier") unless Smaak::Utils.non_blank_string?(identifier)
  @identifier = identifier
end

#set_private_key(key) ⇒ Object



16
17
18
# File 'lib/smaak/client.rb', line 16

def set_private_key(key)
  set_key(key)
end

#set_route_info(route_info) ⇒ Object



25
26
27
28
# File 'lib/smaak/client.rb', line 25

def set_route_info(route_info)
  @route_info = route_info
  @route_info ||= ""
end

#sign_request(associate_identifier, adaptor) ⇒ Object

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
# File 'lib/smaak/client.rb', line 30

def sign_request(associate_identifier, adaptor)
  raise ArgumentError.new("Associate invalid") unless validate_associate(associate_identifier)
  associate = @association_store[associate_identifier]
  raise ArgumentError.new("Invalid adaptor") if adaptor.nil?
  auth_message = Smaak::AuthMessage.create(associate['public_key'].export, associate['psk'], @token_life, @identifier, @route_info, associate['encrypt'])
  adaptor.body = Smaak::Crypto.encrypt(adaptor.body, associate['public_key']) if auth_message.encrypt
  Smaak.sign_authorization_headers(@key, auth_message, adaptor, Smaak::Cavage04::SPECIFICATION)
end