{"id":20485284,"url":"https://github.com/runnable/api-client","last_synced_at":"2025-03-05T16:23:32.363Z","repository":{"id":70964419,"uuid":"52130100","full_name":"Runnable/api-client","owner":"Runnable","description":null,"archived":false,"fork":false,"pushed_at":"2019-10-23T22:59:21.000Z","size":189,"stargazers_count":0,"open_issues_count":58,"forks_count":0,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-02-16T07:17:10.974Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Runnable.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-20T01:19:15.000Z","updated_at":"2016-02-20T01:19:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"e22af2cf-d798-41e9-90bf-ccdb71e8a9d7","html_url":"https://github.com/Runnable/api-client","commit_stats":{"total_commits":98,"total_committers":9,"mean_commits":10.88888888888889,"dds":0.6836734693877551,"last_synced_commit":"e6089c4ed0b8c6ed383a82cbd50514e1e720f154"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Runnable%2Fapi-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Runnable%2Fapi-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Runnable%2Fapi-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Runnable%2Fapi-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Runnable","download_url":"https://codeload.github.com/Runnable/api-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242058990,"owners_count":20065202,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T16:29:11.011Z","updated_at":"2025-03-05T16:23:32.340Z","avatar_url":"https://github.com/Runnable.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"runnable-api-client\n===================\n\n[![Build Status](https://travis-ci.org/Runnable/api-client.svg?branch=master)](https://travis-ci.org/Runnable/api-client)\n\nRunnable Api Client\n\n# Usage\n\n## Users\n\n### Tokenless\n```js\nvar user = new Runnable();\n```\n\n### Github Login\n```js\nvar user = new Runnable();\n\nuser.githubLogin(function (err, body) {\n  // ...\n});\n```\n\n### Github Token Login\n```js\nvar user = new Runnable();\n\nuser.githubLogin(token, function (err, body) {\n  // ...\n});\n```\n\n### Logout\n```js\nvar user = new Runnable();\n\nuser.logout('user', 'pass', function (err, body) {\n  // ...\n});\n```\n\n## Resources\n\n### First level resource (projects)\n```js\nvar user = new Runnable();\n\nuser.login('user', 'pass', function (err, body) {\n  // fetch a specific resource\n  var project = user.fetchProject(projectId, function (err, body, code) {\n    // project becomes a project model\n  });\n  // factory methods and parent actions\n  project = user.newProject(attrs, opts);\n  project = user.fetchProject(projectId, cb);\n  project = user.createProject({ json: data }, cb);\n  project = user.updateProject(projectId, { json: data }, cb);\n  user.destroyProject(projectId, cb);\n  // model methods\n  project.fetch(cb); // fetch latest\n  project.update({ json: attrs }, cb); // update the resource attrs\n  project.destroy(cb); // delete the resource through the api\n  project.toJSON(); // last clientside known state of the resource\n\n  // fetch a collection of resources\n  var projects = user.fetchProjects(projectId, function (err, body, code) {\n    // project becomes a collection of projects\n  });\n  projects.models; // are all models of the resources fetched\n});\n```\n\n\n# Development\n\n## How to add a Model\n\nRunnable api client's directory structure follows the api url\nstructure and the structure of our resources.\n\n### Example - Adding a model for project environments:\nProject environments are a nested resource - /projects/:id/environments/:id\n\n#### Create a new file - lib/models/project/environment.js\n\nNote: the singular form of each resource used for the folder and file names.\n\n```js\n'use strict';\n\nvar util = require('util');\nvar Base = require('../base');\nvar urlJoin = require('../../url-join');\n\nmodule.exports = Environment;\n\nfunction Environment (attr, opts) {\n  opts = opts || {};\n  opts.urlPath = urlJoin(opts.parentPath, 'environments');\n  return Base.apply(this, arguments);\n}\n\nutil.inherits(Environment, Base);\n```\n\nAll (99%) of the new models will inherit from the Base Model class like the example above.\nNested Models use `urlJoin(opts.parentPath, \u003crelativePath\u003e)` create their urlPath using\nopts.parentPath. `opts` are being passed to the constructor from `extend-with-factories`\nwhich is explained below. First level resources like Projects (/projects), just need their\nurlPath set directly `Projects.prototype.urlPath = 'projects'` or `opts.urlPath = 'projects'`.\n\n#### Update the parent model Class - lib/models/project.js\n\nThe parent model in this example is Project. Here is the Project Class:\n\n```js\nvar util = require('util');\nvar Base = require('./base');\n\nmodule.exports = Project;\n\nfunction Project () {\n  return Base.apply(this, arguments);\n}\n\nutil.inherits(Project, Base);\n\nProject.prototype.urlPath = 'projects';\n```\n\nAdd the following line to the parent model to automagically create submodel factory/action methods:\n```js\nrequire('../extend-with-factories')(Project);\n```\n\n#### Example usage of the newly created environment model\n\n```js\nvar projectId = \"real-project-id\";\nvar user = new Runnable(), environment;\n\nuser.anonymous(function (err) {\n  if (err) { throw err; }\n\n  var project = user.fetchProject(projectId, function (err) {\n    if (err) { throw err; }\n\n    // automagical environment factory methods:\n    environment = project.newEnvironment(attrs, opts);  // create a new environment instance\n    environment = project.fetchEnvironment(projectId, cb); // fetches an environment instance from the api server\n    environment = project.createEnvironment({ json: attrs }, cb); // makes a post request to create a new environment\n    // automagical environment action methods:\n    project.updateEnvironment(projectId, { json: attrs }, cb);\n    project.destroyEnvironment(projectId, cb);\n\n    // Action methods inherited by the Base Model\n    environment.fetch(cb); // get latest data from server\n    environment.update({ json: attrs }, cb);\n    environment.destroy(cb);\n  });\n});\n\n```\n\n## How to add a Collection\n\nCreating a collection is very similar to the model example. The only difference is that you\nshould inherit from the Base collection. Also, factory methods created use the plural form\nof the resource name - Ex: `project.getEnvironments(cb)`. There are examples of all types of\nmodels and collections (first level and nested), when in doubt look for an existing example\nin the code base.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frunnable%2Fapi-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frunnable%2Fapi-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frunnable%2Fapi-client/lists"}