lib/howitzer/mailgun/client.rb in howitzer-1.1.0 vs lib/howitzer/mailgun/client.rb in howitzer-1.1.1

- old
+ new

@@ -8,13 +8,15 @@ # A Mailgun::Client object is used to communicate with the Mailgun API. It is a # wrapper around RestClient so you don't have to worry about the HTTP aspect # of communicating with our API. class Client + attr_reader :api_key - def initialize(api_key, api_host="api.mailgun.net", api_version="v2", ssl=true) + def initialize(api_key, api_host="api.mailgun.net", api_version="v3", ssl=true) endpoint = endpoint_generator(api_host, api_version, ssl) + @api_key = api_key @http_client = RestClient::Resource.new(endpoint, :user => "api", :password => api_key, :user_agent => "mailgun-sdk-ruby/1.0.1") end @@ -29,9 +31,24 @@ def get(resource_path, params=nil, accept="*/*") http_params = {:accept => accept} http_params = http_params.merge(params: params) if params response = @http_client[resource_path].get(http_params) + Response.new(response) + rescue => e + log.error Howitzer::CommunicationError, e.message + end + + def get_url(url, params=nil, accept="*/*") + response = ::RestClient::Request.execute( + method: :get, + url: url, + user: 'api', + password: api_key, + user_agent: 'mailgun-sdk-ruby', + accept: accept, + params: params + ) Response.new(response) rescue => e log.error Howitzer::CommunicationError, e.message end