Class: MailinatorClient::Client
- Inherits:
-
Object
- Object
- MailinatorClient::Client
- Defined in:
- lib/mailinator_client/client.rb
Overview
Mailinator API
User API for accessing Mailinator data
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
readonly
Returns the value of attribute auth_token.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #authenticators ⇒ Object
- #domains ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #messages ⇒ Object
- #request(options = {}) ⇒ Object
- #rules ⇒ Object
- #stats ⇒ Object
- #webhooks ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
11 12 13 14 |
# File 'lib/mailinator_client/client.rb', line 11 def initialize( = {}) @auth_token = .fetch(:auth_token, nil) @url = "https://api.mailinator.com/api/v2" end |
Instance Attribute Details
#auth_token ⇒ Object (readonly)
Returns the value of attribute auth_token.
9 10 11 |
# File 'lib/mailinator_client/client.rb', line 9 def auth_token @auth_token end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
9 10 11 |
# File 'lib/mailinator_client/client.rb', line 9 def url @url end |
Instance Method Details
#authenticators ⇒ Object
16 17 18 |
# File 'lib/mailinator_client/client.rb', line 16 def authenticators @authenticators ||= Authenticators.new(self) end |
#domains ⇒ Object
20 21 22 |
# File 'lib/mailinator_client/client.rb', line 20 def domains @domains ||= Domains.new(self) end |
#messages ⇒ Object
28 29 30 |
# File 'lib/mailinator_client/client.rb', line 28 def @messages ||= Messages.new(self) end |
#request(options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/mailinator_client/client.rb', line 40 def request( = {}) headers = .fetch(:headers, {}) method = .fetch(:method, :get) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" headers["User-Agent"] = "Mailinator SDK - Ruby V#{MailinatorClient::VERSION}" headers["Authorization"] = @auth_token if @auth_token path = @url + .fetch(:path, "") debug_request = ENV["MAILINATOR_DEBUG_REQUESTS"].to_s.strip.downcase if debug_request == "1" || debug_request == "true" warn "[mailinator] #{method.to_s.upcase} #{path}" warn "[mailinator] headers=#{headers}" warn "[mailinator] query=#{Utils.fix_query_arrays([:query])}" end response = HTTParty.send(method, path, query: Utils.fix_query_arrays([:query]), body: [:body] && [:body].to_json(), headers: headers, timeout: 125 ) if debug_request == "1" || debug_request == "true" warn "[mailinator] response_code=#{response.code}" warn "[mailinator] response_body=#{response.body}" end result = response.parsed_response if response.code >= 400 raise ResponseError.new(response.code, result, response.body) end result end |
#rules ⇒ Object
32 33 34 |
# File 'lib/mailinator_client/client.rb', line 32 def rules @rules ||= Rules.new(self) end |