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



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

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

Instance Method Details

#authenticatorsObject



38
39
40
# File 'lib/mailinator_client/client.rb', line 38

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

#domainsObject



42
43
44
# File 'lib/mailinator_client/client.rb', line 42

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

#messagesObject



50
51
52
# File 'lib/mailinator_client/client.rb', line 50

def messages
  @messages ||= Messages.new(self)
end

#request(options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/mailinator_client/client.rb', line 62

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)

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

#rulesObject



54
55
56
# File 'lib/mailinator_client/client.rb', line 54

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

#statsObject



46
47
48
# File 'lib/mailinator_client/client.rb', line 46

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

#webhooksObject



58
59
60
# File 'lib/mailinator_client/client.rb', line 58

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