Class: MailinatorClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/mailinator_client/client.rb

Overview

Mailinator API

User API for accessing Mailinator data

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

attr_reader :auth_token, :url



11
12
13
14
# File 'lib/mailinator_client/client.rb', line 11

def initialize(options = {})
  @auth_token = options.fetch(:auth_token, nil)
  @url        = "https://api.mailinator.com/api/v2"
end

Instance Method Details

#authenticatorsObject



16
17
18
# File 'lib/mailinator_client/client.rb', line 16

def authenticators
  @authenticators ||= Authenticators.new(self)
end

#domainsObject



20
21
22
# File 'lib/mailinator_client/client.rb', line 20

def domains
  @domains ||= Domains.new(self)
end

#messagesObject



28
29
30
# File 'lib/mailinator_client/client.rb', line 28

def messages
  @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
# File 'lib/mailinator_client/client.rb', line 40

def request(options = {})
  headers = options.fetch(:headers, {})
  method  = options.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 + options.fetch(:path, "")

  response = HTTParty.send(method, path,
    query: Utils.fix_query_arrays(options[:query]),
    body: options[:body] && options[:body].to_json(),
    headers: headers,
    timeout: 125
  )

  result = response.parsed_response
  if response.code >= 400
    raise ResponseError.new(response.code, result, response.body)
  end
  
  result
end

#rulesObject



32
33
34
# File 'lib/mailinator_client/client.rb', line 32

def rules
  @rules ||= Rules.new(self)
end

#statsObject



24
25
26
# File 'lib/mailinator_client/client.rb', line 24

def stats
  @stats ||= Stats.new(self)
end

#webhooksObject



36
37
38
# File 'lib/mailinator_client/client.rb', line 36

def webhooks
  @webhooks ||= Webhooks.new(self)
end