Class: Sorenson::ThreeSixty::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sorenson/threesixty/base.rb

Constant Summary collapse

TOKEN_SALT =
'beachfr0nt'
@@debug =
false
@@use_ssl =
false

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.debug=(value) ⇒ Object



24
25
26
# File 'lib/sorenson/threesixty/base.rb', line 24

def self.debug=(value)
  @@debug = value
end

.debug?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/sorenson/threesixty/base.rb', line 16

def self.debug?
  !!@@debug
end

.hostObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sorenson/threesixty/base.rb', line 28

def self.host
  host = '360.sorensonmedia.com'
  filename = '/var/tmp/360host'
  if File.exist?(filename)
    data = File.read(filename)
    if data && data != ''
      env = data.split("\n").first.strip
      response = RestClient.get("http://www.sorensonmedia.com/internal/apis/360Env.php?env=#{env}").strip
      host = response unless response == 'invalid option specified'
    end
  end

  host
end

.post_to(url) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/sorenson/threesixty/base.rb', line 51

def self.post_to(url)
  post_to_url = protocol + host + url
  result = RestClient.post(post_to_url, {}).body

  if debug?
    puts '/// URL //////////////////////////////'
    puts post_to_url
    puts '/// DATA //////////////////////////////'
    puts result
  end

  begin
    JSON.parse(result)
  rescue JSON::ParserError => e
    raise InvalidServerResponse.new(e.message)
  end
end

.protocolObject



43
44
45
# File 'lib/sorenson/threesixty/base.rb', line 43

def self.protocol
  use_ssl? ? 'https://' : 'http://'
end

.token_for(username) ⇒ Object



47
48
49
# File 'lib/sorenson/threesixty/base.rb', line 47

def self.token_for(username)
  Digest::SHA1.hexdigest(TOKEN_SALT + username)
end

.use_ssl=(value) ⇒ Object



20
21
22
# File 'lib/sorenson/threesixty/base.rb', line 20

def self.use_ssl=(value)
  @@use_ssl = value
end

.use_ssl?Boolean

Class Methods

Returns:

  • (Boolean)


12
13
14
# File 'lib/sorenson/threesixty/base.rb', line 12

def self.use_ssl?
  !!@@use_ssl
end

Instance Method Details

#post_to(url) ⇒ Object

Instance Methods



70
71
72
# File 'lib/sorenson/threesixty/base.rb', line 70

def post_to(url)
  self.class.post_to(url)
end