Module: Mailercity
- Defined in:
- lib/mailercity.rb,
lib/mailercity/helper.rb,
lib/mailercity/version.rb,
lib/mailercity/errors/authentication_error.rb
Defined Under Namespace
Modules: Helper
Classes: AuthenticationError, Message
Constant Summary
collapse
- VERSION =
"0.0.7"
- @@api_base =
'https://mailercity.onthecity.org'
- @@api_key =
nil
- @@perform_deliveries =
true
- @@logger =
nil
Class Method Summary
collapse
Class Method Details
.api_base ⇒ Object
17
18
19
|
# File 'lib/mailercity.rb', line 17
def self.api_base
@@api_base
end
|
.api_base=(api_base) ⇒ Object
13
14
15
|
# File 'lib/mailercity.rb', line 13
def self.api_base=(api_base)
@@api_base = api_base
end
|
.api_key ⇒ Object
29
30
31
|
# File 'lib/mailercity.rb', line 29
def self.api_key
@@api_key
end
|
.api_key=(api_key) ⇒ Object
25
26
27
|
# File 'lib/mailercity.rb', line 25
def self.api_key=(api_key)
@@api_key = api_key
end
|
.api_url(url = '') ⇒ Object
21
22
23
|
# File 'lib/mailercity.rb', line 21
def self.api_url(url='')
@@api_base + url
end
|
.const_missing(const_name) ⇒ Object
59
60
61
62
63
64
|
# File 'lib/mailercity.rb', line 59
def self.const_missing(const_name)
new_class = Class.new(super_class=Message)
const_set(const_name, new_class)
end
|
.logger ⇒ Object
45
46
47
|
# File 'lib/mailercity.rb', line 45
def self.logger
@@logger
end
|
.logger=(logger) ⇒ Object
41
42
43
|
# File 'lib/mailercity.rb', line 41
def self.logger=(logger)
@@logger = logger
end
|
37
38
39
|
# File 'lib/mailercity.rb', line 37
def self.perform_deliveries
@@perform_deliveries
end
|
33
34
35
|
# File 'lib/mailercity.rb', line 33
def self.perform_deliveries=(perform_deliveries)
@@perform_deliveries = perform_deliveries
end
|
.request(path, args) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/mailercity.rb', line 49
def self.request(path, args)
raise AuthenticationError.new('No API key provided. (HINT: set your API key using "Mailercity.api_key = <API-KEY>".') unless api_key
payload = {:args => args}
response = Faraday.post(api_url(path)) do |req|
req.['Content-Type'] = 'application/json'
req.['X-Api-Key'] = Mailercity.api_key
req.body = payload.to_json
end
end
|