CreateMediaFromURL

From CDYNE Wiki
Jump to navigation Jump to search

Create and add media to your SMS Notify! license key from a URL.

CreateMediaFromUrl Request

Parameter Name Data Type Sample Input Required
FileName: Name of media file being created. String MonkeyPic.jpg TRUE
LicenseKey: License key attached to media file.
Trial Key
Production Key
GUID f01d89fd-5155-5455-5585-e84ab8de8591 TRUE
Tag: Category of new media. String Monkey FALSE
Url: Link being used to create media. String https://i.pinimg.com/736x/01/5.jpg TRUE

CreateMediaFromUrl Response

Parameter Name Data Type Sample Output
FileDate: UTC date and time media was created. DateTime 1999-05-31T11:20:00
FilenName: Name of media file. String MonkeyPic.jpg
FileSize: Size of media file.. Int 97465
MediaId: Unique ID for specific media file. Int 12487
MimeType: Media file type. String image/jpeg
Tag: Category of media file. String Monkey

JSON Request

The following is an example POST request using http://messaging.cdyne.com/Messaging.svc/CreateMediaFromUrl

{
	"Filename" : "monkey.jpg",
	"LicenseKey" : "f01d89fd-5155-5455-5585-e84ab8de8591",
	"Tags" : ["Monkey"],
	"Url" : "https://i.pinimg.com/736x/01/59/40/01594057534c60f94af3165f26d85629--monkey-humor-toddler-christmas.jpg"
}

Ruby

 1 require 'uri'
 2 require 'net/http'
 3 
 4 url = URI("http://messaging.cdyne.com/Messaging.svc/CreateMediaFromUrl")
 5 
 6 http = Net::HTTP.new(url.host, url.port)
 7 
 8 request = Net::HTTP::Post.new(url)
 9 
10 request["content-type"] = 'application/json'
11 
12 request.body = '{
13                "Filename" : "monkey.jpg",
14 	       "LicenseKey" : "f01d89fd-5155-5455-5585-e84ab8de8591",
15 	       "Tags" : ["Monkey"],
16 	       "Url" : "https://i.pinimg.com/736x/01/59/40/01594057534c60f94af3165f26d85629--monkey-humor-toddler-christmas.jpg"}'
17 
18 response = http.request(request)
19 
20 puts response.read_body
21 gets response.read_body

C#

 1 /*http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL*/
 2 
 3 using System;
 4 using System.Collections.Generic;
 5 using System.Linq;
 6 using System.Text;
 7 using System.Threading.Tasks;
 8 using CreateMediaFromURL.WSDL;
 9 
10 namespace CreateMediaFromURL
11 {
12     class Program
13     {
14         static void Main(string[] args)
15         {
16             MessagingClient client = new MessagingClient("mms2wsHttpBinding");
17             CreateMediaUrlRequest req = new CreateMediaUrlRequest();
18 
19             req.Url = @"https://i.pinimg.com/736x/01/59/40/01594057534c60f94af3165f26d85629--monkey-humor-toddler-christmas.jpg";
20             req.Filename = "monkey.jpg";
21             req.LicenseKey = new Guid("f01d89fd-5155-5455-5585-e84ab8de8591");
22             req.Tags = new string[] {"Monkey"};
23 
24             MediaMetadata resp = client.CreateMediaFromUrl(req);
25 
26             Console.WriteLine("UTC File Date: " + resp.FileDate + Environment.NewLine +
27                 "File Name: " + resp.FileName + Environment.NewLine +
28                 "File Size: " + resp.FileSize + Environment.NewLine +
29                 "Media ID: " + resp.MediaId + Environment.NewLine +
30                 "Mime Type: " + resp.MimeType);
31 
32             foreach (var item in resp.Tags)
33             {
34                 Console.Write("{0}", "Tags: " + item + Environment.NewLine + Environment.NewLine);
35             }
36 
37             Console.ReadLine();
38         }
39     }
40 }

VB.Net

 1 'http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL
 2 
 3 Imports CreateMediaFromURL.WSDL
 4 
 5 Module Module1
 6 
 7     Sub Main()
 8 
 9         Dim client As WSDL.MessagingClient = New MessagingClient("mms2wsHttpBinding")
10 
11         Dim req As New WSDL.CreateMediaUrlRequest()
12 
13         req.Url = "https://i.pinimg.com/736x/01/59/40/01594057534c60f94af3165f26d85629--monkey-humor-toddler-christmas.jpg"
14         req.Filename = "VBNMonkey.jpg"
15         req.LicenseKey = New Guid("f01d89fd-5155-5455-5585-e84ab8de8591")
16         req.Tags = New String() {"Monkey"}
17 
18         Dim resp As WSDL.MediaMetadata = client.CreateMediaFromUrl(req)
19 
20         Console.WriteLine("UTC File Date: " + Convert.ToString(resp.FileDate) + Environment.NewLine +
21                            "File Name: " + resp.FileName + Environment.NewLine +
22                            "File Size: " + Convert.ToString(resp.FileSize) + Environment.NewLine +
23                            "Media ID: " + Convert.ToString(resp.MediaId) + Environment.NewLine +
24                            "Mime Type: " + resp.MimeType)
25 
26         For Each item In resp.Tags
27 
28             Console.WriteLine("Tags: " + item + Environment.NewLine + Environment.NewLine)
29 
30         Next
31 
32         Console.ReadLine()
33 
34     End Sub
35 
36 End Module

PHP with cURL

 1 <?php
 2 
 3 $json='{
 4     	"Filename" : "monkeycURL.jpg",
 5 	"LicenseKey" : "f01d89fd-5155-5455-5585-e84ab8de8591",
 6 	"Tags" : ["Monkey"],	
 7 	"Url" : "https://i.pinimg.com/736x/01/59/40/01594057534c60f94af3165f26d85629--monkey-humor-toddler-christmas.jpg"
 8 }';
 9 
10 $url='http://messaging.cdyne.com/Messaging.svc/CreateMediaFromUrl';
11 $cURL = curl_init();
12  
13 curl_setopt($cURL,CURLOPT_URL,$url);
14 curl_setopt($cURL,CURLOPT_POST,true);
15 curl_setopt($cURL,CURLOPT_POSTFIELDS,$json);
16 curl_setopt($cURL,CURLOPT_RETURNTRANSFER, true);  
17 curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Accept: application/json'));
18 //If you desire your results in xml format, use the following line for your httpheaders and comment out the httpheaders code line above.
19 //curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
20 $result = curl_exec($cURL);
21 
22 curl_close($cURL);
23 
24 $array = json_decode($result, true);
25 //print_r($json);
26 //print_r("\n\n\n\n");
27 
28 print_r($array);
29 
30 ?>


VBScript

 1 Dim cXML
 2 
 3 cXML = "<CreateMediaUrlRequest xmlns=""http://sms2.cdyne.com"">" & _
 4   "<Filename>vbsurlmonkey.jpg</Filename>" & _
 5   "<LicenseKey>f01d89fd-5155-5455-5585-e84ab8de8591</LicenseKey>" & _
 6   "<Tags>" & _
 7     "<string xmlns=""http://schemas.microsoft.com/2003/10/Serialization/Arrays"">vbstest</string>" & _
 8   "</Tags>" & _
 9   "<Url>https://i.pinimg.com/736x/01/59/40/01594057534c60f94af3165f26d85629--monkey-humor-toddler-christmas.jpg</Url>" & _
10 "</CreateMediaUrlRequest>"
11 
12 Dim oXMLHTTP
13 Set oXMLHTTP = CreateObject("Microsoft.XMLHTTP")
14 Set oDoc = CreateObject("MSXML2.DOMDocument")
15 Call oXMLHttp.Open("POST", "http://messaging.cdyne.com/Messaging.svc/CreateMediaFromUrl", False)
16 Call oXMLHttp.setRequestHeader("Content-Type", "text/xml")        
17 Call oXMLHttp.send(cXML)
18 
19 MsgBox oXMLHTTP.responseText 
20 
21 Const ForReading = 1, ForWriting = 2, ForAppending = 8
22 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
23 Dim fso, MyFile, FileName, TextLine
24 Set fso = CreateObject("Scripting.FileSystemObject")
25 FileName = "c:\Users\Desktop\MMS.txt"
26 Set MyFile = fso.OpenTextFile(FileName, ForWriting, True)
27 MyFile.WriteLine oXMLHttp.responseText
28 MyFile.Close
29 Set MyFile = fso.OpenTextFile(FileName, ForReading)
30 Do While MyFile.AtEndOfStream <> True
31 TextLine = MyFile.ReadLine
32 Loop
33 
34 MyFile.Close
35 
36 set request = nothing

JAVA

 1 import java.io.BufferedReader;
 2 import java.io.InputStreamReader;
 3 import java.io.PrintWriter;
 4 import java.net.HttpURLConnection;
 5 import java.net.URL;
 6 
 7 public final class CreateMediaFromUrl {
 8 
 9     public static void main(String[] args) throws Exception {
10         String responseContent = "";
11         String response = "";
12 
13         URL url = new URL("http://messaging.cdyne.com/Messaging.svc/CreateMediaFromUrl");
14         HttpURLConnection connection = (HttpURLConnection) url.openConnection();
15 
16         StringBuilder sb = new StringBuilder("<CreateMediaUrlRequest xmlns=\"http://sms2.cdyne.com\">");
17         sb.append("<Filename>JavaMonkey.jpg</Filename>");
18         sb.append("<LicenseKey>f01d89fd-5155-5455-5585-e84ab8de8591</LicenseKey>");
19         sb.append("<Tags>");
20         sb.append("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">Monkey</string>");
21         sb.append("</Tags>");
22         sb.append("<Url>https://i.pinimg.com/736x/01/59/40/01594057534c60f94af3165f26d85629--monkey-humor-toddler-christmas.jpg</Url>");
23         sb.append("</CreateMediaUrlRequest>");
24 
25         connection.setRequestProperty("Content-Length", String.valueOf(sb.toString().length()));
26         connection.setRequestProperty("Content-Type", "text/xml");
27         connection.setRequestProperty("Connection", "Close");
28         connection.setRequestProperty("SoapAction", "");
29         connection.setRequestMethod("POST");
30         connection.setDoInput(true);
31         connection.setDoOutput(true);
32 
33         PrintWriter pw = new PrintWriter(connection.getOutputStream());
34         pw.write(sb.toString());
35         pw.flush();
36         connection.connect();
37 
38         System.out.println(sb.toString());
39         BufferedReader br;
40 
41         if (connection.getResponseCode() == 200) {
42             br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
43         } else {
44             br = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
45         }
46 
47         while ((responseContent = br.readLine()) != null) {
48             response += responseContent;
49         }
50         System.out.println(response);
51     }
52 }