Skip to content

Commit 95bf7c6

Browse files
committed
Merge pull request #89 from skyverge/4.0-beta
Howdy 4.0.0
2 parents 2998f33 + f8593a8 commit 95bf7c6

29 files changed

+813
-732
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
/.settings
22
/.project
33
*.zip
4+
.sass-cache*
5+
6+
# NPM packages used by Grunt.js
7+
/node_modules
8+
9+
# NPM debug log
10+
npm-debug.log

Gruntfile.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* jshint node:true */
2+
module.exports = function( grunt ) {
3+
'use strict';
4+
5+
// load all grunt tasks matching the `grunt-*` pattern
6+
require( 'load-grunt-tasks' )( grunt );
7+
8+
// Show elapsed time
9+
require( 'time-grunt' )( grunt );
10+
11+
var _ = require( 'underscore' );
12+
var path = require( 'path' );
13+
14+
// Set plugin slug option
15+
//grunt.option( 'plugin-slug', path.basename( process.cwd() ) );
16+
17+
var gruntConfig = {};
18+
19+
// options
20+
gruntConfig.options = {};
21+
22+
// Set folder templates
23+
gruntConfig.dirs = {
24+
css: 'assets/css',
25+
js: 'assets/js',
26+
images: 'assets/images',
27+
fonts: 'assets/fonts',
28+
build: 'build'
29+
};
30+
31+
function loadConfig( filepath ) {
32+
var object = {};
33+
var key;
34+
35+
filepath = path.normalize( path.resolve( process.cwd(), filepath ) + '/' )
36+
37+
var files = grunt.file.glob.sync( '*', { cwd: filepath } );
38+
39+
files.forEach( function( option ) {
40+
key = option.replace(/\.js$/,'');
41+
object = _.extend( object, require( filepath + option )( grunt ) );
42+
});
43+
44+
return object;
45+
};
46+
47+
// load task configs
48+
gruntConfig = _.extend( gruntConfig, loadConfig( './grunt/configs/' ) );
49+
50+
// Init Grunt
51+
grunt.initConfig( gruntConfig );
52+
53+
// Register Tasks
54+
grunt.registerTask( 'default', [
55+
'coffee',
56+
'uglify',
57+
'sass',
58+
'clean'
59+
] );
60+
};

grunt/configs/clean.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* jshint node:true */
2+
module.exports = function( grunt ) {
3+
'use strict';
4+
5+
var util = grunt.option( 'util' );
6+
var _ = require( 'underscore' );
7+
var config = {};
8+
9+
// Delete source map from the CoffeeScript compilation
10+
config.clean = {
11+
options: {
12+
force: true
13+
},
14+
clean: [
15+
// Delete map files
16+
'woocommerce/payment-gateway/assets/js/frontend/*.min.js.map'
17+
]
18+
};
19+
20+
return config;
21+
};

grunt/configs/coffee.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* jshint node:true */
2+
module.exports = function( grunt ) {
3+
'use strict';
4+
5+
var config = {};
6+
7+
// Compile CoffeeScript
8+
config.coffee = {
9+
compile: {
10+
options: {
11+
sourceMap: true
12+
},
13+
files: [
14+
{
15+
expand: true,
16+
cwd: 'woocommerce/payment-gateway/assets/js/admin/',
17+
dest: 'woocommerce/payment-gateway/assets/js/admin/',
18+
src: '*.coffee',
19+
ext: '.min.js'
20+
},
21+
{
22+
expand: true,
23+
cwd: 'woocommerce/payment-gateway/assets/js/frontend/',
24+
dest: 'woocommerce/payment-gateway/assets/js/frontend/',
25+
src: '*.coffee',
26+
ext: '.min.js'
27+
}
28+
]
29+
}
30+
};
31+
32+
return config;
33+
};

grunt/configs/sass.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* jshint node:true */
2+
module.exports = function( grunt ) {
3+
'use strict';
4+
5+
var config = {};
6+
7+
// Compile all .scss files.
8+
config.sass = {
9+
compile: {
10+
options: {
11+
style: 'compressed',
12+
sourcemap: true
13+
},
14+
files: [
15+
{
16+
expand: true,
17+
cwd: 'woocommerce/payment-gateway/assets/css/admin/',
18+
dest: 'woocommerce/payment-gateway/assets/css/admin/',
19+
src: ['*.scss', '!_*.scss'],
20+
ext: '.min.css'
21+
},
22+
{
23+
expand: true,
24+
cwd: 'woocommerce/payment-gateway/assets/css/frontend/',
25+
dest: 'woocommerce/payment-gateway/assets/css/frontend/',
26+
src: ['*.scss', '!_*.scss'],
27+
ext: '.min.css'
28+
}
29+
]
30+
}
31+
};
32+
33+
return config;
34+
};

grunt/configs/uglify.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* jshint node:true */
2+
module.exports = function( grunt ) {
3+
'use strict';
4+
var config = {};
5+
6+
// Add Uglify task with legacy rules
7+
config.uglify = {
8+
uglify: {
9+
options : {
10+
sourceMap: true,
11+
sourceMapIncludeSources: true,
12+
sourceMapIn: 'woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-frontend.min.js.map', // input sourcemap from CoffeeScript compilation
13+
sourceMapName: 'woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-frontend.min.map'
14+
},
15+
files : [{
16+
src: [ 'woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-frontend.min.js' ], // uglify JS from CoffeeScript compilation
17+
dest: 'woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-frontend.min.js'
18+
}]
19+
}
20+
}
21+
22+
return config;
23+
};

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "wc-plugin-framework",
3+
"version": "4.0.0",
4+
"author": "SkyVerge Team",
5+
"homepage": "http://www.skyverge.com",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/skyverge/wc-plugin-framework.git"
9+
},
10+
"bugs": {
11+
"url": "https://github.com/skyverge/wc-plugin-framework/issues"
12+
},
13+
"engines": {
14+
"node": ">= 0.10.0"
15+
},
16+
"devDependencies": {
17+
"grunt": "~0.4.5",
18+
"grunt-newer": "~1.1.1",
19+
"grunt-notify": "~0.4.1",
20+
"grunt-contrib-clean": "~0.6.0",
21+
"grunt-contrib-coffee": "~0.13.0",
22+
"grunt-contrib-uglify": "~0.9.1",
23+
"grunt-contrib-sass": "~0.9.2",
24+
"load-grunt-tasks": "~3.2.0",
25+
"time-grunt": "~1.2.1",
26+
"underscore": "~1.8.3",
27+
"underscore.string": "~3.1.1"
28+
}
29+
}

woocommerce/api/class-sv-wc-api-base.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ abstract class SV_WC_API_Base {
8080
/**
8181
* Perform the request and return the parsed response
8282
*
83-
* TODO: during next backwards-incompatible framework update, the try/catch
84-
* block should catch SV_WC_Plugin_Exception for maximum flexibility
85-
*
8683
* @since 2.2.0
8784
* @param object $request class instance which implements \SV_WC_API_Request
8885
* @throws Exception
@@ -110,7 +107,7 @@ protected function perform_request( $request ) {
110107
// parse & validate response
111108
$response = $this->handle_response( $response );
112109

113-
} catch ( SV_WC_API_Exception $e ) {
110+
} catch ( SV_WC_Plugin_Exception $e ) {
114111

115112
// alert other actors that a request has been made
116113
$this->broadcast_request();
@@ -133,7 +130,7 @@ protected function perform_request( $request ) {
133130
* @return array|WP_Error
134131
*/
135132
protected function do_remote_request( $request_uri, $request_args ) {
136-
return wp_remote_request( $request_uri, $request_args );
133+
return wp_safe_remote_request( $request_uri, $request_args );
137134
}
138135

139136

woocommerce/api/class-sv-wc-api-json-response.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*
3333
* Useful for API's that return application/json responses
3434
*
35-
* @since 3.1.2-1
35+
* @since 4.0.0
3636
* @see SV_WC_API_Response
3737
*/
3838
class SV_WC_API_JSON_Response implements SV_WC_API_Response {
@@ -48,7 +48,7 @@ class SV_WC_API_JSON_Response implements SV_WC_API_Response {
4848
/**
4949
* Build a response object from the raw response JSON
5050
*
51-
* @since 3.1.2-1
51+
* @since 4.0.0
5252
* @param string $raw_response_json the raw response JSON
5353
*/
5454
public function __construct( $raw_response_json ) {
@@ -60,7 +60,7 @@ public function __construct( $raw_response_json ) {
6060
/**
6161
* Magic accessor for response data attributes
6262
*
63-
* @since 3.1.2-1
63+
* @since 4.0.0
6464
* @param string $name the attribute name to get
6565
* @return mixed the attribute value
6666
*/
@@ -74,7 +74,7 @@ public function __get( $name ) {
7474
/**
7575
* Returns the string representation of this response
7676
*
77-
* @since 3.1.2-1
77+
* @since 4.0.0
7878
* @see SV_WC_API_Response::to_string()
7979
* @return string the raw response
8080
*/
@@ -88,7 +88,7 @@ public function to_string() {
8888
* Returns the string representation of this response with any and all
8989
* sensitive elements masked or removed
9090
*
91-
* @since 3.1.2-1
91+
* @since 4.0.0
9292
* @see SV_WC_API_Response::to_string_safe()
9393
* @return string response safe for logging/displaying
9494
*/

woocommerce/api/class-sv-wc-api-rest-request.php

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/**
3131
* Base REST API Request class
3232
*
33-
* @since 3.1.2-1
33+
* @since 4.0.0
3434
*/
3535
class SV_WC_API_REST_Request implements SV_WC_API_Request {
3636

@@ -48,7 +48,7 @@ class SV_WC_API_REST_Request implements SV_WC_API_Request {
4848
/**
4949
* Construct REST request object
5050
*
51-
* @since 3.1.2-1
51+
* @since 4.0.0
5252
* @param string $method the request method, one of HEAD, GET, PUT, PATCH, POST, DELETE
5353
* @param string $path optional request path
5454
* @param array $params optional associative array of request parameters
@@ -66,7 +66,7 @@ public function __construct( $method, $path = '', $params = array() ) {
6666
/**
6767
* Returns the method for this request: one of HEAD, GET, PUT, PATCH, POST, DELETE
6868
*
69-
* @since 3.1.2-1
69+
* @since 4.0.0
7070
* @see SV_WC_API_Request::get_method()
7171
* @return string the request method
7272
*/
@@ -78,7 +78,7 @@ public function get_method() {
7878
/**
7979
* Returns the request path
8080
*
81-
* @since 3.1.2-1
81+
* @since 4.0.0
8282
* @see SV_WC_API_Request::get_path()
8383
* @return string the request path
8484
*/
@@ -90,35 +90,54 @@ public function get_path() {
9090
/**
9191
* Returns the request params, if any
9292
*
93-
* @since 3.1.2-1
93+
* @since 4.0.0
9494
* @return array the request params
9595
*/
9696
public function get_params() {
9797
return $this->params;
9898
}
9999

100100

101+
/**
102+
* Returns the request params, url encoded
103+
*
104+
* @since 4.0.0
105+
* @see SV_WC_API_REST_Request::get_params()
106+
* @return array the request params, url encoded
107+
*/
108+
public function get_encoded_params() {
109+
110+
$encoded_params = array();
111+
foreach ( $this->get_params() as $key => $value ) {
112+
$encoded_params[ $key ] = urlencode( $value );
113+
}
114+
115+
return $encoded_params;
116+
}
117+
118+
101119
/** API Helper Methods ******************************************************/
102120

103121

104122
/**
105123
* Returns the string representation of this request
106124
*
107-
* @since 3.1.2-1
125+
* @since 4.0.0
108126
* @see SV_WC_API_Request::to_string()
109127
* @return string request
110128
*/
111129
public function to_string() {
130+
112131
// URL encode params
113-
return build_query( $this->get_params() );
132+
return build_query( $this->get_encoded_params() );
114133
}
115134

116135

117136
/**
118137
* Returns the string representation of this request with any and all
119138
* sensitive elements masked or removed
120139
*
121-
* @since 3.1.2-1
140+
* @since 4.0.0
122141
* @see SV_WC_API_Request::to_string_safe()
123142
* @return string the request, safe for logging/displaying
124143
*/

0 commit comments

Comments
 (0)