Class: KynetxAmApi::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/kynetx_am_api/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#apiObject (readonly)

Returns the value of attribute api.



7
8
9
# File 'lib/kynetx_am_api/application.rb', line 7

def api
  @api
end

#application_idObject (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

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/kynetx_am_api/application.rb', line 4

def name
  @name
end

#userObject (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

#deleteObject



33
34
35
# File 'lib/kynetx_am_api/application.rb', line 33

def delete
  @api.post_app_delete(@application_id)      
end

#development_versionObject



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={})
  options = {
    :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'
    options[:runtime] = "init.kobj.net/js/shared/kobj-static.js"
  when 'info_card'
    options[:image_url] = image_url('icard')
    options[:datasets] = ""
  when 'ie'
    options[:appguid] = @guid
  end

  options.merge!(opts)
  puts "ENDPOINT PARAMS: (#{type}): #{options.inspect}" if $DEBUG
  return @api.post_app_generate(@application_id, type.to_s, options)

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, author, description, format="json")
  options = {
    "extname" => name,
    "extdesc" => description,
    "extauthor" => author.to_s.empty? ? @user.name : author,
    "format" => format
  }
  options["appguid"] = @guid if type.to_s == "ie"
  return @api.post_app_generate(@application_id, type.to_s, options)
  
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
  options = {
    "extname" => name.gsub(/[&'<]/, "_"),
    "datasets" => datasets.to_s,
    "extauthor" => "",
    "env" => env,
    "image_url" => image_url("icard")
  }
  
  return @api.post_app_generate(@application_id, "info_card", options)
end

#invitesObject



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

#ownerObject



101
102
103
104
# File 'lib/kynetx_am_api/application.rb', line 101

def owner
  load_base unless @owner
  return @owner
end

#production_versionObject



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

#reloadObject



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, message)
  load_base unless @name
  return @api.post_app_inviteuser(@application_id, @name, email, message)
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_paramObject



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, message)
  load_base unless @name
  return @api.post_app_transferownershiprequest(@application_id, @name, user_id, message)
end

#transfer_requestObject



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

#usersObject



64
65
66
67
# File 'lib/kynetx_am_api/application.rb', line 64

def users
  load_base unless @users
  return @users
end

#versionObject



73
74
75
# File 'lib/kynetx_am_api/application.rb', line 73

def version
  return development_version
end

#versionsObject



92
93
94
95
# File 'lib/kynetx_am_api/application.rb', line 92

def versions
  load_versions unless @versions
  return @versions      
end