Module: Rufbit
- Defined in:
- lib/rufbit.rb,
lib/rufbit/states.rb,
lib/rufbit/version.rb,
lib/rufbit/exceptions.rb,
lib/rufbit/notification.rb
Defined Under Namespace
Classes: AuthenticationError, InvalidRequestError, RufbitError, State
Constant Summary
collapse
- VERSION =
"1.0.2"
- @@API_KEY =
""
- @@host =
'api.rufbit.com'
- @@port =
'443'
Class Method Summary
collapse
Class Method Details
.API_KEY ⇒ Object
15
16
17
|
# File 'lib/rufbit.rb', line 15
def self.API_KEY
return @@API_KEY
end
|
.API_KEY=(key) ⇒ Object
11
12
13
|
# File 'lib/rufbit.rb', line 11
def self.API_KEY= (key)
@@API_KEY = key
end
|
.host ⇒ Object
19
20
21
|
# File 'lib/rufbit.rb', line 19
def self.host
return @@host
end
|
.port ⇒ Object
23
24
25
|
# File 'lib/rufbit.rb', line 23
def self.port
return @@port
end
|
.send(title, data, state) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/rufbit/notification.rb', line 6
def self.send(title, data, state)
path = "/v1/notify"
body ={
"API_KEY" => Rufbit.API_KEY,
"title" => title,
"data" => data,
"state" => state
}.to_json
request = Net::HTTP::Post.new(path, = {'Content-Type' =>'application/json'})
request.body = body
response = Net::HTTP.new(Rufbit.host, Rufbit.port)
response.ssl_version = :TLSv1
response.use_ssl = true
response.verify_mode = ::OpenSSL::SSL::VERIFY_NONE
response.start {|http| @res = http.request(request) }
case @res.code
when "400"
raise InvalidRequestError.new(@res), "The request could not be processed properly, often due to missing or invalid parameters"
when "401"
raise AuthenticationError.new(@res), "The provided API-Key is invalid or missing"
when "500"
raise RufbitError.new(@res), "Something went wrong on our end. Please contact us if you believe this wasn't supposed to happen."
end
return JSON::parse @res.body
end
|