Created
October 12, 2012 16:35
-
-
Save ticktricktrack/3880133 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'json' | |
| require "httparty" | |
| require 'awesome_print' | |
| class DynectPostBackTest | |
| include HTTParty | |
| base_uri 'https://emailapi.dynect.net/rest/json' | |
| debug_output $stdout | |
| attr_accessor :apikey | |
| def create_subaccount(name) | |
| account_data = { | |
| username: "delete_me_#{name}@incutio.com", | |
| password: 'soegh4i8h813kb', | |
| companyname: 'Test Account', | |
| phone: "01978661666", | |
| apikey: 'our_master_apikey', | |
| bounce_callback_url: "http://clients.mycarrierpigeon.com/bounce?&email=@email&bouncerule=@bouncerule&bouncecode=@bouncecode&bouncetype=@bouncetype&x1=@X-Type&x2=@X-ID&x3=@X-Subscriber-Token&x4=@X-Subscriber-ID", | |
| complaint_callback_url: "http://clients.mycarrierpigeon.com/complaint?&email=@email&x1=@X-Type&x2=@X-ID&x3=@X-Subscriber-Token&x4=@X-Subscriber-ID" | |
| } | |
| response = self.class.post '/accounts', body: account_data | |
| response = JSON.parse response.body | |
| self.apikey = response['response']['data']['apikey'] | |
| puts ap response | |
| end | |
| def get_xheaders | |
| response = self.class.get '/accounts/xheaders', query: { apikey: self.apikey } | |
| puts ap JSON.parse(response.body) | |
| end | |
| end | |
| dynect_test = DynectPostBackTest.new | |
| response = dynect_test.create_subaccount(8) | |
| # opening connection to emailapi.dynect.net... | |
| # opened | |
| # <- "POST /rest/json/accounts HTTP/1.1\r\nConnection: close\r\nHost: emailapi.dynect.net\r\nContent-Length: 594\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n" | |
| # <- "username=delete_me_8%40incutio.com&password=soegh4i8h813kb&companyname=Test%20Account&phone=01978661666&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXXXX&bounce_callback_url=http%3A%2F%2Fclients.mycarrierpigeon.com%2Fbounce%3F%26email%3D%40email%26bouncerule%3D%40bouncerule%26bouncecode%3D%40bouncecode%26bouncetype%3D%40bouncetype%26x1%3D%40X-Type%26x2%3D%40X-ID%26x3%3D%40X-Subscriber-Token%26x4%3D%40X-Subscriber-ID&complaint_callback_url=http%3A%2F%2Fclients.mycarrierpigeon.com%2Fcomplaint%3F%26email%3D%40email%26x1%3D%40X-Type%26x2%3D%40X-ID%26x3%3D%40X-Subscriber-Token%26x4%3D%40X-Subscriber-ID" | |
| # -> "HTTP/1.1 200 OK\r\n" | |
| # -> "Server: nginx/1.0.11\r\n" | |
| # -> "Date: Fri, 12 Oct 2012 16:31:16 GMT\r\n" | |
| # -> "Content-Type: application/json;charset=utf-8\r\n" | |
| # -> "Transfer-Encoding: chunked\r\n" | |
| # -> "Connection: close\r\n" | |
| # -> "X-Powered-By: PHP/5.3.9-1~dotdeb.3\r\n" | |
| # -> "Set-Cookie: PHPSESSID=poinv26pa6v15h9m4qofcgggc3; path=/\r\n" | |
| # -> "Expires: Thu, 19 Nov 1981 08:52:00 GMT\r\n" | |
| # -> "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0\r\n" | |
| # -> "Pragma: no-cache\r\n" | |
| # -> "\r\n" | |
| # -> "5f\r\n" | |
| # reading 95 bytes... | |
| # -> "{\"response\":{\"status\":200,\"message\":\"OK\",\"data\":{\"apikey\":\"XXXXXXXXXXXXXXXXXXXXXXXXXXXX\"}}}" | |
| # read 95 bytes | |
| # reading 2 bytes... | |
| # -> "\r\n" | |
| # read 2 bytes | |
| # -> "0\r\n" | |
| # -> "\r\n" | |
| # Conn close | |
| # { | |
| # "response" => { | |
| # "status" => 200, | |
| # "message" => "OK", | |
| # "data" => { | |
| # "apikey" => "XXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
| # } | |
| # } | |
| # } | |
| # => nil | |
| dynect_test.get_xheaders | |
| # opening connection to emailapi.dynect.net... | |
| # opened | |
| # <- "GET /rest/json/accounts/xheaders?apikey=XXXXXXXXXXXXXX HTTP/1.1\r\nConnection: close\r\nHost: emailapi.dynect.net\r\n\r\n" | |
| # -> "HTTP/1.1 200 OK\r\n" | |
| # -> "Server: nginx/1.0.11\r\n" | |
| # -> "Date: Fri, 12 Oct 2012 16:31:31 GMT\r\n" | |
| # -> "Content-Type: application/json;charset=utf-8\r\n" | |
| # -> "Transfer-Encoding: chunked\r\n" | |
| # -> "Connection: close\r\n" | |
| # -> "X-Powered-By: PHP/5.3.9-1~dotdeb.3\r\n" | |
| # -> "Set-Cookie: PHPSESSID=at5g9sv453b2j9q3aungernm77; path=/\r\n" | |
| # -> "Expires: Thu, 19 Nov 1981 08:52:00 GMT\r\n" | |
| # -> "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0\r\n" | |
| # -> "Pragma: no-cache\r\n" | |
| # -> "\r\n" | |
| # -> "34\r\n" | |
| # reading 52 bytes... | |
| # -> "{\"response\":{\"status\":200,\"message\":\"OK\",\"data\":{}}}" | |
| # read 52 bytes | |
| # reading 2 bytes... | |
| # -> "\r\n" | |
| # read 2 bytes | |
| # -> "0\r\n" | |
| # -> "\r\n" | |
| # Conn close | |
| # { | |
| # "response" => { | |
| # "status" => 200, | |
| # "message" => "OK", | |
| # "data" => {} | |
| # } | |
| # } | |
| # => nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment