Class: Postmark::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/postmark/http_client.rb

Constant Summary collapse

DEFAULTS =
{
  :auth_header_name => 'X-Postmark-Server-Token',
  :host => 'api.postmarkapp.com',
  :secure => true,
  :path_prefix => '/',
  :http_read_timeout => 60,
  :http_open_timeout => 60
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_token, options = {}) ⇒ HttpClient

Returns a new instance of HttpClient.



24
25
26
27
28
29
# File 'lib/postmark/http_client.rb', line 24

def initialize(api_token, options = {})
  @api_token = api_token
  @request_mutex = Mutex.new
  apply_options(options)
  @http = build_http
end

Instance Attribute Details

#api_tokenObject Also known as: api_key

Returns the value of attribute api_token.



6
7
8
# File 'lib/postmark/http_client.rb', line 6

def api_token
  @api_token
end

#auth_header_nameObject (readonly)

Returns the value of attribute auth_header_name.



7
8
9
# File 'lib/postmark/http_client.rb', line 7

def auth_header_name
  @auth_header_name
end

#hostObject (readonly)

Returns the value of attribute host.



7
8
9
# File 'lib/postmark/http_client.rb', line 7

def host
  @host
end

#httpObject (readonly)

Returns the value of attribute http.



7
8
9
# File 'lib/postmark/http_client.rb', line 7

def http
  @http
end

#http_open_timeoutObject (readonly)

Returns the value of attribute http_open_timeout.



7
8
9
# File 'lib/postmark/http_client.rb', line 7

def http_open_timeout
  @http_open_timeout
end

#http_read_timeoutObject (readonly)

Returns the value of attribute http_read_timeout.



7
8
9
# File 'lib/postmark/http_client.rb', line 7

def http_read_timeout
  @http_read_timeout
end

#http_ssl_versionObject (readonly)

Returns the value of attribute http_ssl_version.



7
8
9
# File 'lib/postmark/http_client.rb', line 7

def http_ssl_version
  @http_ssl_version
end

#path_prefixObject (readonly)

Returns the value of attribute path_prefix.



7
8
9
# File 'lib/postmark/http_client.rb', line 7

def path_prefix
  @path_prefix
end

#portObject (readonly)

Returns the value of attribute port.



7
8
9
# File 'lib/postmark/http_client.rb', line 7

def port
  @port
end

#proxy_hostObject (readonly)

Returns the value of attribute proxy_host.



7
8
9
# File 'lib/postmark/http_client.rb', line 7

def proxy_host
  @proxy_host
end

#proxy_passObject (readonly)

Returns the value of attribute proxy_pass.



7
8
9
# File 'lib/postmark/http_client.rb', line 7

def proxy_pass
  @proxy_pass
end

#proxy_portObject (readonly)

Returns the value of attribute proxy_port.



7
8
9
# File 'lib/postmark/http_client.rb', line 7

def proxy_port
  @proxy_port
end

#proxy_userObject (readonly)

Returns the value of attribute proxy_user.



7
8
9
# File 'lib/postmark/http_client.rb', line 7

def proxy_user
  @proxy_user
end

#secureObject (readonly)

Returns the value of attribute secure.



7
8
9
# File 'lib/postmark/http_client.rb', line 7

def secure
  @secure
end

Instance Method Details

#delete(path, query = {}) ⇒ Object



47
48
49
# File 'lib/postmark/http_client.rb', line 47

def delete(path, query = {})
  do_request { |client| client.delete(url_path(path + to_query_string(query)), headers) }
end

#get(path, query = {}) ⇒ Object



43
44
45
# File 'lib/postmark/http_client.rb', line 43

def get(path, query = {})
  do_request { |client| client.get(url_path(path + to_query_string(query)), headers) }
end

#patch(path, data = '') ⇒ Object



39
40
41
# File 'lib/postmark/http_client.rb', line 39

def patch(path, data = '')
  do_request { |client| client.patch(url_path(path), data, headers) }
end

#post(path, data = '') ⇒ Object



31
32
33
# File 'lib/postmark/http_client.rb', line 31

def post(path, data = '')
  do_request { |client| client.post(url_path(path), data, headers) }
end

#protocolObject



51
52
53
# File 'lib/postmark/http_client.rb', line 51

def protocol
  self.secure ? 'https' : 'http'
end

#put(path, data = '') ⇒ Object



35
36
37
# File 'lib/postmark/http_client.rb', line 35

def put(path, data = '')
  do_request { |client| client.put(url_path(path), data, headers) }
end