Class: Moonshado::Configuration

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

Constant Summary collapse

OPTIONS =
[:api_key, :keywords, :sms_uri, 
:keyword_uri, :auto_register_keyword,
:host, :http_open_timeout, :http_read_timeout,
:port, :protocol, :secure,
:production_environment].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/moonshado/configuration.rb', line 27

def initialize
  @secure                   = false
  @host                     = 'heroku.moonshado.com'
  @http_open_timeout        = 10
  @http_read_timeout        = 10
  @production_environment   = true
  @sms_uri                  = '/sms'
  @keywords_uri             = '/keywords'
  @auto_register_keywords   = false
  @port                     = default_port
  @message_length_range     = 3..115
  @message_length_check     = true
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#auto_register_keywordsObject

Returns the value of attribute auto_register_keywords.



18
19
20
# File 'lib/moonshado/configuration.rb', line 18

def auto_register_keywords
  @auto_register_keywords
end

#hostObject

Returns the value of attribute host.



17
18
19
# File 'lib/moonshado/configuration.rb', line 17

def host
  @host
end

#http_open_timeoutObject

Returns the value of attribute http_open_timeout.



15
16
17
# File 'lib/moonshado/configuration.rb', line 15

def http_open_timeout
  @http_open_timeout
end

#http_read_timeoutObject

Returns the value of attribute http_read_timeout.



16
17
18
# File 'lib/moonshado/configuration.rb', line 16

def http_read_timeout
  @http_read_timeout
end

#keywordsObject

Returns the value of attribute keywords.



11
12
13
# File 'lib/moonshado/configuration.rb', line 11

def keywords
  @keywords
end

#keywords_uriObject

Returns the value of attribute keywords_uri.



13
14
15
# File 'lib/moonshado/configuration.rb', line 13

def keywords_uri
  @keywords_uri
end

#message_length_checkObject Also known as: message_length_check?

Returns the value of attribute message_length_check.



22
23
24
# File 'lib/moonshado/configuration.rb', line 22

def message_length_check
  @message_length_check
end

#message_length_rangeObject

Returns the value of attribute message_length_range.



21
22
23
# File 'lib/moonshado/configuration.rb', line 21

def message_length_range
  @message_length_range
end

#portObject

Returns the value of attribute port.



20
21
22
# File 'lib/moonshado/configuration.rb', line 20

def port
  @port
end

#production_environmentObject

Returns the value of attribute production_environment.



19
20
21
# File 'lib/moonshado/configuration.rb', line 19

def production_environment
  @production_environment
end

#secureObject Also known as: secure?

Returns the value of attribute secure.



14
15
16
# File 'lib/moonshado/configuration.rb', line 14

def secure
  @secure
end

#sms_uriObject

Returns the value of attribute sms_uri.



12
13
14
# File 'lib/moonshado/configuration.rb', line 12

def sms_uri
  @sms_uri
end

Instance Method Details

#[](option) ⇒ Object



55
56
57
# File 'lib/moonshado/configuration.rb', line 55

def [](option)
  send(option)
end

#formatted_api_keyObject



45
46
47
48
49
50
51
52
53
# File 'lib/moonshado/configuration.rb', line 45

def formatted_api_key
  url_obj = URI.parse(@api_key)

  if (url_obj.class == URI::Generic)
    @api_key
  else
    url_obj.user
  end
end

#merge(hash) ⇒ Object



65
66
67
# File 'lib/moonshado/configuration.rb', line 65

def merge(hash)
  to_hash.merge(hash)
end

#protocolObject



73
74
75
76
77
78
79
# File 'lib/moonshado/configuration.rb', line 73

def protocol
  if secure?
    'https'
  else
    'http'
  end
end

#to_hashObject



59
60
61
62
63
# File 'lib/moonshado/configuration.rb', line 59

def to_hash
  OPTIONS.inject({}) do |hash, option|
    hash.merge(option.to_sym => send(option))
  end
end