Module: MailCatcher::API::Client
- Defined in:
- lib/mailcatcher/api/client.rb
Constant Summary collapse
- MESSAGE_ENDPOINT =
'/messages/%{message_id}.json'.freeze
- MESSAGE_INDEX_ENDPOINT =
'/messages'.freeze
Class Method Summary collapse
- .delete_all ⇒ Object
- .delete_message(id) ⇒ Object
- .fetch_message(id) ⇒ Object
- .fetch_message_index ⇒ Object
- .http ⇒ Object
- .request(method, path) ⇒ Object
Class Method Details
.delete_all ⇒ Object
19 20 21 |
# File 'lib/mailcatcher/api/client.rb', line 19 def self.delete_all request(:delete, MESSAGE_INDEX_ENDPOINT) end |
.delete_message(id) ⇒ Object
23 24 25 |
# File 'lib/mailcatcher/api/client.rb', line 23 def self.(id) request(:delete, format(MESSAGE_ENDPOINT, message_id: id)) end |
.fetch_message(id) ⇒ Object
15 16 17 |
# File 'lib/mailcatcher/api/client.rb', line 15 def self.(id) request(:get, format(MESSAGE_ENDPOINT, message_id: id)) end |
.fetch_message_index ⇒ Object
11 12 13 |
# File 'lib/mailcatcher/api/client.rb', line 11 def self. request(:get, MESSAGE_INDEX_ENDPOINT) end |
.http ⇒ Object
37 38 39 40 |
# File 'lib/mailcatcher/api/client.rb', line 37 def self.http uri = URI(MailCatcher::API.config.server) Net::HTTP.new(uri.host, uri.port) end |
.request(method, path) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/mailcatcher/api/client.rb', line 27 def self.request(method, path) request = case method when :get; Net::HTTP::Get.new(path) when :delete; Net::HTTP::Delete.new(path) else raise NotImplementedError, "Don't know how to request #{method} method" end response = http.request(request) JSON.load(response.body) end |