Skip to content

Commit 0931509

Browse files
Updated to work with https
1 parent b8092e6 commit 0931509

File tree

10 files changed

+89
-12
lines changed

10 files changed

+89
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [0.0.5]
2+
* Updated to work with HTTPS websites
3+
* Minor bug fixes
4+
* Updated ReadMe
5+
16
## [0.0.4]
27
* Fixed to work without the query_string package
38
* Minor bug fixes

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ WooCommerceAPI wc_api = new WooCommerceAPI(
2424
List _products = new List();
2525
2626
wc_api.getAsync("products?page=2").then((val) {
27-
List parsedMap = JSON.decode(val.body);
28-
setState(() {
29-
parsedMap.forEach((f){
30-
_products.add(f);
31-
});
32-
print(_products.length);
33-
});
27+
List products = val;
28+
print("Got " + products.length + "products received");
3429
});
3530
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.flutter.plugins;
2+
3+
import io.flutter.plugin.common.PluginRegistry;
4+
5+
/**
6+
* Generated file. Do not edit.
7+
*/
8+
public final class GeneratedPluginRegistrant {
9+
public static void registerWith(PluginRegistry registry) {
10+
if (alreadyRegisteredWith(registry)) {
11+
return;
12+
}
13+
}
14+
15+
private static boolean alreadyRegisteredWith(PluginRegistry registry) {
16+
final String key = GeneratedPluginRegistrant.class.getCanonicalName();
17+
if (registry.hasPlugin(key)) {
18+
return true;
19+
}
20+
registry.registrarFor(key);
21+
return false;
22+
}
23+
}

android/local.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sdk.dir=H:\\Android\\sdk
2+
flutter.sdk=H:\\flutter
3+
flutter.versionName=0.0.5

intermediate.tar.tmp

1.59 MB
Binary file not shown.

ios/Flutter/Generated.xcconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This is a generated file; do not edit or check into version control.
2+
FLUTTER_ROOT=H:\flutter
3+
FLUTTER_APPLICATION_PATH=C:\Users\Samarth\Desktop\Projects\woocommerce_api
4+
FLUTTER_TARGET=lib/main.dart
5+
FLUTTER_BUILD_MODE=debug
6+
FLUTTER_BUILD_DIR=build
7+
SYMROOT=${SOURCE_ROOT}/../build\ios
8+
FLUTTER_FRAMEWORK_DIR=H:\flutter\bin\cache\artifacts\engine\ios
9+
FLUTTER_BUILD_NAME=0.0.5
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Generated file. Do not edit.
3+
//
4+
5+
#ifndef GeneratedPluginRegistrant_h
6+
#define GeneratedPluginRegistrant_h
7+
8+
#import <Flutter/Flutter.h>
9+
10+
@interface GeneratedPluginRegistrant : NSObject
11+
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry;
12+
@end
13+
14+
#endif /* GeneratedPluginRegistrant_h */
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// Generated file. Do not edit.
3+
//
4+
5+
#import "GeneratedPluginRegistrant.h"
6+
7+
@implementation GeneratedPluginRegistrant
8+
9+
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
10+
}
11+
12+
@end

lib/woocommerce_api.dart

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,39 @@ import 'package:woocommerce_api/query_string.dart';
1111
import 'package:http/http.dart' as http;
1212

1313
class WooCommerceAPI {
14-
var url;
15-
var consumerKey;
16-
var consumerSecret;
14+
String url;
15+
String consumerKey;
16+
String consumerSecret;
17+
bool isHttps;
1718

1819
WooCommerceAPI(url, consumerKey, consumerSecret){
1920
this.url = url;
2021
this.consumerKey = consumerKey;
2122
this.consumerSecret = consumerSecret;
23+
24+
if(this.url.startsWith("https")){
25+
this.isHttps = true;
26+
} else {
27+
this.isHttps = false;
28+
}
29+
2230
}
2331

2432

2533
_getOAuthURL(String request_method, String endpoint) {
2634
var consumerKey = this.consumerKey; //"ck_4e943ec0f3c76eba33fffac4b7fc0d2f1f3ca91a";
2735
var consumerSecret = this.consumerSecret; //"cs_fbb723138e354e30c3d4d4e0c0f95389bf610044";
36+
2837
var token = "";
2938
var token_secret = "";
3039
var url = this.url + "/wp-json/wc/v2/" + endpoint;
3140
var containsQueryParams = url.contains("?");
3241

42+
// If website is HTTPS based, no need for OAuth, just return the URL with CS and CK as query params
43+
if(this.isHttps == true){
44+
return url + (containsQueryParams == true ? "&consumerKey=" + this.consumerKey + "&consumerSecret=" + this.consumerSecret : "?consumerKey=" + this.consumerKey + "&consumerSecret=" + this.consumerSecret);
45+
}
46+
3347
var rand = new Random();
3448
var codeUnits = new List.generate(10, (index) {
3549
return rand.nextInt(26) + 97;
@@ -129,7 +143,9 @@ class WooCommerceAPI {
129143

130144
var url = this._getOAuthURL("GET", endPoint);
131145

132-
return http.get(url);
146+
final response = await http.get(url);
147+
148+
return json.decode(response.body);
133149

134150
}
135151

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: woocommerce_api
22
description: A package to interact with the WooCommerce API.
3-
version: 0.0.4
3+
version: 0.0.5
44
author: Samarth Agarwal <samarthagarwal@live.com>
55
homepage: https://github.com/samarthagarwal/woocommerce_dart
66

0 commit comments

Comments
 (0)