appril-cli 0.2.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d28e060372bfb237fc2f55ce5f175d22638b826
4
- data.tar.gz: 3c8ff729036829a42d8325e03beb31c133327db9
3
+ metadata.gz: f1dc24aad4f54cd214c7e2cf371da2dfaa73a585
4
+ data.tar.gz: 73a5ddff69205eac86f5c391030d3bb0e1219853
5
5
  SHA512:
6
- metadata.gz: 670bdd5a1c68d0455a57bb1780fececf8a3051664767481a06a0a2899c20d4753f7191fe5943cce7395b1f0f92422f84923dae4fe19c4b0aa35ef718c4fff7ab
7
- data.tar.gz: 70cad4caf1e501927fcb530e2a956891c9c4a39f37344d5189a08c74f5687a0c193298158a9fc17129eab97fef595a3c1c165c04e5003f461c204ed557076623
6
+ metadata.gz: f5fedc40fc4c6dd2fe67f8d90a2c548ac796eea2f324597a70b2b59b8a2877e94127b9d2bef1880312203589e2520c7087340ec03a80f2b32a503c7735869454
7
+ data.tar.gz: d76ea8aab153e7d1ea3c03b0f2eb74f1e536bd1794590b72e8e994f953550e7f89e5a8e4350db7c00b0b75ff1056bf4cf2bdea01535c9cf16dff84dd61dd46bd
@@ -12,3 +12,6 @@ export function on_response(response) {
12
12
  export function on_error(error) {
13
13
  Alert.error(error)
14
14
  }
15
+
16
+ // extra headers to be appended to every request
17
+ export const headers = {}
@@ -1,15 +1,14 @@
1
1
  import {reduce} from 'lodash'
2
2
  import {urlify} from 'appril-utils'
3
- import xhr_api_builder from './api/xhr'
4
- import rtcp_api_builder from './api/rtcp'
5
- import * as callbacks from './api/callbacks'
3
+ import xhr from 'appril-api/xhr'
6
4
  import rtcp from './rtcp'
5
+ import * as callbacks_and_headers from 'base/api'
7
6
  import {components, default_api} from 'app/appril.json'
8
7
 
9
8
  export default reduce(components, function(map,component) {
10
9
  component.url = urlify(component.url)
11
- component.xhr = xhr_api_builder(component, callbacks)
12
- component.rtcp = rtcp_api_builder(component, rtcp)
10
+ component.xhr = xhr(component, callbacks_and_headers)
11
+ component.rtcp = rtcp.api(component)
13
12
  Object.defineProperty(component, 'api', {get() {return component[default_api]}})
14
13
  map[component.name] = component
15
14
  return map
@@ -1,14 +1,16 @@
1
- import {map, filter} from 'lodash'
1
+ import {map, filter, compact} from 'lodash'
2
2
  import Vue from 'vue'
3
3
  import VueRouter from 'vue-router'
4
4
 
5
5
  import components from './components'
6
6
  import store from './store'
7
7
  import componentify from './component'
8
- import {client_url} from 'app/appril.json'
8
+ import {dev_server_url, client_url} from 'app/appril.json'
9
9
 
10
10
  Vue.use(VueRouter)
11
11
 
12
+ const BASEURL = compact([dev_server_url, client_url, APP_ENV]).join('')
13
+
12
14
  export default new VueRouter({
13
15
  mode: 'history',
14
16
  base: __dirname,
@@ -16,7 +18,7 @@ export default new VueRouter({
16
18
  return {
17
19
  name: component.name,
18
20
  path: component.url_pattern,
19
- component: (resolve, reject) => load_component(component, resolve, reject)
21
+ component: (resolve) => load_component(component, resolve)
20
22
  }
21
23
  })
22
24
  })
@@ -34,7 +36,7 @@ function resolve_component(component, constructor, resolve) {
34
36
  }
35
37
  }
36
38
 
37
- function load_component(component, resolve, reject) {
39
+ function load_component(component, resolve) {
38
40
  const xhr = new XMLHttpRequest()
39
41
 
40
42
  xhr.onreadystatechange = function() {
@@ -42,16 +44,16 @@ function load_component(component, resolve, reject) {
42
44
  return
43
45
 
44
46
  if (parseInt(xhr.status / 100) !== 2)
45
- return reject(xhr.responseText)
47
+ return console.error(xhr.responseText)
46
48
 
47
49
  resolve_component(component, _eval(xhr.responseText), resolve)
48
50
  }
49
51
 
50
- xhr.onerror = function() {
51
- reject('Network error occurred')
52
+ xhr.onerror = function(error = 'Network error occurred') {
53
+ console.error(error)
52
54
  }
53
55
 
54
- xhr.open('GET', `${client_url}/${APP_ENV}/${component.entry_path}.js`)
56
+ xhr.open('GET', `${BASEURL}/${component.entry_path}.js`)
55
57
  xhr.send()
56
58
  }
57
59
 
@@ -1,8 +1,8 @@
1
- import RTCP from 'appril-rtcp'
2
- import * as callbacks from './api/callbacks'
1
+ import RTCP from 'appril-api/rtcp'
2
+ import * as callbacks_and_headers from 'base/api'
3
3
  import {server_url} from 'app/appril.json'
4
4
 
5
- const rtcp = new RTCP(callbacks)
5
+ const rtcp = new RTCP(callbacks_and_headers)
6
6
 
7
7
  rtcp.connect({
8
8
  // make sure this URL is matching RTCPController URL
@@ -2,15 +2,17 @@ class BaseController < Appril::BaseController
2
2
  include Helpers
3
3
  include UserHelpers
4
4
 
5
- map Cfg.server_url
5
+ map(Cfg.server_url)
6
+
7
+ engine(:Liquid)
8
+
9
+ define_layout(:layout, {file: '../templates/layout'})
10
+ layout(:layout)
6
11
 
7
- define_layout :layout, file: '../templates/layout'
8
- layout :layout
9
- engine :Liquid
10
12
  define_template(:index) {''}
11
13
 
12
14
  # highly important setup, do NOT remove
13
- define_template_var(:client_url, File.join(Cfg.client_url, environment).freeze)
15
+ define_template_var(:client_url, File.join(Cfg.dev_server_url.to_s, Cfg.client_url, environment).freeze)
14
16
 
15
17
  def index
16
18
  render
@@ -0,0 +1 @@
1
+ # dev_server_url: http://localhost:8080
@@ -21,6 +21,7 @@ module Appril
21
21
  build_path: config[:build_path],
22
22
  client_url: config[:client_url],
23
23
  server_url: config[:server_url],
24
+ dev_server_url: config[:dev_server_url],
24
25
  default_api: config[:default_api],
25
26
  components: components
26
27
  })
data/app/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "version": "0.0.0",
4
4
  "description": "...",
5
5
  "devDependencies": {
6
- "appril-rtcp": "0",
6
+ "appril-api": ">= 0.0.1",
7
7
  "appril-alert": ">= 0.0.5",
8
8
  "appril-polyfills": ">= 0.0.2",
9
9
  "appril-url": ">= 0.0.5",
@@ -1,5 +1,5 @@
1
1
  module Appril
2
2
  class CLI
3
- VERSION = '0.2.9'.freeze
3
+ VERSION = '0.3.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appril-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Slee Woo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-17 00:00:00.000000000 Z
11
+ date: 2016-08-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Appril CLI
14
14
  email:
@@ -24,14 +24,10 @@ files:
24
24
  - app/.pryrc
25
25
  - app/Gemfile
26
26
  - app/Rakefile
27
+ - app/base/api.js
27
28
  - app/base/app.js
28
29
  - app/base/assets/app.css
29
30
  - app/base/boot.rb
30
- - app/base/bootstrap/api/callbacks.js
31
- - app/base/bootstrap/api/request-methods.js
32
- - app/base/bootstrap/api/rtcp.js
33
- - app/base/bootstrap/api/validate-arguments.js
34
- - app/base/bootstrap/api/xhr.js
35
31
  - app/base/bootstrap/component.js
36
32
  - app/base/bootstrap/components.js
37
33
  - app/base/bootstrap/router.js
@@ -125,5 +121,5 @@ rubyforge_project:
125
121
  rubygems_version: 2.5.1
126
122
  signing_key:
127
123
  specification_version: 4
128
- summary: '["appril-cli-0.2.9", "Appril CLI"]'
124
+ summary: '["appril-cli-0.3.0", "Appril CLI"]'
129
125
  test_files: []
@@ -1,7 +0,0 @@
1
- export default [
2
- 'GET',
3
- 'POST',
4
- 'PUT',
5
- 'DELETE',
6
- 'HEAD'
7
- ]
@@ -1,28 +0,0 @@
1
- import {reduce} from 'lodash'
2
- import validate_arguments from './validate-arguments'
3
- import REQUEST_METHODS from './request-methods'
4
-
5
- export default function(component, rtcp) {
6
-
7
- return reduce(component.api || [], function(component_api, method) {
8
- component_api[method] = function(...args) {
9
-
10
- validate_arguments(args)
11
-
12
- return reduce(REQUEST_METHODS, function(method_api, request_method) {
13
- method_api[request_method.toLowerCase()] = function(callbacks) {
14
-
15
- rtcp.call_server_method(
16
- component.controller_name,
17
- method,
18
- args,
19
- request_method,
20
- callbacks
21
- )
22
- }
23
- return method_api
24
- }, {})
25
- }
26
- return component_api
27
- }, {})
28
- }
@@ -1,29 +0,0 @@
1
- import {forEach} from 'lodash'
2
-
3
- const STRING = '[object String]'
4
- const NUMBER = '[object Number]'
5
- const OBJECT = '[object Object]'
6
-
7
- function get_type(arg) {
8
- const type = Object.prototype.toString.call(arg)
9
- return {
10
- is_string: type === STRING,
11
- is_number: type === NUMBER,
12
- is_object: type === OBJECT,
13
- }
14
- }
15
-
16
- export default function(args) {
17
- forEach(args, function(arg,i) {
18
-
19
- const {is_string, is_number, is_object} = get_type(arg)
20
-
21
- if (!is_string && !is_number && !is_object) {
22
- throw `Api methods accepts only Strings, Numbers and Objects as arguments. Argument #${i} is a ${type} instead.`
23
- }
24
-
25
- if (is_object && i + 1 !== args.length) {
26
- throw `Only last argument can be a Object`
27
- }
28
- })
29
- }
@@ -1,88 +0,0 @@
1
- import {reduce, isObject, isArray, isFunction, last} from 'lodash'
2
- import {url_builder} from 'appril-utils'
3
- import validate_arguments from './validate-arguments'
4
- import REQUEST_METHODS from './request-methods'
5
-
6
- export default function(component, {on_request, on_response, on_error} = {}) {
7
-
8
- return reduce(component.api || [], function(component_api, method) {
9
-
10
- component_api[method] = function(...args) {
11
-
12
- validate_arguments(args)
13
-
14
- return reduce(REQUEST_METHODS, function(method_api, request_method) {
15
-
16
- const is_post = request_method === 'POST'
17
-
18
- method_api[request_method.toLowerCase()] = function(callbacks = {}) {
19
-
20
- const error_reporter = function(error_message) {
21
- if (callbacks.error)
22
- return callbacks.error(error_message)
23
- if (on_error)
24
- return on_error(error_message)
25
- throw error_message
26
- }
27
-
28
- const xhr = new XMLHttpRequest()
29
-
30
- let params = last(args)
31
-
32
- if (isObject(params)) {
33
- if (is_post) {
34
- args.pop()
35
- }
36
- } else {
37
- params = {}
38
- }
39
-
40
- on_request && on_request(params)
41
-
42
- xhr.onreadystatechange = function() {
43
- if (xhr.readyState !== XMLHttpRequest.DONE)
44
- return
45
-
46
- callbacks.done && callbacks.done()
47
-
48
- if (parseInt(xhr.status / 100) !== 2)
49
- return error_reporter(xhr.responseText)
50
-
51
- if (!callbacks.success)
52
- return
53
-
54
- let response = JSON.parse(xhr.responseText)
55
-
56
- on_response && on_response(response)
57
-
58
- callbacks.success(response)
59
- }
60
-
61
- xhr.onerror = function(error_message = 'Network error occurred') {
62
- callbacks.done && callbacks.done()
63
- error_reporter(error_message)
64
- }
65
-
66
- xhr.open(request_method, url_builder(component.url, method, ...args))
67
-
68
- xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
69
- xhr.setRequestHeader('Accept', 'application/json')
70
-
71
- if (is_post) {
72
- xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8')
73
- xhr.send(JSON.stringify(params))
74
- } else {
75
- xhr.send()
76
- }
77
- }
78
-
79
- return method_api
80
- }, {})
81
-
82
- }
83
-
84
- return component_api
85
-
86
- }, {})
87
-
88
- }