Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
SerwerSMSpl committed Jan 22, 2016
1 parent e0d796a commit 8f2c478
Show file tree
Hide file tree
Showing 18 changed files with 1,989 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -4,7 +4,6 @@
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

Expand Down
182 changes: 182 additions & 0 deletions README.md
@@ -0,0 +1,182 @@
# SerwerSMS.pl JAVA Client API
Klient JAVA do komunikacji zdalnej z API v2 SerwerSMS.pl

Zalecane jest, aby komunikacja przez HTTPS API odbywała się z loginów utworzonych specjalnie do połączenia przez API. Konto użytkownika API można utworzyć w Panelu Klienta → Ustawienia interfejsów → HTTPS XML API → Użytkownicy.

#### Przykładowe wywołanie
```java
import java.io.*;
import java.util.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.json.*;
import org.w3c.dom.*;
import org.xml.sax.InputSource;
import SerwerSMS.*;

public class NewMain {

public static void main(String[] args) {

try {

SerwerSMS SerwerSMSApi = new SerwerSMS("demo", "demo");

HashMap<String, String> options = new HashMap<String, String>();
options.put("test", "true");
options.put("details", "true");

String type = "json";
SerwerSMSApi.setFormat(type);
String result = SerwerSMSApi.message.sendSms("500600700", "Test message", "", options);

if (type == "xml") {

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(result)));
NodeList list = document.getElementsByTagName("item");

for (int temp = 0; temp < list.getLength(); temp++) {

Node item = list.item(temp);
if (item.getNodeType() == Node.ELEMENT_NODE) {

Element element = (Element) item;
String id = element.getElementsByTagName("id").item(0).getTextContent();
String phone = element.getElementsByTagName("phone").item(0).getTextContent();
String status = element.getElementsByTagName("status").item(0).getTextContent();

System.out.println(id + " - " + phone + " - " + status);
}
}

} else if (type == "json") {

JSONObject json = new JSONObject(result);
JSONArray jsonArray = new JSONArray(json.get("items").toString());

for (int i = 0; i < jsonArray.length(); i++) {

JSONObject tmp = new JSONObject(jsonArray.get(i).toString());
String id = tmp.get("id").toString();
String phone = tmp.get("phone").toString();
String status = tmp.get("status").toString();

System.out.println(id + " - " + phone + " - " + status);
}
}

} catch (Exception e) {
System.out.println(e.getMessage());
}

}
}
```

#### Wysyłka SMS
```java
try {

SerwerSMS SerwerSMSApi = new SerwerSMS("demo", "demo");
String type = "json";
SerwerSMSApi.setFormat(type);

// SMS FULL
HashMap<String, String> options = new HashMap<String, String>();
options.put("test", "true");
options.put("details", "true");
String result = SerwerSMSApi.message.sendSms("500600700,600700800", "Test message", "INFORMACJA", options);
System.out.println(result);

// SMS ECO
HashMap<String, String> options = new HashMap<String, String>();
options.put("test", "true");
options.put("details", "true");
String result = SerwerSMSApi.message.sendSms("500600700,600700800", "Test message", "", options);
System.out.println(result);

// VOICE from text
HashMap<String, String> options = new HashMap<String, String>();
options.put("test", "true");
options.put("text", "Test message");
options.put("details", "true");
String result = SerwerSMSApi.message.sendVoice("500600700", options);
System.out.println(result);

// MMS
HashMap<String, String> options = new HashMap<String, String>();
options.put("test", "true");
options.put("file_id", "82aa9f108c");
String result = SerwerSMSApi.message.sendMms("500600700", "Title message", options);
System.out.println(result);

} catch (Exception e) {
System.out.println(e.getMessage());
}
```

#### Wysyłka spersonalizowanych SMS
```java
try {

ArrayList<HashMap<String, String>> listMessages = new ArrayList<HashMap<String, String>>();

// Message nr. 1
HashMap<String, String> message = new HashMap<String, String>();
message.put("phone", "500600700");
message.put("text", "Test message 1");
listMessages.add(message);

// Message nr. 2
message = new HashMap<String, String>();
message.put("phone", "600700800");
message.put("text", "Test message 2");
listMessages.add(message);

HashMap<String, String> options = new HashMap<String, String>();
options.put("test", "true");
options.put("details", "true");

String result = SerwerSMSApi.message.sendPersonalized(listMessages, "", options);
System.out.println(result);

} catch (Exception e) {
System.out.println(e.getMessage());
}
```

#### Pobieranie raportów doręczeń
```java
try {

HashMap<String, String> options = new HashMap<String, String>();
options.put("id", "b7ac0db51a,0a83b5d5eb");
String result = SerwerSMSApi.message.reports(options);
System.out.println(result);

} catch (Exception e) {
System.out.println(e.getMessage());
}
```

#### Pobieranie wiadomości przychodzących
```java
try {

HashMap<String, String> options = new HashMap<String, String>();
options.put("phone", "500600700");
String result = SerwerSMSApi.message.recived("ndi",options);

} catch (Exception e) {
System.out.println(e.getMessage());
}
```
## Wymagania
Java SE 8

Biblioteka do obsługi formatu JSON lub XML

## Dokumentacja
http://dev.serwersms.pl
Binary file added dist/SerwerSMS.jar
Binary file not shown.
90 changes: 90 additions & 0 deletions src/SerwerSMS/Account.java
@@ -0,0 +1,90 @@
package SerwerSMS;

import java.util.HashMap;

/**
*
* @author SerwerSMS
* @version: 1.0
* @date 2016-01
*/
public class Account {

private SerwerSMS master = null;

public Account(SerwerSMS object) throws Exception {

master = object;

}

/**
* Register new account
*
* @param array params
* @option String "phone"
* @option String "email"
* @option String "first_name"
* @option String "last_name"
* @option String "company"
* @return array
* @option bool "success"
*/

public String add(HashMap<String, String> params) {

return master.send("account/add", params);

}

/**
* Return limits SMS
*
* @param array params
* @option boolean "show_type"
* @return array
* @option array "items"
* @option string "type" Type of message
* @option string "chars_limit" The maximum length of message
* @option string "value" Limit messages
*
*/
public String limits(HashMap<String, String> params) {

return master.send("account/limits", params);

}

/**
* Return contact details
*
* @return array
* @option String "telephone"
* @option String "email"
* @option String "form"
* @option String "faq"
* @option array "account_maintainer"
* @option String "name"
* @option String "email"
* @option String "telephone"
* @option String "photo"
*/
public String help() {

return master.send("account/help", new HashMap<String, String>());

}

/**
* Return messages from the administrator
*
* @return array
* @option boolean "new" Marking unread message
* @option String "message"
*/
public String messages() {

return master.send("account/messages", new HashMap<String, String>());

}
}
97 changes: 97 additions & 0 deletions src/SerwerSMS/Blacklist.java
@@ -0,0 +1,97 @@
package SerwerSMS;

import java.io.IOException;
import java.util.HashMap;
import java.util.ArrayList;

/**
*
* @author SerwerSMS
* @version: 1.0
* @date 2016-01
*/
public class Blacklist {

private SerwerSMS master = null;

public Blacklist(SerwerSMS object) throws Exception {

master = object;

}

/**
* Add phone to the blacklist
*
* @param String phone
* @return array
* @option boolean "success"
* @option int "id"
*/
public String add(String phone) {

HashMap<String, String> params = new HashMap<String, String>();
params.put("phone", phone);

return master.send("blacklist/add", params);

}

/**
* List of blacklist phones
*
* @param String phone
* @param array params
* @option int "page" The number of the displayed page
* @option int "limit" Limit items are displayed on the single page
* @return array
* @option array "paging"
* @option int "page" The number of current page
* @option int "count" The number of all pages
* @option array "items"
* @option String "phone"
* @option String "added" Date of adding phone
*/
public String index(String phone, HashMap<String, String> params) {

HashMap<String, String> options = new HashMap<String, String>();
options.put("phone", phone);

params.putAll(options);

return master.send("blacklist/index", params);

}

/**
* Checking if phone is blacklisted
*
* @param String phone
* @return array
* @option boolean "exists"
*/
public String check(String phone) {

HashMap<String, String> params = new HashMap<String, String>();
params.put("phone", phone);

return master.send("blacklist/check", params);

}

/**
* Deleting phone from the blacklist
*
* @param String phone
* @return array
* @option boolean "success"
*/
public String delete(String phone) {

HashMap<String, String> params = new HashMap<String, String>();
params.put("phone", phone);

return master.send("blacklist/delete", params);

}
}

0 comments on commit 8f2c478

Please sign in to comment.