Skip to content

Commit 7e5f65b

Browse files
committed
Initial import of the AWS SDK for React Native Core, Amazon DynamoDB, AWS Lambda, Amazon SNS, and AWS S3 Transfer Utility.
1 parent 460979a commit 7e5f65b

File tree

210 files changed

+19043
-201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+19043
-201
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
gradle.properties
2+
gradle-wrapper.properties
3+
*.jar
4+
gradlew
5+
gradlew.bat
6+
keystores
17
.DS_Store
28
build/
9+
xcshareddata
310
*.pbxuser
411
!default.pbxuser
512
*.mode1v3

Core/android/build.gradle

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
}
5+
dependencies {
6+
classpath 'com.android.tools.build:gradle:+'
7+
}
8+
}
9+
10+
apply plugin: 'com.android.library'
11+
12+
android {
13+
compileSdkVersion 23
14+
buildToolsVersion "23.0.3"
15+
16+
defaultConfig {
17+
minSdkVersion 16
18+
targetSdkVersion 23
19+
versionCode 1
20+
versionName "1.0"
21+
}
22+
}
23+
24+
repositories {
25+
mavenCentral()
26+
}
27+
28+
dependencies {
29+
compile 'com.facebook.react:react-native:+'
30+
compile 'com.amazonaws:aws-android-sdk-core:+'
31+
}
32+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!--
2+
Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License").
5+
You may not use this file except in compliance with the License.
6+
A copy of the License is located at
7+
8+
http://aws.amazon.com/apache2.0
9+
10+
or in the "license" file accompanying this file. This file is distributed
11+
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
express or implied. See the License for the specific language governing
13+
permissions and limitations under the License.
14+
-->
15+
16+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
17+
package="com.amazonaws.reactnative.core">
18+
19+
<uses-permission android:name="android.permission.INTERNET" />
20+
21+
</manifest>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License").
5+
// You may not use this file except in compliance with the License.
6+
// A copy of the License is located at
7+
//
8+
// http://aws.amazon.com/apache2.0
9+
//
10+
// or in the "license" file accompanying this file. This file is distributed
11+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
// express or implied. See the License for the specific language governing
13+
// permissions and limitations under the License.
14+
//
15+
package com.amazonaws.reactnative.core;
16+
17+
import com.amazonaws.ClientConfiguration;
18+
19+
public class AWSRNClientConfiguration extends ClientConfiguration {
20+
21+
private static final String USER_AGENT_STRING = "aws-sdk-react-native";
22+
private static final String SDK_VERSION = "0.0.1";
23+
24+
public ClientConfiguration withUserAgent(final String userAgent) {
25+
setUserAgent(USER_AGENT_STRING + "/" + SDK_VERSION + "/" + userAgent);
26+
return this;
27+
}
28+
29+
}
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
//
2+
// Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License").
5+
// You may not use this file except in compliance with the License.
6+
// A copy of the License is located at
7+
//
8+
// http://aws.amazon.com/apache2.0
9+
//
10+
// or in the "license" file accompanying this file. This file is distributed
11+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
// express or implied. See the License for the specific language governing
13+
// permissions and limitations under the License.
14+
//
15+
package com.amazonaws.reactnative.core;
16+
17+
import android.support.annotation.Nullable;
18+
19+
import com.facebook.react.bridge.Arguments;
20+
import com.facebook.react.bridge.ReadableArray;
21+
import com.facebook.react.bridge.ReadableMap;
22+
import com.facebook.react.bridge.ReadableMapKeySetIterator;
23+
import com.facebook.react.bridge.ReadableType;
24+
import com.facebook.react.bridge.WritableArray;
25+
import com.facebook.react.bridge.WritableMap;
26+
import com.google.gson.JsonDeserializationContext;
27+
import com.google.gson.JsonDeserializer;
28+
import com.google.gson.JsonElement;
29+
import com.google.gson.JsonParseException;
30+
import com.google.gson.JsonPrimitive;
31+
import com.google.gson.JsonSerializationContext;
32+
import com.google.gson.JsonSerializer;
33+
34+
import org.json.JSONArray;
35+
import org.json.JSONException;
36+
import org.json.JSONObject;
37+
38+
import java.lang.reflect.Type;
39+
import java.nio.ByteBuffer;
40+
import java.nio.charset.Charset;
41+
import java.util.ArrayList;
42+
import java.util.HashMap;
43+
import java.util.Iterator;
44+
import java.util.List;
45+
import java.util.Map;
46+
47+
48+
public class AWSRNClientMarshaller {
49+
50+
public static Serializer getSerializer() {
51+
return new Serializer();
52+
}
53+
54+
public static Deserializer getDeserializer() {
55+
return new Deserializer();
56+
}
57+
58+
public static Map<String, Object> readableMapToMap(final @Nullable ReadableMap readableMap) {
59+
if (readableMap == null) {
60+
return new HashMap<>();
61+
}
62+
63+
final ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
64+
if (!iterator.hasNextKey()) {
65+
return new HashMap<>();
66+
}
67+
68+
final Map<String, Object> result = new HashMap<>();
69+
while (iterator.hasNextKey()) {
70+
final String key = iterator.nextKey();
71+
result.put(key, toObject(readableMap, key));
72+
}
73+
74+
return result;
75+
}
76+
77+
/**
78+
* toList converts a {@link ReadableArray} into an ArrayList.
79+
*
80+
* @param readableArray The ReadableArray to be conveted.
81+
* @return An ArrayList containing the data that was in the ReadableArray.
82+
*/
83+
public static List<Object> readableArrayToList(final @Nullable ReadableArray readableArray) {
84+
if (readableArray == null) {
85+
return null;
86+
}
87+
88+
List<Object> result = new ArrayList<>(readableArray.size());
89+
for (int index = 0; index < readableArray.size(); index++) {
90+
final ReadableType readableType = readableArray.getType(index);
91+
switch (readableType) {
92+
case Null:
93+
result.add(String.valueOf(index));
94+
break;
95+
case Boolean:
96+
result.add(readableArray.getBoolean(index));
97+
break;
98+
case Number:
99+
// Can be int or double.
100+
double tmp = readableArray.getDouble(index);
101+
if (tmp == (int) tmp) {
102+
result.add((int) tmp);
103+
} else {
104+
result.add(tmp);
105+
}
106+
break;
107+
case String:
108+
result.add(readableArray.getString(index));
109+
break;
110+
case Map:
111+
result.add(readableMapToMap(readableArray.getMap(index)));
112+
break;
113+
case Array:
114+
result = readableArrayToList(readableArray.getArray(index));
115+
break;
116+
default:
117+
throw new IllegalArgumentException("Could not convert object with index: " + index + ".");
118+
}
119+
}
120+
121+
return result;
122+
}
123+
124+
public static Object toObject(@Nullable ReadableMap readableMap, String key) {
125+
if (readableMap == null) {
126+
return null;
127+
}
128+
129+
Object result;
130+
131+
final ReadableType readableType = readableMap.getType(key);
132+
switch (readableType) {
133+
case Null:
134+
result = key;
135+
break;
136+
case Boolean:
137+
result = readableMap.getBoolean(key);
138+
break;
139+
case Number:
140+
// Can be int or double.
141+
double tmp = readableMap.getDouble(key);
142+
if (tmp == (int) tmp) {
143+
result = (int) tmp;
144+
} else {
145+
result = tmp;
146+
}
147+
break;
148+
case String:
149+
result = readableMap.getString(key);
150+
break;
151+
case Map:
152+
result = readableMapToMap(readableMap.getMap(key));
153+
break;
154+
case Array:
155+
result = readableArrayToList(readableMap.getArray(key));
156+
break;
157+
default:
158+
throw new IllegalArgumentException("Could not convert object with key: " + key + ".");
159+
}
160+
161+
return result;
162+
}
163+
164+
public static WritableArray jsonToReact(final JSONArray jsonArray) throws JSONException {
165+
final WritableArray writableArray = Arguments.createArray();
166+
for (int i = 0; i < jsonArray.length(); i++) {
167+
final Object value = jsonArray.get(i);
168+
if (value instanceof Float || value instanceof Double) {
169+
writableArray.pushDouble(jsonArray.getDouble(i));
170+
} else if (value instanceof Number) {
171+
writableArray.pushInt(jsonArray.getInt(i));
172+
} else if (value instanceof String) {
173+
writableArray.pushString(jsonArray.getString(i));
174+
} else if (value instanceof Boolean) {
175+
writableArray.pushBoolean(jsonArray.getBoolean(i));
176+
} else if (value instanceof JSONObject) {
177+
writableArray.pushMap(jsonToReact(jsonArray.getJSONObject(i)));
178+
} else if (value instanceof JSONArray) {
179+
writableArray.pushArray(jsonToReact(jsonArray.getJSONArray(i)));
180+
} else if (value == JSONObject.NULL) {
181+
writableArray.pushNull();
182+
}
183+
}
184+
return writableArray;
185+
}
186+
187+
public static WritableMap jsonToReact(final JSONObject jsonObject) throws JSONException {
188+
final WritableMap writableMap = Arguments.createMap();
189+
final Iterator iterator = jsonObject.keys();
190+
while (iterator.hasNext()) {
191+
final String key = (String) iterator.next();
192+
final Object value = jsonObject.get(key);
193+
if (value instanceof Float || value instanceof Double) {
194+
writableMap.putDouble(key, jsonObject.getDouble(key));
195+
} else if (value instanceof Number) {
196+
writableMap.putInt(key, jsonObject.getInt(key));
197+
} else if (value instanceof String) {
198+
writableMap.putString(key, jsonObject.getString(key));
199+
} else if (value instanceof JSONObject) {
200+
writableMap.putMap(key, jsonToReact(jsonObject.getJSONObject(key)));
201+
} else if (value instanceof JSONArray) {
202+
writableMap.putArray(key, jsonToReact(jsonObject.getJSONArray(key)));
203+
} else if (value instanceof Boolean) {
204+
writableMap.putBoolean(key, jsonObject.getBoolean(key));
205+
} else if (value == JSONObject.NULL) {
206+
writableMap.putNull(key);
207+
}
208+
}
209+
return writableMap;
210+
}
211+
212+
private static final class Serializer implements JsonSerializer<ByteBuffer> {
213+
@Override
214+
public JsonElement serialize(final ByteBuffer src, final Type typeOfSrc, final JsonSerializationContext context) {
215+
final String payload = new String(src.array(), Charset.forName("UTF-8"));
216+
return new JsonPrimitive(payload);
217+
}
218+
}
219+
220+
private static final class Deserializer implements JsonDeserializer<ByteBuffer> {
221+
@Override
222+
public ByteBuffer deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context)
223+
throws JsonParseException {
224+
final String payload = json.getAsString();
225+
return ByteBuffer.wrap(payload.getBytes());
226+
}
227+
}
228+
229+
}

0 commit comments

Comments
 (0)