I would know if it's possible to download a specific files (json) from github to insert a directory without to download all the files via a zip.
I have this
$json = #file_get_contents($this->GetGithubRepo() . '/' . $module_name . '/contents/' . $this->ModuleInfosJson . '?ref=master', true, $this->context );
This line read the json, I would to write the json on a directory.
Objective is to create a cache and read the cache before to read on github.
Thank you
Github is not "in love" with this behavior, but I have an entire framework that runs on the same paradigm. I do, however, use the zip. You can hit the raw content following this pattern:
https://raw.githubusercontent.com/YOURHANDLE/THE_REPO/THE_BRANCH/FILE/PATH/ETC
Look for the "raw" option on a particular file when browsing.
Here is a config file from one of my repo in a format similar to how you wish:
https://raw.githubusercontent.com/datamafia/ShopifyETL/master/config.cfg
should currently return
[all]
SHOPIFY_KEY=YOUR-SHOPIFY-API-KEY
SHOPIFY_PASSWORD=YOUR-SHOPIFY-API-PW
SHOPIFY_STORE=YOUR-SHOPIFY-STORE-DOES-NOT-EXIST
SHOPIFY_BASE_URL=SHOPIFY_STORE.myshopify.com-or-custom-FQDN
Pay attention to document type and encoding, these could trip you up. Your JSON may not be JSON via the header (should not be).
One final problem, beyond encoding, is that of private accounts. Once private a big can of work will be put on your plate to auth in and see the data.
The header, mildly changed:
Date: Thu, 13 Apr 2017 00:02:48 GMT
Via: 1.1 varnish
Cache-Control: max-age=300
Etag: "154ec087bc75e501a18e72d4e14a6f17bc2f706b"
Connection: keep-alive
X-Served-By: cache-dfw1840-DFW
X-Cache: HIT
x-cache-hits: 1
X-Timer: S1492012345.3876515,VS0,VE0
Vary: Authorization,Accept-Encoding
Access-Control-Allow-Origin: *
X-Fastly-Request-ID: XYZABCXYZABCXYZABCXYZABCXYZABC
Expires: Thu, 13 Apr 2017 00:07:48 GMT
Source-Age: 35
Document type is "plain" (text), so some casting and checking will be important. There are tools in PHP to handle the incoming data and use as JSON. Good luck.
Related
The following 'code' is sometimes (random) printed on a webpage after refresh.
>HTTP/1.1 200 OK
>Date: Fri, 18 Mar 2016 09:05:03 GMT
>Server: Apache
>X-Powered-By: PHP/5.3.6-pl0-gentoo
>X-Frame-Options: DENY
>X-XSS-Protection: 1; mode=block
>X-Content-Type-Options: nosniff
>Expires: Thu, 19 Nov 1981 08:52:00 GMT
>Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
>Pragma: no-cache
>Keep-Alive: timeout=15, max=86
>Connection: Keep-Alive
>Transfer-Encoding: chunked
>Content-Type: text/html
>5
(the last number, 5 in this case, is random, the rest is constant.
This is what I tried to solved this annoying 'bug?':
Removing HTML <head> contents
Removing HTML <body> contents
Removing AJAX (XHR) calls
Updating Smarty (engine that parses the templates)
PHP trim() around output to prevent unnessary spaces before or after <doctype> and <html> tags
Killing almost all PHP code (this is to much to explain here, but since I stripped it down complety I am 99% sure it is not the serverside (PHP) code)
Looking for PHP functions that are able to print these headers (greps for headers_list, getallheaders, apache_request_headers, etc.)
Tried multiple pages, same results, no matter its contents.
My customer sees the seem results on Microsoft Edge browser.
Updated other components, like browser detection
Added PHP ob_start();
Validated HTML
Made sure to clean Javascript console errors (now clean)
Gave a go on WireShark for Windows, to look at what headers are received, but this was to difficult for me. (should I retry?)
This problem sounds a lot like mine, but wasn't helping to fix mine: bugzilla DOT mozilla DOT org/show_bug.cgi?id=229710
Checked other Stack Overflow questions. Could not find a matching question/solution.
More, which I forgot :)
Notes:
The site is server over HTTPS with a valid certificate.
Here is the site link: https://www.10voordeleraar.nl
Attached screenshot links below.
The funny thing is, this only happens on Microsoft Edge, sometimes. It is behaving properly on all other browsers, so do my other sites.
Regards,
Laird
Screenshots:
Printed HTTP headers example on site top
Printed HTTP headers example in DOM inspect
I am trying to write a backup script for cloudfiles (using Rackspace) , which will only copy the files that are modified since the last backup time.
Is there a way to query for a list files that are modified since a specific time ? (Using PHP )
Note: using php-opencloud library.
Currently, I haven't found a way to query/filter based on the last modified date.
What you can do is look at the metadata for each object in a container. At a low level, this requires just a HEAD operation on each object. While this probably requires you to check each object, you're only grabbing the headers and not downloading each one.
The last modified date is in the HTTP headers when making a HEAD operation on an object:
HEAD /<api version>/<account>/<container>/<object> HTTP/1.1
Host: storage.clouddrive.com
X-Auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
No response body is returned, but the HTTP headers have juicy details:
HTTP/1.1 200 OK
Date: Thu, 07 Jun 2007 20:59:39 GMT
Last-Modified: Fri, 12 Jun 2007 13:40:18 GMT
ETag: 8a964ee2a5e88be344f36c22562a6486
Content-Length: 512000
Content-Type: text/plain; charset=UTF-8
X-Object-Meta-Meat: Bacon
There is a method in the PHP library called fetch that can get just the headers of the object, but it's private and I don't see it being used anywhere. This looks like the type of thing to raise an issue on GitHub or make a PR of your own for.
Right now you can get each object and pull the headers out yourself:
$obj = $container->DataObject();
$headers = $obj->metadataHeaders();
$headers["Last-Modified"]
Sorry that doesn't help completely. I pinged one of the PHP devs directly and hopefully we'll find another option if this doesn't work out.
Try using glob() and filemtime().
Example:
$lastBackupTime = 1234567890; //You'll have to figure out how to store and retrieve this
$modified = array();
// Change the input of glob() to use the directory and file extension you're looking for
foreach (glob('/some/directory/*.txt') as $file) {
if (filemtime($file) > $lastBackupTime) {
$modified[] = $file;
}
}
foreach ($modified as $file) {
//do something
}
I tried this REST WS http://phprestsql.sourceforge.net/
When I select PUT verb and copy and paste in textbox
firstname=Jim
surname=Example
email=jim#example.org
company_uid=1
I do get this response error :
HTTP/1.x 405 Method Not Allowed
Date: Sun, 18 Aug 2013 16:50:06 GMT
Via: 1.1 varnish
Allow: GET, HEAD
Server: Apache/2.2.15 (CentOS)
Age: 0
Vary: Host, Accept-Encoding
Content-Type: text/html
Cache-Control: max-age=172800
X-Varnish: 244445725
Connection: keep-alive
Content-Length: 0
Expires: Tue, 20 Aug 2013 16:50:06 GMT
Why don't I get as expected
HTTP/1.x 201 Created
PUT requires you to know the specific resource ID already - it is intended to REPLACE the content of the current record with the content of a new record (that you provide). If you are just creating a new record that has never existed before and you don't want to replace or overwrite anything else, you should use POST.
From the website linked:
There are two ways to add a row to a table:
Using a PUT method we can write a resource to a specific URL, but to
do this we must already know the primary key we want to insert it at
(since the primary key forms part of the URL). The PUT method should
be used to create or overwrite a known named resource.
Using a POST method we can send a rows representation to a tables URL
and get it to append it to itself. The POST method should be used to
create a brand new resource as a sub-resource of a collection (and
when you want the server to make up the URL for you).
First, here is what my current system looks like:
CouchDB 1.0.2
PHP 5.3.6
Apache httpd 2.2.19
PECL http 1.7.1
CouchDB-Lucene 0.6.1
I am building a mini search engine with CouchDB and CouchDB-Lucene. When the user enters a query I POST to my PHP script which then queries couchdb-lucene. Couchdb-lucene will then return a list of matching document keys to the PHP script. Then, I POST data (with http_post_data) to a List Function with that list of keys (detailed here, under "Querying Options"). This List Function returns HTML formatted results. This is the part that works.
My needs are now changing and I would like to query only the view and get back JSON. However, when I do, this is the response from the http_post_data call:
HTTP/1.1 415 Unsupported Media Type
Server: CouchDB/1.0.2 (Erlang OTP/R13B)
Date: Sat, 09 Jul 2011 22:22:51 GMT
Content-Type: text/plain;charset=utf-8
Content-Length: 78
Cache-Control: must-revalidate
{"error":"bad_content_type","reason":"Content-Type must be application/json"}
The URL that I generate for this view is correct. I can change my POST call to
http_post_data(url/of/view, $key_string, "Content-Type:application/json");
but nothing will actually be returned (I am looking at output in Firebug). To send back my results, here is the relevant PHP:
HttpResponse::setContentType("application/json");
HttpResponse::setData($response);
$response contains the response from the http_post_data call to CouchDB.
Any suggestions? This has been driving me mad for a day and a bit now.
Thanks.
http_post_data supposed to receive an assoc array (not a string) for options.
You should use array('headers' => array('content-type' => 'application/json')) instead of "Content-Type:application/json"
Can anyone enlighten me how to create a _$folder$ using Google storage API? Here is the class that I have so far (I managed to list/filter files), but no success with creating a 'directory'. http://guy.codepad.org/lEO4J6hL
When I try to create a test_$folder$, this is what I send to the server:
PUT /test_$folder$ HTTP/1.1
Host: static.hotelpublisher.com.commondatastorage.googleapis.com
Date: Mon, 29 Nov 2010 19:45:49 GMT
Content-Length: 0
Content-Type: application/octet-stream
Content-MD5: 1B2M2Y8AsgTpgAmY7PhCfg==
Authorization: GOOG1 GOOGRVMFQJPKHRXAU3F6:gtzlxexMjBOafn5tOZKF7UZGv1I=
x-goog-acl: public-read
This is what I get in return:
<?xml version='1.0' encoding='UTF-8'?><Error><Code>MalformedHeaderValue</Code><Message>An HTTP header value was malformed.</Message><Date>mon, 29 nov 2010 19:34:23</Date></Error>
This is done following the Google provided documentation, thus I don't see why this does not work.
Hm... have you tried taking out the Content-MD5 header? It doesn't look like it's necessary since your Content-Length is 0.