Class: UserApi

Inherits:
Sinatra::Base
  • Object
show all
Includes:
Helpers, YottaaAuth
Defined in:
controllers/users_api.rb

Overview

Overview:

Users API allow 3rd party applications to access information and setting that are within a user.

And Users API also allow end user to access your own data at Yottaa.

Authentication:

3rd Party Application

For 3rd party applications can access the Users API using OAuth 2.0 specification. For more information on OAuth 2.0, you can go to:

http://hueniverse.com/2010/05/introducing-oauth-2-0
http://tools.ietf.org/html/draft-ietf-oauth-v2-10

End User

For end user, you can access Users API with your API Key and User ID, and you can get them at your "API Key" Page (apps.yottaa.com/dashboard/settings/api_key).

You can flush your site's CDN cache like this:

curl -H "YOTTAA-API-KEY: your-api-key-here" \\
  -X PUT \\
  -F "user_id=your-user-id" \\
  "https://api.yottaa.com/sites/site-id/flush_cache"

Get your sites list like this:

curl -H "YOTTAA-API-KEY: your-api-key-here" "https://api.yottaa.com/sites?user_id=your-user-id-here"

Get detail of one site:

curl -H "YOTTAA-API-KEY: your-api-key-here" "https://api.yottaa.com/sites/site-id-here?user_id=your-user-id-here"

To create one site:

curl -H "YOTTAA-API-KEY: your-api-key-here" \\
  -F "host=www.yoursite.com" \\
  -F "user_id=your-user-id" \\
  "https://api.yottaa.com/sites"

Note: All the examples below in this documentation are for 3rd party applications using OAuth2, end user just need to follow the examples above.

OAuth 2.0:

Which kind of application can use Users API?

Currently, we only support Web Applications to use the Users API and the OAuth 2.0.

Being browser based, a web application or service is able to use the full web-based OAuth process which means the user has the smoothest of the authentication methods. It is important you manage the association of OAuth tokens to your application's user identities carefully. The way you do this will be dependent on your application and setup.

How long does an access token last?

We do not currently expire access tokens. Your access token will be invalid if a user explicitly rejects your application from their authorizations or if Yottaa suspends your application. If your application is suspended there will be a note on your API page saying that it has been suspended.

Usage:

You need to create your own application to use Users API, here is what you need to do before start using Users API.

1. You need to go to https://apps.yottaa.com/dashboard/settings/api_key page, click "Get new API key" button to generate an API key.
2. Click the "Add App" button to create your own app.
3. Click the "Get Client Secret" button to get your app's client id and client secret.
4. You can use your app's client id, client secret, url, and redirect url(the redirect_uri parameter) to use the Users API now.

Remember that you need to make sure the redirect url matches the redirect_uri parameter when you make a API request, and when your app's callback url changed, you need to update the application information in the API Key & Authorized Apps(apps.yottaa.com/dashboard/settings/api_key) page as well.

We have some code samples for how to use Users API in different languages, you can check it here.

Instance Method Summary (collapse)

Instance Method Details

- (Object) DELETE '/monitors.?:response_type?'

Remove monitors.

Overview:

Remove monitors

URL:

/monitors

Requires Authentication:

YES

HTTP Method

DELETE

Parameters:

NONE

Body

ids: [
  id1,
  id2,
  ...
]

Examples:

curl -H "Authorization: OAuth 1488858a0d746aca3d1705939b102097f41c997500066ca9eb4d51973f4130b1" \\
  -X DELETE --data "{\"ids\":[\"506297afc3666e1df8000014\"]}" http://api.yottaa.com/monitors

Responses:

[

{
  monitor json
}

]

- (Object) DELETE '/tests.?:response_type?'

Remove tests.

Overview:

Remove tests

URL:

/tests

Requires Authentication:

YES

HTTP Method

DELETE

Parameters:

NONE

Body

ids: [id1, id2, ...]

Examples:

curl -H "Authorization: OAuth 1488858a0d746aca3d1705939b102097f41c997500066ca9eb4d51973f4130b1" \\
  -X DELETE --data "{\"ids\":[\"506297afc3666e1df8000014\"]}" http://api.yottaa.com/tests

Responses:

[

{
  test json
}

]

- (Object) GET '/monitors.?:response_type?'

Get monitor list

Overview:

Returns all the monitors of a user, the default is to return the first (per_page) monitors, if the (page) is given in the url, it will return the monitors in that page. per_page is up to 100, default is 10.

URL:

/monitors

Filtering Parameters:

per_page

The maximum number of tests objects that are returned for this request. Default (10)

page

The set of test objects that are returned. Example page=2&per_page=7. The request will return 8-14. Default (1)

search_term

allows you to filter the test by name. Default (null)

Requires Authentication:

YES

HTTP Method

GET

Examples:

curl -H "Authorization: OAuth 1488858a0d746aca3d1705939b102097f41c997500066ca9eb4d51973f4130b1" http://localhost:9292/monitors

Responses:

[

rows: {
  See the API for /monitors/<monitor_id>.json
}

]

- (Object) GET '/monitors/:monitor_id.?:response_type?'

Get a monitor

Overview:

get monitor detail data

URL:

/monitors/<monitor_id>

Parameters:

* monitor_id: the id of the user's monitor

Requires Authentication:

YES

HTTP Method

GET

Examples:

curl -H "Authorization: OAuth 1488858a0d746aca3d1705939b102097f41c997500066ca9eb4d51973f4130b1" http://localhost:9292/monitors/5062989cc3666e1df8000019

- (Object) GET '/samples.?:response_type?'

Retrieve sample list

Overview:

fetch sample list

URL:

/samples

Filtering Parameters:

**is required, others are optional:

**profile_and_locations

specify some monitor/test and some locations

per_page

The maximum number of tests objects that are returned for this request. Default (10)

page

The set of test objects that are returned. Example page=2&per_page=7. The request will return 8-14. Default (1)

Search Parameters:

All search parameters are optional.

metrics

specify one or multi metric data to return (Array)

from

The beginning of the time range to search for. The value is a JavaScript date String, or UTC long vaue

to

The end of the time range to search for. The value is a JavaScript date String, or UTC long vaue

location

An array of locations to query. The location is the data_center field of the Location object.s To find the available browsers use the location API.

sample_type

specify which type samples to be return -1: all, 0: no issue, 1: warning issue, 2: error issue, 3: critical issue

Parameter Example:

{

"from":"10/29/2012 00:00",
"per_page":"10",
"profile_and_locations":[
  {
    "profile_id":"50889e27c3666e04b9000015",
    "locations":["Oregon"],
    "location":"All Locations"
  }
],
"to":"10/31/2012 23:59",
"page":"1",
"metrics":["time_to_interact","yottaa_score","last_byte"],
"sample_type":"-1"

}

Requires Authentication:

YES

HTTP Method

GET

Examples:

curl -H "Authorization: OAuth 1488858a0d746aca3d1705939b102097f41c997500066ca9eb4d51973f4130b1" "http://api.yottaa.com/samples?sample_type=-1&from=10%2F29%2F2012+00%3A00&to=10%2F31%2F2012+23%3A59&type=null&metrics%5B%5D=time_to_interact&metrics%5B%5D=yottaa_score&metrics%5B%5D=last_byte&profile_and_locations%5B0%5D%5Bprofile_id%5D=50889e27c3666e04b9000015&profile_and_locations%5B0%5D%5Blocation%5D=All+Locations&profile_and_locations%5B0%5D%5Blocations%5D%5B%5D=Oregon&per_page=10&page=1"

- (Object) GET '/samples/:sample_id.?:response_type?'

Retrieve sample detail

Overview:

fetch one sample

URL:

/samples/<sample_id>

Parameters:

* sample_id: the id of sample

screenshots

(boolean) - default is false. If you want to have the screenshots include then you must add screenshots=true

Requires Authentication:

YES

HTTP Method

GET

Examples:

curl -H "Authorization: OAuth 1488858a0d746aca3d1705939b102097f41c997500066ca9eb4d51973f4130b1" http://localhost:9292/samples/506297afc3666e1df8000014

- (Object) GET '/sites.?:response_type?'

Returns all the sites of a user.

Overview:

Returns all the sites of a user.

URL:

sites

Requires Authentication:

NO

HTTP Method

GET

Parameters:

host: Search sites with host name. If this is not specified, all sites will be returned.

Responses:

{

sites: [
          {
              "id": "4e2dfb5b0fcb1530e500000b",
              "host": "www.google.com",
              "optimizer": "preview",
              "portal_url": "https://www.yottaa.com/dashboard/sites/4e2dfb5b0fcb1530e500000b",
              "api_url": "https://api.yottaa.com/sites/4e2dfb5b0fcb1530e500000b",
              "yottaa_cname: "1234567890abcde.yottaa.org",
              "preview_url" : "https://apps.yottaa.com/framework/web/sites/4e2dfb5b0fcb1530e500000c/optimizer?first_time=true
          }
      ]

}

Examples:

curl -v -H "Authorization: OAuth 31d2c228d16043fcb8606c68316ca61da775033efb82d12e875e5c3fa43d1584" \\
    "https://api.yottaa.com/sites"

- (Object) GET '/sites/:site_id.?:response_type?'

Returns a single site's overview information.

Overview:

Returns a single site's overview information.

URL:

sites/<site-id>

Requires Authentication:

NO

HTTP Method

GET

Parameters:

NONE

Responses:

"id": "4e2dfb5b0fcb1530e500000b",
"host": "www.google.com",
"optimizer": "preview",
"portal_url": "https://www.yottaa.com/dashboard/sites/4e2dfb5b0fcb1530e500000b",
"api_url": "https://api.yottaa.com/sites/4e2dfb5b0fcb1530e500000b",
"yottaa_cname": "1234567890abdefg.yottaa.org",
"preview_url" : "https://apps.yottaa.com/framework/web/sites/4e2dfb5b0fcb1530e500000c/optimizer?first_time=true

Examples:

curl -v -H "Authorization: OAuth 31d2c228d16043fcb8606c68316ca61da775033efb82d12e875e5c3fa43d1584" \\
  "https://api.yottaa.com/sites/4e2dfb5b0fcb1530e500000b"

- (Object) GET '/sites/:site_id/profiles.?:response_type?'

Returns all the profiles of a site.

Overview:

Returns all the profiles of a site.

URL:

/sites/<site_id>/profiles

Requires Authentication:

NO

HTTP Method

GET

Parameters:

*site_id

Responses:

type => 0: general/default profile, 1: user defined

{

profiles: [
          {
              "id": "522e7f96c3666e029f0000df",
              "name": "Default Profile",
              "type": 0,
              "enabled": true
          },
          {
              "id": "522e7f97c3666e029f0000ff",
              "name": "Mobile",
              "type": 1,
              "enabled": false
          }
      ]

}

Examples:

curl -v -H "Authorization: OAuth 31d2c228d16043fcb8606c68316ca61da775033efb82d12e875e5c3fa43d1584" \\
    "https://api.yottaa.com/sites/4e2dfb5b0fcb1530e500000b/profiles"

- (Object) GET '/sites/:site_id/profiles/:profile_id.?:response_type?'

Returns a single profile's overview information.

Overview:

Returns a single profile's overview information.

URL:

/sites/<site_id>/profiles/<profile_id>

Requires Authentication:

NO

HTTP Method

GET

Parameters:

*site_id *profile_id

Responses:

type => 0: general/default profile, 1: user defined

"id": "522e7f96c3666e029f0000df",
"name": "Default Profile",
"type": 0,
"enabled": true

Examples:

curl -v -H "Authorization: OAuth 31d2c228d16043fcb8606c68316ca61da775033efb82d12e875e5c3fa43d1584" \\
    "https://api.yottaa.com/sites/4e2dfb5b0fcb1530e500000b/profiles/522e7f96c3666e029f0000df"

- (Object) GET '/sites/:site_id/settings.?:response_type?'

Get site's default profile's optimization settings

Overview:

Return site's default profile's optimization settings.

URL:

sites/<site_id>/settings

Requires Authentication:

YES

HTTP Method

GET

Parameters:

* site_id

Responses:

{
   "defaultActions": {
     "documentActions": {
       "badAssetRemoval": [
         {
           "_id": "5073c776c3666e6c7700001f",
           "enabled": true,
           "filters": []
         }
       ],
       ..
   },
   "resourceRules": [ ],
   "documentRules": [ ]
}

Examples:

curl -v -H "Authorization: OAuth 31d2c228d16043fcb8606c68316ca61da775033efb82d12e875e5c3fa43d1584" \\
  "https://api.yottaa.com/sites/1234567890abcdef/settings"

- (Object) GET '/tests.?:response_type?'

Get test list

Overview:

Returns all the tests of a user, the default is to return the first (per_page) tests, if the (page) is given in the url, it will return the tests in that page. per_page is up to 100, default is 10.

URL:

/tests

Filtering Parameters:

per_page

The maximum number of tests objects that are returned for this request. Default (10)

page

The set of test objects that are returned. Example page=2&per_page=7. The request will return 8-14. Default (1)

search_term

allows you to filter the test by name. Default (null)

Requires Authentication:

YES

HTTP Method

GET

Examples:

curl -H "Authorization: OAuth 1488858a0d746aca3d1705939b102097f41c997500066ca9eb4d51973f4130b1" http://localhost:9292/tests

Responses:

[

rows: {
  See the API for /tests/<test_id>.json
}

]

- (Object) GET '/tests/:test_id.?:response_type?'

Get a test

Overview:

get test detail data

URL:

/tests/<test_id>

Parameters:

* test_id: the id of the user's test

Requires Authentication:

YES

HTTP Method

GET

Examples:

curl -H "Authorization: OAuth 1488858a0d746aca3d1705939b102097f41c997500066ca9eb4d51973f4130b1" http://localhost:9292/tests/506297afc3666e1df8000014

- (Object) GET '/users/email'

- (Object) POST '/monitors.?:response_type?'

Create a monitor

Overview:

create a monitor for partner

URL:

/monitors

Body

"name": "Webpage Monitor",
"user_id": "4e2dfb5b0fcb1530e500000b",
"constants": {
  url: "www.baidu.com"
  protocol: "{HTTP | HTTPS"
  http_headers: {[
      {
        name: "",
        value: ""
      }
  ]}, //DEFAULT(NULL)
  auth: "bob", password: "123456"
},
"template_type": "multi-location",
"variables": {
  locations: ["SFO", "DC",... ],
  connectivities: [{
     bandwidth_down: "", //Kbps
     bandwidth_up: "", //Kbps
     latency: "", //MS
     drop_rate: "" //%
  }, ...]
},
"timing" : {
  "interval": INT (> 5) Minutes,
  "policy": | PARALLEL,
  "duration": INT, //if test
  "run_times": INT, //if test is count
},
"type": "| WEBPAGE",
"status": "| RUNNING | SUSPENDED",
"suspended_message": "some status message for why it was suspended"

}

If the type of the monitor is equal to HTTP

{

"constants": {
  http_method: {POST | GET | DELETE | PUT} //DEFAULT(GET)
  http_body: "" //DEFAULT(NULL)
},
"type": "HTTP"

}

If the type of the monitor is equal to WEBPAGE

{

"constants": {
  screenshots: {true | false} //DEFAULT(false)
  browser_cache: {EMPTY | EMPTY_AND_FULL} //DEFAULT(EMPTY)
},
"variables": {
  browsers: [{
    name: "Firefox",
    version: "7.0"
  }]
},
"type": "WEBPAGE"

}

Requires Authentication:

YES

HTTP Method

POST

Examples:

curl -X POST \\
  --data "{\"user_id\": \"4ec1c53d421aa904c800005a\", \"name\":\"chenlei\", \"template_type\":\"multi-location\", \"timing\":{\"interval\":\"14400\"}, \"variables\":{\"browsers\":[{\"name\":\"chrome\", \"version\":\"latest\"}], \"connectivities\": [{\"bandwidth_up\":\"6144\", \"drop_rate\":\"0\", \"bandwidth_down\":\"45056\", \"latency\":\"4\"}], \"locations\":[\"San Francisco\", \"Washington DC\"]}, \"type\":\"webpage\", \"constants\":{\"browser_cache\":\"EMPTY\", \"url\":\"www.google.com\", \"protocol\":\"HTTP\"}, \"status\":\"running\", \"screen_capture\":true}" \\
  -H "Authorization: OAuth 31d2c228d16043fcb8606c68316ca61da775033efb82d12e875e5c3fa43d1584" \\
  http://api.yottaa.com/monitors

- (Object) POST '/sites.?:response_type?'

Adds a site to the user account

Overview:

Adds a site to the users account. The site will be created with one keypage which is the homepage. The homepage will be automatically monitored for performance data.

URL:

sites

Requires Authentication:

NO

HTTP Method

PUT

Parameters:

*host

Responses:

{
 "site_id": "4e2dfb5b0fcb1530e500000b",
 "host": "www.yottaa.com",
 "yottaa_cname": "1234567890abcde.yottaa.org"
}

Examples:

curl -v -H "Authorization: OAuth 31d2c228d16043fcb8606c68316ca61da775033efb82d12e875e5c3fa43d1584" \\
    -d "host=www.yottaa.com" \\
    "https://api.yottaa.com/sites"

- (Object) POST '/sites/:site_id/purge_cache.?:response_type?'

- (Object) POST '/tests.?:response_type?'

Create a test

Overview:

create a test for partner

URL:

/tests

Body

refer to create a monitor

Requires Authentication:

YES

HTTP Method

POST

Examples:

curl -X POST \\
  --data "{\"user_id\": \"4ec1c53d421aa904c800005a\", \"template_type\":\"multi-location\",\"duration\":{\"policy\":\"COUNT\",\"length\":1},\"variables\":{\"browsers\":[{\"name\":\"ie\",\"version\":\"9\"}],\"connectivities\":[{\"bandwidth_up\":\"6144\",\"bandwidth_down\":\"45056\",\"drop_rate\":\"0\",\"latency\":\"4\"}],\"locations\":[\"San Francisco\",\"Washington DC\"]},\"type\":\"webpage\",\"constants\":{\"url\":\"www.baidu.com\",\"browser_cache\":\"EMPTY\",\"screenshots\":true}}" \\
  -H "Authorization: OAuth 31d2c228d16043fcb8606c68316ca61da775033efb82d12e875e5c3fa43d1584" \\
  https://api.yottaa.com/tests

- (Object) PUT '/monitors/:monitor_id/start.?:response_type?'

Start a monitor.

Overview:

Start a monitor

URL:

/monitors/<monitor_id>/start

Requires Authentication:

YES

HTTP Method

PUT

Parameters:

NONE

Examples:

curl -H "Authorization: OAuth 1488858a0d746aca3d1705939b102097f41c997500066ca9eb4d51973f4130b1" \\
  -X PUT https://api.yottaa.com/monitors/1488858a0d746aca3d1/start

Responses:

[

{
  monitor json
}

]

- (Object) PUT '/monitors/:monitor_id/stop.?:response_type?'

Pause a monitor.

Overview:

Pause a monitor

URL:

/monitors/<monitor_id>/pause

Requires Authentication:

YES

HTTP Method

PUT

Parameters:

NONE

Examples:

curl -H "Authorization: OAuth 1488858a0d746aca3d1705939b102097f41c997500066ca9eb4d51973f4130b1" \\
  -X PUT https://api.yottaa.com/monitors/1488858a0d746aca3d1/pause

Responses:

[

{
  monitor json
}

]

- (Object) PUT '/optimizers/:site_id/bypass.?:response_type?'

Pause the optimizer to 'bypass' for the site.

Overview:

Pause the optimizer to 'bypass' for the site.

URL:

optimizers/<site_id>/bypass

Parameters:

none

Requires Authentication:

YES

HTTP Method

PUT

Examples:

curl PUT \\
  -H "Authorization: OAuth 31d2c228d16043fcb8606c68316ca61da775033efb82d12e875e5c3fa43d1584" \\
  https://api.yottaa.com/optimizers/abcdefg1234567890/bypass

- (Object) PUT '/optimizers/:site_id/pause.?:response_type?'

Pause the optimizer to 'bypass' for the site.

Overview:

Pause the optimizer to 'bypass' for the site. This API will be retired in next version, please the new API:

put '/optimizers/:site_id/bypass.?:response_type?'

instead.

URL:

optimizers/<site_id>/pause

Parameters:

none

Requires Authentication:

YES

HTTP Method

PUT

Examples:

curl PUT \\
  -H "Authorization: OAuth 31d2c228d16043fcb8606c68316ca61da775033efb82d12e875e5c3fa43d1584" \\
  https://api.yottaa.com/optimizers/abcdefg1234567890/pause

- (Object) PUT '/optimizers/:site_id/resume.?:response_type?'

Resume the optimizer for the site

Overview:

Resume the optimizer for the site.

URL:

optimizers/<site_id>/resume

Parameters:

none

Requires Authentication:

YES

HTTP Method

PUT

Examples:

curl -X PUT \\
  -H "Authorization: OAuth 31d2c228d16043fcb8606c68316ca61da775033efb82d12e875e5c3fa43d1584" \\
  https://api.yottaa.com/optimizers/abcdefg1234567890/resume

- (Object) PUT '/optimizers/:site_id/transparent.?:response_type?'

Pause the optimizer to 'transparent' for the site.

Overview:

Pause the optimizer to 'transparent' for the site.

URL:

optimizers/<site_id>/transparent

Parameters:

none

Requires Authentication:

YES

HTTP Method

PUT

Examples:

curl PUT \\
  -H "Authorization: OAuth 31d2c228d16043fcb8606c68316ca61da775033efb82d12e875e5c3fa43d1584" \\
  https://api.yottaa.com/optimizers/abcdefg1234567890/transparent

- (Object) PUT '/sites/:site_id/flush_cache.?:response_type?'

Flush default profile's CDN cache

Overview:

Flush default profile's CDN cache.

URL:

/sites/<site_id>/flush_cache

Requires Authentication:

YES

HTTP Method

PUT

Parameters:

* site_id

Responses:

{
  success: true
}

Examples:

curl -v -H "Authorization: OAuth 31d2c228d16043fcb8606c68316ca61da775033efb82d12e875e5c3fa43d1584" \\
  -X PUT \\
  "https://api.yottaa.com/sites/1234567890abcdef/flush_cache"