<commit_before># SPOC - SharePoint Online Connector.

SPOC is a client-side Javascript library (with NO dependencies) that helps you interact with the **SharePoint Online & Yammer REST APIs**. It also contains handy helper and utility functions that are regularly used when working on Front-end SharePoint projects. The library currently lets you interact with:  

  - Sites
  - Lists
  - List Items
  - User Profiles
  - Yammer Messages
  - Yammer Profiles 
  
## Getting Started
First download  **SPOC.min.js** from this repo and include it in your project or add it to your masterpage or page layouts. Note that **If you want to interact with Yammer from within SharePoint Online, you must also include the Yammer JS SDK** by adding the following into your masterpage or page layouts (must be loaded before SPOC.min.js).

```html 
<script type="text/javascript" data-app-id="ADD YAMMER APP ID" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script>
```
> To use the Yammer API, you must first register an app on your network and set the app-id shown above. You can find out how to do this by visting the [Yammer help pages](https://developer.yammer.com/docs/app-registration)

## Basic Examples
##### 1. Get all items from a List
This example shows how to get list items from a list in the current site
```javascript
// Create a new site instance. Passing no url with set it as the current site
var site = new SPOC.SP.Site();

// Pass in the name of the list that you want to query 
var exampleList = site.listItems('List Name');

// Query list and retrive results in a JS promise
exampleList.query().then(function(results){
    console.log(results);
});

```
##### 1. Get filtered items from a List
The list item method allows you to pass in filters and query settings via a JS object. It supports all default OData query string operators (select, filter, orderBy, expand, top etc) More information can be found on [MSDN](https://msdn.microsoft.com/en-us/library/office/fp142385.aspx#sectionSection0)    
```javascript
// Create a new site instance. Passing no url with set it as the current site
var site = new SPOC.SP.Site();

// Create an object with your required settings
    var settings = {
        select: "Title,Created",
        filter: "Title eq 'My Item Title'",
        orderBy: 'Created'
    };
// Pass in the name of the list that you want to query 
var exampleList = site.listItems('List Name');

// Query list and retrive results in a JS promise
exampleList.query().then(function(results){
    console.log(results);
});

```
##### 2. Create a new list item to a list in a subsite
This example shows how to create a new list item to a list in a different site to that being viewed
```javascript
// Create a new site instance. Pass in the url to the subsite that contains the list
var subSite = new SPOC.SP.Site('https://example.sharepoint.com/sites/mysite/mysubsite');

// Create an object with a property for each column.
    var item = {
        Title: "My Item title,
        description: "text for the description column"
    };
// Pass in the name of the list that you want to query 
var exampleList = subSite.listItems('List Name');

// Query list and retrive results in a JS promise. This examples includes handling errors via a error callback
exampleList.create(item).then(function(results){
    console.log(results);
}, function(err){
    console.log(err);
});

```

##### 3. Get the current users profile details
This examples shows how to get the current users profile properties
```javascript<commit_msg>Fix(): Readme error<commit_after># SPOC - SharePoint Online Connector.

SPOC is a client-side Javascript library (with NO dependencies) that helps you interact with the **SharePoint Online & Yammer REST APIs**. It also contains handy helper and utility functions that are regularly used when working on Front-end SharePoint projects. The library currently lets you interact with:  

  - Sites
  - Lists
  - List Items
  - User Profiles
  - Yammer Messages
  - Yammer Profiles 
  
## Getting Started
First download  **SPOC.min.js** from this repo and include it in your project or add it to your masterpage or page layouts. Note that **If you want to interact with Yammer from within SharePoint Online, you must also include the Yammer JS SDK** by adding the following into your masterpage or page layouts (must be loaded before SPOC.min.js).

```html 
<script type="text/javascript" data-app-id="ADD YAMMER APP ID" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script>
```
> To use the Yammer API, you must first register an app on your network and set the app-id shown above. You can find out how to do this by visting the [Yammer help pages](https://developer.yammer.com/docs/app-registration)

## Basic Examples
##### 1. Get all items from a List
This example shows how to get list items from a list in the current site
```javascript
// Create a new site instance. Passing no url with set it as the current site
var site = new SPOC.SP.Site();

// Pass in the name of the list that you want to query 
var exampleList = site.listItems('List Name');

// Query list and retrive results in a JS promise
exampleList.query().then(function(results){
    console.log(results);
});

```
##### 1. Get filtered items from a List
The list item method allows you to pass in filters and query settings via a JS object. It supports all default OData query string operators (select, filter, orderBy, expand, top etc) More information can be found on [MSDN](https://msdn.microsoft.com/en-us/library/office/fp142385.aspx#sectionSection0)

```javascript
// Create a new site instance. Passing no url with set it as the current site
var site = new SPOC.SP.Site();

// Create an object with your required settings
    var settings = {
        select: "Title,Created",
        filter: "Title eq 'My Item Title'",
        orderBy: 'Created'
    };

// Pass in the name of the list that you want to query 
var exampleList = site.listItems('List Name');

// Query list and retrive results in a JS promise
exampleList.query().then(function(results){
    console.log(results);
});

```

##### 2. Create a new list item to a list in a subsite
This example shows how to create a new list item to a list in a different site to that being viewed

```javascript
// Create a new site instance. Pass in the url to the subsite that contains the list
var subSite = new SPOC.SP.Site('https://example.sharepoint.com/sites/mysite/mysubsite');

// Create an object with a property for each column.
    var item = {
        Title: "My Item title,
        description: "text for the description column"
    };
    
// Pass in the name of the list that you want to query 
var exampleList = subSite.listItems('List Name');

// Query list and retrive results in a JS promise. This examples includes handling errors via a error callback
exampleList.create(item).then(function(results){
    console.log(results);
}, function(err){
    console.log(err);
});

```

##### 3. Get the current users profile details
This examples shows how to get the current users profile properties

```javascript
{'fraction_non_alphanumeric': 0.09005338578252318, 'fraction_numerical': 0.003652711435796572, 'mean_word_length': 3.781061114842176, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2031664', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1902, 'n_words': 951}