Skip to content
This repository has been archived by the owner on Apr 25, 2019. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sigod committed Aug 23, 2015
2 parents 9fe4d8b + 2f44234 commit 21e3b25
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions source/gcm.d
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,39 @@ class GCM

this(string key)
{
assert(key.length, "API key is required");

m_key = key;
}

GCMResponse send(T)(GCMessage!T message)
Nullable!GCMResponse send(T)(GCMessage!T message)
in
{
assert(message.to.length, "to is required");

if (!message.notification.isNull)
assert(message.notification.icon.length, "notification.icon is required");
}
body
{
import std.net.curl;

HTTP client = HTTP();

// Windows issues
//client.handle.set(CurlOption.ssl_verifypeer, 0);

client.addRequestHeader("Content-Type", "application/json");
client.addRequestHeader("Authorization", "key=" ~ m_key);

auto response = post("https://gcm-http.googleapis.com/gcm/send", convert(message).toString(), client);
try {
auto response = post("https://gcm-http.googleapis.com/gcm/send", convert(message).toString(), client);

return cast(Nullable!GCMResponse)parse(response);
}
catch (Exception e) {
import std.stdio : stderr;
stderr.writeln("[GCM] request failed: ", e);

return parse(response);
return Nullable!GCMResponse.init;
}
}

private static GCMResponse parse(char[] response)
Expand Down Expand Up @@ -219,7 +234,6 @@ template isISOExtStringSerializable(T)
}

//TODO: support classes
//TODO: `required` fields
//TODO: `asString` fields
JSONValue convert(T)(T value)
{
Expand Down

0 comments on commit 21e3b25

Please sign in to comment.