Skip to content

Instantly share code, notes, and snippets.

View iaintshine's full-sized avatar

Boguslaw Mista iaintshine

View GitHub Profile
@iaintshine
iaintshine / lead_samples.php
Created June 18, 2015 20:57
Base PHP wrapper samples related to leads
<?php
require 'vendor/autoload.php';
function getAccessToken()
{
$token = getenv("BASECRM_ACCESS_TOKEN");
if (!$token) throw new Exception('"BASECRM_ACCESS_TOKEN" environment variable has not been found.');
return $token;
}
@iaintshine
iaintshine / basecrm_create_lead.php
Created June 17, 2015 22:58
Create a new lead using php 5.3 and Base API v2
<?php
function createLead($accessToken, array $lead)
{
$method = 'post';
$absUrl = 'https://api.getbase.com/v2/leads';
$headers = array(
'User-Agent: BaseCRM/PHP Sample',
'Authorization: Bearer ' . $accessToken,
'Accept: application/json',
@iaintshine
iaintshine / basecrm_sync_sample.php
Created June 12, 2015 09:55
Sample usage of Base CRM high-level Sync API wrapper
<?php
require 'vendor/autoload.php';
function getAccessToken()
{
$token = getenv("BASECRM_ACCESS_TOKEN");
if (!$token) throw new Exception('"BASECRM_ACCESS_TOKEN" environment variable has not been found');
return $token;
}
@iaintshine
iaintshine / test_mock.py
Created June 1, 2015 21:05
python mock consecutive calls example
import unittest
try:
from unittest import mock
except ImportError:
import mock
class SyncTests(unittest.TestCase):
@property
def device_uuid(self):
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace basecrmcsharp
{
class MainClass
{
public static void Main (string[] args)
@iaintshine
iaintshine / fetch_deals.php
Created April 22, 2015 17:37
Fetch first page of deals
<?php
// create a new intsance of BaseCRM php client
$client = new \BaseCRM\Client(['accessToken' => getenv('BASECRM_ACCESS_TOKEN')]);
// fetch first 100 deals
$deals = $client->deals->all(['page' => 1, 'per_page' => 100]);
// write deals to csv
$csv = fopen("/tmp/deals.csv", "w");
@iaintshine
iaintshine / envelope_json_parsing.go
Created January 29, 2015 11:06
Parsing nested json payloads wrapped in envelope in golang
package main
import "fmt"
import "encoding/json"
type NestedData struct {
Nested string `json:"nested"`
}
type Data struct {
@iaintshine
iaintshine / passing_context.go
Created January 26, 2015 22:33
Passing context between golang's http handlers using unsafe pointer
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"unsafe"
)
@iaintshine
iaintshine / bearer_token_authorization.md
Last active August 29, 2015 14:11
OAuth 2 server authorization algorithms

Bearer token authorisation:

Errors (status code, error code, description):

HTTP status code error code (error) description (message) WWW-Authenticate
401 (unauthorized) token_missing Request lacks any authentication information. Bearer realm="OAuth API”
400 (bad request) invalid_request The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed. Bearer realm="OAuth API", error="#{code}", error_description="#{message}”
401 (unauthorized) invalid_token The access token provided is expired, revoked, malformed, or invalid for other reasons. Bearer realm="OAuth API", error="#{code}", error_description="#{message}”
401 (unauthorised) insufficient_scope The request requires higher privileges than provided by the access token. `Bearer realm="OAuth API", error="#{code}", error_description="#{messa
@iaintshine
iaintshine / quick_sort.rb
Created August 15, 2014 09:37
A Ruby implementation of a Quicksort Algorithm
require 'test/unit'
module Sort
extend self
def quicksort(container)
return container if container.size < 2
pivot = container.size / 2
e = container[pivot]