Class: Sugester::SugesterQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/sugester.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(secret) ⇒ SugesterQueue



30
31
32
33
# File 'lib/sugester.rb', line 30

def initialize(secret)
  @secret = secret
  @sqs = Aws::SQS::Client.new(config(:config))
end

Class Method Details

.decrypt(msg) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sugester.rb', line 10

def self.decrypt(msg)
  begin
    cipher = OpenSSL::Cipher.new('AES-128-ECB')
    cipher.decrypt()
    cipher.key = "JKLGHJFHGFUOYTIUKYGbhjgvcutytfiCktyD845^8^f6d%df65*I"
    tempkey = Base64.decode64(URI.decode(msg))
    crypt = cipher.update(tempkey)
    crypt << cipher.final()
  rescue
    crypt = nil
  end
  return crypt
end

Instance Method Details

#activity(client_id, activity_name, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sugester.rb', line 35

def activity(client_id, activity_name, options = {})
  #TODO assert client_id
  msg = {
    activity: activity_name,
    client_id: client_id,
    token: config(:token),
    prefix: config(:prefix),
  }
  #TODO max length
  @sqs.send_message({
    queue_url: config(:url),
    message_body: msg.to_json,
  })
end

#config(property) ⇒ Object



24
25
26
27
28
# File 'lib/sugester.rb', line 24

def config(property)
  JSON.parse(SugesterQueue.decrypt(@secret)).deep_symbolize_keys[property]
rescue JSON::ParserError => e
  raise "secret corrupted"
end