-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Capacitor Cookies & Capacitor Http core plugins
* feat: capacitor core http initial implementation * chore: run build and run fmt * feat: merge cookies and http * chore: allow branch for ci dev release * chore: allow dev release * feat: add support for disabling http via config * fix: angular zone.js race condition * fix: default http method to GET * fix: default cap http to opt-in * chore: run fmt * fix: get response headers for XHR * chore(ios): swiftlint fixes * feat: add opt-in config for cookies * fix(ci): verify tests * Update declarations.ts
- Loading branch information
Showing
24 changed files
with
3,119 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
65 changes: 65 additions & 0 deletions
65
android/capacitor/src/main/java/com/getcapacitor/JSValue.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.getcapacitor; | ||
|
||
import org.json.JSONException; | ||
|
||
/** | ||
* Represents a single user-data value of any type on the capacitor PluginCall object. | ||
*/ | ||
public class JSValue { | ||
|
||
private final Object value; | ||
|
||
/** | ||
* @param call The capacitor plugin call, used for accessing the value safely. | ||
* @param name The name of the property to access. | ||
*/ | ||
public JSValue(PluginCall call, String name) { | ||
this.value = this.toValue(call, name); | ||
} | ||
|
||
/** | ||
* Returns the coerced but uncasted underlying value. | ||
*/ | ||
public Object getValue() { | ||
return this.value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.getValue().toString(); | ||
} | ||
|
||
/** | ||
* Returns the underlying value as a JSObject, or throwing if it cannot. | ||
* | ||
* @throws JSONException If the underlying value is not a JSObject. | ||
*/ | ||
public JSObject toJSObject() throws JSONException { | ||
if (this.value instanceof JSObject) return (JSObject) this.value; | ||
throw new JSONException("JSValue could not be coerced to JSObject."); | ||
} | ||
|
||
/** | ||
* Returns the underlying value as a JSArray, or throwing if it cannot. | ||
* | ||
* @throws JSONException If the underlying value is not a JSArray. | ||
*/ | ||
public JSArray toJSArray() throws JSONException { | ||
if (this.value instanceof JSArray) return (JSArray) this.value; | ||
throw new JSONException("JSValue could not be coerced to JSArray."); | ||
} | ||
|
||
/** | ||
* Returns the underlying value this object represents, coercing it into a capacitor-friendly object if supported. | ||
*/ | ||
private Object toValue(PluginCall call, String name) { | ||
Object value = null; | ||
value = call.getArray(name, null); | ||
if (value != null) return value; | ||
value = call.getObject(name, null); | ||
if (value != null) return value; | ||
value = call.getString(name, null); | ||
if (value != null) return value; | ||
return call.getData().opt(name); | ||
} | ||
} |
Oops, something went wrong.