├── .DS_Store ├── Angular simple images ├── README.md ├── angular.min.js ├── app.js └── index.html ├── Auth0 integration ├── README.md ├── index.html └── styles.css ├── Blogdown ├── README.md ├── css │ ├── blog.css │ └── prism.css ├── index.html ├── js │ └── prism.js └── masterpage.html ├── C# fileupload └── upload.cs ├── Dashboard ├── README.md ├── applications.json ├── code.js └── dashboard.png ├── Highcharts ├── README.md └── projectreport.html ├── Java ├── README.md ├── lib │ └── json-simple-1.1.1.jar ├── restdb.sh └── src │ └── guillaume │ └── agis │ ├── Main.java │ └── RestDBClient.java ├── Media archive ├── README.md └── index.html ├── PHP ├── README.md ├── composer.json ├── composer.lock ├── composer.phar ├── restdbclient.php └── vendor │ ├── autoload.php │ ├── composer │ ├── ClassLoader.php │ ├── LICENSE │ ├── autoload_classmap.php │ ├── autoload_files.php │ ├── autoload_namespaces.php │ ├── autoload_psr4.php │ ├── autoload_real.php │ └── installed.json │ ├── guzzlehttp │ ├── guzzle │ │ ├── .travis.yml │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── README.md │ │ ├── UPGRADING.md │ │ ├── composer.json │ │ └── src │ │ │ ├── Client.php │ │ │ ├── ClientInterface.php │ │ │ ├── Cookie │ │ │ ├── CookieJar.php │ │ │ ├── CookieJarInterface.php │ │ │ ├── FileCookieJar.php │ │ │ ├── SessionCookieJar.php │ │ │ └── SetCookie.php │ │ │ ├── Exception │ │ │ ├── BadResponseException.php │ │ │ ├── ClientException.php │ │ │ ├── ConnectException.php │ │ │ ├── GuzzleException.php │ │ │ ├── RequestException.php │ │ │ ├── SeekException.php │ │ │ ├── ServerException.php │ │ │ ├── TooManyRedirectsException.php │ │ │ └── TransferException.php │ │ │ ├── Handler │ │ │ ├── CurlFactory.php │ │ │ ├── CurlFactoryInterface.php │ │ │ ├── CurlHandler.php │ │ │ ├── CurlMultiHandler.php │ │ │ ├── EasyHandle.php │ │ │ ├── MockHandler.php │ │ │ ├── Proxy.php │ │ │ └── StreamHandler.php │ │ │ ├── HandlerStack.php │ │ │ ├── MessageFormatter.php │ │ │ ├── Middleware.php │ │ │ ├── Pool.php │ │ │ ├── PrepareBodyMiddleware.php │ │ │ ├── RedirectMiddleware.php │ │ │ ├── RequestOptions.php │ │ │ ├── RetryMiddleware.php │ │ │ ├── TransferStats.php │ │ │ ├── UriTemplate.php │ │ │ ├── functions.php │ │ │ └── functions_include.php │ ├── promises │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.md │ │ ├── composer.json │ │ ├── phpunit.xml.dist │ │ ├── src │ │ │ ├── AggregateException.php │ │ │ ├── CancellationException.php │ │ │ ├── EachPromise.php │ │ │ ├── FulfilledPromise.php │ │ │ ├── Promise.php │ │ │ ├── PromiseInterface.php │ │ │ ├── PromisorInterface.php │ │ │ ├── RejectedPromise.php │ │ │ ├── RejectionException.php │ │ │ ├── TaskQueue.php │ │ │ ├── functions.php │ │ │ └── functions_include.php │ │ └── tests │ │ │ ├── AggregateExceptionTest.php │ │ │ ├── EachPromiseTest.php │ │ │ ├── FulfilledPromiseTest.php │ │ │ ├── NotPromiseInstance.php │ │ │ ├── PromiseTest.php │ │ │ ├── RejectedPromiseTest.php │ │ │ ├── RejectionExceptionTest.php │ │ │ ├── TaskQueueTest.php │ │ │ ├── Thennable.php │ │ │ ├── bootstrap.php │ │ │ └── functionsTest.php │ └── psr7 │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.md │ │ ├── composer.json │ │ ├── phpunit.xml.dist │ │ ├── src │ │ ├── AppendStream.php │ │ ├── BufferStream.php │ │ ├── CachingStream.php │ │ ├── DroppingStream.php │ │ ├── FnStream.php │ │ ├── InflateStream.php │ │ ├── LazyOpenStream.php │ │ ├── LimitStream.php │ │ ├── MessageTrait.php │ │ ├── MultipartStream.php │ │ ├── NoSeekStream.php │ │ ├── PumpStream.php │ │ ├── Request.php │ │ ├── Response.php │ │ ├── Stream.php │ │ ├── StreamDecoratorTrait.php │ │ ├── StreamWrapper.php │ │ ├── Uri.php │ │ ├── functions.php │ │ └── functions_include.php │ │ └── tests │ │ ├── AppendStreamTest.php │ │ ├── BufferStreamTest.php │ │ ├── CachingStreamTest.php │ │ ├── DroppingStreamTest.php │ │ ├── FnStreamTest.php │ │ ├── FunctionsTest.php │ │ ├── InflateStreamTest.php │ │ ├── LazyOpenStreamTest.php │ │ ├── LimitStreamTest.php │ │ ├── MultipartStreamTest.php │ │ ├── NoSeekStreamTest.php │ │ ├── PumpStreamTest.php │ │ ├── RequestTest.php │ │ ├── ResponseTest.php │ │ ├── StreamDecoratorTraitTest.php │ │ ├── StreamTest.php │ │ ├── StreamWrapperTest.php │ │ ├── UriTest.php │ │ └── bootstrap.php │ └── psr │ └── http-message │ ├── LICENSE │ ├── README.md │ ├── composer.json │ └── src │ ├── MessageInterface.php │ ├── RequestInterface.php │ ├── ResponseInterface.php │ ├── ServerRequestInterface.php │ ├── StreamInterface.php │ ├── UploadedFileInterface.php │ └── UriInterface.php ├── Python File Upload ├── .gitignore ├── README.md ├── image.jpeg └── upload.py ├── Python ├── README.md └── sample.py ├── README.md ├── images ├── banner.png ├── chat-restdbio-streamdataio.png ├── restdb-banner.png └── restdbio.png ├── jQuery ├── README.md └── index.html ├── realtime-react ├── .gitignore ├── README.md ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ └── manifest.json └── src │ ├── App.css │ ├── App.js │ ├── App.test.js │ ├── Autotrader.js │ ├── helper.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ └── registerServiceWorker.js ├── restdb_io realtime chat ├── index.html └── public │ ├── code.js │ └── styles.css └── streamdata_io_chat ├── README.md └── index.html /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RestDB/clientexamples/e5504d04123d2eca15340d4634e139e759ba5904/.DS_Store -------------------------------------------------------------------------------- /Angular simple images/README.md: -------------------------------------------------------------------------------- 1 | ## Angular simple image demo 2 | Simple image + caption upload and CRUD using AngularJS and restdb.io by Federico Portoghese federico.portoghese@gmail.com 3 | 4 | Requirements: 5 | an accessible restdb.io database with one collection, two fields are required: 6 | 7 | 1. A Text field called "Name" 8 | 2. An Image field called "Image" 9 | 10 | ## Setup 11 | 12 | Edit app.js and change this to your database: 13 | 14 | ```js 15 | hImages.constant("config", { 16 | apiKey: /* Enter your CORS API key here. Eg. "57483247g45b25478968j7d9fg" */, 17 | dbName: /* Enter your database name here. Eg. "images-8a0b" */, 18 | collectionName: /* Enter your collection name here. Eg. "images" */ 19 | }); 20 | ``` 21 | **important**: Create a valid [CORS API key](https://restdb.io/docs/apikeys-and-cors#restdb), use * as Access-Control-Allow-Origin for running from a local machine. 22 | 23 | Open index.html and run the App. 24 | 25 | -------------------------------------------------------------------------------- /Angular simple images/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Simple image + caption upload and CRUD using AngularJS and restdb.io 6 | 7 | 8 | 9 | 10 |

11 |
12 |
13 |
14 | 15 |

16 |

17 | 18 |

19 |

20 |
21 | 22 |

23 | 24 | 25 | 28 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Auth0 integration/README.md: -------------------------------------------------------------------------------- 1 | # Auth0 - restdb.io Authentication SPA demo 2 | 3 | ToDo Web app with user authentication integrated with Auth.com 4 | 5 | View live demo here (as a public HTML Page in the database): 6 | 7 | https://www-myapp-7175.restdb.io 8 | 9 | Read blog post here: 10 | 11 | https://restdb.io/blog/#!posts/57cece1a2d5dbc27000000d3 12 | 13 | 14 | -------------------------------------------------------------------------------- /Auth0 integration/styles.css: -------------------------------------------------------------------------------- 1 | body{ 2 | background-color:#EEEEEE; 3 | } 4 | .todolist{ 5 | background-color:#FFF; 6 | padding:20px 20px 10px 20px; 7 | margin-top:30px; 8 | } 9 | .todolist h1{ 10 | margin:0; 11 | padding-bottom:20px; 12 | text-align:center; 13 | } 14 | .form-control{ 15 | border-radius:0; 16 | } 17 | li.ui-state-default{ 18 | background:#fff; 19 | border:none; 20 | border-bottom:1px solid #ddd; 21 | } 22 | 23 | li.ui-state-default:last-child{ 24 | border-bottom:none; 25 | } 26 | 27 | .todo-footer{ 28 | background-color:#F4FCE8; 29 | margin:0 -20px -10px -20px; 30 | padding: 10px 20px; 31 | } 32 | #done-items li{ 33 | padding:10px 0; 34 | border-bottom:1px solid #ddd; 35 | text-decoration:line-through; 36 | } 37 | #done-items li:last-child{ 38 | border-bottom:none; 39 | } 40 | #checkAll{ 41 | margin-top:10px; 42 | } -------------------------------------------------------------------------------- /Blogdown/README.md: -------------------------------------------------------------------------------- 1 | # Markdown demo 2 | 3 | Blog database with Twitter bootstrap and Markdown editor for blog posts. 4 | 5 | https://www-blogdown-b422.restdb.io 6 | 7 | Read blog post here: 8 | 9 | https://restdb.io/blog/#!posts/57f388a0a5631e2a0000071e 10 | 11 | 12 | -------------------------------------------------------------------------------- /Blogdown/css/blog.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Start Bootstrap - Blog Post (http://startbootstrap.com/) 3 | * Copyright 2013-2016 Start Bootstrap 4 | * Licensed under MIT (https://github.com/BlackrockDigital/startbootstrap/blob/gh-pages/LICENSE) 5 | */ 6 | 7 | body { 8 | padding-top: 70px; /* Required padding for .navbar-fixed-top. Remove if using .navbar-static-top. Change if height of navigation changes. */ 9 | } 10 | 11 | footer { 12 | margin: 50px 0; 13 | } 14 | 15 | .blogsep { 16 | height: 7px; 17 | background: #efefef; 18 | margin-bottom: 40px; 19 | margin-top: 40px; 20 | } 21 | 22 | table { 23 | width: 100%; 24 | } 25 | td, th{ 26 | border: 1px solid lightgrey; 27 | padding: 4px; 28 | } 29 | 30 | .profileimg{ 31 | width:20px; 32 | height:20px; 33 | border-radius:50%; 34 | overflow:hidden; 35 | } 36 | -------------------------------------------------------------------------------- /Blogdown/index.html: -------------------------------------------------------------------------------- 1 | {{#context}} 2 | { 3 | "posts": { 4 | "collection": "blogposts", 5 | {{#if request.query.searchterm}} 6 | "query": {"published": true,"_tags": {"$regex": "{{_ "replace" request.query.searchterm " " "|"}}"}}, 7 | {{else}} 8 | "query": {"published": true}, 9 | {{/if}} 10 | "hint": {"$orderby": {"publishdate": -1}} 11 | }, 12 | "category": { 13 | "collection": "category", 14 | "query": {} 15 | } 16 | } 17 | {{/context}} 18 | {{#inherit 'masterpage'}} 19 | {{#block 'blogposts'}} 20 | {{#each posts}} 21 |

{{title}}

22 |

23 | {{author.0.name}} 24 |

25 |

Posted on {{moment publishdate format="LLL"}}, 26 | 27 | {{#each categories}} 28 | {{name}} 29 | {{/each}} 30 |

31 |
32 |

{{{markdown content}}}

33 |
34 | {{/each}} 35 | {{/block}} 36 | {{/inherit}} 37 | -------------------------------------------------------------------------------- /C# fileupload/upload.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * C# example file upload to restdb.io 3 | * Using mulipart form data protocol 4 | */ 5 | 6 | byte[] data; // fill with some binary data 7 | 8 | string tmpId = ""; 9 | 10 | Uri webService = new Uri("https://somedb-c1c0.restdb.io/media"); 11 | 12 | HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, webService); 13 | requestMessage.Headers.ExpectContinue = false; 14 | 15 | MultipartFormDataContent multiPartContent = new MultipartFormDataContent("----MyGreatBoundary"); 16 | 17 | ByteArrayContent byteArrayContent = new ByteArrayContent(data); 18 | byteArrayContent.Headers.Add("Content-Type", "application/octet-stream"); 19 | multiPartContent.Add(byteArrayContent, "profilePic", "profilePic.png"); 20 | requestMessage.Content = multiPartContent; 21 | requestMessage.Headers.Add("x-apikey", "YOUR API KEY HERE"); 22 | 23 | HttpClient httpClient = new HttpClient(); 24 | 25 | try { 26 | 27 | Task < HttpResponseMessage > httpRequest = httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseContentRead); 28 | HttpResponseMessage httpResponse = httpRequest.Result; 29 | HttpStatusCode statusCode = httpResponse.StatusCode; 30 | HttpContent responseContent = httpResponse.Content; 31 | 32 | if (responseContent != null) { 33 | Task < String > stringContentsTask = responseContent.ReadAsStringAsync(); 34 | String stringContents = stringContentsTask.Result; 35 | 36 | if (!stringContents.Substring(0, 1).Equals("[")) { 37 | string tmpStr = "[" + stringContents + "]"; 38 | stringContents = tmpStr; 39 | } 40 | 41 | var objects = JArray.Parse(stringContents); // parse as array 42 | foreach(JObject root in objects) 43 | { 44 | foreach(KeyValuePair < String, JToken > app in root) 45 | { 46 | if (app.Key.Equals("ids")) { 47 | tmpId = (String)app.Value[0]; 48 | } 49 | } 50 | } 51 | } 52 | } 53 | 54 | catch (Exception ex) 55 | { 56 | string errStr = ex.Message; 57 | } 58 | -------------------------------------------------------------------------------- /Dashboard/README.md: -------------------------------------------------------------------------------- 1 | # Dashboard with RestDB 2 | 3 | Example code from blog post on how to create Dashboards in RestDB. 4 | The Dashboard shows statistics for a job application database. 5 | 6 | ![Screen shot](./dashboard.png) 7 | 8 | Read blogpost: https://restdb.io/blog/how-to-create-dashboards 9 | 10 | View live demo here: 11 | https://jobapplications-5c54.restdb.io/views/public/dashboard 12 | -------------------------------------------------------------------------------- /Dashboard/dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RestDB/clientexamples/e5504d04123d2eca15340d4634e139e759ba5904/Dashboard/dashboard.png -------------------------------------------------------------------------------- /Highcharts/README.md: -------------------------------------------------------------------------------- 1 | # Highcharts report 2 | 3 | Minimal html page with a Highcharts Basic bar chart of a Project database. 4 | 5 | You can run the example by opening the file directly from a local file in your browser. 6 | 7 | View live demo here (as a Page in the database): 8 | https://rdb-proexample.restdb.io/public/Workreport -------------------------------------------------------------------------------- /Highcharts/projectreport.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |

Project Report in Highcharts

11 | 12 |
13 |
14 | 15 | 16 | 19 | 20 | 21 | 22 | 136 | 137 | -------------------------------------------------------------------------------- /Java/README.md: -------------------------------------------------------------------------------- 1 | # RestDBClient-JAVA 2 | 3 | RestDB client example in Java 4 | 5 | The sources are into the folder src/guillaume/agis. Guillaume.agis is actually the name of the package. 6 | 7 | ## How to launch the program 8 | 9 | - Just run ./restdb.sh in your term. The script will compile and execute the program. 10 | - if you can't run restdb.sh, please verify the right on the file. 11 | 12 | You can change the right of the file with this command : 13 | ``` 14 | chmod 744 restdb.sh 15 | ``` 16 | 17 | ## OUTPUT 18 | 19 | ``` 20 | resultWoobly postRequest : {"_id":"56e9d0b301bf3408000006f4","_created":"2016-03-16T21:31:31.627Z","_changed":"2016-03-16T21:31:31.627Z","_createdby":"api","_changedby":"api","_keywords":["api"],"_tags":"api","_version":0} 21 | resultSnuttgly postRequest : {"_id":"56e9d0b401bf3408000006f5","_created":"2016-03-16T21:31:32.783Z","_changed":"2016-03-16T21:31:32.783Z","_createdby":"api","_changedby":"api","_keywords":["api"],"_tags":"api","_version":0} 22 | result getRequest : [{"_id":"56e9d0b301bf3408000006f4"},{"_id":"56a7af4f0075c62a000012c4","description":"POST from Pyhon code","title":"Python title"},{"_id":"56a7aec20075c62a000012bb","description":"POST from Pyhon code kakemiks","title":"Python title","count":0,"email":""},{"_id":"56992027c429a20e0000061e","title":"jones was here now","description":"They are the best oh yeah","count":8,"email":"wobble@wobble.com"},{"_id":"56a7aef50075c62a000012c2","description":"POST from Pyhon code","title":"Python title"},{"_id":"56992036c429a20e00000621","title":"changed by Python PUT","description":"They are the worst","count":8,"email":"snuggle@snuggle.com"},{"_id":"56a7b1b70075c62a000012cb","description":"POST from Pyhon code","title":"Python title"},{"_id":"56aa23059ed96c3900000b4d","description":"POST from Pyhon code","title":"Python title"},{"_id":"56e87bc7bba86b5900000000"},{"_id":"56e87c52bba86b5900000001"},{"_id":"56e87d39bba86b5900000002"},{"_id":"56e87d61bba86b5900000003"},{"_id":"56e883d9d8c9f74b00000009"},{"_id":"56e883dad8c9f74b0000000a"},{"_id":"56e89dccd8c9f74b0000000b"},{"_id":"56e89dcdd8c9f74b0000000c"},{"_id":"56e89e92d8c9f74b0000000d"},{"_id":"56e89e93d8c9f74b0000000e"},{"_id":"56e8a2cfd8c9f74b00000010"},{"_id":"56e8a301d8c9f74b00000011"},{"_id":"56e8a303d8c9f74b00000012"},{"_id":"56e9c05c01bf3408000006e3"},{"_id":"56e9c1d101bf3408000006e5"},{"_id":"56e9c1ea01bf3408000006e7"},{"_id":"56e9c20d01bf3408000006e9"},{"_id":"56e9c22801bf3408000006eb"},{"_id":"56e9c26d01bf3408000006ed"},{"_id":"56e9c2c801bf3408000006ef"},{"_id":"56e9c2dc01bf3408000006f1"},{"_id":"56e9cdb401bf3408000006f3"},{"_id":"56e9d0b401bf3408000006f5"}] 23 | result getRequestWithFilter : [{"_id":"56a7aec20075c62a000012bb","description":"POST from Pyhon code kakemiks","title":"Python title","count":0,"email":""}] 24 | {"_id":"56e9d0b301bf3408000006f4"} 25 | {"_id":"56e9d0b301bf3408000006f4","_created":"2016-03-16T21:31:31.627Z","_changed":"2016-03-16T21:31:36.457Z","_createdby":"api","_changedby":"api","_keywords":["api"],"_tags":"api","_version":1} 26 | {"result":["56e9d0b301bf3408000006f4"]} 27 | 28 | Process finished with exit code 0 29 | ``` 30 | 31 | 32 | 33 | 34 | Dev by Guillaume Agis, 2016 35 | -------------------------------------------------------------------------------- /Java/lib/json-simple-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RestDB/clientexamples/e5504d04123d2eca15340d4634e139e759ba5904/Java/lib/json-simple-1.1.1.jar -------------------------------------------------------------------------------- /Java/restdb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo "Start compiling RESTDBClient in Java..." 3 | mkdir bin ; javac -cp lib/json-simple-1.1.1.jar src/guillaume/agis/* -d bin 4 | echo "Compilation done. Execute sample..." 5 | java -cp "./bin:./lib/json-simple-1.1.1.jar" guillaume/agis/Main -------------------------------------------------------------------------------- /Java/src/guillaume/agis/Main.java: -------------------------------------------------------------------------------- 1 | package guillaume.agis; 2 | 3 | import org.json.simple.JSONArray; 4 | import org.json.simple.JSONObject; 5 | import org.json.simple.parser.JSONParser; 6 | import org.json.simple.parser.ParseException; 7 | 8 | @SuppressWarnings("unchecked") 9 | public class Main { 10 | 11 | /** 12 | * Collection name 13 | */ 14 | private static final String COLLECTION = "stuff"; 15 | 16 | /** 17 | * Create 2 JSON Objects and add them to the collection 18 | * @param client restDB client 19 | */ 20 | private static void postRequest(final RestDBClient client) { 21 | JSONObject woobly = new JSONObject(); 22 | woobly.put("title", "Wobbly bubbles"); 23 | woobly.put("description", "They are the best"); 24 | woobly.put("count", 4); 25 | woobly.put("email", "wobble@wobble.com"); 26 | 27 | 28 | JSONObject snuttgly = new JSONObject(); 29 | snuttgly.put("title", "Snuggly snuggles"); 30 | snuttgly.put("description", "They are the worst"); 31 | snuttgly.put("count", 8); 32 | snuttgly.put("email", "snuggle@snuggle.com"); 33 | 34 | String resultWoobly = client.post(COLLECTION, woobly.toJSONString()); 35 | 36 | System.out.println("result Woobly postRequest : " + resultWoobly); 37 | String resultSnuttgly = client.post(COLLECTION, snuttgly.toJSONString()); 38 | System.out.println("result Snuttgly postRequest : " + resultSnuttgly); 39 | 40 | // call Garbage collection 41 | snuttgly = null; 42 | woobly = null; 43 | } 44 | 45 | /** 46 | * Get the list of items in the collection 47 | * @param client RestDBClient 48 | * @return list of items in the collection, String format 49 | */ 50 | private static String getRequest(final RestDBClient client) { 51 | String result = client.get(COLLECTION); 52 | System.out.println("result getRequest : " + result); 53 | return result; 54 | } 55 | 56 | 57 | /** 58 | * Get the list of items in the collection where count = 0 59 | * More info about the parameters of the queries here : https://restdb.io/docs/querying-with-the-api 60 | * @param client RestDBClient 61 | * @return list of items in the collection, String format 62 | */ 63 | private static String getRequestWithFilter(final RestDBClient client) { 64 | JSONObject jsonQuery = new JSONObject(); 65 | jsonQuery.put("count", 8); 66 | String query = "?q=" + jsonQuery.toJSONString(); 67 | String result = client.get(COLLECTION + query); 68 | System.out.println("result getRequestWithFilter : " + result); 69 | return result; 70 | } 71 | 72 | /** 73 | * Update an item from a collection given its ID 74 | * @param client RestDBClient 75 | * @param resultGetAll list of items from the collection 76 | * @return ID of the updated item 77 | */ 78 | private static String putRequest(final RestDBClient client, final String resultGetAll) { 79 | JSONParser parser = new JSONParser(); 80 | Object obj = null; 81 | String id = null; 82 | try { 83 | obj = parser.parse(resultGetAll); 84 | JSONArray results = (JSONArray)(obj); 85 | if (!resultGetAll.isEmpty() && results.size() > 0) 86 | { 87 | JSONObject firstOne = (JSONObject)results.get(0); // take first item 88 | System.out.println(firstOne.toJSONString()); 89 | firstOne.put("title", "updated title"); 90 | id = (String)firstOne.get("_id"); 91 | String resultPut = client.put(COLLECTION + "/" + id, firstOne.toJSONString()); 92 | System.out.println(resultPut); 93 | } 94 | } catch (ParseException e) { 95 | e.printStackTrace(); 96 | } 97 | return id; 98 | } 99 | 100 | /** 101 | * Delete item from a collection by aa given ID 102 | * @param client RestDBCliet 103 | * @param id ID of the item to delete from the collection 104 | */ 105 | private static void deleteRequest(final RestDBClient client, final String id) { 106 | String resultDelete = client.delete(COLLECTION + "/" + id); 107 | System.out.println(resultDelete); 108 | } 109 | 110 | /** 111 | * entry point 112 | * @param args arguments, there is currently no argument given to this app 113 | */ 114 | public static void main(String[] args) { 115 | 116 | RestDBClient client = new RestDBClient(); 117 | 118 | postRequest(client); 119 | String resultGetAll = getRequest(client); 120 | getRequestWithFilter(client); 121 | String id = putRequest(client, resultGetAll); 122 | deleteRequest(client, id); 123 | 124 | // Garbage collection 125 | client = null; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /Media archive/README.md: -------------------------------------------------------------------------------- 1 | # Media archive API 2 | 3 | Minimal html page with jQuery for calling the RestDB Media archive API. 4 | 5 | You can run the example by opening the file directly from a local file in your browser. 6 | 7 | Read blog post here: 8 | https://restdb.io/blog/#!posts/570d28ae385af21e000000af 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Media archive/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | upload 7 | 8 | 9 | 23 | 24 | 25 | 26 |

27 |

28 |


29 |
Status: initial
30 | 31 |

Images

32 |
33 | 34 | 137 | 138 | -------------------------------------------------------------------------------- /PHP/README.md: -------------------------------------------------------------------------------- 1 | PHP - restdb.io REST calls 2 | 3 | We are using Guzzle 6.0 for this PHP example. 4 | 5 | See installation instructions here: http://docs.guzzlephp.org/en/latest/overview.html 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /PHP/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "guzzlehttp/guzzle": "~6.0" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /PHP/composer.phar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RestDB/clientexamples/e5504d04123d2eca15340d4634e139e759ba5904/PHP/composer.phar -------------------------------------------------------------------------------- /PHP/restdbclient.php: -------------------------------------------------------------------------------- 1 | 'https://rdb-examples.restdb.io/rest/', 8 | // You can set any number of default request options. 9 | 'timeout' => 2.0, 10 | 'headers' => ['X-apikey' => '58aef41e2c4ed27f0da9dd05a1720d6698be3'] 11 | ]); 12 | 13 | // Create object wobbly 14 | $wobbly['title'] = 'Wobbly bubbles'; 15 | $wobbly['description'] = "They are the best"; 16 | $wobbly['count'] = 4; 17 | $wobbly['email'] = "wobble@wobble.com"; 18 | 19 | // POST it 20 | $response = $client->post("stuff",['json'=>$wobbly]); 21 | $code = $response->getStatusCode(); 22 | 23 | //Create object snuttgly 24 | $snuggly['title'] = 'Snuggly snuggles'; 25 | $snuggly['description'] = "They are the worst"; 26 | $snuggly['count'] = 8; 27 | $snuggly['email'] = "snuggle@snuggle.com"; 28 | 29 | // POST another one 30 | $response = $client->post("stuff",['json'=>$snuggly]); 31 | $code = $response->getStatusCode(); 32 | 33 | // GET all 34 | $response = $client->get("stuff"); 35 | $items = json_decode($response->getBody()); 36 | $item1 = $items[0]; 37 | $item1->count += 1; 38 | 39 | // PUT back a change 40 | $puturl = "stuff/" . $item1->_id; 41 | $response = $client->put($puturl,['json'=>$item1]); 42 | $code = $response->getStatusCode(); 43 | 44 | // DELete an item 45 | $item2 = $items[1]; 46 | $delurl = "stuff/" . $item2->_id; 47 | $response = $client->delete($delurl); 48 | $code = $response->getStatusCode(); 49 | echo $code 50 | 51 | ?> 52 | -------------------------------------------------------------------------------- /PHP/vendor/autoload.php: -------------------------------------------------------------------------------- 1 | $vendorDir . '/guzzlehttp/promises/src/functions_include.php', 10 | 'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php', 11 | '37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php', 12 | ); 13 | -------------------------------------------------------------------------------- /PHP/vendor/composer/autoload_namespaces.php: -------------------------------------------------------------------------------- 1 | array($vendorDir . '/psr/http-message/src'), 10 | 'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'), 11 | 'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'), 12 | 'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'), 13 | ); 14 | -------------------------------------------------------------------------------- /PHP/vendor/composer/autoload_real.php: -------------------------------------------------------------------------------- 1 | $path) { 28 | $loader->set($namespace, $path); 29 | } 30 | 31 | $map = require __DIR__ . '/autoload_psr4.php'; 32 | foreach ($map as $namespace => $path) { 33 | $loader->setPsr4($namespace, $path); 34 | } 35 | 36 | $classMap = require __DIR__ . '/autoload_classmap.php'; 37 | if ($classMap) { 38 | $loader->addClassMap($classMap); 39 | } 40 | 41 | $loader->register(true); 42 | 43 | $includeFiles = require __DIR__ . '/autoload_files.php'; 44 | foreach ($includeFiles as $fileIdentifier => $file) { 45 | composerRequire61b62c6d62f95804ea729c74b3dbfc33($fileIdentifier, $file); 46 | } 47 | 48 | return $loader; 49 | } 50 | } 51 | 52 | function composerRequire61b62c6d62f95804ea729c74b3dbfc33($fileIdentifier, $file) 53 | { 54 | if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { 55 | require $file; 56 | 57 | $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/guzzle/.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | sudo: false 4 | 5 | php: 6 | - 5.5 7 | - 5.6 8 | - 7.0 9 | - hhvm 10 | 11 | before_script: 12 | - curl --version 13 | - composer self-update 14 | - composer install --no-interaction --prefer-source --dev 15 | - ~/.nvm/nvm.sh install v0.6.14 16 | - ~/.nvm/nvm.sh run v0.6.14 17 | 18 | script: make test 19 | 20 | matrix: 21 | allow_failures: 22 | - php: hhvm 23 | - php: 7.0 24 | fast_finish: true 25 | 26 | before_deploy: 27 | - make package 28 | 29 | deploy: 30 | provider: releases 31 | api_key: 32 | secure: UpypqlYgsU68QT/x40YzhHXvzWjFwCNo9d+G8KAdm7U9+blFfcWhV1aMdzugvPMl6woXgvJj7qHq5tAL4v6oswCORhpSBfLgOQVFaica5LiHsvWlAedOhxGmnJqMTwuepjBCxXhs3+I8Kof1n4oUL9gKytXjOVCX/f7XU1HiinU= 33 | file: 34 | - build/artifacts/guzzle.phar 35 | - build/artifacts/guzzle.zip 36 | on: 37 | repo: guzzle/guzzle 38 | tags: true 39 | all_branches: true 40 | php: 5.5 41 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/guzzle/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2015 Michael Dowling, https://github.com/mtdowling 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/guzzle/README.md: -------------------------------------------------------------------------------- 1 | Guzzle, PHP HTTP client 2 | ======================= 3 | 4 | [![Build Status](https://secure.travis-ci.org/guzzle/guzzle.svg?branch=master)](http://travis-ci.org/guzzle/guzzle) 5 | 6 | Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and 7 | trivial to integrate with web services. 8 | 9 | - Simple interface for building query strings, POST requests, streaming large 10 | uploads, streaming large downloads, using HTTP cookies, uploading JSON data, 11 | etc... 12 | - Can send both synchronous and asynchronous requests using the same interface. 13 | - Uses PSR-7 interfaces for requests, responses, and streams. This allows you 14 | to utilize other PSR-7 compatible libraries with Guzzle. 15 | - Abstracts away the underlying HTTP transport, allowing you to write 16 | environment and transport agnostic code; i.e., no hard dependency on cURL, 17 | PHP streams, sockets, or non-blocking event loops. 18 | - Middleware system allows you to augment and compose client behavior. 19 | 20 | ```php 21 | $client = new GuzzleHttp\Client(); 22 | $res = $client->request('GET', 'https://api.github.com/user', [ 23 | 'auth' => ['user', 'pass'] 24 | ]); 25 | echo $res->getStatusCode(); 26 | // 200 27 | echo $res->getHeader('content-type'); 28 | // 'application/json; charset=utf8' 29 | echo $res->getBody(); 30 | // {"type":"User"...' 31 | 32 | // Send an asynchronous request. 33 | $request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org'); 34 | $promise = $client->sendAsync($request)->then(function ($response) { 35 | echo 'I completed! ' . $response->getBody(); 36 | }); 37 | $promise->wait(); 38 | ``` 39 | 40 | ## Help and docs 41 | 42 | - [Documentation](http://guzzlephp.org/) 43 | - [stackoverflow](http://stackoverflow.com/questions/tagged/guzzle) 44 | - [Gitter](https://gitter.im/guzzle/guzzle) 45 | 46 | 47 | ## Installing Guzzle 48 | 49 | The recommended way to install Guzzle is through 50 | [Composer](http://getcomposer.org). 51 | 52 | ```bash 53 | # Install Composer 54 | curl -sS https://getcomposer.org/installer | php 55 | ``` 56 | 57 | Next, run the Composer command to install the latest stable version of Guzzle: 58 | 59 | ```bash 60 | composer.phar require guzzlehttp/guzzle 61 | ``` 62 | 63 | After installing, you need to require Composer's autoloader: 64 | 65 | ```php 66 | require 'vendor/autoload.php'; 67 | ``` 68 | 69 | You can then later update Guzzle using composer: 70 | 71 | ```bash 72 | composer.phar update 73 | ``` 74 | 75 | 76 | ## Version Guidance 77 | 78 | | Version | Status | Packagist | Namespace | Repo | Docs | PSR-7 | 79 | |---------|-------------|---------------------|--------------|---------------------|---------------------|-------| 80 | | 3.x | EOL | `guzzle/guzzle` | `Guzzle` | [v3][guzzle-3-repo] | [v3][guzzle-3-docs] | No | 81 | | 4.x | EOL | `guzzlehttp/guzzle` | `GuzzleHttp` | N/A | N/A | No | 82 | | 5.x | Maintained | `guzzlehttp/guzzle` | `GuzzleHttp` | [v5][guzzle-5-repo] | [v5][guzzle-5-docs] | No | 83 | | 6.x | Latest | `guzzlehttp/guzzle` | `GuzzleHttp` | [v6][guzzle-6-repo] | [v6][guzzle-6-docs] | Yes | 84 | 85 | [guzzle-3-repo]: https://github.com/guzzle/guzzle3 86 | [guzzle-5-repo]: https://github.com/guzzle/guzzle/tree/5.3 87 | [guzzle-6-repo]: https://github.com/guzzle/guzzle 88 | [guzzle-3-docs]: http://guzzle3.readthedocs.org/en/latest/ 89 | [guzzle-5-docs]: http://guzzle.readthedocs.org/en/5.3/ 90 | [guzzle-6-docs]: http://guzzle.readthedocs.org/en/latest/ 91 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/guzzle/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzlehttp/guzzle", 3 | "type": "library", 4 | "description": "Guzzle is a PHP HTTP client library", 5 | "keywords": ["framework", "http", "rest", "web service", "curl", "client", "HTTP client"], 6 | "homepage": "http://guzzlephp.org/", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Michael Dowling", 11 | "email": "mtdowling@gmail.com", 12 | "homepage": "https://github.com/mtdowling" 13 | } 14 | ], 15 | "require": { 16 | "php": ">=5.5.0", 17 | "guzzlehttp/psr7": "~1.1", 18 | "guzzlehttp/promises": "~1.0" 19 | }, 20 | "require-dev": { 21 | "ext-curl": "*", 22 | "phpunit/phpunit": "~4.0", 23 | "psr/log": "~1.0" 24 | }, 25 | "autoload": { 26 | "files": ["src/functions_include.php"], 27 | "psr-4": { 28 | "GuzzleHttp\\": "src/" 29 | } 30 | }, 31 | "autoload-dev": { 32 | "psr-4": { 33 | "GuzzleHttp\\Tests\\": "tests/" 34 | } 35 | }, 36 | "extra": { 37 | "branch-alias": { 38 | "dev-master": "6.1-dev" 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/guzzle/src/ClientInterface.php: -------------------------------------------------------------------------------- 1 | filename = $cookieFile; 27 | $this->storeSessionCookies = $storeSessionCookies; 28 | 29 | if (file_exists($cookieFile)) { 30 | $this->load($cookieFile); 31 | } 32 | } 33 | 34 | /** 35 | * Saves the file when shutting down 36 | */ 37 | public function __destruct() 38 | { 39 | $this->save($this->filename); 40 | } 41 | 42 | /** 43 | * Saves the cookies to a file. 44 | * 45 | * @param string $filename File to save 46 | * @throws \RuntimeException if the file cannot be found or created 47 | */ 48 | public function save($filename) 49 | { 50 | $json = []; 51 | foreach ($this as $cookie) { 52 | /** @var SetCookie $cookie */ 53 | if (CookieJar::shouldPersist($cookie, $this->storeSessionCookies)) { 54 | $json[] = $cookie->toArray(); 55 | } 56 | } 57 | 58 | if (false === file_put_contents($filename, json_encode($json))) { 59 | throw new \RuntimeException("Unable to save file {$filename}"); 60 | } 61 | } 62 | 63 | /** 64 | * Load cookies from a JSON formatted file. 65 | * 66 | * Old cookies are kept unless overwritten by newly loaded ones. 67 | * 68 | * @param string $filename Cookie file to load. 69 | * @throws \RuntimeException if the file cannot be loaded. 70 | */ 71 | public function load($filename) 72 | { 73 | $json = file_get_contents($filename); 74 | if (false === $json) { 75 | throw new \RuntimeException("Unable to load file {$filename}"); 76 | } 77 | 78 | $data = json_decode($json, true); 79 | if (is_array($data)) { 80 | foreach (json_decode($json, true) as $cookie) { 81 | $this->setCookie(new SetCookie($cookie)); 82 | } 83 | } elseif (strlen($data)) { 84 | throw new \RuntimeException("Invalid cookie file: {$filename}"); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/guzzle/src/Cookie/SessionCookieJar.php: -------------------------------------------------------------------------------- 1 | sessionKey = $sessionKey; 26 | $this->storeSessionCookies = $storeSessionCookies; 27 | $this->load(); 28 | } 29 | 30 | /** 31 | * Saves cookies to session when shutting down 32 | */ 33 | public function __destruct() 34 | { 35 | $this->save(); 36 | } 37 | 38 | /** 39 | * Save cookies to the client session 40 | */ 41 | public function save() 42 | { 43 | $json = []; 44 | foreach ($this as $cookie) { 45 | /** @var SetCookie $cookie */ 46 | if (CookieJar::shouldPersist($cookie, $this->storeSessionCookies)) { 47 | $json[] = $cookie->toArray(); 48 | } 49 | } 50 | 51 | $_SESSION[$this->sessionKey] = json_encode($json); 52 | } 53 | 54 | /** 55 | * Load the contents of the client session into the data array 56 | */ 57 | protected function load() 58 | { 59 | $cookieJar = isset($_SESSION[$this->sessionKey]) 60 | ? $_SESSION[$this->sessionKey] 61 | : null; 62 | 63 | $data = json_decode($cookieJar, true); 64 | if (is_array($data)) { 65 | foreach ($data as $cookie) { 66 | $this->setCookie(new SetCookie($cookie)); 67 | } 68 | } elseif (strlen($data)) { 69 | throw new \RuntimeException("Invalid cookie data"); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/guzzle/src/Exception/BadResponseException.php: -------------------------------------------------------------------------------- 1 | stream = $stream; 16 | $msg = $msg ?: 'Could not seek the stream to position ' . $pos; 17 | parent::__construct($msg); 18 | } 19 | 20 | /** 21 | * @return StreamInterface 22 | */ 23 | public function getStream() 24 | { 25 | return $this->stream; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/guzzle/src/Exception/ServerException.php: -------------------------------------------------------------------------------- 1 | factory = isset($options['handle_factory']) 29 | ? $options['handle_factory'] 30 | : new CurlFactory(3); 31 | } 32 | 33 | public function __invoke(RequestInterface $request, array $options) 34 | { 35 | if (isset($options['delay'])) { 36 | usleep($options['delay'] * 1000); 37 | } 38 | 39 | $easy = $this->factory->create($request, $options); 40 | curl_exec($easy->handle); 41 | $easy->errno = curl_errno($easy->handle); 42 | 43 | return CurlFactory::finish($this, $easy, $this->factory); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/guzzle/src/Handler/EasyHandle.php: -------------------------------------------------------------------------------- 1 | headers)) { 48 | throw new \RuntimeException('No headers have been received'); 49 | } 50 | 51 | // HTTP-version SP status-code SP reason-phrase 52 | $startLine = explode(' ', array_shift($this->headers), 3); 53 | $headers = \GuzzleHttp\headers_from_lines($this->headers); 54 | $normalizedKeys = \GuzzleHttp\normalize_header_keys($headers); 55 | 56 | if (!empty($this->options['decode_content']) 57 | && isset($normalizedKeys['content-encoding']) 58 | ) { 59 | unset($headers[$normalizedKeys['content-encoding']]); 60 | if (isset($normalizedKeys['content-length'])) { 61 | $bodyLength = (int) $this->sink->getSize(); 62 | if ($bodyLength) { 63 | $headers[$normalizedKeys['content-length']] = $bodyLength; 64 | } else { 65 | unset($headers[$normalizedKeys['content-length']]); 66 | } 67 | } 68 | } 69 | 70 | // Attach a response to the easy handle with the parsed headers. 71 | $this->response = new Response( 72 | $startLine[1], 73 | $headers, 74 | $this->sink, 75 | substr($startLine[0], 5), 76 | isset($startLine[2]) ? (string) $startLine[2] : null 77 | ); 78 | } 79 | 80 | public function __get($name) 81 | { 82 | $msg = $name === 'handle' 83 | ? 'The EasyHandle has been released' 84 | : 'Invalid property: ' . $name; 85 | throw new \BadMethodCallException($msg); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php: -------------------------------------------------------------------------------- 1 | true, 'HEAD' => true]; 19 | 20 | /** 21 | * @param callable $nextHandler Next handler to invoke. 22 | */ 23 | public function __construct(callable $nextHandler) 24 | { 25 | $this->nextHandler = $nextHandler; 26 | } 27 | 28 | /** 29 | * @param RequestInterface $request 30 | * @param array $options 31 | * 32 | * @return PromiseInterface 33 | */ 34 | public function __invoke(RequestInterface $request, array $options) 35 | { 36 | $fn = $this->nextHandler; 37 | 38 | // Don't do anything if the request has no body. 39 | if (isset(self::$skipMethods[$request->getMethod()]) 40 | || $request->getBody()->getSize() === 0 41 | ) { 42 | return $fn($request, $options); 43 | } 44 | 45 | $modify = []; 46 | 47 | // Add a default content-type if possible. 48 | if (!$request->hasHeader('Content-Type')) { 49 | if ($uri = $request->getBody()->getMetadata('uri')) { 50 | if ($type = Psr7\mimetype_from_filename($uri)) { 51 | $modify['set_headers']['Content-Type'] = $type; 52 | } 53 | } 54 | } 55 | 56 | // Add a default content-length or transfer-encoding header. 57 | if (!isset(self::$skipMethods[$request->getMethod()]) 58 | && !$request->hasHeader('Content-Length') 59 | && !$request->hasHeader('Transfer-Encoding') 60 | ) { 61 | $size = $request->getBody()->getSize(); 62 | if ($size !== null) { 63 | $modify['set_headers']['Content-Length'] = $size; 64 | } else { 65 | $modify['set_headers']['Transfer-Encoding'] = 'chunked'; 66 | } 67 | } 68 | 69 | // Add the expect header if needed. 70 | $this->addExpectHeader($request, $options, $modify); 71 | 72 | return $fn(Psr7\modify_request($request, $modify), $options); 73 | } 74 | 75 | private function addExpectHeader( 76 | RequestInterface $request, 77 | array $options, 78 | array &$modify 79 | ) { 80 | // Determine if the Expect header should be used 81 | if ($request->hasHeader('Expect')) { 82 | return; 83 | } 84 | 85 | $expect = isset($options['expect']) ? $options['expect'] : null; 86 | 87 | // Return if disabled or if you're not using HTTP/1.1 or HTTP/2.0 88 | if ($expect === false || $request->getProtocolVersion() < 1.1) { 89 | return; 90 | } 91 | 92 | // The expect header is unconditionally enabled 93 | if ($expect === true) { 94 | $modify['set_headers']['Expect'] = '100-Continue'; 95 | return; 96 | } 97 | 98 | // By default, send the expect header when the payload is > 1mb 99 | if ($expect === null) { 100 | $expect = 1048576; 101 | } 102 | 103 | // Always add if the body cannot be rewound, the size cannot be 104 | // determined, or the size is greater than the cutoff threshold 105 | $body = $request->getBody(); 106 | $size = $body->getSize(); 107 | 108 | if ($size === null || $size >= (int) $expect || !$body->isSeekable()) { 109 | $modify['set_headers']['Expect'] = '100-Continue'; 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/guzzle/src/RetryMiddleware.php: -------------------------------------------------------------------------------- 1 | decider = $decider; 37 | $this->nextHandler = $nextHandler; 38 | $this->delay = $delay ?: __CLASS__ . '::exponentialDelay'; 39 | } 40 | 41 | /** 42 | * Default exponential backoff delay function. 43 | * 44 | * @param $retries 45 | * 46 | * @return int 47 | */ 48 | public static function exponentialDelay($retries) 49 | { 50 | return (int) pow(2, $retries - 1); 51 | } 52 | 53 | /** 54 | * @param RequestInterface $request 55 | * @param array $options 56 | * 57 | * @return PromiseInterface 58 | */ 59 | public function __invoke(RequestInterface $request, array $options) 60 | { 61 | if (!isset($options['retries'])) { 62 | $options['retries'] = 0; 63 | } 64 | 65 | $fn = $this->nextHandler; 66 | return $fn($request, $options) 67 | ->then( 68 | $this->onFulfilled($request, $options), 69 | $this->onRejected($request, $options) 70 | ); 71 | } 72 | 73 | private function onFulfilled(RequestInterface $req, array $options) 74 | { 75 | return function ($value) use ($req, $options) { 76 | if (!call_user_func( 77 | $this->decider, 78 | $options['retries'], 79 | $req, 80 | $value, 81 | null 82 | )) { 83 | return $value; 84 | } 85 | return $this->doRetry($req, $options); 86 | }; 87 | } 88 | 89 | private function onRejected(RequestInterface $req, array $options) 90 | { 91 | return function ($reason) use ($req, $options) { 92 | if (!call_user_func( 93 | $this->decider, 94 | $options['retries'], 95 | $req, 96 | null, 97 | $reason 98 | )) { 99 | return new RejectedPromise($reason); 100 | } 101 | return $this->doRetry($req, $options); 102 | }; 103 | } 104 | 105 | private function doRetry(RequestInterface $request, array $options) 106 | { 107 | $options['delay'] = call_user_func($this->delay, ++$options['retries']); 108 | 109 | return $this($request, $options); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/guzzle/src/TransferStats.php: -------------------------------------------------------------------------------- 1 | request = $request; 35 | $this->response = $response; 36 | $this->transferTime = $transferTime; 37 | $this->handlerErrorData = $handlerErrorData; 38 | $this->handlerStats = $handlerStats; 39 | } 40 | 41 | /** 42 | * @return RequestInterface 43 | */ 44 | public function getRequest() 45 | { 46 | return $this->request; 47 | } 48 | 49 | /** 50 | * Returns the response that was received (if any). 51 | * 52 | * @return ResponseInterface|null 53 | */ 54 | public function getResponse() 55 | { 56 | return $this->response; 57 | } 58 | 59 | /** 60 | * Returns true if a response was received. 61 | * 62 | * @return bool 63 | */ 64 | public function hasResponse() 65 | { 66 | return $this->response !== null; 67 | } 68 | 69 | /** 70 | * Gets handler specific error data. 71 | * 72 | * This might be an exception, a integer representing an error code, or 73 | * anything else. Relying on this value assumes that you know what handler 74 | * you are using. 75 | * 76 | * @return mixed 77 | */ 78 | public function getHandlerErrorData() 79 | { 80 | return $this->handlerErrorData; 81 | } 82 | 83 | /** 84 | * Get the effective URI the request was sent to. 85 | * 86 | * @return UriInterface 87 | */ 88 | public function getEffectiveUri() 89 | { 90 | return $this->request->getUri(); 91 | } 92 | 93 | /** 94 | * Get the estimated time the request was being transferred by the handler. 95 | * 96 | * @return float Time in seconds. 97 | */ 98 | public function getTransferTime() 99 | { 100 | return $this->transferTime; 101 | } 102 | 103 | /** 104 | * Gets an array of all of the handler specific transfer data. 105 | * 106 | * @return array 107 | */ 108 | public function getHandlerStats() 109 | { 110 | return $this->handlerStats; 111 | } 112 | 113 | /** 114 | * Get a specific handler statistic from the handler by name. 115 | * 116 | * @param string $stat Handler specific transfer stat to retrieve. 117 | * 118 | * @return mixed|null 119 | */ 120 | public function getHandlerStat($stat) 121 | { 122 | return isset($this->handlerStats[$stat]) 123 | ? $this->handlerStats[$stat] 124 | : null; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/guzzle/src/functions_include.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/promises/Makefile: -------------------------------------------------------------------------------- 1 | all: clean test 2 | 3 | test: 4 | vendor/bin/phpunit 5 | 6 | coverage: 7 | vendor/bin/phpunit --coverage-html=artifacts/coverage 8 | 9 | view-coverage: 10 | open artifacts/coverage/index.html 11 | 12 | clean: 13 | rm -rf artifacts/* 14 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/promises/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzlehttp/promises", 3 | "type": "library", 4 | "description": "Guzzle promises library", 5 | "keywords": ["promise"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.5.0" 16 | }, 17 | "require-dev": { 18 | "phpunit/phpunit": "~4.0" 19 | }, 20 | "autoload": { 21 | "psr-4": { 22 | "GuzzleHttp\\Promise\\": "src/" 23 | }, 24 | "files": ["src/functions_include.php"] 25 | }, 26 | "extra": { 27 | "branch-alias": { 28 | "dev-master": "1.0-dev" 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/promises/phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | tests 7 | 8 | 9 | 10 | 11 | src 12 | 13 | src/ 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/promises/src/AggregateException.php: -------------------------------------------------------------------------------- 1 | value = $value; 22 | } 23 | 24 | public function then( 25 | callable $onFulfilled = null, 26 | callable $onRejected = null 27 | ) { 28 | // Return itself if there is no onFulfilled function. 29 | if (!$onFulfilled) { 30 | return $this; 31 | } 32 | 33 | $queue = queue(); 34 | $p = new Promise([$queue, 'run']); 35 | $value = $this->value; 36 | $queue->add(static function () use ($p, $value, $onFulfilled) { 37 | if ($p->getState() === self::PENDING) { 38 | try { 39 | $p->resolve($onFulfilled($value)); 40 | } catch (\Exception $e) { 41 | $p->reject($e); 42 | } 43 | } 44 | }); 45 | 46 | return $p; 47 | } 48 | 49 | public function otherwise(callable $onRejected) 50 | { 51 | return $this->then(null, $onRejected); 52 | } 53 | 54 | public function wait($unwrap = true, $defaultDelivery = null) 55 | { 56 | return $unwrap ? $this->value : null; 57 | } 58 | 59 | public function getState() 60 | { 61 | return self::FULFILLED; 62 | } 63 | 64 | public function resolve($value) 65 | { 66 | if ($value !== $this->value) { 67 | throw new \LogicException("Cannot resolve a fulfilled promise"); 68 | } 69 | } 70 | 71 | public function reject($reason) 72 | { 73 | throw new \LogicException("Cannot reject a fulfilled promise"); 74 | } 75 | 76 | public function cancel() 77 | { 78 | // pass 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/promises/src/PromiseInterface.php: -------------------------------------------------------------------------------- 1 | reason = $reason; 22 | } 23 | 24 | public function then( 25 | callable $onFulfilled = null, 26 | callable $onRejected = null 27 | ) { 28 | // If there's no onRejected callback then just return self. 29 | if (!$onRejected) { 30 | return $this; 31 | } 32 | 33 | $queue = queue(); 34 | $reason = $this->reason; 35 | $p = new Promise([$queue, 'run']); 36 | $queue->add(static function () use ($p, $reason, $onRejected) { 37 | if ($p->getState() === self::PENDING) { 38 | try { 39 | // Return a resolved promise if onRejected does not throw. 40 | $p->resolve($onRejected($reason)); 41 | } catch (\Exception $e) { 42 | // onRejected threw, so return a rejected promise. 43 | $p->reject($e); 44 | } 45 | } 46 | }); 47 | 48 | return $p; 49 | } 50 | 51 | public function otherwise(callable $onRejected) 52 | { 53 | return $this->then(null, $onRejected); 54 | } 55 | 56 | public function wait($unwrap = true, $defaultDelivery = null) 57 | { 58 | if ($unwrap) { 59 | throw exception_for($this->reason); 60 | } 61 | } 62 | 63 | public function getState() 64 | { 65 | return self::REJECTED; 66 | } 67 | 68 | public function resolve($value) 69 | { 70 | throw new \LogicException("Cannot resolve a rejected promise"); 71 | } 72 | 73 | public function reject($reason) 74 | { 75 | if ($reason !== $this->reason) { 76 | throw new \LogicException("Cannot reject a rejected promise"); 77 | } 78 | } 79 | 80 | public function cancel() 81 | { 82 | // pass 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/promises/src/RejectionException.php: -------------------------------------------------------------------------------- 1 | reason = $reason; 21 | 22 | $message = 'The promise was rejected'; 23 | 24 | if ($description) { 25 | $message .= ' with reason: ' . $description; 26 | } elseif (is_string($reason) 27 | || (is_object($reason) && method_exists($reason, '__toString')) 28 | ) { 29 | $message .= ' with reason: ' . $this->reason; 30 | } elseif ($reason instanceof \JsonSerializable) { 31 | $message .= ' with reason: ' 32 | . json_encode($this->reason, JSON_PRETTY_PRINT); 33 | } 34 | 35 | parent::__construct($message); 36 | } 37 | 38 | /** 39 | * Returns the rejection reason. 40 | * 41 | * @return mixed 42 | */ 43 | public function getReason() 44 | { 45 | return $this->reason; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/promises/src/TaskQueue.php: -------------------------------------------------------------------------------- 1 | run(); 12 | */ 13 | class TaskQueue 14 | { 15 | private $enableShutdown = true; 16 | private $queue = []; 17 | 18 | public function __construct($withShutdown = true) 19 | { 20 | if ($withShutdown) { 21 | register_shutdown_function(function () { 22 | if ($this->enableShutdown) { 23 | // Only run the tasks if an E_ERROR didn't occur. 24 | $err = error_get_last(); 25 | if (!$err || ($err['type'] ^ E_ERROR)) { 26 | $this->run(); 27 | } 28 | } 29 | }); 30 | } 31 | } 32 | 33 | /** 34 | * Returns true if the queue is empty. 35 | * 36 | * @return bool 37 | */ 38 | public function isEmpty() 39 | { 40 | return !$this->queue; 41 | } 42 | 43 | /** 44 | * Adds a task to the queue that will be executed the next time run is 45 | * called. 46 | * 47 | * @param callable $task 48 | */ 49 | public function add(callable $task) 50 | { 51 | $this->queue[] = $task; 52 | } 53 | 54 | /** 55 | * Execute all of the pending task in the queue. 56 | */ 57 | public function run() 58 | { 59 | while ($task = array_shift($this->queue)) { 60 | $task(); 61 | } 62 | } 63 | 64 | /** 65 | * The task queue will be run and exhausted by default when the process 66 | * exits IFF the exit is not the result of a PHP E_ERROR error. 67 | * 68 | * You can disable running the automatic shutdown of the queue by calling 69 | * this function. If you disable the task queue shutdown process, then you 70 | * MUST either run the task queue (as a result of running your event loop 71 | * or manually using the run() method) or wait on each outstanding promise. 72 | * 73 | * Note: This shutdown will occur before any destructors are triggered. 74 | */ 75 | public function disableShutdown() 76 | { 77 | $this->enableShutdown = false; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/promises/src/functions_include.php: -------------------------------------------------------------------------------- 1 | assertContains('foo', $e->getMessage()); 12 | $this->assertEquals(['baz', 'bar'], $e->getReason()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/promises/tests/FulfilledPromiseTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('fulfilled', $p->getState()); 16 | $this->assertEquals('foo', $p->wait(true)); 17 | } 18 | 19 | public function testCannotCancel() 20 | { 21 | $p = new FulfilledPromise('foo'); 22 | $this->assertEquals('fulfilled', $p->getState()); 23 | $p->cancel(); 24 | $this->assertEquals('foo', $p->wait()); 25 | } 26 | 27 | /** 28 | * @expectedException \LogicException 29 | * @exepctedExceptionMessage Cannot resolve a fulfilled promise 30 | */ 31 | public function testCannotResolve() 32 | { 33 | $p = new FulfilledPromise('foo'); 34 | $p->resolve('bar'); 35 | } 36 | 37 | /** 38 | * @expectedException \LogicException 39 | * @exepctedExceptionMessage Cannot reject a fulfilled promise 40 | */ 41 | public function testCannotReject() 42 | { 43 | $p = new FulfilledPromise('foo'); 44 | $p->reject('bar'); 45 | } 46 | 47 | public function testCanResolveWithSameValue() 48 | { 49 | $p = new FulfilledPromise('foo'); 50 | $p->resolve('foo'); 51 | } 52 | 53 | /** 54 | * @expectedException \InvalidArgumentException 55 | */ 56 | public function testCannotResolveWithPromise() 57 | { 58 | new FulfilledPromise(new Promise()); 59 | } 60 | 61 | public function testReturnsSelfWhenNoOnFulfilled() 62 | { 63 | $p = new FulfilledPromise('a'); 64 | $this->assertSame($p, $p->then()); 65 | } 66 | 67 | public function testAsynchronouslyInvokesOnFulfilled() 68 | { 69 | $p = new FulfilledPromise('a'); 70 | $r = null; 71 | $f = function ($d) use (&$r) { $r = $d; }; 72 | $p2 = $p->then($f); 73 | $this->assertNotSame($p, $p2); 74 | $this->assertNull($r); 75 | \GuzzleHttp\Promise\queue()->run(); 76 | $this->assertEquals('a', $r); 77 | } 78 | 79 | public function testReturnsNewRejectedWhenOnFulfilledFails() 80 | { 81 | $p = new FulfilledPromise('a'); 82 | $f = function () { throw new \Exception('b'); }; 83 | $p2 = $p->then($f); 84 | $this->assertNotSame($p, $p2); 85 | try { 86 | $p2->wait(); 87 | $this->fail(); 88 | } catch (\Exception $e) { 89 | $this->assertEquals('b', $e->getMessage()); 90 | } 91 | } 92 | 93 | public function testOtherwiseIsSugarForRejections() 94 | { 95 | $c = null; 96 | $p = new FulfilledPromise('foo'); 97 | $p->otherwise(function ($v) use (&$c) { $c = $v; }); 98 | $this->assertNull($c); 99 | } 100 | 101 | public function testDoesNotTryToFulfillTwiceDuringTrampoline() 102 | { 103 | $fp = new FulfilledPromise('a'); 104 | $t1 = $fp->then(function ($v) { return $v . ' b'; }); 105 | $t1->resolve('why!'); 106 | $this->assertEquals('why!', $t1->wait()); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/promises/tests/NotPromiseInstance.php: -------------------------------------------------------------------------------- 1 | nextPromise = new Promise(); 14 | } 15 | 16 | public function then(callable $res = null, callable $rej = null) 17 | { 18 | return $this->nextPromise->then($res, $rej); 19 | } 20 | 21 | public function otherwise(callable $onRejected) 22 | { 23 | return $this->then($onRejected); 24 | } 25 | 26 | public function resolve($value) 27 | { 28 | $this->nextPromise->resolve($value); 29 | } 30 | 31 | public function reject($reason) 32 | { 33 | $this->nextPromise->reject($reason); 34 | } 35 | 36 | public function wait($unwrap = true, $defaultResolution = null) 37 | { 38 | 39 | } 40 | 41 | public function cancel() 42 | { 43 | 44 | } 45 | 46 | public function getState() 47 | { 48 | return $this->nextPromise->getState(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/promises/tests/RejectedPromiseTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('rejected', $p->getState()); 16 | try { 17 | $p->wait(true); 18 | $this->fail(); 19 | } catch (\Exception $e) { 20 | $this->assertEquals('rejected', $p->getState()); 21 | $this->assertContains('foo', $e->getMessage()); 22 | } 23 | } 24 | 25 | public function testCannotCancel() 26 | { 27 | $p = new RejectedPromise('foo'); 28 | $p->cancel(); 29 | $this->assertEquals('rejected', $p->getState()); 30 | } 31 | 32 | /** 33 | * @expectedException \LogicException 34 | * @exepctedExceptionMessage Cannot resolve a rejected promise 35 | */ 36 | public function testCannotResolve() 37 | { 38 | $p = new RejectedPromise('foo'); 39 | $p->resolve('bar'); 40 | } 41 | 42 | /** 43 | * @expectedException \LogicException 44 | * @exepctedExceptionMessage Cannot reject a rejected promise 45 | */ 46 | public function testCannotReject() 47 | { 48 | $p = new RejectedPromise('foo'); 49 | $p->reject('bar'); 50 | } 51 | 52 | public function testCanRejectWithSameValue() 53 | { 54 | $p = new RejectedPromise('foo'); 55 | $p->reject('foo'); 56 | } 57 | 58 | public function testThrowsSpecificException() 59 | { 60 | $e = new \Exception(); 61 | $p = new RejectedPromise($e); 62 | try { 63 | $p->wait(true); 64 | $this->fail(); 65 | } catch (\Exception $e2) { 66 | $this->assertSame($e, $e2); 67 | } 68 | } 69 | 70 | /** 71 | * @expectedException \InvalidArgumentException 72 | */ 73 | public function testCannotResolveWithPromise() 74 | { 75 | new RejectedPromise(new Promise()); 76 | } 77 | 78 | public function testReturnsSelfWhenNoOnReject() 79 | { 80 | $p = new RejectedPromise('a'); 81 | $this->assertSame($p, $p->then()); 82 | } 83 | 84 | public function testInvokesOnRejectedAsynchronously() 85 | { 86 | $p = new RejectedPromise('a'); 87 | $r = null; 88 | $f = function ($reason) use (&$r) { $r = $reason; }; 89 | $p->then(null, $f); 90 | $this->assertNull($r); 91 | \GuzzleHttp\Promise\queue()->run(); 92 | $this->assertEquals('a', $r); 93 | } 94 | 95 | public function testReturnsNewRejectedWhenOnRejectedFails() 96 | { 97 | $p = new RejectedPromise('a'); 98 | $f = function () { throw new \Exception('b'); }; 99 | $p2 = $p->then(null, $f); 100 | $this->assertNotSame($p, $p2); 101 | try { 102 | $p2->wait(); 103 | $this->fail(); 104 | } catch (\Exception $e) { 105 | $this->assertEquals('b', $e->getMessage()); 106 | } 107 | } 108 | 109 | public function testWaitingIsNoOp() 110 | { 111 | $p = new RejectedPromise('a'); 112 | $p->wait(false); 113 | } 114 | 115 | public function testOtherwiseIsSugarForRejections() 116 | { 117 | $p = new RejectedPromise('foo'); 118 | $p->otherwise(function ($v) use (&$c) { $c = $v; }); 119 | \GuzzleHttp\Promise\queue()->run(); 120 | $this->assertSame('foo', $c); 121 | } 122 | 123 | public function testCanResolveThenWithSuccess() 124 | { 125 | $actual = null; 126 | $p = new RejectedPromise('foo'); 127 | $p->otherwise(function ($v) { 128 | return $v . ' bar'; 129 | })->then(function ($v) use (&$actual) { 130 | $actual = $v; 131 | }); 132 | \GuzzleHttp\Promise\queue()->run(); 133 | $this->assertEquals('foo bar', $actual); 134 | } 135 | 136 | public function testDoesNotTryToRejectTwiceDuringTrampoline() 137 | { 138 | $fp = new RejectedPromise('a'); 139 | $t1 = $fp->then(null, function ($v) { return $v . ' b'; }); 140 | $t1->resolve('why!'); 141 | $this->assertEquals('why!', $t1->wait()); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/promises/tests/RejectionExceptionTest.php: -------------------------------------------------------------------------------- 1 | message = $message; 11 | } 12 | 13 | public function __toString() 14 | { 15 | return $this->message; 16 | } 17 | } 18 | 19 | class Thing2 implements \JsonSerializable 20 | { 21 | public function jsonSerialize() 22 | { 23 | return '{}'; 24 | } 25 | } 26 | 27 | /** 28 | * @covers GuzzleHttp\Promise\RejectionException 29 | */ 30 | class RejectionExceptionTest extends \PHPUnit_Framework_TestCase 31 | { 32 | public function testCanGetReasonFromException() 33 | { 34 | $thing = new Thing1('foo'); 35 | $e = new RejectionException($thing); 36 | 37 | $this->assertSame($thing, $e->getReason()); 38 | $this->assertEquals('The promise was rejected with reason: foo', $e->getMessage()); 39 | } 40 | 41 | public function testCanGetReasonMessageFromJson() 42 | { 43 | $reason = new Thing2(); 44 | $e = new RejectionException($reason); 45 | $this->assertContains("{}", $e->getMessage()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/promises/tests/TaskQueueTest.php: -------------------------------------------------------------------------------- 1 | assertTrue($tq->isEmpty()); 12 | } 13 | 14 | public function testKnowsIfFull() 15 | { 16 | $tq = new TaskQueue(false); 17 | $tq->add(function () {}); 18 | $this->assertFalse($tq->isEmpty()); 19 | } 20 | 21 | public function testExecutesTasksInOrder() 22 | { 23 | $tq = new TaskQueue(false); 24 | $called = []; 25 | $tq->add(function () use (&$called) { $called[] = 'a'; }); 26 | $tq->add(function () use (&$called) { $called[] = 'b'; }); 27 | $tq->add(function () use (&$called) { $called[] = 'c'; }); 28 | $tq->run(); 29 | $this->assertEquals(['a', 'b', 'c'], $called); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/promises/tests/Thennable.php: -------------------------------------------------------------------------------- 1 | nextPromise = new Promise(); 13 | } 14 | 15 | public function then(callable $res = null, callable $rej = null) 16 | { 17 | return $this->nextPromise->then($res, $rej); 18 | } 19 | 20 | public function resolve($value) 21 | { 22 | $this->nextPromise->resolve($value); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/promises/tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/Makefile: -------------------------------------------------------------------------------- 1 | all: clean test 2 | 3 | test: 4 | vendor/bin/phpunit $(TEST) 5 | 6 | coverage: 7 | vendor/bin/phpunit --coverage-html=artifacts/coverage $(TEST) 8 | 9 | view-coverage: 10 | open artifacts/coverage/index.html 11 | 12 | clean: 13 | rm -rf artifacts/* 14 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzlehttp/psr7", 3 | "type": "library", 4 | "description": "PSR-7 message implementation", 5 | "keywords": ["message", "stream", "http", "uri"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.4.0", 16 | "psr/http-message": "~1.0" 17 | }, 18 | "require-dev": { 19 | "phpunit/phpunit": "~4.0" 20 | }, 21 | "provide": { 22 | "psr/http-message-implementation": "1.0" 23 | }, 24 | "autoload": { 25 | "psr-4": { 26 | "GuzzleHttp\\Psr7\\": "src/" 27 | }, 28 | "files": ["src/functions_include.php"] 29 | }, 30 | "extra": { 31 | "branch-alias": { 32 | "dev-master": "1.0-dev" 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | tests 7 | 8 | 9 | 10 | 11 | src 12 | 13 | src/ 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/src/BufferStream.php: -------------------------------------------------------------------------------- 1 | hwm = $hwm; 29 | } 30 | 31 | public function __toString() 32 | { 33 | return $this->getContents(); 34 | } 35 | 36 | public function getContents() 37 | { 38 | $buffer = $this->buffer; 39 | $this->buffer = ''; 40 | 41 | return $buffer; 42 | } 43 | 44 | public function close() 45 | { 46 | $this->buffer = ''; 47 | } 48 | 49 | public function detach() 50 | { 51 | $this->close(); 52 | } 53 | 54 | public function getSize() 55 | { 56 | return strlen($this->buffer); 57 | } 58 | 59 | public function isReadable() 60 | { 61 | return true; 62 | } 63 | 64 | public function isWritable() 65 | { 66 | return true; 67 | } 68 | 69 | public function isSeekable() 70 | { 71 | return false; 72 | } 73 | 74 | public function rewind() 75 | { 76 | $this->seek(0); 77 | } 78 | 79 | public function seek($offset, $whence = SEEK_SET) 80 | { 81 | throw new \RuntimeException('Cannot seek a BufferStream'); 82 | } 83 | 84 | public function eof() 85 | { 86 | return strlen($this->buffer) === 0; 87 | } 88 | 89 | public function tell() 90 | { 91 | throw new \RuntimeException('Cannot determine the position of a BufferStream'); 92 | } 93 | 94 | /** 95 | * Reads data from the buffer. 96 | */ 97 | public function read($length) 98 | { 99 | $currentLength = strlen($this->buffer); 100 | 101 | if ($length >= $currentLength) { 102 | // No need to slice the buffer because we don't have enough data. 103 | $result = $this->buffer; 104 | $this->buffer = ''; 105 | } else { 106 | // Slice up the result to provide a subset of the buffer. 107 | $result = substr($this->buffer, 0, $length); 108 | $this->buffer = substr($this->buffer, $length); 109 | } 110 | 111 | return $result; 112 | } 113 | 114 | /** 115 | * Writes data to the buffer. 116 | */ 117 | public function write($string) 118 | { 119 | $this->buffer .= $string; 120 | 121 | // TODO: What should happen here? 122 | if (strlen($this->buffer) >= $this->hwm) { 123 | return false; 124 | } 125 | 126 | return strlen($string); 127 | } 128 | 129 | public function getMetadata($key = null) 130 | { 131 | if ($key == 'hwm') { 132 | return $this->hwm; 133 | } 134 | 135 | return $key ? null : []; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/src/CachingStream.php: -------------------------------------------------------------------------------- 1 | remoteStream = $stream; 31 | $this->stream = $target ?: new Stream(fopen('php://temp', 'r+')); 32 | } 33 | 34 | public function getSize() 35 | { 36 | return max($this->stream->getSize(), $this->remoteStream->getSize()); 37 | } 38 | 39 | public function rewind() 40 | { 41 | $this->seek(0); 42 | } 43 | 44 | public function seek($offset, $whence = SEEK_SET) 45 | { 46 | if ($whence == SEEK_SET) { 47 | $byte = $offset; 48 | } elseif ($whence == SEEK_CUR) { 49 | $byte = $offset + $this->tell(); 50 | } elseif ($whence == SEEK_END) { 51 | $size = $this->remoteStream->getSize(); 52 | if ($size === null) { 53 | $size = $this->cacheEntireStream(); 54 | } 55 | $byte = $size + $offset; 56 | } else { 57 | throw new \InvalidArgumentException('Invalid whence'); 58 | } 59 | 60 | $diff = $byte - $this->stream->getSize(); 61 | 62 | if ($diff > 0) { 63 | // If the seek byte is greater the number of read bytes, then read 64 | // the difference of bytes to cache the bytes and inherently seek. 65 | $this->read($diff); 66 | } else { 67 | // We can just do a normal seek since we've already seen this byte. 68 | $this->stream->seek($byte); 69 | } 70 | } 71 | 72 | public function read($length) 73 | { 74 | // Perform a regular read on any previously read data from the buffer 75 | $data = $this->stream->read($length); 76 | $remaining = $length - strlen($data); 77 | 78 | // More data was requested so read from the remote stream 79 | if ($remaining) { 80 | // If data was written to the buffer in a position that would have 81 | // been filled from the remote stream, then we must skip bytes on 82 | // the remote stream to emulate overwriting bytes from that 83 | // position. This mimics the behavior of other PHP stream wrappers. 84 | $remoteData = $this->remoteStream->read( 85 | $remaining + $this->skipReadBytes 86 | ); 87 | 88 | if ($this->skipReadBytes) { 89 | $len = strlen($remoteData); 90 | $remoteData = substr($remoteData, $this->skipReadBytes); 91 | $this->skipReadBytes = max(0, $this->skipReadBytes - $len); 92 | } 93 | 94 | $data .= $remoteData; 95 | $this->stream->write($remoteData); 96 | } 97 | 98 | return $data; 99 | } 100 | 101 | public function write($string) 102 | { 103 | // When appending to the end of the currently read stream, you'll want 104 | // to skip bytes from being read from the remote stream to emulate 105 | // other stream wrappers. Basically replacing bytes of data of a fixed 106 | // length. 107 | $overflow = (strlen($string) + $this->tell()) - $this->remoteStream->tell(); 108 | if ($overflow > 0) { 109 | $this->skipReadBytes += $overflow; 110 | } 111 | 112 | return $this->stream->write($string); 113 | } 114 | 115 | public function eof() 116 | { 117 | return $this->stream->eof() && $this->remoteStream->eof(); 118 | } 119 | 120 | /** 121 | * Close both the remote stream and buffer stream 122 | */ 123 | public function close() 124 | { 125 | $this->remoteStream->close() && $this->stream->close(); 126 | } 127 | 128 | private function cacheEntireStream() 129 | { 130 | $target = new FnStream(['write' => 'strlen']); 131 | copy_to_stream($this, $target); 132 | 133 | return $this->tell(); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/src/DroppingStream.php: -------------------------------------------------------------------------------- 1 | stream = $stream; 23 | $this->maxLength = $maxLength; 24 | } 25 | 26 | public function write($string) 27 | { 28 | $diff = $this->maxLength - $this->stream->getSize(); 29 | 30 | // Begin returning 0 when the underlying stream is too large. 31 | if ($diff <= 0) { 32 | return 0; 33 | } 34 | 35 | // Write the stream or a subset of the stream if needed. 36 | if (strlen($string) < $diff) { 37 | return $this->stream->write($string); 38 | } 39 | 40 | return $this->stream->write(substr($string, 0, $diff)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/src/FnStream.php: -------------------------------------------------------------------------------- 1 | methods = $methods; 28 | 29 | // Create the functions on the class 30 | foreach ($methods as $name => $fn) { 31 | $this->{'_fn_' . $name} = $fn; 32 | } 33 | } 34 | 35 | /** 36 | * Lazily determine which methods are not implemented. 37 | * @throws \BadMethodCallException 38 | */ 39 | public function __get($name) 40 | { 41 | throw new \BadMethodCallException(str_replace('_fn_', '', $name) 42 | . '() is not implemented in the FnStream'); 43 | } 44 | 45 | /** 46 | * The close method is called on the underlying stream only if possible. 47 | */ 48 | public function __destruct() 49 | { 50 | if (isset($this->_fn_close)) { 51 | call_user_func($this->_fn_close); 52 | } 53 | } 54 | 55 | /** 56 | * Adds custom functionality to an underlying stream by intercepting 57 | * specific method calls. 58 | * 59 | * @param StreamInterface $stream Stream to decorate 60 | * @param array $methods Hash of method name to a closure 61 | * 62 | * @return FnStream 63 | */ 64 | public static function decorate(StreamInterface $stream, array $methods) 65 | { 66 | // If any of the required methods were not provided, then simply 67 | // proxy to the decorated stream. 68 | foreach (array_diff(self::$slots, array_keys($methods)) as $diff) { 69 | $methods[$diff] = [$stream, $diff]; 70 | } 71 | 72 | return new self($methods); 73 | } 74 | 75 | public function __toString() 76 | { 77 | return call_user_func($this->_fn___toString); 78 | } 79 | 80 | public function close() 81 | { 82 | return call_user_func($this->_fn_close); 83 | } 84 | 85 | public function detach() 86 | { 87 | return call_user_func($this->_fn_detach); 88 | } 89 | 90 | public function getSize() 91 | { 92 | return call_user_func($this->_fn_getSize); 93 | } 94 | 95 | public function tell() 96 | { 97 | return call_user_func($this->_fn_tell); 98 | } 99 | 100 | public function eof() 101 | { 102 | return call_user_func($this->_fn_eof); 103 | } 104 | 105 | public function isSeekable() 106 | { 107 | return call_user_func($this->_fn_isSeekable); 108 | } 109 | 110 | public function rewind() 111 | { 112 | call_user_func($this->_fn_rewind); 113 | } 114 | 115 | public function seek($offset, $whence = SEEK_SET) 116 | { 117 | call_user_func($this->_fn_seek, $offset, $whence); 118 | } 119 | 120 | public function isWritable() 121 | { 122 | return call_user_func($this->_fn_isWritable); 123 | } 124 | 125 | public function write($string) 126 | { 127 | return call_user_func($this->_fn_write, $string); 128 | } 129 | 130 | public function isReadable() 131 | { 132 | return call_user_func($this->_fn_isReadable); 133 | } 134 | 135 | public function read($length) 136 | { 137 | return call_user_func($this->_fn_read, $length); 138 | } 139 | 140 | public function getContents() 141 | { 142 | return call_user_func($this->_fn_getContents); 143 | } 144 | 145 | public function getMetadata($key = null) 146 | { 147 | return call_user_func($this->_fn_getMetadata, $key); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/src/InflateStream.php: -------------------------------------------------------------------------------- 1 | stream = new Stream($resource); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/src/LazyOpenStream.php: -------------------------------------------------------------------------------- 1 | filename = $filename; 27 | $this->mode = $mode; 28 | } 29 | 30 | /** 31 | * Creates the underlying stream lazily when required. 32 | * 33 | * @return StreamInterface 34 | */ 35 | protected function createStream() 36 | { 37 | return stream_for(try_fopen($this->filename, $this->mode)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/src/LimitStream.php: -------------------------------------------------------------------------------- 1 | stream = $stream; 33 | $this->setLimit($limit); 34 | $this->setOffset($offset); 35 | } 36 | 37 | public function eof() 38 | { 39 | // Always return true if the underlying stream is EOF 40 | if ($this->stream->eof()) { 41 | return true; 42 | } 43 | 44 | // No limit and the underlying stream is not at EOF 45 | if ($this->limit == -1) { 46 | return false; 47 | } 48 | 49 | return $this->stream->tell() >= $this->offset + $this->limit; 50 | } 51 | 52 | /** 53 | * Returns the size of the limited subset of data 54 | * {@inheritdoc} 55 | */ 56 | public function getSize() 57 | { 58 | if (null === ($length = $this->stream->getSize())) { 59 | return null; 60 | } elseif ($this->limit == -1) { 61 | return $length - $this->offset; 62 | } else { 63 | return min($this->limit, $length - $this->offset); 64 | } 65 | } 66 | 67 | /** 68 | * Allow for a bounded seek on the read limited stream 69 | * {@inheritdoc} 70 | */ 71 | public function seek($offset, $whence = SEEK_SET) 72 | { 73 | if ($whence !== SEEK_SET || $offset < 0) { 74 | throw new \RuntimeException(sprintf( 75 | 'Cannot seek to offset % with whence %s', 76 | $offset, 77 | $whence 78 | )); 79 | } 80 | 81 | $offset += $this->offset; 82 | 83 | if ($this->limit !== -1) { 84 | if ($offset > $this->offset + $this->limit) { 85 | $offset = $this->offset + $this->limit; 86 | } 87 | } 88 | 89 | $this->stream->seek($offset); 90 | } 91 | 92 | /** 93 | * Give a relative tell() 94 | * {@inheritdoc} 95 | */ 96 | public function tell() 97 | { 98 | return $this->stream->tell() - $this->offset; 99 | } 100 | 101 | /** 102 | * Set the offset to start limiting from 103 | * 104 | * @param int $offset Offset to seek to and begin byte limiting from 105 | * 106 | * @throws \RuntimeException if the stream cannot be seeked. 107 | */ 108 | public function setOffset($offset) 109 | { 110 | $current = $this->stream->tell(); 111 | 112 | if ($current !== $offset) { 113 | // If the stream cannot seek to the offset position, then read to it 114 | if ($this->stream->isSeekable()) { 115 | $this->stream->seek($offset); 116 | } elseif ($current > $offset) { 117 | throw new \RuntimeException("Could not seek to stream offset $offset"); 118 | } else { 119 | $this->stream->read($offset - $current); 120 | } 121 | } 122 | 123 | $this->offset = $offset; 124 | } 125 | 126 | /** 127 | * Set the limit of bytes that the decorator allows to be read from the 128 | * stream. 129 | * 130 | * @param int $limit Number of bytes to allow to be read from the stream. 131 | * Use -1 for no limit. 132 | */ 133 | public function setLimit($limit) 134 | { 135 | $this->limit = $limit; 136 | } 137 | 138 | public function read($length) 139 | { 140 | if ($this->limit == -1) { 141 | return $this->stream->read($length); 142 | } 143 | 144 | // Check if the current position is less than the total allowed 145 | // bytes + original offset 146 | $remaining = ($this->offset + $this->limit) - $this->stream->tell(); 147 | if ($remaining > 0) { 148 | // Only return the amount of requested data, ensuring that the byte 149 | // limit is not exceeded 150 | return $this->stream->read(min($remaining, $length)); 151 | } 152 | 153 | return ''; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/src/MessageTrait.php: -------------------------------------------------------------------------------- 1 | protocol; 26 | } 27 | 28 | public function withProtocolVersion($version) 29 | { 30 | if ($this->protocol === $version) { 31 | return $this; 32 | } 33 | 34 | $new = clone $this; 35 | $new->protocol = $version; 36 | return $new; 37 | } 38 | 39 | public function getHeaders() 40 | { 41 | return $this->headerLines; 42 | } 43 | 44 | public function hasHeader($header) 45 | { 46 | return isset($this->headers[strtolower($header)]); 47 | } 48 | 49 | public function getHeader($header) 50 | { 51 | $name = strtolower($header); 52 | return isset($this->headers[$name]) ? $this->headers[$name] : []; 53 | } 54 | 55 | public function getHeaderLine($header) 56 | { 57 | return implode(', ', $this->getHeader($header)); 58 | } 59 | 60 | public function withHeader($header, $value) 61 | { 62 | $new = clone $this; 63 | $header = trim($header); 64 | $name = strtolower($header); 65 | 66 | if (!is_array($value)) { 67 | $new->headers[$name] = [trim($value)]; 68 | } else { 69 | $new->headers[$name] = $value; 70 | foreach ($new->headers[$name] as &$v) { 71 | $v = trim($v); 72 | } 73 | } 74 | 75 | // Remove the header lines. 76 | foreach (array_keys($new->headerLines) as $key) { 77 | if (strtolower($key) === $name) { 78 | unset($new->headerLines[$key]); 79 | } 80 | } 81 | 82 | // Add the header line. 83 | $new->headerLines[$header] = $new->headers[$name]; 84 | 85 | return $new; 86 | } 87 | 88 | public function withAddedHeader($header, $value) 89 | { 90 | if (!$this->hasHeader($header)) { 91 | return $this->withHeader($header, $value); 92 | } 93 | 94 | $new = clone $this; 95 | $new->headers[strtolower($header)][] = $value; 96 | $new->headerLines[$header][] = $value; 97 | return $new; 98 | } 99 | 100 | public function withoutHeader($header) 101 | { 102 | if (!$this->hasHeader($header)) { 103 | return $this; 104 | } 105 | 106 | $new = clone $this; 107 | $name = strtolower($header); 108 | unset($new->headers[$name]); 109 | 110 | foreach (array_keys($new->headerLines) as $key) { 111 | if (strtolower($key) === $name) { 112 | unset($new->headerLines[$key]); 113 | } 114 | } 115 | 116 | return $new; 117 | } 118 | 119 | public function getBody() 120 | { 121 | if (!$this->stream) { 122 | $this->stream = stream_for(''); 123 | } 124 | 125 | return $this->stream; 126 | } 127 | 128 | public function withBody(StreamInterface $body) 129 | { 130 | if ($body === $this->stream) { 131 | return $this; 132 | } 133 | 134 | $new = clone $this; 135 | $new->stream = $body; 136 | return $new; 137 | } 138 | 139 | private function setHeaders(array $headers) 140 | { 141 | $this->headerLines = $this->headers = []; 142 | foreach ($headers as $header => $value) { 143 | $header = trim($header); 144 | $name = strtolower($header); 145 | if (!is_array($value)) { 146 | $value = trim($value); 147 | $this->headers[$name][] = $value; 148 | $this->headerLines[$header][] = $value; 149 | } else { 150 | foreach ($value as $v) { 151 | $v = trim($v); 152 | $this->headers[$name][] = $v; 153 | $this->headerLines[$header][] = $v; 154 | } 155 | } 156 | } 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/src/NoSeekStream.php: -------------------------------------------------------------------------------- 1 | source = $source; 46 | $this->size = isset($options['size']) ? $options['size'] : null; 47 | $this->metadata = isset($options['metadata']) ? $options['metadata'] : []; 48 | $this->buffer = new BufferStream(); 49 | } 50 | 51 | public function __toString() 52 | { 53 | try { 54 | return copy_to_string($this); 55 | } catch (\Exception $e) { 56 | return ''; 57 | } 58 | } 59 | 60 | public function close() 61 | { 62 | $this->detach(); 63 | } 64 | 65 | public function detach() 66 | { 67 | $this->tellPos = false; 68 | $this->source = null; 69 | } 70 | 71 | public function getSize() 72 | { 73 | return $this->size; 74 | } 75 | 76 | public function tell() 77 | { 78 | return $this->tellPos; 79 | } 80 | 81 | public function eof() 82 | { 83 | return !$this->source; 84 | } 85 | 86 | public function isSeekable() 87 | { 88 | return false; 89 | } 90 | 91 | public function rewind() 92 | { 93 | $this->seek(0); 94 | } 95 | 96 | public function seek($offset, $whence = SEEK_SET) 97 | { 98 | throw new \RuntimeException('Cannot seek a PumpStream'); 99 | } 100 | 101 | public function isWritable() 102 | { 103 | return false; 104 | } 105 | 106 | public function write($string) 107 | { 108 | throw new \RuntimeException('Cannot write to a PumpStream'); 109 | } 110 | 111 | public function isReadable() 112 | { 113 | return true; 114 | } 115 | 116 | public function read($length) 117 | { 118 | $data = $this->buffer->read($length); 119 | $readLen = strlen($data); 120 | $this->tellPos += $readLen; 121 | $remaining = $length - $readLen; 122 | 123 | if ($remaining) { 124 | $this->pump($remaining); 125 | $data .= $this->buffer->read($remaining); 126 | $this->tellPos += strlen($data) - $readLen; 127 | } 128 | 129 | return $data; 130 | } 131 | 132 | public function getContents() 133 | { 134 | $result = ''; 135 | while (!$this->eof()) { 136 | $result .= $this->read(1000000); 137 | } 138 | 139 | return $result; 140 | } 141 | 142 | public function getMetadata($key = null) 143 | { 144 | if (!$key) { 145 | return $this->metadata; 146 | } 147 | 148 | return isset($this->metadata[$key]) ? $this->metadata[$key] : null; 149 | } 150 | 151 | private function pump($length) 152 | { 153 | if ($this->source) { 154 | do { 155 | $data = call_user_func($this->source, $length); 156 | if ($data === false || $data === null) { 157 | $this->source = null; 158 | return; 159 | } 160 | $this->buffer->write($data); 161 | $length -= strlen($data); 162 | } while ($length > 0); 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/src/Request.php: -------------------------------------------------------------------------------- 1 | method = strtoupper($method); 52 | $this->uri = $uri; 53 | $this->setHeaders($headers); 54 | $this->protocol = $protocolVersion; 55 | 56 | $host = $uri->getHost(); 57 | if ($host && !$this->hasHeader('Host')) { 58 | $this->updateHostFromUri($host); 59 | } 60 | 61 | if ($body) { 62 | $this->stream = stream_for($body); 63 | } 64 | } 65 | 66 | public function getRequestTarget() 67 | { 68 | if ($this->requestTarget !== null) { 69 | return $this->requestTarget; 70 | } 71 | 72 | $target = $this->uri->getPath(); 73 | if ($target == null) { 74 | $target = '/'; 75 | } 76 | if ($this->uri->getQuery()) { 77 | $target .= '?' . $this->uri->getQuery(); 78 | } 79 | 80 | return $target; 81 | } 82 | 83 | public function withRequestTarget($requestTarget) 84 | { 85 | if (preg_match('#\s#', $requestTarget)) { 86 | throw new InvalidArgumentException( 87 | 'Invalid request target provided; cannot contain whitespace' 88 | ); 89 | } 90 | 91 | $new = clone $this; 92 | $new->requestTarget = $requestTarget; 93 | return $new; 94 | } 95 | 96 | public function getMethod() 97 | { 98 | return $this->method; 99 | } 100 | 101 | public function withMethod($method) 102 | { 103 | $new = clone $this; 104 | $new->method = strtoupper($method); 105 | return $new; 106 | } 107 | 108 | public function getUri() 109 | { 110 | return $this->uri; 111 | } 112 | 113 | public function withUri(UriInterface $uri, $preserveHost = false) 114 | { 115 | if ($uri === $this->uri) { 116 | return $this; 117 | } 118 | 119 | $new = clone $this; 120 | $new->uri = $uri; 121 | 122 | if (!$preserveHost) { 123 | if ($host = $uri->getHost()) { 124 | $new->updateHostFromUri($host); 125 | } 126 | } 127 | 128 | return $new; 129 | } 130 | 131 | public function withHeader($header, $value) 132 | { 133 | /** @var Request $newInstance */ 134 | $newInstance = $this->withParentHeader($header, $value); 135 | return $newInstance; 136 | } 137 | 138 | private function updateHostFromUri($host) 139 | { 140 | // Ensure Host is the first header. 141 | // See: http://tools.ietf.org/html/rfc7230#section-5.4 142 | if ($port = $this->uri->getPort()) { 143 | $host .= ':' . $port; 144 | } 145 | 146 | $this->headerLines = ['Host' => [$host]] + $this->headerLines; 147 | $this->headers = ['host' => [$host]] + $this->headers; 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/src/Response.php: -------------------------------------------------------------------------------- 1 | 'Continue', 16 | 101 => 'Switching Protocols', 17 | 102 => 'Processing', 18 | 200 => 'OK', 19 | 201 => 'Created', 20 | 202 => 'Accepted', 21 | 203 => 'Non-Authoritative Information', 22 | 204 => 'No Content', 23 | 205 => 'Reset Content', 24 | 206 => 'Partial Content', 25 | 207 => 'Multi-status', 26 | 208 => 'Already Reported', 27 | 300 => 'Multiple Choices', 28 | 301 => 'Moved Permanently', 29 | 302 => 'Found', 30 | 303 => 'See Other', 31 | 304 => 'Not Modified', 32 | 305 => 'Use Proxy', 33 | 306 => 'Switch Proxy', 34 | 307 => 'Temporary Redirect', 35 | 400 => 'Bad Request', 36 | 401 => 'Unauthorized', 37 | 402 => 'Payment Required', 38 | 403 => 'Forbidden', 39 | 404 => 'Not Found', 40 | 405 => 'Method Not Allowed', 41 | 406 => 'Not Acceptable', 42 | 407 => 'Proxy Authentication Required', 43 | 408 => 'Request Time-out', 44 | 409 => 'Conflict', 45 | 410 => 'Gone', 46 | 411 => 'Length Required', 47 | 412 => 'Precondition Failed', 48 | 413 => 'Request Entity Too Large', 49 | 414 => 'Request-URI Too Large', 50 | 415 => 'Unsupported Media Type', 51 | 416 => 'Requested range not satisfiable', 52 | 417 => 'Expectation Failed', 53 | 418 => 'I\'m a teapot', 54 | 422 => 'Unprocessable Entity', 55 | 423 => 'Locked', 56 | 424 => 'Failed Dependency', 57 | 425 => 'Unordered Collection', 58 | 426 => 'Upgrade Required', 59 | 428 => 'Precondition Required', 60 | 429 => 'Too Many Requests', 61 | 431 => 'Request Header Fields Too Large', 62 | 500 => 'Internal Server Error', 63 | 501 => 'Not Implemented', 64 | 502 => 'Bad Gateway', 65 | 503 => 'Service Unavailable', 66 | 504 => 'Gateway Time-out', 67 | 505 => 'HTTP Version not supported', 68 | 506 => 'Variant Also Negotiates', 69 | 507 => 'Insufficient Storage', 70 | 508 => 'Loop Detected', 71 | 511 => 'Network Authentication Required', 72 | ]; 73 | 74 | /** @var null|string */ 75 | private $reasonPhrase = ''; 76 | 77 | /** @var int */ 78 | private $statusCode = 200; 79 | 80 | /** 81 | * @param int $status Status code for the response, if any. 82 | * @param array $headers Headers for the response, if any. 83 | * @param mixed $body Stream body. 84 | * @param string $version Protocol version. 85 | * @param string $reason Reason phrase (a default will be used if possible). 86 | */ 87 | public function __construct( 88 | $status = 200, 89 | array $headers = [], 90 | $body = null, 91 | $version = '1.1', 92 | $reason = null 93 | ) { 94 | $this->statusCode = (int) $status; 95 | 96 | if ($body !== null) { 97 | $this->stream = stream_for($body); 98 | } 99 | 100 | $this->setHeaders($headers); 101 | if (!$reason && isset(self::$phrases[$this->statusCode])) { 102 | $this->reasonPhrase = self::$phrases[$status]; 103 | } else { 104 | $this->reasonPhrase = (string) $reason; 105 | } 106 | 107 | $this->protocol = $version; 108 | } 109 | 110 | public function getStatusCode() 111 | { 112 | return $this->statusCode; 113 | } 114 | 115 | public function getReasonPhrase() 116 | { 117 | return $this->reasonPhrase; 118 | } 119 | 120 | public function withStatus($code, $reasonPhrase = '') 121 | { 122 | $new = clone $this; 123 | $new->statusCode = (int) $code; 124 | if (!$reasonPhrase && isset(self::$phrases[$new->statusCode])) { 125 | $reasonPhrase = self::$phrases[$new->statusCode]; 126 | } 127 | $new->reasonPhrase = $reasonPhrase; 128 | return $new; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/src/StreamDecoratorTrait.php: -------------------------------------------------------------------------------- 1 | stream = $stream; 18 | } 19 | 20 | /** 21 | * Magic method used to create a new stream if streams are not added in 22 | * the constructor of a decorator (e.g., LazyOpenStream). 23 | * 24 | * @param string $name Name of the property (allows "stream" only). 25 | * 26 | * @return StreamInterface 27 | */ 28 | public function __get($name) 29 | { 30 | if ($name == 'stream') { 31 | $this->stream = $this->createStream(); 32 | return $this->stream; 33 | } 34 | 35 | throw new \UnexpectedValueException("$name not found on class"); 36 | } 37 | 38 | public function __toString() 39 | { 40 | try { 41 | if ($this->isSeekable()) { 42 | $this->seek(0); 43 | } 44 | return $this->getContents(); 45 | } catch (\Exception $e) { 46 | // Really, PHP? https://bugs.php.net/bug.php?id=53648 47 | trigger_error('StreamDecorator::__toString exception: ' 48 | . (string) $e, E_USER_ERROR); 49 | return ''; 50 | } 51 | } 52 | 53 | public function getContents() 54 | { 55 | return copy_to_string($this); 56 | } 57 | 58 | /** 59 | * Allow decorators to implement custom methods 60 | * 61 | * @param string $method Missing method name 62 | * @param array $args Method arguments 63 | * 64 | * @return mixed 65 | */ 66 | public function __call($method, array $args) 67 | { 68 | $result = call_user_func_array([$this->stream, $method], $args); 69 | 70 | // Always return the wrapped object if the result is a return $this 71 | return $result === $this->stream ? $this : $result; 72 | } 73 | 74 | public function close() 75 | { 76 | $this->stream->close(); 77 | } 78 | 79 | public function getMetadata($key = null) 80 | { 81 | return $this->stream->getMetadata($key); 82 | } 83 | 84 | public function detach() 85 | { 86 | return $this->stream->detach(); 87 | } 88 | 89 | public function getSize() 90 | { 91 | return $this->stream->getSize(); 92 | } 93 | 94 | public function eof() 95 | { 96 | return $this->stream->eof(); 97 | } 98 | 99 | public function tell() 100 | { 101 | return $this->stream->tell(); 102 | } 103 | 104 | public function isReadable() 105 | { 106 | return $this->stream->isReadable(); 107 | } 108 | 109 | public function isWritable() 110 | { 111 | return $this->stream->isWritable(); 112 | } 113 | 114 | public function isSeekable() 115 | { 116 | return $this->stream->isSeekable(); 117 | } 118 | 119 | public function rewind() 120 | { 121 | $this->seek(0); 122 | } 123 | 124 | public function seek($offset, $whence = SEEK_SET) 125 | { 126 | $this->stream->seek($offset, $whence); 127 | } 128 | 129 | public function read($length) 130 | { 131 | return $this->stream->read($length); 132 | } 133 | 134 | public function write($string) 135 | { 136 | return $this->stream->write($string); 137 | } 138 | 139 | /** 140 | * Implement in subclasses to dynamically create streams when requested. 141 | * 142 | * @return StreamInterface 143 | * @throws \BadMethodCallException 144 | */ 145 | protected function createStream() 146 | { 147 | throw new \BadMethodCallException('Not implemented'); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/src/StreamWrapper.php: -------------------------------------------------------------------------------- 1 | isReadable()) { 33 | $mode = $stream->isWritable() ? 'r+' : 'r'; 34 | } elseif ($stream->isWritable()) { 35 | $mode = 'w'; 36 | } else { 37 | throw new \InvalidArgumentException('The stream must be readable, ' 38 | . 'writable, or both.'); 39 | } 40 | 41 | return fopen('guzzle://stream', $mode, null, stream_context_create([ 42 | 'guzzle' => ['stream' => $stream] 43 | ])); 44 | } 45 | 46 | /** 47 | * Registers the stream wrapper if needed 48 | */ 49 | public static function register() 50 | { 51 | if (!in_array('guzzle', stream_get_wrappers())) { 52 | stream_wrapper_register('guzzle', __CLASS__); 53 | } 54 | } 55 | 56 | public function stream_open($path, $mode, $options, &$opened_path) 57 | { 58 | $options = stream_context_get_options($this->context); 59 | 60 | if (!isset($options['guzzle']['stream'])) { 61 | return false; 62 | } 63 | 64 | $this->mode = $mode; 65 | $this->stream = $options['guzzle']['stream']; 66 | 67 | return true; 68 | } 69 | 70 | public function stream_read($count) 71 | { 72 | return $this->stream->read($count); 73 | } 74 | 75 | public function stream_write($data) 76 | { 77 | return (int) $this->stream->write($data); 78 | } 79 | 80 | public function stream_tell() 81 | { 82 | return $this->stream->tell(); 83 | } 84 | 85 | public function stream_eof() 86 | { 87 | return $this->stream->eof(); 88 | } 89 | 90 | public function stream_seek($offset, $whence) 91 | { 92 | $this->stream->seek($offset, $whence); 93 | 94 | return true; 95 | } 96 | 97 | public function stream_stat() 98 | { 99 | static $modeMap = [ 100 | 'r' => 33060, 101 | 'r+' => 33206, 102 | 'w' => 33188 103 | ]; 104 | 105 | return [ 106 | 'dev' => 0, 107 | 'ino' => 0, 108 | 'mode' => $modeMap[$this->mode], 109 | 'nlink' => 0, 110 | 'uid' => 0, 111 | 'gid' => 0, 112 | 'rdev' => 0, 113 | 'size' => $this->stream->getSize() ?: 0, 114 | 'atime' => 0, 115 | 'mtime' => 0, 116 | 'ctime' => 0, 117 | 'blksize' => 0, 118 | 'blocks' => 0 119 | ]; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/src/functions_include.php: -------------------------------------------------------------------------------- 1 | assertTrue($b->isReadable()); 12 | $this->assertTrue($b->isWritable()); 13 | $this->assertFalse($b->isSeekable()); 14 | $this->assertEquals(null, $b->getMetadata('foo')); 15 | $this->assertEquals(10, $b->getMetadata('hwm')); 16 | $this->assertEquals([], $b->getMetadata()); 17 | } 18 | 19 | public function testRemovesReadDataFromBuffer() 20 | { 21 | $b = new BufferStream(); 22 | $this->assertEquals(3, $b->write('foo')); 23 | $this->assertEquals(3, $b->getSize()); 24 | $this->assertFalse($b->eof()); 25 | $this->assertEquals('foo', $b->read(10)); 26 | $this->assertTrue($b->eof()); 27 | $this->assertEquals('', $b->read(10)); 28 | } 29 | 30 | /** 31 | * @expectedException \RuntimeException 32 | * @expectedExceptionMessage Cannot determine the position of a BufferStream 33 | */ 34 | public function testCanCastToStringOrGetContents() 35 | { 36 | $b = new BufferStream(); 37 | $b->write('foo'); 38 | $b->write('baz'); 39 | $this->assertEquals('foo', $b->read(3)); 40 | $b->write('bar'); 41 | $this->assertEquals('bazbar', (string) $b); 42 | $b->tell(); 43 | } 44 | 45 | public function testDetachClearsBuffer() 46 | { 47 | $b = new BufferStream(); 48 | $b->write('foo'); 49 | $b->detach(); 50 | $this->assertTrue($b->eof()); 51 | $this->assertEquals(3, $b->write('abc')); 52 | $this->assertEquals('abc', $b->read(10)); 53 | } 54 | 55 | public function testExceedingHighwaterMarkReturnsFalseButStillBuffers() 56 | { 57 | $b = new BufferStream(5); 58 | $this->assertEquals(3, $b->write('hi ')); 59 | $this->assertFalse($b->write('hello')); 60 | $this->assertEquals('hi hello', (string) $b); 61 | $this->assertEquals(4, $b->write('test')); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/tests/DroppingStreamTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(3, $drop->write('hel')); 14 | $this->assertEquals(2, $drop->write('lo')); 15 | $this->assertEquals(5, $drop->getSize()); 16 | $this->assertEquals('hello', $drop->read(5)); 17 | $this->assertEquals(0, $drop->getSize()); 18 | $drop->write('12345678910'); 19 | $this->assertEquals(5, $stream->getSize()); 20 | $this->assertEquals(5, $drop->getSize()); 21 | $this->assertEquals('12345', (string) $drop); 22 | $this->assertEquals(0, $drop->getSize()); 23 | $drop->write('hello'); 24 | $this->assertSame(0, $drop->write('test')); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/tests/FnStreamTest.php: -------------------------------------------------------------------------------- 1 | seek(1); 19 | } 20 | 21 | public function testProxiesToFunction() 22 | { 23 | $s = new FnStream([ 24 | 'read' => function ($len) { 25 | $this->assertEquals(3, $len); 26 | return 'foo'; 27 | } 28 | ]); 29 | 30 | $this->assertEquals('foo', $s->read(3)); 31 | } 32 | 33 | public function testCanCloseOnDestruct() 34 | { 35 | $called = false; 36 | $s = new FnStream([ 37 | 'close' => function () use (&$called) { 38 | $called = true; 39 | } 40 | ]); 41 | unset($s); 42 | $this->assertTrue($called); 43 | } 44 | 45 | public function testDoesNotRequireClose() 46 | { 47 | $s = new FnStream([]); 48 | unset($s); 49 | } 50 | 51 | public function testDecoratesStream() 52 | { 53 | $a = Psr7\stream_for('foo'); 54 | $b = FnStream::decorate($a, []); 55 | $this->assertEquals(3, $b->getSize()); 56 | $this->assertEquals($b->isWritable(), true); 57 | $this->assertEquals($b->isReadable(), true); 58 | $this->assertEquals($b->isSeekable(), true); 59 | $this->assertEquals($b->read(3), 'foo'); 60 | $this->assertEquals($b->tell(), 3); 61 | $this->assertEquals($a->tell(), 3); 62 | $this->assertSame('', $a->read(1)); 63 | $this->assertEquals($b->eof(), true); 64 | $this->assertEquals($a->eof(), true); 65 | $b->seek(0); 66 | $this->assertEquals('foo', (string) $b); 67 | $b->seek(0); 68 | $this->assertEquals('foo', $b->getContents()); 69 | $this->assertEquals($a->getMetadata(), $b->getMetadata()); 70 | $b->seek(0, SEEK_END); 71 | $b->write('bar'); 72 | $this->assertEquals('foobar', (string) $b); 73 | $this->assertInternalType('resource', $b->detach()); 74 | $b->close(); 75 | } 76 | 77 | public function testDecoratesWithCustomizations() 78 | { 79 | $called = false; 80 | $a = Psr7\stream_for('foo'); 81 | $b = FnStream::decorate($a, [ 82 | 'read' => function ($len) use (&$called, $a) { 83 | $called = true; 84 | return $a->read($len); 85 | } 86 | ]); 87 | $this->assertEquals('foo', $b->read(3)); 88 | $this->assertTrue($called); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/tests/InflateStreamTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('test', (string) $b); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/tests/LazyOpenStreamTest.php: -------------------------------------------------------------------------------- 1 | fname = tempnam('/tmp', 'tfile'); 13 | 14 | if (file_exists($this->fname)) { 15 | unlink($this->fname); 16 | } 17 | } 18 | 19 | public function tearDown() 20 | { 21 | if (file_exists($this->fname)) { 22 | unlink($this->fname); 23 | } 24 | } 25 | 26 | public function testOpensLazily() 27 | { 28 | $l = new LazyOpenStream($this->fname, 'w+'); 29 | $l->write('foo'); 30 | $this->assertInternalType('array', $l->getMetadata()); 31 | $this->assertFileExists($this->fname); 32 | $this->assertEquals('foo', file_get_contents($this->fname)); 33 | $this->assertEquals('foo', (string) $l); 34 | } 35 | 36 | public function testProxiesToFile() 37 | { 38 | file_put_contents($this->fname, 'foo'); 39 | $l = new LazyOpenStream($this->fname, 'r'); 40 | $this->assertEquals('foo', $l->read(4)); 41 | $this->assertTrue($l->eof()); 42 | $this->assertEquals(3, $l->tell()); 43 | $this->assertTrue($l->isReadable()); 44 | $this->assertTrue($l->isSeekable()); 45 | $this->assertFalse($l->isWritable()); 46 | $l->seek(1); 47 | $this->assertEquals('oo', $l->getContents()); 48 | $this->assertEquals('foo', (string) $l); 49 | $this->assertEquals(3, $l->getSize()); 50 | $this->assertInternalType('array', $l->getMetadata()); 51 | $l->close(); 52 | } 53 | 54 | public function testDetachesUnderlyingStream() 55 | { 56 | file_put_contents($this->fname, 'foo'); 57 | $l = new LazyOpenStream($this->fname, 'r'); 58 | $r = $l->detach(); 59 | $this->assertInternalType('resource', $r); 60 | fseek($r, 0); 61 | $this->assertEquals('foo', stream_get_contents($r)); 62 | fclose($r); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/tests/NoSeekStreamTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder('Psr\Http\Message\StreamInterface') 20 | ->setMethods(['isSeekable', 'seek']) 21 | ->getMockForAbstractClass(); 22 | $s->expects($this->never())->method('seek'); 23 | $s->expects($this->never())->method('isSeekable'); 24 | $wrapped = new NoSeekStream($s); 25 | $this->assertFalse($wrapped->isSeekable()); 26 | $wrapped->seek(2); 27 | } 28 | 29 | /** 30 | * @expectedException \RuntimeException 31 | * @expectedExceptionMessage Cannot write to a non-writable stream 32 | */ 33 | public function testHandlesClose() 34 | { 35 | $s = Psr7\stream_for('foo'); 36 | $wrapped = new NoSeekStream($s); 37 | $wrapped->close(); 38 | $wrapped->write('foo'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/tests/PumpStreamTest.php: -------------------------------------------------------------------------------- 1 | ['foo' => 'bar'], 14 | 'size' => 100 15 | ]); 16 | 17 | $this->assertEquals('bar', $p->getMetadata('foo')); 18 | $this->assertEquals(['foo' => 'bar'], $p->getMetadata()); 19 | $this->assertEquals(100, $p->getSize()); 20 | } 21 | 22 | public function testCanReadFromCallable() 23 | { 24 | $p = Psr7\stream_for(function ($size) { 25 | return 'a'; 26 | }); 27 | $this->assertEquals('a', $p->read(1)); 28 | $this->assertEquals(1, $p->tell()); 29 | $this->assertEquals('aaaaa', $p->read(5)); 30 | $this->assertEquals(6, $p->tell()); 31 | } 32 | 33 | public function testStoresExcessDataInBuffer() 34 | { 35 | $called = []; 36 | $p = Psr7\stream_for(function ($size) use (&$called) { 37 | $called[] = $size; 38 | return 'abcdef'; 39 | }); 40 | $this->assertEquals('a', $p->read(1)); 41 | $this->assertEquals('b', $p->read(1)); 42 | $this->assertEquals('cdef', $p->read(4)); 43 | $this->assertEquals('abcdefabc', $p->read(9)); 44 | $this->assertEquals([1, 9, 3], $called); 45 | } 46 | 47 | public function testInifiniteStreamWrappedInLimitStream() 48 | { 49 | $p = Psr7\stream_for(function () { return 'a'; }); 50 | $s = new LimitStream($p, 5); 51 | $this->assertEquals('aaaaa', (string) $s); 52 | } 53 | 54 | public function testDescribesCapabilities() 55 | { 56 | $p = Psr7\stream_for(function () {}); 57 | $this->assertTrue($p->isReadable()); 58 | $this->assertFalse($p->isSeekable()); 59 | $this->assertFalse($p->isWritable()); 60 | $this->assertNull($p->getSize()); 61 | $this->assertEquals('', $p->getContents()); 62 | $this->assertEquals('', (string) $p); 63 | $p->close(); 64 | $this->assertEquals('', $p->read(10)); 65 | $this->assertTrue($p->eof()); 66 | 67 | try { 68 | $this->assertFalse($p->write('aa')); 69 | $this->fail(); 70 | } catch (\RuntimeException $e) {} 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/tests/StreamDecoratorTraitTest.php: -------------------------------------------------------------------------------- 1 | c = fopen('php://temp', 'r+'); 25 | fwrite($this->c, 'foo'); 26 | fseek($this->c, 0); 27 | $this->a = Psr7\stream_for($this->c); 28 | $this->b = new Str($this->a); 29 | } 30 | 31 | public function testCatchesExceptionsWhenCastingToString() 32 | { 33 | $s = $this->getMockBuilder('Psr\Http\Message\StreamInterface') 34 | ->setMethods(['read']) 35 | ->getMockForAbstractClass(); 36 | $s->expects($this->once()) 37 | ->method('read') 38 | ->will($this->throwException(new \Exception('foo'))); 39 | $msg = ''; 40 | set_error_handler(function ($errNo, $str) use (&$msg) { $msg = $str; }); 41 | echo new Str($s); 42 | restore_error_handler(); 43 | $this->assertContains('foo', $msg); 44 | } 45 | 46 | public function testToString() 47 | { 48 | $this->assertEquals('foo', (string) $this->b); 49 | } 50 | 51 | public function testHasSize() 52 | { 53 | $this->assertEquals(3, $this->b->getSize()); 54 | } 55 | 56 | public function testReads() 57 | { 58 | $this->assertEquals('foo', $this->b->read(10)); 59 | } 60 | 61 | public function testCheckMethods() 62 | { 63 | $this->assertEquals($this->a->isReadable(), $this->b->isReadable()); 64 | $this->assertEquals($this->a->isWritable(), $this->b->isWritable()); 65 | $this->assertEquals($this->a->isSeekable(), $this->b->isSeekable()); 66 | } 67 | 68 | public function testSeeksAndTells() 69 | { 70 | $this->b->seek(1); 71 | $this->assertEquals(1, $this->a->tell()); 72 | $this->assertEquals(1, $this->b->tell()); 73 | $this->b->seek(0); 74 | $this->assertEquals(0, $this->a->tell()); 75 | $this->assertEquals(0, $this->b->tell()); 76 | $this->b->seek(0, SEEK_END); 77 | $this->assertEquals(3, $this->a->tell()); 78 | $this->assertEquals(3, $this->b->tell()); 79 | } 80 | 81 | public function testGetsContents() 82 | { 83 | $this->assertEquals('foo', $this->b->getContents()); 84 | $this->assertEquals('', $this->b->getContents()); 85 | $this->b->seek(1); 86 | $this->assertEquals('oo', $this->b->getContents(1)); 87 | } 88 | 89 | public function testCloses() 90 | { 91 | $this->b->close(); 92 | $this->assertFalse(is_resource($this->c)); 93 | } 94 | 95 | public function testDetaches() 96 | { 97 | $this->b->detach(); 98 | $this->assertFalse($this->b->isReadable()); 99 | } 100 | 101 | public function testWrapsMetadata() 102 | { 103 | $this->assertSame($this->b->getMetadata(), $this->a->getMetadata()); 104 | $this->assertSame($this->b->getMetadata('uri'), $this->a->getMetadata('uri')); 105 | } 106 | 107 | public function testWrapsWrites() 108 | { 109 | $this->b->seek(0, SEEK_END); 110 | $this->b->write('foo'); 111 | $this->assertEquals('foofoo', (string) $this->a); 112 | } 113 | 114 | /** 115 | * @expectedException \UnexpectedValueException 116 | */ 117 | public function testThrowsWithInvalidGetter() 118 | { 119 | $this->b->foo; 120 | } 121 | 122 | /** 123 | * @expectedException \BadMethodCallException 124 | */ 125 | public function testThrowsWhenGetterNotImplemented() 126 | { 127 | $s = new BadStream(); 128 | $s->stream; 129 | } 130 | } 131 | 132 | class BadStream 133 | { 134 | use StreamDecoratorTrait; 135 | 136 | public function __construct() {} 137 | } 138 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/tests/StreamWrapperTest.php: -------------------------------------------------------------------------------- 1 | assertSame('foo', fread($handle, 3)); 17 | $this->assertSame(3, ftell($handle)); 18 | $this->assertSame(3, fwrite($handle, 'bar')); 19 | $this->assertSame(0, fseek($handle, 0)); 20 | $this->assertSame('foobar', fread($handle, 6)); 21 | $this->assertSame('', fread($handle, 1)); 22 | $this->assertTrue(feof($handle)); 23 | 24 | // This fails on HHVM for some reason 25 | if (!defined('HHVM_VERSION')) { 26 | $this->assertEquals([ 27 | 'dev' => 0, 28 | 'ino' => 0, 29 | 'mode' => 33206, 30 | 'nlink' => 0, 31 | 'uid' => 0, 32 | 'gid' => 0, 33 | 'rdev' => 0, 34 | 'size' => 6, 35 | 'atime' => 0, 36 | 'mtime' => 0, 37 | 'ctime' => 0, 38 | 'blksize' => 0, 39 | 'blocks' => 0, 40 | 0 => 0, 41 | 1 => 0, 42 | 2 => 33206, 43 | 3 => 0, 44 | 4 => 0, 45 | 5 => 0, 46 | 6 => 0, 47 | 7 => 6, 48 | 8 => 0, 49 | 9 => 0, 50 | 10 => 0, 51 | 11 => 0, 52 | 12 => 0, 53 | ], fstat($handle)); 54 | } 55 | 56 | $this->assertTrue(fclose($handle)); 57 | $this->assertSame('foobar', (string) $stream); 58 | } 59 | 60 | /** 61 | * @expectedException \InvalidArgumentException 62 | */ 63 | public function testValidatesStream() 64 | { 65 | $stream = $this->getMockBuilder('Psr\Http\Message\StreamInterface') 66 | ->setMethods(['isReadable', 'isWritable']) 67 | ->getMockForAbstractClass(); 68 | $stream->expects($this->once()) 69 | ->method('isReadable') 70 | ->will($this->returnValue(false)); 71 | $stream->expects($this->once()) 72 | ->method('isWritable') 73 | ->will($this->returnValue(false)); 74 | StreamWrapper::getResource($stream); 75 | } 76 | 77 | /** 78 | * @expectedException \PHPUnit_Framework_Error_Warning 79 | */ 80 | public function testReturnsFalseWhenStreamDoesNotExist() 81 | { 82 | fopen('guzzle://foo', 'r'); 83 | } 84 | 85 | public function testCanOpenReadonlyStream() 86 | { 87 | $stream = $this->getMockBuilder('Psr\Http\Message\StreamInterface') 88 | ->setMethods(['isReadable', 'isWritable']) 89 | ->getMockForAbstractClass(); 90 | $stream->expects($this->once()) 91 | ->method('isReadable') 92 | ->will($this->returnValue(false)); 93 | $stream->expects($this->once()) 94 | ->method('isWritable') 95 | ->will($this->returnValue(true)); 96 | $r = StreamWrapper::getResource($stream); 97 | $this->assertInternalType('resource', $r); 98 | fclose($r); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /PHP/vendor/guzzlehttp/psr7/tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | =5.3.0" 14 | }, 15 | "autoload": { 16 | "psr-4": { 17 | "Psr\\Http\\Message\\": "src/" 18 | } 19 | }, 20 | "extra": { 21 | "branch-alias": { 22 | "dev-master": "1.0.x-dev" 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /PHP/vendor/psr/http-message/src/ResponseInterface.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | RestDB jQuery example 7 | 8 | 9 | 10 |

RestDB jQuery boiler plate code

11 |
12 |
13 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /realtime-react/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /realtime-react/README.md: -------------------------------------------------------------------------------- 1 | ## React in realtime 2 | 3 | This is the full source code for the React / restdb.io example application developed this blog post: 4 | 5 | [React in realtime](https://restdb.io/blog/react-in-realtime) 6 | 7 | This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app). 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /realtime-react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "realtime-react", 3 | "version": "0.1.0", 4 | "private": true, 5 | "homepage": ".", 6 | "dependencies": { 7 | "axios": "^0.16.2", 8 | "lodash": "^4.17.4", 9 | "react": "^15.6.1", 10 | "react-dom": "^15.6.1", 11 | "react-scripts": "1.0.10" 12 | }, 13 | "scripts": { 14 | "start": "react-scripts start", 15 | "build": "react-scripts build", 16 | "test": "react-scripts test --env=jsdom", 17 | "eject": "react-scripts eject", 18 | "deploy": "restdb-cli --cmd upload --src ./build --dest /reactrealtime --database reactrealtime-6683 --apikey c500cef6b35c5e0260a05d73943dc48e961eb" 19 | } 20 | } -------------------------------------------------------------------------------- /realtime-react/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RestDB/clientexamples/e5504d04123d2eca15340d4634e139e759ba5904/realtime-react/public/favicon.ico -------------------------------------------------------------------------------- /realtime-react/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | 23 | React App 24 | 25 | 26 | 27 | 30 |
31 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /realtime-react/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "192x192", 8 | "type": "image/png" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /realtime-react/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | animation: App-logo-spin infinite 20s linear; 7 | height: 40px; 8 | } 9 | 10 | .App-header { 11 | background-color: #222; 12 | height: 100px; 13 | padding: 20px; 14 | color: white; 15 | } 16 | 17 | .App-intro { 18 | font-size: large; 19 | } 20 | 21 | @keyframes App-logo-spin { 22 | from { 23 | transform: rotate(0deg); 24 | } 25 | to { 26 | transform: rotate(360deg); 27 | } 28 | } -------------------------------------------------------------------------------- /realtime-react/src/App.js: -------------------------------------------------------------------------------- 1 | // App.js 2 | import React, { Component } from 'react'; 3 | import _ from 'lodash'; 4 | import logo from './logo.svg'; 5 | import './App.css'; 6 | import Trade from './Autotrader'; 7 | import { restdb, realtimeURL } from './helper.js'; 8 | 9 | 10 | class Tickers extends Component { 11 | constructor(props) { 12 | super(props); 13 | 14 | this.state = {ping: new Date(), evt: '', tickers: []}; 15 | 16 | // connect to the realtime database stream 17 | let eventSource = new EventSource(realtimeURL); 18 | 19 | // check if the realtime connection is dead, reload client if dead 20 | setInterval(() => { 21 | let now = new Date().getTime(); 22 | let diff = (now - this.state.ping.getTime()) / 1000; 23 | 24 | // haven't heard from the server in 20 secs? 25 | if (diff > 20) { 26 | // hard reload of client 27 | window.location.reload(); 28 | } 29 | }, 10000); 30 | 31 | // listen on ping from server, keep time 32 | eventSource.addEventListener('ping', function(e) { 33 | this.setState(previousState => { 34 | return {ping: new Date(e.data)}; 35 | }); 36 | }.bind(this), false); 37 | 38 | // listen for database REST operations 39 | eventSource.addEventListener('put', (e) => { 40 | this.getTickerData() 41 | 42 | }, false); 43 | 44 | eventSource.addEventListener('delete', (e) => { 45 | this.getTickerData() 46 | 47 | }, false); 48 | 49 | eventSource.addEventListener('post', (e) => { 50 | this.getTickerData(); 51 | 52 | }, false); 53 | 54 | eventSource.addEventListener("error", (e) => { 55 | // typically lost network connection 56 | console.log("Error", e); 57 | }); 58 | 59 | eventSource.onmessage = (e) => { 60 | // generic messages 61 | console.log("Message", e); 62 | } 63 | } 64 | 65 | // GET 20 stocks to display and trade 66 | getTickerData = () => { 67 | restdb.get("/rest/nasdaq?sort=symbol&max=20&metafields=true") 68 | .then(res => { 69 | let now = new Date().getTime(); 70 | let tickers = res.data; 71 | let diff = null; 72 | 73 | // tag stocks that are changed in the last 10 secs 74 | _.each(tickers, (t) => { 75 | diff = (now - new Date(t._changed).getTime()) / 1000; 76 | if (diff < 10) { 77 | t.isChanged = true; 78 | } else { 79 | t.isChanged = false; 80 | } 81 | }); 82 | 83 | this.setState(previousState => { 84 | return { tickers }; 85 | }); 86 | }); 87 | } 88 | componentDidMount() { 89 | console.log("Start client"); 90 | this.getTickerData(); 91 | } 92 | 93 | render() { 94 | return ( 95 |
96 |
26 | {{hImage.Name}} 27 | 29 | 30 | 31 | 32 | 33 |
97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | {this.state.tickers.map(tic => 108 | 109 | 0 ? "up" : "down") : "passive"}> 110 | 111 | 112 | 113 | 114 | 115 | )} 116 | 117 | 118 |
SymbolCompanyPriceChange
{tic.symbol}{tic.name}{tic.price.toFixed(2) || 0.0}{tic['net chg'] ? tic['net chg'].toFixed(2) : 0.0}
119 | 120 | ); 121 | } 122 | } 123 | 124 | class App extends Component { 125 | componentDidMount() { 126 | // start trading 127 | } 128 | render() { 129 | return ( 130 |
131 |
132 | logo 133 |

React & RestDB.io in Realtime

134 |
135 | 136 |

Nasdaq trading bots fake

137 | 138 | 139 |
140 | ); 141 | } 142 | } 143 | 144 | export default App; 145 | -------------------------------------------------------------------------------- /realtime-react/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | }); 9 | -------------------------------------------------------------------------------- /realtime-react/src/Autotrader.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { restdb, trade_delay } from './helper.js'; 3 | 4 | // emulate price change on stocks 5 | class Trader extends Component { 6 | constructor(props) { 7 | super(props); 8 | this.state = {stocks: [], lasttrade: null}; 9 | 10 | // GET 20 stocks 11 | restdb.get("/rest/nasdaq?sort=symbol&max=20") 12 | .then(res => { 13 | const stocks = res.data; 14 | this.setState(previousState => { 15 | return { stocks }; 16 | }); 17 | }); 18 | 19 | // update a random stock each 10 sec 20 | setInterval(() => { 21 | let stockpos = Math.floor(Math.random() * 19); 22 | if (this.state.stocks[stockpos]) { 23 | let stockID = this.state.stocks[stockpos]._id; 24 | let newprice = (Math.random() * 1000.0) + 1.0; 25 | // PUT new price on one stock 26 | restdb.put(`/rest/nasdaq/${stockID}`, 27 | {price: newprice} 28 | ) 29 | .then((response) => { 30 | 31 | this.setState(previousState => { 32 | return {lasttrade: response.data}; 33 | }); 34 | }) 35 | .catch(function (error) { 36 | console.log(error); 37 | }); 38 | } 39 | }, trade_delay); 40 | } 41 | 42 | render() { 43 | return ( 44 |
45 |

Trading: {this.state.lasttrade ? (this.state.lasttrade.symbol + ' at ' + this.state.lasttrade.price.toFixed(2)) : 'none'}

46 |
47 | ); 48 | } 49 | } 50 | 51 | 52 | export default Trader; -------------------------------------------------------------------------------- /realtime-react/src/helper.js: -------------------------------------------------------------------------------- 1 | // helper.js 2 | import axios from 'axios'; 3 | 4 | // CORS enabled apikey 5 | const apikey = '595f6501afce09e87211ea68'; 6 | 7 | // Autotrade delay 8 | const trade_delay = 5000; // millis 9 | 10 | // REST endpoint 11 | let restdb = axios.create({ 12 | baseURL: 'https://reactrealtime-6683.restdb.io', 13 | timeout: 1000, 14 | headers: { 'x-apikey': apikey } 15 | }); 16 | // Eventource endpoint 17 | const realtimeURL = `https://reactrealtime-6683.restdb.io/realtime?apikey=${apikey}` 18 | 19 | export { apikey, restdb, realtimeURL, trade_delay }; -------------------------------------------------------------------------------- /realtime-react/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: sans-serif; 5 | } 6 | 7 | .tickers { 8 | display: inline-block; 9 | } 10 | 11 | .table { 12 | text-align: left; 13 | } 14 | 15 | .num { 16 | text-align: right; 17 | } 18 | 19 | .up { 20 | background: green; 21 | } 22 | 23 | .down { 24 | background: red; 25 | } -------------------------------------------------------------------------------- /realtime-react/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import registerServiceWorker from './registerServiceWorker'; 6 | 7 | ReactDOM.render( < App / > , document.getElementById('root')); 8 | registerServiceWorker(); -------------------------------------------------------------------------------- /realtime-react/src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /realtime-react/src/registerServiceWorker.js: -------------------------------------------------------------------------------- 1 | // In production, we register a service worker to serve assets from local cache. 2 | 3 | // This lets the app load faster on subsequent visits in production, and gives 4 | // it offline capabilities. However, it also means that developers (and users) 5 | // will only see deployed updates on the "N+1" visit to a page, since previously 6 | // cached resources are updated in the background. 7 | 8 | // To learn more about the benefits of this model, read https://goo.gl/KwvDNy. 9 | // This link also includes instructions on opting out of this behavior. 10 | 11 | const isLocalhost = Boolean( 12 | window.location.hostname === 'localhost' || 13 | // [::1] is the IPv6 localhost address. 14 | window.location.hostname === '[::1]' || 15 | // 127.0.0.1/8 is considered localhost for IPv4. 16 | window.location.hostname.match( 17 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 18 | ) 19 | ); 20 | 21 | export default function register() { 22 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 23 | // The URL constructor is available in all browsers that support SW. 24 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location); 25 | if (publicUrl.origin !== window.location.origin) { 26 | // Our service worker won't work if PUBLIC_URL is on a different origin 27 | // from what our page is served on. This might happen if a CDN is used to 28 | // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374 29 | return; 30 | } 31 | 32 | window.addEventListener('load', () => { 33 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 34 | 35 | if (!isLocalhost) { 36 | // Is not local host. Just register service worker 37 | registerValidSW(swUrl); 38 | } else { 39 | // This is running on localhost. Lets check if a service worker still exists or not. 40 | checkValidServiceWorker(swUrl); 41 | } 42 | }); 43 | } 44 | } 45 | 46 | function registerValidSW(swUrl) { 47 | navigator.serviceWorker 48 | .register(swUrl) 49 | .then(registration => { 50 | registration.onupdatefound = () => { 51 | const installingWorker = registration.installing; 52 | installingWorker.onstatechange = () => { 53 | if (installingWorker.state === 'installed') { 54 | if (navigator.serviceWorker.controller) { 55 | // At this point, the old content will have been purged and 56 | // the fresh content will have been added to the cache. 57 | // It's the perfect time to display a "New content is 58 | // available; please refresh." message in your web app. 59 | console.log('New content is available; please refresh.'); 60 | } else { 61 | // At this point, everything has been precached. 62 | // It's the perfect time to display a 63 | // "Content is cached for offline use." message. 64 | console.log('Content is cached for offline use.'); 65 | } 66 | } 67 | }; 68 | }; 69 | }) 70 | .catch(error => { 71 | console.error('Error during service worker registration:', error); 72 | }); 73 | } 74 | 75 | function checkValidServiceWorker(swUrl) { 76 | // Check if the service worker can be found. If it can't reload the page. 77 | fetch(swUrl) 78 | .then(response => { 79 | // Ensure service worker exists, and that we really are getting a JS file. 80 | if ( 81 | response.status === 404 || 82 | response.headers.get('content-type').indexOf('javascript') === -1 83 | ) { 84 | // No service worker found. Probably a different app. Reload the page. 85 | navigator.serviceWorker.ready.then(registration => { 86 | registration.unregister().then(() => { 87 | window.location.reload(); 88 | }); 89 | }); 90 | } else { 91 | // Service worker found. Proceed as normal. 92 | registerValidSW(swUrl); 93 | } 94 | }) 95 | .catch(() => { 96 | console.log( 97 | 'No internet connection found. App is running in offline mode.' 98 | ); 99 | }); 100 | } 101 | 102 | export function unregister() { 103 | if ('serviceWorker' in navigator) { 104 | navigator.serviceWorker.ready.then(registration => { 105 | registration.unregister(); 106 | }); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /restdb_io realtime chat/public/code.js: -------------------------------------------------------------------------------- 1 | var hightlight = function(id) { 2 | $(id).addClass("highlight"); 3 | setTimeout(function(){ 4 | $(id).removeClass("highlight"); 5 | }, 5000); 6 | } 7 | 8 | function makeid() 9 | { 10 | var text = ""; 11 | var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 12 | for( var i=0; i < 5; i++ ){ 13 | text += possible.charAt(Math.floor(Math.random() * possible.length)); 14 | } 15 | return text; 16 | } 17 | 18 | $( document ).ready(function() { 19 | var apikey = "577ed0a645c8ac6e5b035fbe"; 20 | var myid = makeid(); 21 | var db = null; 22 | try { 23 | db = new restdb(apikey, {realtime: true}); 24 | $("#status").text("Ok, got the api").addClass("online"); 25 | hightlight("#init_block"); 26 | } catch (ex) { 27 | $("#status").text("Error loading jsapi"); 28 | } 29 | 30 | $("#oneliner").keyup(function(e){ 31 | if(e.keyCode == 13 && $(this).val() !== '') 32 | { 33 | hightlight("#input_block"); 34 | var payload = {"oneliner": $(this).val(), "userid": myid}; 35 | $(this).val(""); 36 | var newline = new db.chat(payload); 37 | newline.save(); 38 | } 39 | }); 40 | 41 | db.chat.on('POST', function(err, mess) { 42 | hightlight("#post_block"); 43 | var text = $("
").text(mess.data.userid + ": " + mess.data.oneliner); 44 | text.attr("id", mess.data._id); 45 | text.hide(); 46 | $("#messages").prepend(text); 47 | text.toggle("scale"); 48 | text.dblclick(function() { 49 | var deleteme = new db.chat({_id: mess.data._id}); 50 | deleteme.delete(); 51 | }); 52 | }); 53 | 54 | db.chat.on('PUT', function(err, mess) { 55 | hightlight("#put_block"); 56 | db.chat.find({"_id": mess.data}, {}, function(err, updatedline){ 57 | $("#"+mess.data).text(updatedline[0].oneliner); 58 | }); 59 | }); 60 | 61 | // double click on text to delete 62 | db.chat.on('DELETE', function(err, mess) { 63 | hightlight("#delete_block"); 64 | _.each(mess.data, function(oneid){ 65 | $("#"+oneid).remove(); 66 | }); 67 | }); 68 | 69 | db.on("CONNECT", function() { 70 | hightlight("#connect_block"); 71 | $("#status").addClass("online").removeClass("offline").text("online"); 72 | $("#messages").empty(); 73 | db.chat.find({}, {"$max": 100,"$orderby": {"_created": -1}}, function(err, lines){ 74 | _.each(lines, function(aline){ 75 | var text = $("
").text(aline.userid + ": " + aline.oneliner); 76 | text.attr("id", aline._id); 77 | $("#messages").append(text); 78 | text.dblclick(function() { 79 | var deleteme = new db.chat({_id: aline._id}); 80 | deleteme.delete(); 81 | }); 82 | }); 83 | }) 84 | 85 | }); 86 | db.on("DISCONNECT", function() { 87 | hightlight("#disconnect_block"); 88 | $("#status").removeClass("online").addClass("offline").text("offline"); 89 | }); 90 | db.on("RECONNECT", function() { 91 | hightlight("#reconnect_block"); 92 | $("#status").addClass("online").removeClass("offline").text("Back again"); 93 | }); 94 | 95 | 96 | 97 | }); -------------------------------------------------------------------------------- /restdb_io realtime chat/public/styles.css: -------------------------------------------------------------------------------- 1 | img { 2 | padding: 20px; 3 | max-width: 400px; 4 | } 5 | table { 6 | font-size: 12px; 7 | border-collapse: collapse; 8 | } 9 | td { 10 | white-space: pre-wrap; 11 | border: 1px solid gray; 12 | } 13 | .offline { 14 | color: red !important; 15 | } 16 | .online { 17 | color: green !important; 18 | } 19 | #messages { 20 | /* height: 400px; */ 21 | overflow: auto; 22 | background-color: #000; 23 | color: greenyellow; 24 | margin-top: 5px; 25 | font-family: sans-serif; 26 | font-weight: 100; 27 | font-size: 16px; 28 | padding-left: 10px; 29 | padding-right: 10px; 30 | } 31 | #oneliner { 32 | width: 100%; 33 | font-size: 16px; 34 | } 35 | 36 | .highlight { 37 | color: green; 38 | border: 4px solid gray; 39 | } 40 | 41 | pre { 42 | font-size: 10px; 43 | } 44 | 45 | .navbar-logo { 46 | position: relative; 47 | top: -5px; 48 | height: 68px; 49 | margin-top: -9px; 50 | } 51 | -------------------------------------------------------------------------------- /streamdata_io_chat/README.md: -------------------------------------------------------------------------------- 1 | # streamdata.io and restdb.io chat example 2 | 3 | Full story in this [blog-post](https://restdb.io/blog/#!posts/57026178d768113700004116). You might go there first. Live demo can be found [here](https://streamdata-68e1.restdb.io/public/streamdatatest) 4 | 5 | This example requires that you have a streamdata.io account set up (and of course a restdb.io account as well). 6 | 7 | To replicate this example for yourself, you should create a database with a simple collection named "Notifications" with two text fields: "message" and "nick". 8 | 9 | The next step is to create a restdb.io "Page" in your database and paste the contents of the index.html file into it. You should change the URLs so that they point to your database. 10 | 11 | Note: To access the restdb.io Page externally, you need to have a Basic subscription. 12 | 13 | Thanks to Bhaumik Patel for the [chat bootstrap template](http://bootsnipp.com/snippets/featured/chat-widget). 14 | 15 | Chat is only one example of live streaming data. The code for retrieving updated data using streamdata.io is identical for other scenarios. 16 | 17 | Have fun! 18 | 19 | chat screenshot 20 | 21 | 22 | --------------------------------------------------------------------------------