Socket
Book a DemoInstallSign in
Socket

md-notes-resource

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

md-notes-resource

2.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

Getting Started with MdNotes

Getting Started

Introduction

API for Markdown Notes app.

Install the Package

Install the gem from the command line:

gem install md-notes-resource -v 2.0

Or add the gem to your Gemfile and run bundle:

gem 'md-notes-resource', '2.0'

For additional gem details, see the RubyGems page for the md-notes-resource gem.

Initialize the API Client

The following parameters are configurable for the API Client:

ParameterTypeDescription
o_auth_client_idStringOAuth 2 Client ID
o_auth_client_secretStringOAuth 2 Client Secret
o_auth_usernameStringOAuth 2 Resource Owner Username
o_auth_passwordStringOAuth 2 Resource Owner Password
timeoutFloatThe value to use for connection timeout.
Default: 60
max_retriesIntegerThe number of times to retry an endpoint call if it fails.
Default: 0
retry_intervalFloatPause in seconds between retries.
Default: 1
backoff_factorFloatThe amount to multiply each successive retry's interval amount by in order to provide backoff.
Default: 2
retry_statusesArrayA list of HTTP statuses to retry.
Default: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524]
retry_methodsArrayA list of HTTP methods to retry.
Default: %i[get put]
o_auth_tokenOAuthTokenObject for storing information about the OAuth token

The API client can be initialized as follows:

client = MdNotes::Client.new(
  o_auth_client_id: 'OAuthClientId',
  o_auth_client_secret: 'OAuthClientSecret',
  o_auth_username: 'OAuthUsername',
  o_auth_password: 'OAuthPassword',
)

Authorization

The SDK will attempt to authorize by providing no scopes in case an endpoint requiring authentication is called. You can also authorize the client yourself.

Your application must obtain user authorization before it can execute an endpoint call. The SDK uses OAuth 2.0 Authorization to authorize the client.

The authorize() method will exchange the user's credentials for an access token. The access token is an object containing information for authorizing client requests and refreshing the token itself.

begin
  client.auth.authorize()
rescue OAuthProviderException => ex
  # handle exception
rescue APIException => ex
  # handle exception
end

The client can now make authorized endpoint calls.

Refreshing the token

An access token may expire after sometime. To extend its lifetime, you must refresh the token.

if client.auth.is_token_expired
  begin
    client.auth.refresh_token
  rescue OAuthProviderException => ex
    # handle exception
  end
end

If a token expires, the SDK will attempt to automatically refresh the token before the next endpoint call requiring authentication.

Storing an access token for reuse

It is recommended that you store the access token for reuse.

# store token
save_token_to_database(client.config.o_auth_token)

Creating a client from a stored token

To authorize a client from a stored access token, just set the access token in Configuration along with the other configuration parameters before creating the client:

# load token later...
client.config.o_auth_token = load_token_from_database

# Set other configuration, then instantiate client
client = Client.new

Complete example

require 'md_notes'

include md_notes

# function for storing token to database
def save_token_to_database(token)
  # code to save the token to database
end

# function for loading token from database
def load_token_from_database
  # load token from database and return it (return nil if no token exists)
end

# create a new client
client = MdNotes::Client.new(
  o_auth_client_id: 'OAuthClientId',
  o_auth_client_secret: 'OAuthClientSecret',
  o_auth_username: 'OAuthUsername',
  o_auth_password: 'OAuthPassword',
)

# obtain access token, needed for client to be authorized
previous_token = load_token_from_database
if previous_token
  # restore previous access token
  client.config.o_auth_token = previous_token
else
  # obtain new access token
  begin
    client.auth.authorize()
  rescue OAuthProviderException => ex
    # handle exception
  rescue APIException => ex
    # handle exception
  end
end

# the client is now authorized; you can use client to make endpoint calls
# client will automatically refresh the token when it expires and call the token update callback

Client Class Documentation

MdNotes Client

The gateway for the SDK. This class acts as a factory for the Controllers and also holds the configuration of the SDK.

Controllers

NameDescription
serviceGets ServiceController
userGets UserController
o_auth_authorizationGets OAuthAuthorizationController

API Reference

List of APIs

  • Service
  • User

Service

Overview

Get instance

An instance of the ServiceController class can be accessed from the API Client.

service_controller = client.service

Get Status

def get_status
Response Type

ServiceStatus

Example Usage
result = service_controller.get_status()

User

Overview

Get instance

An instance of the UserController class can be accessed from the API Client.

user_controller = client.user

Get User

def get_user
Response Type

User

Example Usage
result = user_controller.get_user()

Model Reference

Structures

Note

Class Name

Note

Fields
NameTypeTagsDescription
idLongRequired-
titleStringRequired-
bodyStringRequired-
user_idLongRequired-
created_atStringRequired-
updated_atStringRequired-
Example (as JSON)
{
  "id": 112,
  "title": "title4",
  "body": "body6",
  "user_id": 208,
  "created_at": "created_at2",
  "updated_at": "updated_at4"
}

Service Status

Class Name

ServiceStatus

Fields
NameTypeTagsDescription
appStringRequired-
motoStringRequired-
notesIntegerRequired-
usersIntegerRequired-
timeStringRequired-
osStringRequired-
php_versionStringRequired-
statusStringRequired-
Example (as JSON)
{
  "app": "app2",
  "moto": "moto8",
  "notes": 134,
  "users": 202,
  "time": "time0",
  "os": "os8",
  "php_version": "php_version4",
  "status": "status8"
}

User

Class Name

User

Fields
NameTypeTagsDescription
idIntegerRequired-
nameStringRequired-
emailStringRequired-
created_atStringRequired-
updated_atStringRequired-
Example (as JSON)
{
  "id": 112,
  "name": "name0",
  "email": "email6",
  "created_at": "created_at2",
  "updated_at": "updated_at4"
}

O Auth Token

OAuth 2 Authorization endpoint response

Class Name

OAuthToken

Fields
NameTypeTagsDescription
access_tokenStringRequiredAccess token
token_typeStringRequiredType of access token
expires_inLongOptionalTime in seconds before the access token expires
scopeStringOptionalList of scopes granted
This is a space-delimited list of strings.
expiryLongOptionalTime of token expiry as unix timestamp (UTC)
refresh_tokenStringOptionalRefresh token
Used to get a new access token when it expires.
Example (as JSON)
{
  "access_token": "access_token8",
  "token_type": "token_type2",
  "expires_in": null,
  "scope": null,
  "expiry": null,
  "refresh_token": null
}

Enumerations

O Auth Provider Error

OAuth 2 Authorization error codes

Class Name

OAuthProviderErrorEnum

Fields
NameDescription
INVALID_REQUESTThe request is missing a required parameter, includes an unsupported parameter value (other than grant type), repeats a parameter, includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed.
INVALID_CLIENTClient authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method).
INVALID_GRANTThe provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.
UNAUTHORIZED_CLIENTThe authenticated client is not authorized to use this authorization grant type.
UNSUPPORTED_GRANT_TYPEThe authorization grant type is not supported by the authorization server.
INVALID_SCOPEThe requested scope is invalid, unknown, malformed, or exceeds the scope granted by the resource owner.

Exceptions

O Auth Provider

OAuth 2 Authorization endpoint exception.

Class Name

OAuthProviderException

Fields
NameTypeTagsDescription
errorOAuthProviderErrorEnumRequiredGets or sets error code.
error_descriptionStringOptionalGets or sets human-readable text providing additional information on error.
Used to assist the client developer in understanding the error that occurred.
error_uriStringOptionalGets or sets a URI identifying a human-readable web page with information about the error, used to provide the client developer with additional information about the error.
Example (as JSON)
{
  "error": "invalid_request",
  "error_description": null,
  "error_uri": null
}

Utility Classes Documentation

ApiHelper Class

API utility class.

Methods

NameReturn TypeDescription
json_deserializeHashDeserializes a JSON string to a Ruby Hash.
rfc3339DateTimeSafely converts a string into an RFC3339 DateTime object.

Common Code Documentation

HttpResponse

Http response received.

Properties

NameTypeDescription
status_codeIntegerThe status code returned by the server.
reason_phraseStringThe reason phrase returned by the server.
headersHashResponse headers.
raw_bodyStringResponse body.
requestHttpRequestThe request that resulted in this response.

HttpRequest

Represents a single Http Request.

Properties

NameTypeTagDescription
http_methodHttpMethodEnumThe HTTP method of the request.
query_urlStringThe endpoint URL for the API request.
headersHashOptionalRequest headers.
parametersHashOptionalRequest body.

FAQs

Package last updated on 24 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.