{"size": 1247, "ext": "js", "max_stars_repo_path": "src/js/util/url-builder.js", "max_stars_repo_name": "ComixZap/comixzap-browser-ui", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/js/util/url-builder.js", "max_issues_repo_name": "ComixZap/comixzap-browser-ui", "max_issues_repo_issues_event_min_datetime": "2015-01-24T15:41:26.000Z", "max_issues_repo_issues_event_max_datetime": "2015-01-24T15:52:13.000Z", "max_forks_repo_path": "src/js/util/url-builder.js", "max_forks_repo_name": "ComixZap/comixzap-browser-ui", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 29.6904761905, "max_line_length": 108, "alphanum_fraction": 0.6343223737}
'use strict';

var config = require('config');

var API_ROOT = config.api_root || '';
var FILES_URL = '/file-list';
var PAGES_URL = '/comic/list';
var IMAGE_URL = '/comic/image';

var UrlBuilder = module.exports = {
  setApiRoot: function (apiRoot) {
    API_ROOT = apiRoot;
  },
  getFileListUrl: function (path) {
    return API_ROOT + FILES_URL + UrlBuilder.objectToQueryString({directory: path}, '?');
  },
  getComicPagesUrl: function (path) {
    return API_ROOT + PAGES_URL + UrlBuilder.objectToQueryString({file: path}, '?');
  },
  getImageFilenameUrl: function (path, filename) {
    return API_ROOT + IMAGE_URL + UrlBuilder.objectToQueryString({file: path, extract_file: filename}, '?');
  },
  getImageOffsetUrl: function (path, offset) {
    return API_ROOT + IMAGE_URL + UrlBuilder.objectToQueryString({file: path, offset: offset}, '?');
  },
  objectToQueryString: function (obj, prefix) {
    var str,
      groups = [],
      prefix = prefix || '';
    for (var x in obj) {
      var value = obj[x];
      if (typeof value != 'undefined') {
        groups.push(encodeURIComponent(x) + '=' + encodeURIComponent(value));
      }
    }
    if (groups.length < 1) {
      return '';
    }
    return prefix + groups.join('&');
  }
};
