Class: KynetxAmApi::DirectApi

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tokens_and_secrets = {}) ⇒ DirectApi

Create a new session to the KynetxApi Manager.

request_token request_secret

:request_token
:request_secret
:oauth_verifier
:access_token
:access_secret


21
22
23
# File 'lib/kynetx_am_api/direct_api.rb', line 21

def initialize(tokens_and_secrets = {})
  @oauth = KynetxAmApi::Oauth.new(tokens_and_secrets)
end

Instance Attribute Details

#oauthObject

Returns the value of attribute oauth.



8
9
10
# File 'lib/kynetx_am_api/direct_api.rb', line 8

def oauth
  @oauth
end

Instance Method Details

#get_app_details(application_id) ⇒ Object



105
106
107
# File 'lib/kynetx_am_api/direct_api.rb', line 105

def get_app_details(application_id)
  return get_response("app/#{application_id}/details", :json)
end

#get_app_info(application_id) ⇒ Object



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

def get_app_info(application_id)
  return get_response("app/#{application_id}/info", :json)
end

#get_app_source(application_id, version, format = :krl) ⇒ Object



96
97
98
99
# File 'lib/kynetx_am_api/direct_api.rb', line 96

def get_app_source(application_id, version, format = :krl)
  data =  get_response("app/#{application_id}/source/#{version}/#{format}", format)
  return data
end

#get_app_stats_kpis(application_id, range) ⇒ Object



160
161
162
# File 'lib/kynetx_am_api/direct_api.rb', line 160

def get_app_stats_kpis(application_id, range)
  return get_response("app/#{application_id}/stats/kpis/#{range}", :json)
end

#get_appcreateObject



48
49
50
# File 'lib/kynetx_am_api/direct_api.rb', line 48

def get_appcreate
  return get_response("appcreate", :json)
end

#get_applistObject



44
45
46
# File 'lib/kynetx_am_api/direct_api.rb', line 44

def get_applist
  return get_response("applist", :json)
end

#get_authorize_urlObject

Provides the url to direct user to if the application has not been authorized.



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

def get_authorize_url
  return get_request_token.authorize_url
end

#get_request_tokenObject



26
27
28
# File 'lib/kynetx_am_api/direct_api.rb', line 26

def get_request_token
  @oauth.get_request_token
end

#get_stats_interfaceObject



177
178
179
# File 'lib/kynetx_am_api/direct_api.rb', line 177

def get_stats_interface
  return get_response("stats/interface", :json)
end

#get_stats_logging(application_id, range) ⇒ Object



181
182
183
# File 'lib/kynetx_am_api/direct_api.rb', line 181

def get_stats_logging(application_id, range)
  return get_response("app/#{application_id}/stats/logging/#{range}", :json)
end

#get_stats_query(k, d, c = nil, r = nil) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/kynetx_am_api/direct_api.rb', line 164

def get_stats_query(k,d,c=nil,r=nil)
  q_params = QueryParams.new.merge({:k => k, :d => d})
  if c 
    # c are the conditions and they are supplied like so:
    # [ {:field => "fieldname", :value => "value"}, ...]
    c.each do |condition|
      q_params["where_#{condition[:field]}".to_sym] = condition[:value]
    end
  end
  q_params[:r] = r if r
  return get_response("stats/query" + q_params.to_params, :json)
end

#get_user_infoObject



149
150
151
152
153
154
155
156
157
158
# File 'lib/kynetx_am_api/direct_api.rb', line 149

def 
  user = @oauth.user
  if user.username.to_s.empty?
     = get_response("userinfo", :json)
    user.username = ["username"]
    user.userid = ["userid"]
    user.name = ["name"]
  end
  return user
end

#pingObject



145
146
147
# File 'lib/kynetx_am_api/direct_api.rb', line 145

def ping
  return get_response("ping")
end

#post_app_delete(application_id) ⇒ Object



52
53
54
# File 'lib/kynetx_am_api/direct_api.rb', line 52

def post_app_delete(application_id)
  return post_response("app/#{application_id}/delete", {})
end

#post_app_generate(application_id, type, opts = {}) ⇒ Object

type is one of ff = firefox, ie = internet explorer, cr = google chrome



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/kynetx_am_api/direct_api.rb', line 79

def post_app_generate(application_id, type, opts={})
        # 
        # default_options = {
        #   "name" => "",
        #   "author" => "",
        #   "description" => "",
        #   "guid" => "",
        #   "datasets" => "",
        #   "env" => "prod",
        #   "image_url" => "http://appresource.s3.amazonaws.com/apiappimages/missing_icard.jpg",
        #   "runtime" => ""
        # }
        # options = default_options.merge(opts)
  return post_response("app/#{application_id}/generate/#{type}", opts,:json)
end

#post_app_invitecancel(application_id, invite_id) ⇒ Object



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

def post_app_invitecancel(application_id, invite_id)
  return post_response("app/#{application_id}/invitecancel",{"inviteid" => invite_id})
end

#post_app_inviteuser(application_id, application_name, email, message) ⇒ Object



60
61
62
# File 'lib/kynetx_am_api/direct_api.rb', line 60

def post_app_inviteuser(application_id, application_name, email, message)
  return post_response("app/#{application_id}/inviteuser", {"email" => email, "message" => message, "appname" => application_name.to_s})
end

#post_app_ownershiptransfercancel(application_id, transfer_id) ⇒ Object



72
73
74
# File 'lib/kynetx_am_api/direct_api.rb', line 72

def post_app_ownershiptransfercancel(application_id,transfer_id)
  return post_response("app/#{application_id}/ownershiptransfercancel", {"ownershiptransferrequestid" => transfer_id})
end

#post_app_setproductversion(application_id, version) ⇒ Object



121
122
123
# File 'lib/kynetx_am_api/direct_api.rb', line 121

def post_app_setproductversion(application_id, version)
  return post_response("app/#{application_id}/setproductionversion", {"version" => version})
end

#post_app_setversionnote(application_id, version, note) ⇒ Object



125
126
127
# File 'lib/kynetx_am_api/direct_api.rb', line 125

def post_app_setversionnote(application_id, version, note)
  return post_response("app/#{application_id}/setversionnote", {"version" => version, "note" => note}, :json)
end

#post_app_source(application_id, source, type = "krl") ⇒ Object



110
111
112
113
114
115
116
117
118
# File 'lib/kynetx_am_api/direct_api.rb', line 110

def post_app_source(application_id, source, type = "krl")
  data = ""
  if type == "krl"
    data = {:krl => source.to_s}
  else
    data = {:json => source.to_json}
  end
  return post_response("app/#{application_id}/source", data)
end

#post_app_transferownershiprequest(application_id, application_name, user_id, message) ⇒ Object



68
69
70
# File 'lib/kynetx_am_api/direct_api.rb', line 68

def post_app_transferownershiprequest(application_id,application_name,user_id,message)
  return post_response("app/#{application_id}/ownershiptransferrequest", {"userid" => user_id, "message" => message, "appname" => application_name})
end

#post_app_updateappimage(application_id, filename, content_type, image_data) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/kynetx_am_api/direct_api.rb', line 129

def post_app_updateappimage(application_id, filename, content_type, image_data)
  # TODO: Make this go through the APIß
  response = ""      
  url = URI.parse('https://accounts.kynetx.com/api/0.1/updateAppInfo')      
  StringIO.open(image_data) do |i|
    req = Net::HTTP::Post::Multipart.new url.path,
      "image" => UploadIO.new(i, content_type, filename),
      "appid" => application_id
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    response = http.start { |h| h.request(req) }        
  end
  
  return response
end

#post_remove_user(application_id, user_id) ⇒ Object



56
57
58
# File 'lib/kynetx_am_api/direct_api.rb', line 56

def post_remove_user(application_id, user_id)
  return post_response("app/#{application_id}/removeuser", {"userid" => user_id})
end