Class: SurenotifyRails::Client
- Inherits:
-
Object
- Object
- SurenotifyRails::Client
- Defined in:
- lib/surenotify_rails/client.rb
Constant Summary collapse
- API_URL =
"https://mail.surenotifyapi.com/v1".freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#verify_ssl ⇒ Object
readonly
Returns the value of attribute verify_ssl.
Instance Method Summary collapse
- #events(filters = {}) ⇒ Object
-
#initialize(api_key, verify_ssl = true) ⇒ Client
constructor
A new instance of Client.
- #send_message(options) ⇒ Object
Constructor Details
#initialize(api_key, verify_ssl = true) ⇒ Client
Returns a new instance of Client.
10 11 12 13 |
# File 'lib/surenotify_rails/client.rb', line 10 def initialize(api_key, verify_ssl = true) @api_key = api_key @verify_ssl = verify_ssl end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/surenotify_rails/client.rb', line 8 def api_key @api_key end |
#verify_ssl ⇒ Object (readonly)
Returns the value of attribute verify_ssl.
8 9 10 |
# File 'lib/surenotify_rails/client.rb', line 8 def verify_ssl @verify_ssl end |
Instance Method Details
#events(filters = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/surenotify_rails/client.rb', line 23 def events(filters = {}) uri = URI("#{API_URL}/events") uri.query = URI.encode_www_form(filters) unless filters.empty? request = Net::HTTP::Get.new(uri) apply_headers(request) response = perform(uri, request) unless response.is_a?(Net::HTTPSuccess) raise APIError.new("Surenotify API error: #{response.code}", code: response.code, body: response.body) end JSON.parse(response.body) end |
#send_message(options) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/surenotify_rails/client.rb', line 15 def () uri = URI("#{API_URL}/messages") request = Net::HTTP::Post.new(uri) apply_headers(request) request.body = JSON.dump() perform(uri, request) end |