-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce duplication pulling posts #1017
Changes from 52 commits
84c3f03
77080f6
7ab2dad
af11b17
4db4780
df37d77
a844ea3
12c2831
70a894c
f0f7677
a66607d
ba34f34
d0592a5
1d47baa
7407ebe
b354d48
b888f41
dc30738
e13c440
3f4ba02
dd8dd9c
3c4d187
76fa01a
97dd3a1
40d03c6
a6db663
db58d8a
929547b
918af12
0f6df49
9958f8c
ec02077
1f6de6e
cb79bf7
8111b78
958c8e0
3080b9f
83ecd7c
619d50a
a2b95c4
c8a11e7
ba2c907
2483490
bc5772d
e0f4d31
0df5b63
e7cbbc3
05dcce6
fa68246
9dd5746
827d4d6
e747fb6
27b729c
62d165f
0efefda
671837f
18eb1e4
442113f
c83fde1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Todo: Make sure this doesn't affect the wp.com oauth flow. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,11 @@ public function __construct( $args ) { | |
* @return array | ||
*/ | ||
public function format_get_args( $args = array(), $context = array() ) { | ||
if ( ! isset( $args['headers'] ) ) { | ||
$args['headers'] = array(); | ||
} | ||
$args['headers']['X-Distributor-Version'] = DT_VERSION; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @peterwilsoncc I see we are repeating this multiple times in the code base. I am okay with explicitly adding this in the header, but I want to check if we can add this header automatically with a filter hook to any distributor-related call. |
||
|
||
/** | ||
* Format request args for a GET request so auth occurs. | ||
* | ||
|
@@ -71,6 +76,11 @@ public function format_get_args( $args = array(), $context = array() ) { | |
* @return array | ||
*/ | ||
public function format_post_args( $args, $context = array() ) { | ||
if ( ! isset( $args['headers'] ) ) { | ||
$args['headers'] = array(); | ||
} | ||
$args['headers']['X-Distributor-Version'] = DT_VERSION; | ||
|
||
/** | ||
* Format request args for a POST request so auth occurs | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
* @method array get_media() | ||
* @method array post_data() | ||
* @method array to_insert( array $args = [] ) | ||
* @method array to_pull_list( array $args = [] ) | ||
* @method array to_rest( array $args = [] ) | ||
*/ | ||
class DistributorPost { | ||
|
@@ -816,6 +817,38 @@ protected function to_insert( $args = array() ) { | |
return $insert; | ||
} | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @peterwilsoncc Can we add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
* Get the post data in a format suitable for the pull screen. | ||
* | ||
* This is a wrapper for the ::to_insert() method that includes extra | ||
* data required for the pull screen. | ||
* | ||
* @param mixed $args { | ||
* Optional. Array of push arguments | ||
* @see ::to_insert() for arguments. | ||
* } | ||
* @return array Post data formatted for the pull screen. | ||
*/ | ||
protected function to_pull_list( $args = array() ) { | ||
$display_data = $this->to_insert( $args ); | ||
|
||
// Additional information required for pull screen. | ||
$display_data['ID'] = $this->post->ID; | ||
$display_data['post_date'] = $this->post->post_date; | ||
$display_data['post_date_gmt'] = $this->post->post_date_gmt; | ||
$display_data['post_modified'] = $this->post->post_modified; | ||
$display_data['post_modified_gmt'] = $this->post->post_modified_gmt; | ||
$display_data['post_password'] = $this->post->post_password; | ||
$display_data['guid'] = $this->post->guid; | ||
$display_data['comment_status'] = $this->post->comment_status; | ||
$display_data['ping_status'] = $this->post->ping_status; | ||
$display_data['link'] = $this->get_permalink(); | ||
$display_data['distributor_original_site_name'] = $this->source_site['name']; | ||
$display_data['distributor_original_site_url'] = $this->source_site['home_url']; | ||
|
||
return $display_data; | ||
} | ||
|
||
/** | ||
* Get the post data in a format suitable for the distributor REST API endpoint. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterwilsoncc I am not aware why we add distributor-related information to all API requests. Is it required? Can we limit it to distributor-specific rest API requests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure of the design decision here, let's open a ticket as a maybe later.