TokiCLI 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.gitignore +9 -17
- data/.rspec +3 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +4 -0
- data/README.md +99 -163
- data/Rakefile +5 -0
- data/TokiCLI.gemspec +5 -4
- data/bin/toki +2 -2
- data/lib/API/helpers.rb +27 -170
- data/lib/API/toki_api.rb +227 -0
- data/lib/API/toki_db.rb +67 -0
- data/lib/TokiCLI.rb +270 -5
- data/lib/TokiCLI/adnimport.rb +202 -0
- data/lib/TokiCLI/fileops.rb +187 -0
- data/lib/TokiCLI/status.rb +49 -37
- data/lib/TokiCLI/version.rb +1 -1
- data/lib/TokiCLI/view.rb +133 -86
- data/lib/TokiServer/.bowerrc +3 -0
- data/lib/TokiServer/.gitignore +2 -0
- data/lib/TokiServer/Gemfile +1 -0
- data/lib/TokiServer/bower.json +0 -0
- data/lib/TokiServer/bower_components/fastclick/.bower.json +4 -4
- data/lib/TokiServer/bower_components/fastclick/bower.json +1 -1
- data/lib/TokiServer/bower_components/fastclick/lib/fastclick.js +33 -2
- data/lib/TokiServer/bower_components/foundation/.bower.json +5 -4
- data/lib/TokiServer/bower_components/foundation/bower.json +2 -1
- data/lib/TokiServer/bower_components/foundation/css/foundation.css +2173 -922
- data/lib/TokiServer/bower_components/foundation/css/foundation.css.map +7 -0
- data/lib/TokiServer/bower_components/foundation/css/normalize.css +53 -16
- data/lib/TokiServer/bower_components/foundation/css/normalize.css.map +7 -0
- data/lib/TokiServer/bower_components/foundation/js/foundation.js +782 -542
- data/lib/TokiServer/bower_components/foundation/js/foundation.min.js +4 -3
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.abide.js +45 -31
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.accordion.js +12 -6
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.alert.js +5 -5
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.clearing.js +34 -10
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.dropdown.js +83 -29
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.equalizer.js +3 -3
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.interchange.js +25 -12
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.joyride.js +112 -40
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.js +19 -5
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.magellan.js +22 -11
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.offcanvas.js +52 -8
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.orbit.js +133 -271
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.reveal.js +27 -20
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.slider.js +73 -33
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.tab.js +88 -31
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.tooltip.js +7 -5
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.topbar.js +44 -24
- data/lib/TokiServer/bower_components/foundation/js/vendor/fastclick.js +2 -2
- data/lib/TokiServer/bower_components/foundation/js/vendor/modernizr.js +2 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation.scss +38 -38
- data/lib/TokiServer/bower_components/foundation/scss/foundation/_functions.scss +3 -3
- data/lib/TokiServer/bower_components/foundation/scss/foundation/_settings.scss +417 -271
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_accordion.scss +110 -6
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_alert-boxes.scss +2 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_block-grid.scss +2 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_breadcrumbs.scss +8 -3
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_button-groups.scss +99 -9
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_buttons.scss +66 -28
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_clearing.scss +5 -5
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_dropdown-buttons.scss +4 -4
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_dropdown.scss +48 -35
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_forms.scss +104 -32
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_global.scss +48 -30
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_grid.scss +19 -4
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_icon-bar.scss +293 -0
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_joyride.scss +11 -9
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_keystrokes.scss +4 -4
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_labels.scss +4 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_magellan.scss +1 -1
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_offcanvas.scss +193 -35
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_orbit.scss +92 -147
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_pagination.scss +22 -10
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_panels.scss +10 -7
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_pricing-tables.scss +11 -11
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_progress-bars.scss +2 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_range-slider.scss +29 -9
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_reveal.scss +60 -56
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_side-nav.scss +3 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_split-buttons.scss +2 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_sub-nav.scss +2 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_switches.scss +226 -0
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_tables.scss +13 -7
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_tabs.scss +22 -8
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_thumbs.scss +2 -4
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_toolbar.scss +70 -0
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_tooltips.scss +9 -7
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_top-bar.scss +77 -44
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_type.scss +21 -9
- data/lib/TokiServer/bower_components/modernizr/.bower.json +4 -4
- data/lib/TokiServer/bower_components/modernizr/feature-detects/workers-blobworkers.js +2 -2
- data/lib/TokiServer/bower_components/modernizr/grunt.js +1 -1
- data/lib/TokiServer/bower_components/modernizr/modernizr.js +2 -2
- data/lib/TokiServer/config.rb +0 -0
- data/lib/TokiServer/humans.txt +0 -0
- data/lib/TokiServer/{itunesicon.rb → itunesicons.rb} +25 -23
- data/lib/TokiServer/js/app.js +0 -0
- data/lib/TokiServer/public/stylesheets/app.css +2636 -1610
- data/lib/TokiServer/robots.txt +0 -0
- data/lib/TokiServer/scss/_settings.scss +0 -0
- data/lib/TokiServer/scss/app.scss +7 -1
- data/lib/TokiServer/tokiserver.rb +239 -244
- data/lib/TokiServer/views/activity.erb +42 -0
- data/lib/TokiServer/views/apps_total.erb +8 -2
- data/lib/TokiServer/views/error.erb +13 -4
- data/lib/TokiServer/views/index.erb +36 -27
- data/lib/TokiServer/views/logs_total.erb +34 -0
- data/spec/TokiCLI_spec.rb +354 -0
- data/spec/mock/mock.sqlite3 +0 -0
- data/spec/spec_helper.rb +26 -0
- metadata +78 -23
- data/lib/API/dbapi.rb +0 -488
- data/lib/TokiCLI/app.rb +0 -389
- data/lib/TokiCLI/authorize.rb +0 -77
- data/lib/TokiCLI/export.rb +0 -81
- data/lib/TokiCLI/get_channels.rb +0 -22
- data/lib/TokiCLI/get_messages.rb +0 -32
- data/lib/TokiCLI/import.rb +0 -122
- data/lib/TokiCLI/scan.rb +0 -19
- data/lib/TokiCLI/search_messages.rb +0 -23
- data/lib/TokiServer/README.md +0 -37
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_reveal-new.scss +0 -0
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_switch.scss +0 -294
- data/lib/TokiServer/views/name_log.erb +0 -50
- data/lib/TokiServer/views/name_split.erb +0 -37
- data/lib/TokiServer/views/name_total.erb +0 -34
data/lib/TokiServer/robots.txt
CHANGED
File without changes
|
File without changes
|
@@ -47,6 +47,11 @@ h1.title {
|
|
47
47
|
border-bottom: 1px solid $blue;
|
48
48
|
}
|
49
49
|
|
50
|
+
h3.total {
|
51
|
+
text-align: center;
|
52
|
+
color: $white;
|
53
|
+
}
|
54
|
+
|
50
55
|
.name {
|
51
56
|
color: $blue;
|
52
57
|
}
|
@@ -98,5 +103,6 @@ h3.back {
|
|
98
103
|
}
|
99
104
|
|
100
105
|
img.icon {
|
101
|
-
margin
|
106
|
+
margin: 2em auto;
|
107
|
+
text-align: center;
|
102
108
|
}
|
@@ -3,10 +3,48 @@
|
|
3
3
|
|
4
4
|
require "sinatra"
|
5
5
|
require "sinatra/assetpack"
|
6
|
-
require_relative
|
6
|
+
require_relative '../API/toki_api'
|
7
|
+
require_relative '../TokiCLI/fileops'
|
8
|
+
require_relative "itunesicons"
|
9
|
+
require "sinatra/reloader"
|
7
10
|
|
8
11
|
class TokiServer < Sinatra::Application
|
9
12
|
|
13
|
+
class Getters
|
14
|
+
|
15
|
+
def initialize(toki, fileops)
|
16
|
+
@toki = toki
|
17
|
+
@fileops = fileops
|
18
|
+
end
|
19
|
+
|
20
|
+
def bundles_from_name(bundles)
|
21
|
+
@fileops.get_bundle_from_name(Array(bundles))
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
# TOKI INIT
|
27
|
+
|
28
|
+
fileops = TokiCLI::FileOps.new
|
29
|
+
toki = TokiCLI::TokiAPI.new(fileops.db_file, fileops.bundles)
|
30
|
+
# Each toki instance has @response, which always contains the last result from a command
|
31
|
+
# So you can go with state (updated toki.response) or stateless (create new TokiAPI instances)
|
32
|
+
getters = Getters.new(toki, fileops)
|
33
|
+
icons = ItunesIcons.new(fileops)
|
34
|
+
|
35
|
+
|
36
|
+
# SINATRA INIT
|
37
|
+
|
38
|
+
configure :development do
|
39
|
+
register Sinatra::Reloader
|
40
|
+
end
|
41
|
+
|
42
|
+
configure do
|
43
|
+
file = File.new("#{fileops.log_path}/server.log", 'a+')
|
44
|
+
file.sync = true
|
45
|
+
use Rack::CommonLogger, file
|
46
|
+
end
|
47
|
+
|
10
48
|
set :server, %w[thin webrick]
|
11
49
|
set :port, 4567
|
12
50
|
set :root, File.dirname(__FILE__)
|
@@ -14,6 +52,11 @@ class TokiServer < Sinatra::Application
|
|
14
52
|
assets do
|
15
53
|
serve '/js', :from => 'js'
|
16
54
|
serve '/bower_components', :from => 'bower_components'
|
55
|
+
# serve '/css', :from => 'public/stylesheets'
|
56
|
+
|
57
|
+
# css :application, '/stylesheets/app.css', [
|
58
|
+
# '/stylesheets/app.css'
|
59
|
+
# ]
|
17
60
|
|
18
61
|
js :modernizr, [
|
19
62
|
'/bower_components/modernizr/modernizr.js',
|
@@ -31,347 +74,299 @@ class TokiServer < Sinatra::Application
|
|
31
74
|
js_compression :jsmin
|
32
75
|
end
|
33
76
|
|
34
|
-
|
35
|
-
|
77
|
+
|
78
|
+
# WEB ROUTES
|
36
79
|
|
37
80
|
get '/' do
|
38
81
|
erb :index
|
39
82
|
end
|
40
83
|
|
41
|
-
get '/api/?' do
|
42
|
-
endpoints = %w{apps/total apps/top apps/top/NUMBER apps/day/DATE apps/before/DATE apps/since/DATE apps/range/DATE1/DATE2 find/APP_NAME/log bundle/BUNDLE_ID/log find/APP_NAME/total bundle/BUNDLE_ID/total find/APP_NAME/before/DATE bundle/BUNDLE_ID/before/DATE find/APP_NAME/since/DATE bundle/BUNDLE_ID/since/DATE find/APP_NAME/range/DATE1/DATE2 bundle/BUNDLE_ID/range/DATE1/DATE2 find/APP_NAME/split/DATE bundle/BUNDLE_ID/split/DATE}
|
43
|
-
api_endpoints = endpoints.map {|url| "api/#{url}"}
|
44
|
-
content_type :json
|
45
|
-
{
|
46
|
-
meta: {code: 200, message: 'Welcome to the Toki API!'},
|
47
|
-
data: {
|
48
|
-
api_endpoints: api_endpoints,
|
49
|
-
web_endpoints: endpoints
|
50
|
-
}
|
51
|
-
}.to_json
|
52
|
-
end
|
53
|
-
|
54
84
|
get '/apps/total/?' do
|
55
|
-
|
56
|
-
|
57
|
-
erb :apps_total, locals: {
|
85
|
+
data = JSON.parse(toki.apps_total)['data']
|
86
|
+
total = toki.helpers.calc_apps_total(data)
|
87
|
+
erb :apps_total, locals: { toki: toki, title: 'Total', data: data, total: total }
|
58
88
|
end
|
59
89
|
|
60
|
-
get '/
|
61
|
-
|
62
|
-
|
90
|
+
get '/apps/top/?:number?' do
|
91
|
+
data = if params[:number]
|
92
|
+
max = params[:number].to_i
|
93
|
+
JSON.parse(toki.apps_top(max))['data']
|
94
|
+
else
|
95
|
+
JSON.parse(toki.apps_top)['data']
|
96
|
+
end
|
97
|
+
erb :apps_total, locals: { toki: toki, title: 'Total', data: data, total: nil }
|
63
98
|
end
|
64
99
|
|
65
|
-
get '/apps/
|
66
|
-
|
67
|
-
|
100
|
+
get '/apps/day/?:day?' do
|
101
|
+
day = params[:day]
|
102
|
+
data = JSON.parse(toki.apps_day(day))['data']
|
103
|
+
erb :apps_total, locals: { toki: toki, title: 'Total', data: data, total: nil }
|
68
104
|
end
|
69
105
|
|
70
|
-
get '/
|
71
|
-
|
72
|
-
|
106
|
+
get '/apps/range/:day1/?:day2?' do
|
107
|
+
day1, day2 = params[:day1], params[:day2]
|
108
|
+
data = JSON.parse(toki.apps_range(day1, day2))['data']
|
109
|
+
erb :apps_total, locals: { toki: toki, title: 'Total', data: data, total: nil }
|
73
110
|
end
|
74
111
|
|
75
|
-
get '/apps/
|
76
|
-
|
77
|
-
|
78
|
-
|
112
|
+
get '/apps/since/?:day?' do
|
113
|
+
day = params[:day]
|
114
|
+
data = JSON.parse(toki.apps_since(day))['data']
|
115
|
+
erb :apps_total, locals: { toki: toki, title: 'Total', data: data, total: nil }
|
79
116
|
end
|
80
117
|
|
81
|
-
get '/
|
82
|
-
|
83
|
-
|
84
|
-
|
118
|
+
get '/apps/before/?:day?' do
|
119
|
+
day = params[:day]
|
120
|
+
data = JSON.parse(toki.apps_before(day))['data']
|
121
|
+
erb :apps_total, locals: { toki: toki, title: 'Total', data: data, total: nil }
|
85
122
|
end
|
86
123
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
erb :apps_total, locals: {tk: tk, title: title, resp: resp}
|
91
|
-
else
|
92
|
-
erb :error, locals: {resp: resp, message: 'No data for this request'}
|
93
|
-
end
|
124
|
+
get '/activity/?' do
|
125
|
+
data = JSON.parse(toki.log_since)['data']
|
126
|
+
erb :activity, locals: { toki: toki, title: 'Activity', data: data, total: nil, name: 'Recent activity', icon: nil }
|
94
127
|
end
|
95
128
|
|
96
|
-
get '/
|
129
|
+
get '/activity/day/?:day?' do
|
97
130
|
day = params[:day]
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
erb :apps_total, locals: {tk: tk, title: title, resp: resp}
|
102
|
-
else
|
103
|
-
erb :error, locals: {resp: resp, message: 'No data for this request'}
|
104
|
-
end
|
131
|
+
data = JSON.parse(toki.log_day(day))['data']
|
132
|
+
total = toki.helpers.calc_logs_total(data)
|
133
|
+
erb :activity, locals: { toki: toki, title: 'Activity', data: data, total: total, name: "#{day} -", icon: nil }
|
105
134
|
end
|
106
135
|
|
107
|
-
get '/
|
136
|
+
get '/activity/since/?:day?' do
|
108
137
|
day = params[:day]
|
109
|
-
|
110
|
-
|
138
|
+
data = JSON.parse(toki.log_since(day))['data']
|
139
|
+
total = toki.helpers.calc_logs_total(data)
|
140
|
+
erb :activity, locals: { toki: toki, title: 'Activity', data: data, total: total, name: "Since #{day} -", icon: nil }
|
111
141
|
end
|
112
142
|
|
113
|
-
get '/
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
else
|
120
|
-
erb :error, locals: {resp: resp, message: 'No data for this request'}
|
121
|
-
end
|
143
|
+
get '/logs/bundle/:bundle/total/?' do
|
144
|
+
bundle = params[:bundle]
|
145
|
+
data = JSON.parse(toki.bundle_log(bundle))['data']
|
146
|
+
name = toki.bundles[bundle]
|
147
|
+
icon_url = icons.grab_small(name)
|
148
|
+
erb :activity, locals: { toki: toki, title: 'Total', data: data, total: nil, name: "#{bundle} - #{name}", icon: icon_url }
|
122
149
|
end
|
123
150
|
|
124
|
-
get '/
|
125
|
-
day = params[:day]
|
126
|
-
|
127
|
-
|
151
|
+
get '/logs/bundle/:bundle/day/?:day?' do
|
152
|
+
bundle, day = params[:bundle], params[:day]
|
153
|
+
data = JSON.parse(toki.bundle_log_day(bundle, day))['data']
|
154
|
+
total = toki.helpers.calc_logs_total(data)
|
155
|
+
name = toki.bundles[bundle]
|
156
|
+
icon_url = icons.grab_small(name)
|
157
|
+
erb :activity, locals: { toki: toki, title: 'Total', data: data, total: total, name: "#{bundle} - #{name} -", icon: icon_url }
|
128
158
|
end
|
129
159
|
|
130
|
-
get '/
|
131
|
-
day = params[:day]
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
end
|
160
|
+
get '/logs/bundle/:bundle/since/?:day?' do
|
161
|
+
bundle, day = params[:bundle], params[:day]
|
162
|
+
data = JSON.parse(toki.bundle_log_since(bundle, day))['data']
|
163
|
+
total = toki.helpers.calc_logs_total(data)
|
164
|
+
name = toki.bundles[bundle]
|
165
|
+
icon_url = icons.grab_small(name)
|
166
|
+
erb :activity, locals: { toki: toki, title: 'Total', data: data, total: total, name: "#{bundle} - #{name} -", icon: icon_url }
|
138
167
|
end
|
139
168
|
|
140
|
-
get '/
|
141
|
-
day = params[:day]
|
142
|
-
|
143
|
-
|
169
|
+
get '/logs/bundle/:bundle/before/?:day?' do
|
170
|
+
bundle, day = params[:bundle], params[:day]
|
171
|
+
data = JSON.parse(toki.bundle_log_before(bundle, day))['data']
|
172
|
+
total = toki.helpers.calc_logs_total(data)
|
173
|
+
name = toki.bundles[bundle]
|
174
|
+
icon_url = icons.grab_small(name)
|
175
|
+
erb :activity, locals: { toki: toki, title: 'Total', data: data, total: total, name: "#{bundle} - #{name} -", icon: icon_url }
|
144
176
|
end
|
145
177
|
|
146
|
-
get '/
|
147
|
-
day1, day2 = params[:day1], params[:day2]
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
if d1 > d2
|
154
|
-
title = "#{day2} #{day1}"
|
155
|
-
resp = JSON.parse tk.apps_range day2, day1
|
156
|
-
else
|
157
|
-
title = "#{day1} #{day2}"
|
158
|
-
resp = JSON.parse tk.apps_range day1, day2
|
159
|
-
end
|
160
|
-
if resp['meta']['code'] == 200
|
161
|
-
erb :apps_total, locals: {tk: tk, title: title, resp: resp}
|
162
|
-
else
|
163
|
-
erb :error, locals: {resp: resp, message: 'No data for this request'}
|
164
|
-
end
|
178
|
+
get '/logs/bundle/:bundle/range/?:day1/?:day2?' do
|
179
|
+
bundle, day1, day2 = params[:bundle], params[:day1], params[:day2]
|
180
|
+
data = JSON.parse(toki.bundle_log_range(bundle, day1, day2))['data']
|
181
|
+
total = toki.helpers.calc_logs_total(data)
|
182
|
+
name = toki.bundles[bundle]
|
183
|
+
icon_url = icons.grab_small(name)
|
184
|
+
erb :activity, locals: { toki: toki, title: 'Total', data: data, total: total, name: "#{bundle} - #{name} -", icon: icon_url }
|
165
185
|
end
|
166
186
|
|
167
|
-
|
168
|
-
day1, day2 = params[:day1], params[:day2]
|
169
|
-
content_type :json
|
170
|
-
tk.apps_range day1, day2
|
171
|
-
end
|
187
|
+
# /logs/app will be added when I find time to create an interactive page with fields, checks, apps list, etc
|
172
188
|
|
173
|
-
get '/find/:name/total/?' do
|
174
|
-
name = params[:name]
|
175
|
-
resp = JSON.parse tk.name_total(name)
|
176
|
-
if resp['meta']['code'] == 200
|
177
|
-
#@icon_url = itunesgrabber.grab_big(name)
|
178
|
-
erb :name_total, locals: {tk: tk, title: basic_title, resp: resp}
|
179
|
-
else
|
180
|
-
erb :error, locals: {resp: resp, message: "Unable to find '#{name}'"}
|
181
|
-
end
|
182
|
-
end
|
183
189
|
|
184
|
-
get '/api/find/:name/total/?' do
|
185
|
-
name = params[:name]
|
186
|
-
content_type :json
|
187
|
-
tk.name_total name
|
188
|
-
end
|
189
190
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
191
|
+
|
192
|
+
# API ROUTES
|
193
|
+
|
194
|
+
get '/api/?' do
|
195
|
+
content_type :json
|
196
|
+
{
|
197
|
+
'meta' => {
|
198
|
+
'code' => 200,
|
199
|
+
'message' => 'Welcome to the Toki API server.'
|
200
|
+
},
|
201
|
+
'data' => {
|
202
|
+
'routes' => %w{/api/apps/total /api/apps/top/[number] api/apps/day/(iso8601_date) /api/apps/range/(iso8601_date)/(iso8601_date) /api/apps/since/(iso8601_date) /api/apps/before/(iso8601_date) /api/activity /api/activity/day/(iso8601_date) /api/activity/since/(iso8601_date) /api/logs/bundle/(bundle_id)/total /api/logs/bundle/(bundle_id)/day/(iso8601_date) /api/logs/bundle/(bundle_id)/since/(iso8601_date) /api/logs/bundle/(bundle_id)/before/(iso8601_date) /api/logs/bundle/(bundle_id)/range/(iso8601_date)/(iso8601_date) /api/logs/app/(app_name)/total /api/logs/app/(app_name)/day/(iso8601_date) /api/logs/app/(app_name)/since/(iso8601_date) /api/logs/app/(app_name)/before/(iso8601_date) /api/logs/app/(app_name)/range/(iso8601_date)/(iso8601_date) /api/user /api/bundles}
|
203
|
+
}
|
204
|
+
}.to_json
|
194
205
|
end
|
195
206
|
|
196
|
-
get '/api/
|
197
|
-
bundle = params[:bundle]
|
207
|
+
get '/api/apps/total/?' do
|
198
208
|
content_type :json
|
199
|
-
|
209
|
+
toki.apps_total()
|
200
210
|
end
|
201
211
|
|
202
|
-
get '/
|
203
|
-
|
204
|
-
|
205
|
-
if
|
206
|
-
|
207
|
-
erb :name_total, locals: {tk: tk, title: basic_title, resp: resp}
|
212
|
+
get '/api/apps/top/?:number?' do
|
213
|
+
max = params[:number].to_i
|
214
|
+
content_type :json
|
215
|
+
if params[:number]
|
216
|
+
toki.apps_top(max)
|
208
217
|
else
|
209
|
-
|
218
|
+
toki.apps_top()
|
210
219
|
end
|
211
220
|
end
|
212
221
|
|
213
|
-
get '/api/
|
214
|
-
|
222
|
+
get '/api/apps/day/?:day?' do
|
223
|
+
day = params[:day]
|
215
224
|
content_type :json
|
216
|
-
|
225
|
+
toki.apps_day(day)
|
217
226
|
end
|
218
227
|
|
219
|
-
get '/
|
220
|
-
|
221
|
-
|
222
|
-
|
228
|
+
get '/api/apps/range/:day1/?:day2?' do
|
229
|
+
day1, day2 = params[:day1], params[:day2]
|
230
|
+
content_type :json
|
231
|
+
toki.apps_range(day1, day2)
|
223
232
|
end
|
224
233
|
|
225
|
-
get '/api/
|
226
|
-
|
234
|
+
get '/api/apps/since/?:day?' do
|
235
|
+
day = params[:day]
|
227
236
|
content_type :json
|
228
|
-
|
237
|
+
toki.apps_since(day)
|
229
238
|
end
|
230
239
|
|
231
|
-
get '/
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
#@icon_url = itunesgrabber.grab_big(name)
|
236
|
-
erb :name_total, locals: {tk: tk, title: basic_title, resp: resp}
|
237
|
-
else
|
238
|
-
erb :error, locals: {resp: resp, message: "Unable to find '#{name}'"}
|
239
|
-
end
|
240
|
+
get '/api/apps/before/?:day?' do
|
241
|
+
day = params[:day]
|
242
|
+
content_type :json
|
243
|
+
toki.apps_before(day)
|
240
244
|
end
|
241
245
|
|
242
|
-
get '/api/
|
243
|
-
name, day = params[:name], params[:day]
|
246
|
+
get '/api/activity/?' do
|
244
247
|
content_type :json
|
245
|
-
|
248
|
+
toki.log_since()
|
246
249
|
end
|
247
250
|
|
248
|
-
get '/
|
249
|
-
|
250
|
-
|
251
|
-
erb :name_total, locals: {tk: tk, title: basic_title, resp: resp}
|
251
|
+
get '/api/activity/recent/?' do
|
252
|
+
content_type :json
|
253
|
+
toki.log_since()
|
252
254
|
end
|
253
255
|
|
254
|
-
get '/api/
|
255
|
-
name, day = params[:name], params[:day]
|
256
|
+
get '/api/activity/today/?' do
|
256
257
|
content_type :json
|
257
|
-
|
258
|
+
toki.log_since()
|
258
259
|
end
|
259
260
|
|
260
|
-
get '/
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
resp = JSON.parse tk.name_total_range name, day2, day1
|
265
|
-
else
|
266
|
-
title = "#{day1} #{day2}"
|
267
|
-
resp = JSON.parse tk.name_total_range name, day1, day2
|
268
|
-
end
|
269
|
-
if resp['meta']['code'] == 200
|
270
|
-
#@icon_url = itunesgrabber.grab_big(name)
|
271
|
-
erb :name_total, locals: {tk: tk, title: title, resp: resp}
|
272
|
-
else
|
273
|
-
erb :error, locals: {resp: resp, message: "Unable to find '#{name}'"}
|
274
|
-
end
|
261
|
+
get '/api/activity/day/?:day?' do
|
262
|
+
day = params[:day]
|
263
|
+
content_type :json
|
264
|
+
toki.log_day(day)
|
275
265
|
end
|
276
266
|
|
277
|
-
get '/api/
|
278
|
-
|
267
|
+
get '/api/activity/since/?:day?' do
|
268
|
+
day = params[:day]
|
279
269
|
content_type :json
|
280
|
-
|
270
|
+
toki.log_since(day)
|
281
271
|
end
|
282
272
|
|
283
|
-
get '/bundle/:
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
resp = JSON.parse tk.bundle_total_range name, day2, day1
|
288
|
-
else
|
289
|
-
title = "#{day1} #{day2}"
|
290
|
-
resp = JSON.parse tk.bundle_total_range name, day1, day2
|
291
|
-
end
|
292
|
-
erb :name_total, locals: {tk: tk, title: basic_title, resp: resp}
|
273
|
+
get '/api/logs/bundle/:bundle/total/?' do
|
274
|
+
bundle = params[:bundle]
|
275
|
+
content_type :json
|
276
|
+
toki.bundle_log(bundle)
|
293
277
|
end
|
294
278
|
|
295
|
-
get '/api/bundle/:
|
296
|
-
|
279
|
+
get '/api/logs/bundle/:bundle/day/?:day?' do
|
280
|
+
bundle, day = params[:bundle], params[:day]
|
297
281
|
content_type :json
|
298
|
-
|
282
|
+
toki.bundle_log_day(bundle, day)
|
299
283
|
end
|
300
284
|
|
301
|
-
get '/
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
285
|
+
get '/api/logs/bundle/:bundle/since/?:day?' do
|
286
|
+
bundle, day = params[:bundle], params[:day]
|
287
|
+
content_type :json
|
288
|
+
toki.bundle_log_since(bundle, day)
|
289
|
+
end
|
290
|
+
|
291
|
+
get '/api/logs/bundle/:bundle/before/?:day?' do
|
292
|
+
bundle, day = params[:bundle], params[:day]
|
293
|
+
content_type :json
|
294
|
+
toki.bundle_log_before(bundle, day)
|
310
295
|
end
|
311
296
|
|
312
|
-
get '/api/
|
313
|
-
|
297
|
+
get '/api/logs/bundle/:bundle/range/?:day1/?:day2?' do
|
298
|
+
bundle, day1, day2 = params[:bundle], params[:day1], params[:day2]
|
314
299
|
content_type :json
|
315
|
-
|
300
|
+
toki.bundle_log_range(bundle, day1, day2)
|
316
301
|
end
|
317
302
|
|
318
|
-
get '/
|
319
|
-
|
320
|
-
|
321
|
-
|
303
|
+
get '/api/logs/app/:app/total/?' do
|
304
|
+
app = params[:app]
|
305
|
+
content_type :json
|
306
|
+
candidates = getters.bundles_from_name(app)
|
307
|
+
candidates.map {|bundle| toki.bundle_log(bundle)}
|
322
308
|
end
|
323
309
|
|
324
|
-
get '/api/
|
325
|
-
|
310
|
+
get '/api/logs/app/:app/day/?:day?' do
|
311
|
+
app, day = params[:app], params[:day]
|
326
312
|
content_type :json
|
327
|
-
|
313
|
+
candidates = getters.bundles_from_name(app)
|
314
|
+
candidates.map {|bundle| toki.bundle_log_day(bundle, day)}
|
328
315
|
end
|
329
316
|
|
330
|
-
get '/
|
331
|
-
|
332
|
-
|
333
|
-
|
317
|
+
get '/api/logs/app/:app/since/?:day?' do
|
318
|
+
app, day = params[:app], params[:day]
|
319
|
+
content_type :json
|
320
|
+
candidates = getters.bundles_from_name(app)
|
321
|
+
candidates.map {|bundle| toki.bundle_log_since(bundle, day)}
|
334
322
|
end
|
335
323
|
|
336
|
-
get '/api/
|
337
|
-
|
324
|
+
get '/api/logs/app/:app/before/?:day?' do
|
325
|
+
app, day = params[:app], params[:day]
|
338
326
|
content_type :json
|
339
|
-
|
327
|
+
candidates = getters.bundles_from_name(app)
|
328
|
+
candidates.map {|bundle| toki.bundle_log_before(bundle, day)}
|
340
329
|
end
|
341
330
|
|
342
|
-
get '/
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
erb :name_log, locals: {tk: tk, title: 'Log', resp: resp}
|
348
|
-
else
|
349
|
-
erb :error, locals: {resp: resp, message: "Unable to find '#{name}'"}
|
350
|
-
end
|
331
|
+
get '/api/logs/app/:app/range/?:day1/?:day2?' do
|
332
|
+
app, day1, day2 = params[:app], params[:day1], params[:day2]
|
333
|
+
content_type :json
|
334
|
+
candidates = getters.bundles_from_name(app)
|
335
|
+
candidates.map {|bundle| toki.bundle_log_range(bundle, day1, day2)}
|
351
336
|
end
|
352
337
|
|
353
|
-
get '/api/
|
354
|
-
name = params[:name]
|
338
|
+
get '/api/user/?' do
|
355
339
|
content_type :json
|
356
|
-
|
340
|
+
File.read(fileops.user_file)
|
357
341
|
end
|
358
342
|
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
bucket << [id, content]
|
363
|
-
end
|
364
|
-
bucket.sort_by! {|id, content| content['start']}
|
365
|
-
bucket.each do |id, content|
|
366
|
-
net[id] = content
|
367
|
-
end
|
368
|
-
resp['data']['log'] = net
|
369
|
-
resp
|
343
|
+
get '/api/bundles/?' do
|
344
|
+
content_type :json
|
345
|
+
fileops.bundles.to_json
|
370
346
|
end
|
371
347
|
|
372
|
-
|
373
|
-
|
348
|
+
get '/api/names/?' do
|
349
|
+
content_type :json
|
350
|
+
fileops.bundles.to_json
|
351
|
+
end
|
352
|
+
|
353
|
+
# ---
|
354
|
+
|
355
|
+
not_found do
|
356
|
+
message = request.env['sinatra.error'].to_s.split('::')[1]
|
357
|
+
if request.path_info =~ /\/api/
|
358
|
+
content_type :json
|
359
|
+
{
|
360
|
+
'meta' => {
|
361
|
+
'code' => 404,
|
362
|
+
'message' => message,
|
363
|
+
'processed_at' => Time.now
|
364
|
+
},
|
365
|
+
'data' => request.env
|
366
|
+
}.to_json
|
367
|
+
else
|
368
|
+
erb :error, locals: { title: '404', data: request.env, error: message }
|
369
|
+
end
|
374
370
|
end
|
375
371
|
|
376
372
|
end
|
377
|
-
|