Class: Transistor::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



12
13
14
15
16
# File 'lib/transistor.rb', line 12

def initialize
  @host = 'api.transistor.fm'
  @secure = true
  @tracking_url = 'track.transistor.fm/:entry_id.:format/:url'
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



10
11
12
# File 'lib/transistor.rb', line 10

def host
  @host
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/transistor.rb', line 10

def id
  @id
end

#secretObject

Returns the value of attribute secret.



10
11
12
# File 'lib/transistor.rb', line 10

def secret
  @secret
end

#secureObject

Returns the value of attribute secure.



10
11
12
# File 'lib/transistor.rb', line 10

def secure
  @secure
end

Instance Method Details

#base_urlObject



18
19
20
21
22
23
24
# File 'lib/transistor.rb', line 18

def base_url
  if self.secure
    "https://#{self.host}"
  else
    "http://#{self.host}"
  end
end

#credentialsObject



26
27
28
29
30
31
32
# File 'lib/transistor.rb', line 26

def credentials
  {
    id: self.id,
    key: self.secret,
    algorithm: 'sha256'
  }
end

#protocolObject



38
39
40
41
42
43
44
# File 'lib/transistor.rb', line 38

def protocol
  if self.secure
    'https'
  else
    'http'
  end
end

#tracking_url(entry_id, format, url) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/transistor.rb', line 46

def tracking_url(entry_id, format, url)
  full_url = @tracking_url
    .gsub(':entry_id', entry_id.to_s)
    .gsub(':format', format.to_s)
    .gsub(':url', url)
  [self.protocol, '://', full_url].join()
end

#user_agentObject



34
35
36
# File 'lib/transistor.rb', line 34

def user_agent
  "Transistor Ruby Client, Version #{Transistor::Version}"
end