Class: KynetxAmApi::Application
- Inherits:
-
Object
- Object
- KynetxAmApi::Application
- Defined in:
- lib/kynetx_am_api/application.rb
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#application_id ⇒ Object
readonly
Returns the value of attribute application_id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#bookmarklet(env = "prod", runtime = "init.kobj.net/js/shared/kobj-static.js") ⇒ Object
—– Distrubution Methods.
- #cancel_invite(invite_id) ⇒ Object
- #cancel_transfer(request_id) ⇒ Object
- #create_initial_app(name, description) ⇒ Object
- #delete ⇒ Object
- #development_version ⇒ Object
-
#endpoint(type, opts = {}) ⇒ Object
Returns an endpoint.
- #extension(type, name, author, description, format = "json") ⇒ Object
- #image_url(size = "normal") ⇒ Object
- #infocard(name, datasets, env = "prod") ⇒ Object
-
#initialize(user, application_id) ⇒ Application
constructor
constructor takes a KynextAmApi::User object and an application id (ruleset_id).
- #invites ⇒ Object
-
#kpis(range = "previous_day") ⇒ Object
—– Stats Methods.
- #krl(v = nil) ⇒ Object
- #krl=(krl) ⇒ Object
- #logging(range = "previous_day") ⇒ Object
- #owner ⇒ Object
- #production_version ⇒ Object
- #production_version=(version) ⇒ Object
- #reload ⇒ Object
- #remove_user(userid) ⇒ Object
- #set_image(filename, content_type, image_data) ⇒ Object
- #set_version_note(version, note) ⇒ Object
- #share(email, message) ⇒ Object
- #stats(k, d, c = nil, r = nil) ⇒ Object
- #to_param ⇒ Object
- #transfer_owner(user_id, message) ⇒ Object
- #transfer_request ⇒ Object
- #users ⇒ Object
- #version ⇒ Object
- #versions ⇒ Object
Constructor Details
#initialize(user, application_id) ⇒ Application
constructor takes a KynextAmApi::User object and an application id (ruleset_id)
10 11 12 13 14 15 |
# File 'lib/kynetx_am_api/application.rb', line 10 def initialize(user, application_id) @api = user.api @application_id = application_id @user = user load_base end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
7 8 9 |
# File 'lib/kynetx_am_api/application.rb', line 7 def api @api end |
#application_id ⇒ Object (readonly)
Returns the value of attribute application_id.
6 7 8 |
# File 'lib/kynetx_am_api/application.rb', line 6 def application_id @application_id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/kynetx_am_api/application.rb', line 4 def name @name end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
5 6 7 |
# File 'lib/kynetx_am_api/application.rb', line 5 def user @user end |
Instance Method Details
#bookmarklet(env = "prod", runtime = "init.kobj.net/js/shared/kobj-static.js") ⇒ Object
—– Distrubution Methods
158 159 160 |
# File 'lib/kynetx_am_api/application.rb', line 158 def bookmarklet(env="prod", runtime="init.kobj.net/js/shared/kobj-static.js") return @api.post_app_generate(@application_id, "bookmarklet", {"env" => env, "runtime" => runtime})["data"] end |
#cancel_invite(invite_id) ⇒ Object
130 131 132 |
# File 'lib/kynetx_am_api/application.rb', line 130 def cancel_invite(invite_id) return @api.post_app_invitecancel(@application_id, invite_id) end |
#cancel_transfer(request_id) ⇒ Object
116 117 118 |
# File 'lib/kynetx_am_api/application.rb', line 116 def cancel_transfer(request_id) return @api.post_app_ownershiptransfercancel(@application_id, request_id) end |
#create_initial_app(name, description) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kynetx_am_api/application.rb', line 21 def create_initial_app(name, description) @name = name @description = description @meta = DEFAULT_META.gsub("<<NAME>>", name).gsub("<<DESCRIPTION>>", description) @global = DEFAULT_GLOBAL @dispatch = DEFAULT_DISPATCH @first_rule = DEFAULT_RULE.gsub("<<NAME>>", "first_rule") set_krl(gen_default_krl) load_base return self end |
#delete ⇒ Object
33 34 35 |
# File 'lib/kynetx_am_api/application.rb', line 33 def delete @api.post_app_delete(@application_id) end |
#development_version ⇒ Object
77 78 79 80 |
# File 'lib/kynetx_am_api/application.rb', line 77 def development_version load_versions unless @development_version return @development_version end |
#endpoint(type, opts = {}) ⇒ Object
Returns an endpoint
type is a String or Symbol of one of the following:
:chrome
:ie
:firefox
:info_card
:bookmarklet
:sitetags
opts is a Hash of options that has the following keys: (see Kynetx App Management API documentation on “generate” for more information)
-
:extname (endpoint name - defaults to app name.)
-
:extauthor (endpoint author - defaults to user generating the endpoint.)
-
:extdesc (endpoint description - defaults to empty.)
-
:force_build (‘Y’ or ‘N’ force a regeneration of the endpoint - defaults to ‘N’.)
-
:contents ( ‘compiled’ or ‘src’ specifies whether you want the endpoint or the source code of the endpoint - defaults to ‘compiled’.)
-
:format (‘url’ or ‘json’ specifies how the endpoint is returned - default is ‘json’ which returns a Base64 encoded data string.)
-
:datasets (used for infocards - defaults to empty)
-
:env (‘dev’ or ‘prod’ specifies whether to run the development or production version of the app - defaults to ‘prod’.)
-
:image_url (a fully qualified url to the image that will be used for the infocard. It must be a 240x160 jpg - defaults to a cropped version of the app image in appBuilder.)
-
:runtime (specific runtime to be used. This only works with bookmarklets - defaults to init.kobj.net/js/shared/kobj-static.js )
Returns a hash formatted as follows: => “endpoint as specified in the :format option”,
:file_name => "filename.*",
:content_type => 'content type',
:errors => []
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/kynetx_am_api/application.rb', line 217 def endpoint(type, opts={}) = { :extname => @name, :extdesc => "", :extauthor => @user.name, :force_build => 'N', :contents => "compiled", :format => 'json', :env => 'prod' } # Set type specific options case type.to_s when 'bookmarklet' [:runtime] = "init.kobj.net/js/shared/kobj-static.js" when 'info_card' [:image_url] = image_url('icard') [:datasets] = "" when 'ie' [:appguid] = @guid end .merge!(opts) puts "ENDPOINT PARAMS: (#{type}): #{.inspect}" if $DEBUG return @api.post_app_generate(@application_id, type.to_s, ) end |
#extension(type, name, author, description, format = "json") ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/kynetx_am_api/application.rb', line 175 def extension(type, name, , description, format="json") = { "extname" => name, "extdesc" => description, "extauthor" => .to_s.empty? ? @user.name : , "format" => format } ["appguid"] = @guid if type.to_s == "ie" return @api.post_app_generate(@application_id, type.to_s, ) end |
#image_url(size = "normal") ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/kynetx_am_api/application.rb', line 41 def image_url(size="normal") # returns the image url of a given size load_base unless @images if @images.empty? defaults = { "thumb" => "http://appresource.s3.amazonaws.com/apiappimages/missing_thumb.png", "normal" => "http://appresource.s3.amazonaws.com/apiappimages/missing.png", "original" => "http://appresource.s3.amazonaws.com/apiappimages/missing.png", "icard" => "http://appresource.s3.amazonaws.com/apiappimages/missing_icard.jpg" } return defaults[size.to_s] end return @images[size.to_s] end |
#infocard(name, datasets, env = "prod") ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/kynetx_am_api/application.rb', line 162 def infocard(name, datasets, env="prod") load_base unless @guid = { "extname" => name.gsub(/[&'<]/, "_"), "datasets" => datasets.to_s, "extauthor" => "", "env" => env, "image_url" => image_url("icard") } return @api.post_app_generate(@application_id, "info_card", ) end |
#invites ⇒ Object
125 126 127 128 |
# File 'lib/kynetx_am_api/application.rb', line 125 def invites load_base unless @invites return @invites end |
#kpis(range = "previous_day") ⇒ Object
—– Stats Methods
141 142 143 |
# File 'lib/kynetx_am_api/application.rb', line 141 def kpis(range="previous_day") return @api.get_app_stats_kpis(@application_id, range) end |
#krl(v = nil) ⇒ Object
37 38 39 |
# File 'lib/kynetx_am_api/application.rb', line 37 def krl(v=nil) @krl ||= @api.get_app_source(@application_id, v ? v : "development", :krl) end |
#krl=(krl) ⇒ Object
60 61 62 |
# File 'lib/kynetx_am_api/application.rb', line 60 def krl=(krl) set_krl(krl) end |
#logging(range = "previous_day") ⇒ Object
152 153 154 |
# File 'lib/kynetx_am_api/application.rb', line 152 def logging(range="previous_day") return @api.get_stats_logging(@application_id, range) end |
#owner ⇒ Object
101 102 103 104 |
# File 'lib/kynetx_am_api/application.rb', line 101 def owner load_base unless @owner return @owner end |
#production_version ⇒ Object
82 83 84 85 |
# File 'lib/kynetx_am_api/application.rb', line 82 def production_version load_versions unless @production_version return @production_version end |
#production_version=(version) ⇒ Object
87 88 89 90 |
# File 'lib/kynetx_am_api/application.rb', line 87 def production_version=(version) @api.post_app_setproductversion(@application_id, version) @production_version = version end |
#reload ⇒ Object
134 135 136 137 |
# File 'lib/kynetx_am_api/application.rb', line 134 def reload load_base load_versions end |
#remove_user(userid) ⇒ Object
69 70 71 |
# File 'lib/kynetx_am_api/application.rb', line 69 def remove_user(userid) return @api.post_remove_user(@application_id, userid) end |
#set_image(filename, content_type, image_data) ⇒ Object
56 57 58 |
# File 'lib/kynetx_am_api/application.rb', line 56 def set_image(filename, content_type, image_data) return @api.post_app_updateappimage(@application_id, filename, content_type, image_data) end |
#set_version_note(version, note) ⇒ Object
97 98 99 |
# File 'lib/kynetx_am_api/application.rb', line 97 def set_version_note(version, note) @api.post_app_setversionnote(@application_id, version, note) end |
#share(email, message) ⇒ Object
120 121 122 123 |
# File 'lib/kynetx_am_api/application.rb', line 120 def share(email, ) load_base unless @name return @api.post_app_inviteuser(@application_id, @name, email, ) end |
#stats(k, d, c = nil, r = nil) ⇒ Object
145 146 147 148 149 150 |
# File 'lib/kynetx_am_api/application.rb', line 145 def stats(k,d,c=nil,r=nil) # Accept kpis and dims as a String or Array kpis = k.class == Array ? k.split(",") : k dims = d.class == Array ? d.split(",") : d return @api.get_stats_query(kpis,dims,c,r) end |
#to_param ⇒ Object
17 18 19 |
# File 'lib/kynetx_am_api/application.rb', line 17 def to_param return @application_id end |
#transfer_owner(user_id, message) ⇒ Object
111 112 113 114 |
# File 'lib/kynetx_am_api/application.rb', line 111 def transfer_owner(user_id, ) load_base unless @name return @api.post_app_transferownershiprequest(@application_id, @name, user_id, ) end |
#transfer_request ⇒ Object
106 107 108 109 |
# File 'lib/kynetx_am_api/application.rb', line 106 def transfer_request load_base unless @transfer_request return @transfer_request end |
#users ⇒ Object
64 65 66 67 |
# File 'lib/kynetx_am_api/application.rb', line 64 def users load_base unless @users return @users end |
#version ⇒ Object
73 74 75 |
# File 'lib/kynetx_am_api/application.rb', line 73 def version return development_version end |
#versions ⇒ Object
92 93 94 95 |
# File 'lib/kynetx_am_api/application.rb', line 92 def versions load_versions unless @versions return @versions end |