Skip to content

Instantly share code, notes, and snippets.

@Frenchcooc
Last active June 12, 2019 13:21
Show Gist options
  • Save Frenchcooc/4693c214245ba8fe572e89472ef9dfe4 to your computer and use it in GitHub Desktop.
Save Frenchcooc/4693c214245ba8fe572e89472ef9dfe4 to your computer and use it in GitHub Desktop.
Collection of different SDK

Below is a collection of different SDK for the following APIs:

Stripe

Source: https://stripe.com/docs/api/checkout/sessions/object

const stripe = require("stripe")("sk_test_4eC39HqLyjWDarjtT1zdp7dc");

stripe.checkout.sessions.create({
  success_url: "https://example.com/success",
  cancel_url: "https://example.com/cancel",
  payment_method_types: ["card"],
  line_items: [{
    name: "T-shirt",
    description: "Comfortable cotton t-shirt",
    amount: 1500,
    currency: "usd",
    quantity: 2
  }]
}, function(err, session) {
  // asynchronously called
});
import stripe
stripe.api_key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"

stripe.checkout.Session.create(
  success_url="https://example.com/success",
  cancel_url="https://example.com/cancel",
  payment_method_types=["card"],
  line_items=[
    {
      "name": "T-shirt",
      "description": "Comfortable cotton t-shirt",
      "amount": 1500,
      "currency": "usd",
      "quantity": 2
    }
  ]
)
require 'stripe'
Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'

Stripe::Checkout::Session.create({
  success_url: "https://example.com/success",
  cancel_url: "https://example.com/cancel",
  payment_method_types: ["card"],
  line_items: [{
    name: "T-shirt",
    description: "Comfortable cotton t-shirt",
    amount: 1500,
    currency: "usd",
    quantity: 2,
  }],
})

Twilio

var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // Your Account SID from www.twilio.com/console
var authToken = 'your_auth_token';   // Your Auth Token from www.twilio.com/console

var twilio = require('twilio');
var client = new twilio(accountSid, authToken);

client.messages.create({
    body: 'Hello from Node',
    to: '+12345678901',  // Text this number
    from: '+12345678901' // From a valid Twilio number
})
.then((message) => console.log(message.sid));

Source: https://www.twilio.com/docs/libraries/node

from twilio.rest import Client

# Your Account SID from twilio.com/console
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# Your Auth Token from twilio.com/console
auth_token  = "your_auth_token"

client = Client(account_sid, auth_token)

message = client.messages.create(
    to="+15558675309", 
    from_="+15017250604",
    body="Hello from Python!")

print(message.sid)

Source: https://www.twilio.com/docs/libraries/python

require 'twilio-ruby'

account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # Your Account SID from www.twilio.com/console
auth_token = "your_auth_token"   # Your Auth Token from www.twilio.com/console

@client = Twilio::REST::Client.new account_sid, auth_token
message = @client.messages.create(
    body: "Hello from Ruby",
    to: "+12345678901",    # Replace with your phone number
    from: "+12345678901")  # Replace with your Twilio number

puts message.sid

Source: https://www.twilio.com/docs/libraries/ruby

<?php
// Required if your environment does not handle autoloading
require __DIR__ . '/vendor/autoload.php';

// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;

// Your Account SID and Auth Token from twilio.com/console
$sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$token = 'your_auth_token';
$client = new Client($sid, $token);

// Use the client to do fun stuff like send text messages!
$client->messages->create(
    // the number you'd like to send the message to
    '+15558675309',
    array(
        // A Twilio phone number you purchased at twilio.com/console
        'from' => '+15017250604',
        // the body of the text message you'd like to send
        'body' => 'Hey Jenny! Good luck on the bar exam!'
    )
);

Source: https://www.twilio.com/docs/libraries/php

AWS

// Load the SDK and UUID
var AWS = require('aws-sdk');
var uuid = require('uuid');

// Create unique bucket name
var bucketName = 'node-sdk-sample-' + uuid.v4();
// Create name for uploaded object key
var keyName = 'hello_world.txt';

// Create a promise on S3 service object
var bucketPromise = new AWS.S3({apiVersion: '2006-03-01'}).createBucket({Bucket: bucketName}).promise();

// Handle promise fulfilled/rejected states
bucketPromise.then(
  function(data) {
    // Create params for putObject call
    var objectParams = {Bucket: bucketName, Key: keyName, Body: 'Hello World!'};
    // Create object upload promise
    var uploadPromise = new AWS.S3({apiVersion: '2006-03-01'}).putObject(objectParams).promise();
    uploadPromise.then(
      function(data) {
        console.log("Successfully uploaded data to " + bucketName + "/" + keyName);
      });
}).catch(
  function(err) {
    console.error(err, err.stack);
});

Source: https://docs.aws.amazon.com/fr_fr/sdk-for-javascript/v2/developer-guide/getting-started-nodejs.html

import boto3
s3 = boto3.resource('s3')
copy_source = {
    'Bucket': 'mybucket',
    'Key': 'mykey'
}
bucket = s3.Bucket('otherbucket')
bucket.copy(copy_source, 'otherkey')

Source: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#bucket

# list buckets in Amazon S3
s3 = Aws::S3::Client.new
resp = s3.list_buckets
resp.buckets.map(&:name)
#=> ["bucket-1", "bucket-2", ...]

Source: https://github.com/aws/aws-sdk-ruby#api-clients

Googleapis

const {google} = require('googleapis');
const sampleClient = require('../sampleclient');

// initialize the Youtube API library
const youtube = google.youtube({
  version: 'v3',
  auth: sampleClient.oAuth2Client,
});

// a very simple example of searching for youtube videos
async function runSample() {
  const res = await youtube.search.list({
    part: 'id,snippet',
    q: 'Node.js on Google Cloud',
  });
  console.log(res.data);
}

const scopes = ['https://www.googleapis.com/auth/youtube'];

sampleClient
  .authenticate(scopes)
  .then(runSample)
  .catch(console.error);

Source: https://github.com/googleapis/google-api-nodejs-client/blob/master/samples/youtube/search.js

# Call the search.list method to retrieve results matching the specified
# query term.
search_response = youtube.search().list(
  q=options.q,
  part='id,snippet',
  maxResults=options.max_results
).execute()

Source: https://github.com/youtube/api-samples/blob/master/python/search.py

client = Google::APIClient.new(
  :key => DEVELOPER_KEY,
  :authorization => nil,
  :application_name => $PROGRAM_NAME,
  :application_version => '1.0.0'
)
youtube = client.discovered_api(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION)
  
# Call the search.list method to retrieve results matching the specified
# query term.
search_response = client.execute!(
  :api_method => youtube.search.list,
  :parameters => {
    :part => 'snippet',
    :q => opts[:q],
    :maxResults => opts[:max_results]
  }
)
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, new HttpRequestInitializer() {
    public void initialize(HttpRequest request) throws IOException {
    }
}).setApplicationName("youtube-cmdline-search-sample").build();

// Prompt the user to enter a query term.
String queryTerm = getInputQuery();

// Define the API request for retrieving search results.
YouTube.Search.List search = youtube.search().list("id,snippet");

// Set your developer key from the {{ Google Cloud Console }} for
// non-authenticated requests. See:
// {{ https://cloud.google.com/console }}
String apiKey = properties.getProperty("youtube.apikey");
search.setKey(apiKey);
search.setQ(queryTerm);

// Restrict the search results to only include videos. See:
// https://developers.google.com/youtube/v3/docs/search/list#type
search.setType("video");

// To increase efficiency, only retrieve the fields that the
// application uses.
search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url)");
search.setMaxResults(NUMBER_OF_VIDEOS_RETURNED);

// Call the API and print results.
SearchListResponse searchResponse = search.execute();
List<SearchResult> searchResultList = searchResponse.getItems();
if (searchResultList != null) {
    prettyPrint(searchResultList.iterator(), queryTerm);
}

Source: https://github.com/youtube/api-samples/blob/master/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/Search.java

Evernote

Source: https://dev.evernote.com/doc/

var client = new Evernote.Client({
  consumerKey: 'my-consumer-key',
  consumerSecret: 'my-consumer-secret',
  sandbox: true,
  china: false,
});
client.getAccessToken(req.session.oauthToken,
  req.session.oauthTokenSecret,
  req.query.oauth_verifier,
function(error, oauthToken, oauthTokenSecret, results) {
  if (error) {
    // do your error handling
  } else {
    // oauthAccessToken is the token you need;
    var authenticatedClient = new Evernote.Client({
      token: oauthToken,
      sandbox: true,
      china: false,
    });
    var noteStore = authenticatedClient.getNoteStore();
    noteStore.listNotebooks().then(function(notebooks) {
      console.log(notebooks); // the user's notebooks!
    });
  }
});
dev_token = "put your dev token here"
client = EvernoteClient(token=dev_token)
userStore = client.get_user_store()
user = userStore.getUser()
print user.username
<?php
require __DIR__ . '/../../vendor/autoload.php';

$token = '%YOUR_TOKEN%';
$sandbox = true;
$china   = false;
$client = new \Evernote\Client($token, $sandbox, null, null, $china);

$note         = new \Evernote\Model\Note();
$note->title  = 'Test note';
$note->content = new \Evernote\Model\PlainTextNoteContent('Some plain text content.');
$note->tagNames = array('tag1', 'tag2');

$notebook = null;
$client->uploadNote($note, $notebook);

Leanplum

Source: https://docs.leanplum.com/reference

// This value should be set to true only if you're developing on your server.
var isDevelopmentMode = true;

// Sample variables. This can be any JSON object.
var variables = {
 items: {
   color: 'red',
   size: 20,
   showBadges: true
 },
 showAds: true
};

// We've inserted your Test API keys here for you :)
if (isDevelopmentMode) {
 Leanplum.setAppIdForDevelopmentMode("YOUR_APP_ID", "YOUR_DEVELOPMENT_KEY");
} else {
 Leanplum.setAppIdForProductionMode("YOUR_APP_ID", "YOUR_PRODUCTION_KEY");
}

Leanplum.setVariables(variables);
Leanplum.start(function(success) {
 console.log('Success: ' + success);
 console.log('Variables', Leanplum.getVariables());
});
import UIKit
#if DEBUG
    import AdSupport
#endif
import Leanplum

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
  Leanplum.setAppId("YOUR_APP_ID",
      withProductionKey: "YOUR_PRODUCTION_KEY")

  Leanplum.trackInAppPurchases()
  Leanplum.trackAllAppScreens()
  
  Leanplum.setAppVersion("2.4.1")

  Leanplum.start()

  return true
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment