File: account_api_client.rb

package info (click to toggle)
ruby-postmark 1.25.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 480 kB
  • sloc: ruby: 5,413; makefile: 4
file content (158 lines) | stat: -rw-r--r-- 4,521 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
module Postmark

  class AccountApiClient < Client

    def initialize(api_token, options = {})
      options = options.dup
      options[:auth_header_name] = 'X-Postmark-Account-Token'
      super
    end

    def senders(options = {})
      find_each('senders', 'SenderSignatures', options)
    end
    alias_method :signatures, :senders

    def get_senders(options = {})
      load_batch('senders', 'SenderSignatures', options).last
    end
    alias_method :get_signatures, :get_senders

    def get_senders_count(options = {})
      get_resource_count('senders', options)
    end
    alias_method :get_signatures_count, :get_senders_count

    def get_sender(id)
      format_response http_client.get("senders/#{id.to_i}")
    end
    alias_method :get_signature, :get_sender

    def create_sender(attributes = {})
      data = serialize(HashHelper.to_postmark(attributes))

      format_response http_client.post('senders', data)
    end
    alias_method :create_signature, :create_sender

    def update_sender(id, attributes = {})
      data = serialize(HashHelper.to_postmark(attributes))

      format_response http_client.put("senders/#{id.to_i}", data)
    end
    alias_method :update_signature, :update_sender

    def resend_sender_confirmation(id)
      format_response http_client.post("senders/#{id.to_i}/resend")
    end
    alias_method :resend_signature_confirmation, :resend_sender_confirmation

    def verified_sender_spf?(id)
      !!http_client.post("senders/#{id.to_i}/verifyspf")['SPFVerified']
    end
    alias_method :verified_signature_spf?, :verified_sender_spf?

    def request_new_sender_dkim(id)
      format_response http_client.post("senders/#{id.to_i}/requestnewdkim")
    end
    alias_method :request_new_signature_dkim, :request_new_sender_dkim

    def delete_sender(id)
      format_response http_client.delete("senders/#{id.to_i}")
    end
    alias_method :delete_signature, :delete_sender

    def domains(options = {})
      find_each('domains', 'Domains', options)
    end

    def get_domains(options = {})
      load_batch('domains', 'Domains', options).last
    end

    def get_domains_count(options = {})
      get_resource_count('domains', options)
    end

    def get_domain(id)
      format_response http_client.get("domains/#{id.to_i}")
    end

    def create_domain(attributes = {})
      data = serialize(HashHelper.to_postmark(attributes))

      format_response http_client.post('domains', data)
    end

    def update_domain(id, attributes = {})
      data = serialize(HashHelper.to_postmark(attributes))

      format_response http_client.put("domains/#{id.to_i}", data)
    end

    def verify_domain_dkim(id)
      format_response http_client.put("domains/#{id.to_i}/verifydkim")
    end

    def verify_domain_return_path(id)
      format_response http_client.put("domains/#{id.to_i}/verifyreturnpath")
    end

    def verified_domain_spf?(id)
      !!http_client.post("domains/#{id.to_i}/verifyspf")['SPFVerified']
    end

    def rotate_domain_dkim(id)
      format_response http_client.post("domains/#{id.to_i}/rotatedkim")
    end

    def delete_domain(id)
      format_response http_client.delete("domains/#{id.to_i}")
    end

    def servers(options = {})
      find_each('servers', 'Servers', options)
    end

    def get_servers(options = {})
      load_batch('servers', 'Servers', options).last
    end

    def get_servers_count(options = {})
      get_resource_count('servers', options)
    end

    def get_server(id)
      format_response http_client.get("servers/#{id.to_i}")
    end

    def create_server(attributes = {})
      data = serialize(HashHelper.to_postmark(attributes))
      format_response http_client.post('servers', data)
    end

    def update_server(id, attributes = {})
      data = serialize(HashHelper.to_postmark(attributes))
      format_response http_client.put("servers/#{id.to_i}", data)
    end

    def delete_server(id)
      format_response http_client.delete("servers/#{id.to_i}")
    end

    def push_templates(attributes = {})
      data = serialize(HashHelper.to_postmark(attributes))
      _, batch = format_batch_response(http_client.put('templates/push', data), "Templates")
      batch
    end

    def get_data_removal_status(id)
      format_response(http_client.get("data-removals/#{id}"))
    end

    def request_data_removal(attributes = {})
      data = serialize(HashHelper.to_postmark(attributes))
      format_response(http_client.post('data-removals', data))
    end
  end
end