Class: Dyn::Messaging::Client
- Inherits:
-
Object
- Object
- Dyn::Messaging::Client
- Defined in:
- lib/dyn/messaging.rb
Instance Attribute Summary collapse
-
#apikey ⇒ Object
Returns the value of attribute apikey.
-
#rest ⇒ Object
Returns the value of attribute rest.
Instance Method Summary collapse
- #accounts ⇒ Object
-
#api_request(&block) ⇒ Object
Handles making Dynect API requests and formatting the responses properly.
- #bounces ⇒ Object
- #clicks ⇒ Object
- #complaints ⇒ Object
- #delivery ⇒ Object
-
#get(path_part, query_params = {}, additional_headers = {}, &block) ⇒ Object
Raw GET request, formatted for Dyn.
-
#initialize(apikey, verbose = false) ⇒ Client
constructor
Creates a new base object for interacting with Dyn’s REST API.
- #issues ⇒ Object
- #opens ⇒ Object
-
#post(path_part, form_params = {}, additional_headers = {}, &block) ⇒ Object
Raw POST request, formatted for Dyn.
- #recipients ⇒ Object
- #send_mail ⇒ Object
-
#senders ⇒ Object
Senders API.
- #sent_mail ⇒ Object
- #suppressions ⇒ Object
Constructor Details
#initialize(apikey, verbose = false) ⇒ Client
Creates a new base object for interacting with Dyn’s REST API
49 50 51 52 53 54 55 56 57 |
# File 'lib/dyn/messaging.rb', line 49 def initialize(apikey, verbose=false) @apikey = apikey @rest = Dyn::HttpClient::DefaultClient.new("emailapi.dynect.net", "443", "https") @rest.default_headers = { 'User-Agent' => 'dyn-rb 1.0.3', 'Content-Type' => 'application/x-www-form-urlencoded' } @verbose = verbose end |
Instance Attribute Details
#apikey ⇒ Object
Returns the value of attribute apikey.
43 44 45 |
# File 'lib/dyn/messaging.rb', line 43 def apikey @apikey end |
#rest ⇒ Object
Returns the value of attribute rest.
43 44 45 |
# File 'lib/dyn/messaging.rb', line 43 def rest @rest end |
Instance Method Details
#accounts ⇒ Object
66 67 68 |
# File 'lib/dyn/messaging.rb', line 66 def accounts Dyn::Messaging::Accounts.new(self) end |
#api_request(&block) ⇒ Object
Handles making Dynect API requests and formatting the responses properly.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/dyn/messaging.rb', line 135 def api_request(&block) response_body = begin response = block.call response.body rescue Exception => e if @verbose puts "I have #{e.inspect} with #{e.http_code}" end e.response end response = JSON.parse(response_body || '{}') if (response["response"] && response["response"]["status"] == 200) response["response"]["data"] else response end end |
#bounces ⇒ Object
86 87 88 |
# File 'lib/dyn/messaging.rb', line 86 def bounces Dyn::Messaging::Bounces.new(self) end |
#clicks ⇒ Object
102 103 104 |
# File 'lib/dyn/messaging.rb', line 102 def clicks Dyn::Messaging::Clicks.new(self) end |
#complaints ⇒ Object
90 91 92 |
# File 'lib/dyn/messaging.rb', line 90 def complaints Dyn::Messaging::Complaints.new(self) end |
#delivery ⇒ Object
78 79 80 |
# File 'lib/dyn/messaging.rb', line 78 def delivery Dyn::Messaging::Delivery.new(self) end |
#get(path_part, query_params = {}, additional_headers = {}, &block) ⇒ Object
Raw GET request, formatted for Dyn. See list of endpoints at:
117 118 119 |
# File 'lib/dyn/messaging.rb', line 117 def get(path_part, query_params = {}, additional_headers = {}, &block) api_request { @rest.get("/rest/json/#{path_part}?" + URI.encode_www_form(query_params.merge({apikey:@apikey})), nil, additional_headers, &block) } end |
#issues ⇒ Object
94 95 96 |
# File 'lib/dyn/messaging.rb', line 94 def issues Dyn::Messaging::Issues.new(self) end |
#opens ⇒ Object
98 99 100 |
# File 'lib/dyn/messaging.rb', line 98 def opens Dyn::Messaging::Opens.new(self) end |
#post(path_part, form_params = {}, additional_headers = {}, &block) ⇒ Object
Raw POST request, formatted for Dyn. See list of endpoints at:
Read the API documentation, and submit the proper data structure from here.
130 131 132 |
# File 'lib/dyn/messaging.rb', line 130 def post(path_part, form_params = {}, additional_headers = {}, &block) api_request { @rest.post("/rest/json/#{path_part}", URI.encode_www_form(form_params.merge({apikey:@apikey})), additional_headers, &block) } end |
#recipients ⇒ Object
70 71 72 |
# File 'lib/dyn/messaging.rb', line 70 def recipients Dyn::Messaging::Recipients.new(self) end |
#send_mail ⇒ Object
106 107 108 |
# File 'lib/dyn/messaging.rb', line 106 def send_mail Dyn::Messaging::SendMail.new(self) end |
#senders ⇒ Object
Senders API
62 63 64 |
# File 'lib/dyn/messaging.rb', line 62 def senders Dyn::Messaging::Senders.new(self) end |
#sent_mail ⇒ Object
82 83 84 |
# File 'lib/dyn/messaging.rb', line 82 def sent_mail Dyn::Messaging::SentMail.new(self) end |
#suppressions ⇒ Object
74 75 76 |
# File 'lib/dyn/messaging.rb', line 74 def suppressions Dyn::Messaging::Suppressions.new(self) end |