From 300cf02e687e4f00113fe07301fad1c1aa39b5ee Mon Sep 17 00:00:00 2001 From: Senthil Date: Thu, 20 Nov 2014 21:14:57 -0800 Subject: [PATCH] add sample apis --- Samples/datadog.js | 35 ++++++++++++++++++++++++++++++ Samples/github.rb | 24 +++++++++++++++++++++ Samples/imgur.py | 22 +++++++++++++++++++ Samples/pubnub.go | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 Samples/datadog.js create mode 100644 Samples/github.rb create mode 100644 Samples/imgur.py create mode 100644 Samples/pubnub.go diff --git a/Samples/datadog.js b/Samples/datadog.js new file mode 100644 index 0000000..74c8359 --- /dev/null +++ b/Samples/datadog.js @@ -0,0 +1,35 @@ +// Datadog is cloud Monitoring as a Service, where you can +// see metrics from all of your apps, tools & services in +// one place with Datadog's cloud monitoring as a service +// solution. +// +// This example streams the events sent to the api. +// +// Please see these for more information: +// +// http://docs.datadoghq.com/api/ +// https://github.com/brettlangdon/node-dogapi for more details + +var dogapi = require('dogapi'); + +var options = { + api_key: '', + app_key: '', +}; + +var api = new dogapi(options); + +var end = parseInt(new Date().getTime() / 1000); +var start = end - 86400; + +api.stream(start, end, function(error, result, status_code){ + if(error){ + console.log('Error: ', error); + console.log('Status Code: ', status_code); + return; + } + + result['events'].forEach(function(event){ + console.log(event['id'] + ': ' + event['title']); + }); +}); diff --git a/Samples/github.rb b/Samples/github.rb new file mode 100644 index 0000000..524681a --- /dev/null +++ b/Samples/github.rb @@ -0,0 +1,24 @@ +# Github is online project hosting using Git. Includes +# source-code browser, in-line editing, wikis, and ticketing. +# +# This example uses their ruby sdk to authenticate a user +# and make requests on their behalf. +# +# Please see these for more information: +# +# https://developer.github.com/v3/ +# https://github.com/octokit/octokit.rb + +require 'octokit' +require 'pry' + +Octokit.configure do |c| + c.login = '' + c.password = '' +end + +user = Octokit.user +puts user + +repo = Octokit.repo 'koding/global.hackathon' +puts repo diff --git a/Samples/imgur.py b/Samples/imgur.py new file mode 100644 index 0000000..2e3c19d --- /dev/null +++ b/Samples/imgur.py @@ -0,0 +1,22 @@ +# Imgur is used to share photos with social networks and +# on-line communities. +# +# This example uses python sdk to make an anonymous request +# to get the links of latest photos in the gallery. +# +# Please see these for more information: +# +# https://api.imgur.com +# https://github.com/Imgur/imgurpython + +from imgurpython import ImgurClient + +client_id = '' +client_secret = '' + +client = ImgurClient(client_id, client_secret) + +# Example request +items = client.gallery() +for item in items: + print(item.link) diff --git a/Samples/pubnub.go b/Samples/pubnub.go new file mode 100644 index 0000000..046ab66 --- /dev/null +++ b/Samples/pubnub.go @@ -0,0 +1,53 @@ +// PubNub is a Data Stream Network that enables developers to +// rapidly build realtime apps that scale globally, without +// worrying about infrastructure! +// +// This example publishes a event to a channel and then subscribes +// to receive that event. +// +// Please see these for more information: +// +// http://godoc.org/github.com/pubnub/go/messaging +// http://www.pubnub.com/developers/demos + +package main + +import ( + "fmt" + + "github.com/pubnub/go/messaging" +) + +const ( + PublishKey = "" + SubscribeKey = "" + SecretKey = "" + KodingChannel = "koding" + TimeToken = "1000" +) + +var () + +func main() { + var pub = messaging.NewPubnub(PublishKey, SubscribeKey, SecretKey, "", false, "") + + var errorChannel = make(chan []byte, 1) + var successChannel = make(chan []byte, 1) + var messageChannel = make(chan []byte, 1) + + pub.Subscribe(KodingChannel, TimeToken, messageChannel, false, errorChannel) + pub.Publish(KodingChannel, "Hello koders!", errorChannel, successChannel) + + for { + select { + case err := <-errorChannel: + fmt.Printf("Got error :%s\n", err) + case result := <-successChannel: + fmt.Printf("Success :%s\n", result) + case result := <-messageChannel: + fmt.Printf("Got message :%s\n", result) + } + } + + fmt.Println("Exit") +}