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:

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/permissions/profile/settings).

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 end user api key.

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 "YOTTAA-API-KEY: your-api-key-here" \\
  -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 "YOTTAA-API-KEY: your-api-key-here" \\
  -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 "YOTTAA-API-KEY: your-api-key-here" 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 "YOTTAA-API-KEY: your-api-key-here" 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 "YOTTAA-API-KEY: your-api-key-here" "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 "YOTTAA-API-KEY: your-api-key-here" http://localhost:9292/samples/506297afc3666e1df8000014

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

"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 "YOTTAA-API-KEY: your-api-key-here" \\
    "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 "YOTTAA-API-KEY: your-api-key-here" \\
  "https://api.yottaa.com/sites/4e2dfb5b0fcb1530e500000b"

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

Returns the ADN for a site

Overview:

Reads site's adn record.

URL:

/sites/<site_id>/adn

Requires Authentication:

YES

HTTP Method

GET

Parameters:

* site_id

Responses:

{
  document: <adn record>,
  success: true
}

Examples:

curl -v -H "YOTTAA-API-KEY: your-api-key-here" \\
  "https://api.yottaa.com/sites/1234567890abcdef/adn?user_id=9876543210"

- (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?user_id=<user_id>

Requires Authentication:

YES

HTTP Method

GET

Parameters:

* site_id

Responses:

{
  document: [<profile records>],
  success: true
}

Examples:

curl -v -H "YOTTAA-API-KEY: your-api-key-here" \\
  "https://api.yottaa.com/sites/1234567890abcdef/profiles?user_id=9876543210"

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

Returns a site profile

Overview:

Returns a site profile

URL:

/sites/<site_id>/profiles/<profile_id>?user_id=<user_id>

Requires Authentication:

YES

HTTP Method

GET

Parameters:

* site_id
* profile_id

Responses:

{
  document: <profile record>,
  success: true
}

Examples:

curl -v -H "YOTTAA-API-KEY: your-api-key-here" \\
  "https://api.yottaa.com/sites/1234567890abcdef/profiles/1234567890?user_id=9876543210"

- (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 "YOTTAA-API-KEY: your-api-key-here" \\
  "https://api.yottaa.com/sites/1234567890abcdef/settings"

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

Returns all the tods of a site.

Overview:

Returns all the tods of a site.

URL:

/sites/<site_id>/tods?user_id=<user_id>

Requires Authentication:

YES

HTTP Method

GET

Parameters:

* site_id

Responses:

{
  document: [<tod records>],
  success: true
}

Examples:

curl -v -H "YOTTAA-API-KEY: your-api-key-here" \\
  "https://api.yottaa.com/sites/1234567890abcdef/tods?user_id=9876543210"

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

Returns a site Tod

Overview:

Returns a site Tod

URL:

/sites/<site_id>/tods/<profile_id>?user_id=<user_id>

Requires Authentication:

YES

HTTP Method

GET

Parameters:

* site_id
* profile_id

Responses:

{
  document: <tod record>,
  success: true
}

Examples:

curl -v -H "YOTTAA-API-KEY: your-api-key-here" \\
  "https://api.yottaa.com/sites/1234567890abcdef/tods/1234567890?user_id=9876543210"

- (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 "YOTTAA-API-KEY: your-api-key-here" 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 "YOTTAA-API-KEY: your-api-key-here" http://localhost:9292/tests/506297afc3666e1df8000014

- (Object) GET '/users/email'

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

Get the IP addresses of all TPUs & Load Balancers for all sites of the user

Overview:

Fetch all sites of the user; for each site's topology, fetch all Load Balancers and TPUs in the topology.

URL:

/YottaaIPs

Requires Authentication:

YES

HTTP Method

GET

Parameters:

none

Responses:

[
   *all IP addresses*
]

Examples:

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

- (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 "YOTTAA-API-KEY: your-api-key-here" \\
  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 "YOTTAA-API-KEY: your-api-key-here" \\
    -d "host=www.yottaa.com" \\
    "https://api.yottaa.com/sites"

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

Purge cache

Overview:

This YOTTAA Purge API (beta version) let the caller can flexible to purge a resource, and can purge multiple resources(up to 15) via just one call. This API will try to respond as soon as possible, therefor, there is no guarantee that requested resources has been purged when purge service respond. A tracking list will return within response, by detecting the list, users will be able to know whether the target resource have purge.

URL:

/sites/<site_id>/purge_cache

Requires Authentication:

YES

HTTP Method

POST

Parameters:

*site_id
profile_id #if not exist, then purge site's all profiles

Body:

Body string must be JSON format, and the schema should be:
[
  {
    domain: "www.example.com",
    condition:"/index.html", # the page to purge.
    name:"URI", # URI, Just support "URI" for now.
    content_type: "css", # css | js, You need to spefify this if the resource is css or js.
  },
  ...
]

If domain is not specified, the site host will be used as default.

Responses:

if success
  return {success: true}
else
  return {error: 'error message....'}

Examples:

End user:

curl -v -H "YOTTAA-API-KEY: xxxxxxx" \\
   --data  '[{"domain": "www.example.com", "condition":"/jscombine/tc002.html", "name":"URI", "content_type":"css"}]'  \\
   "https://api.yottaa.com/sites/50c1a28fafbc1e2ded00001b/purge_cache?profile_id=522e7f96c3666e029f0000df&user_id=xxxxxxx"

OAuth 2.0:

curl -v -H "YOTTAA-API-KEY: your-api-key-here" \

--data "[{\"condition\": \"/1.css\", \"name\": \"URI\", \"domain\": \"www.example.com\", \"content_type\": \"css\"}]" \\
"https://api.yottaa.com/sites/1234567890abcdef/purge_cache?profile_id=522e7f96c3666e029f0000df"

- (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 "YOTTAA-API-KEY: your-api-key-here" \\
  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 "YOTTAA-API-KEY: your-api-key-here" \\
  -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 "YOTTAA-API-KEY: your-api-key-here" \\
  -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 "YOTTAA-API-KEY: your-api-key-here" \\
  https://api.yottaa.com/optimizers/abcdefg1234567890/bypass

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

Change the state of the site to Maintenance

Overview:

Change the state of the site to Maintenance

URL:

optimizers/<site_id>/maintenance

Parameters:

none

Requires Authentication:

YES

HTTP Method

PUT

Examples:

curl PUT \\
  -H "YOTTAA-API-KEY: your-api-key-here" \\
  https://api.yottaa.com/optimizers/abcdefg1234567890/maintenance

- (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 "YOTTAA-API-KEY: your-api-key-here" \\
  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 "YOTTAA-API-KEY: your-api-key-here" \\
  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 "YOTTAA-API-KEY: your-api-key-here" \\
  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 "YOTTAA-API-KEY: your-api-key-here" \\
  -X PUT \\
  "https://api.yottaa.com/sites/1234567890abcdef/flush_cache"