kynetx_am_api 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -174,7 +174,7 @@ module KynetxAmApi
174
174
 
175
175
  def load_base
176
176
  app_details = @api.get_app_details(@application_id)
177
- puts "APPDETAILS: #{app_details.inspect}"
177
+ puts "APPDETAILS: #{app_details.inspect}" if $DEBUG
178
178
  @name = app_details["name"]
179
179
  @application_id = app_details["appid"]
180
180
  @guid = app_details["guid"]
@@ -197,7 +197,7 @@ module KynetxAmApi
197
197
 
198
198
  def load_versions
199
199
  app_info = @api.get_app_info(@application_id)
200
- puts "APPINFO: #{app_info.inspect}"
200
+ puts "APPINFO: #{app_info.inspect}" if $DEBUG
201
201
  @production_version = app_info["production"]["version"] if app_info["production"]
202
202
  @development_version = app_info["development"]["version"] if app_info["development"]
203
203
  @application_id = app_info["appid"]
@@ -207,7 +207,7 @@ module KynetxAmApi
207
207
  def set_krl(krl)
208
208
  # ensure that the ruleset_id is correct.
209
209
  krl.gsub!(/ruleset.*?\{/m, "ruleset #{@application_id} {")
210
- puts "NEW KRL: #{krl}"
210
+ puts "NEW KRL: #{krl}" if $DEBUG
211
211
  response = @api.post_app_source(@application_id, krl, "krl")
212
212
  response = JSON.parse(response)
213
213
  if response["valid"]
@@ -128,13 +128,9 @@ module KynetxAmApi
128
128
  end
129
129
 
130
130
  def post_app_updateappimage(application_id, filename, content_type, image_data)
131
- # headers = {'Content-type'=>'multipart/form-data'}
132
- # puts "IMAGE INFO: #{image.class}"
133
- # return multipart_post_response("app/#{application_id}/updateappimage", {:image => image})
134
- response = ""
135
-
136
- url = URI.parse('https://accounts.kynetx.com/api/0.1/updateAppInfo')
137
-
131
+ # TODO: Make this go through the APIß
132
+ response = ""
133
+ url = URI.parse('https://accounts.kynetx.com/api/0.1/updateAppInfo')
138
134
  StringIO.open(image_data) do |i|
139
135
  req = Net::HTTP::Post::Multipart.new url.path,
140
136
  "image" => UploadIO.new(i, content_type, filename),
@@ -169,16 +165,16 @@ module KynetxAmApi
169
165
  headers = {'Accept'=>'application/json'}
170
166
  end
171
167
  api_call = "/0.1/#{api_method}"
172
- puts "---------GET---------------"
173
- puts api_call
174
- puts "___________________________"
168
+ puts "---------GET---------------" if $DEBUG
169
+ puts api_call if $DEBUG
170
+ puts "___________________________" if $DEBUG
175
171
  response = @oauth.get_access_token.get(api_call, headers).body
176
- puts response.inspect if RAILS_ENV == 'development'
177
- puts "___________________________"
172
+ puts response.inspect if $DEBUG
173
+ puts "___________________________" if $DEBUG
178
174
  begin
179
175
  response = JSON.parse(response) if format == :json
180
176
  rescue
181
- puts $!
177
+ puts $! if $DEBUG
182
178
  raise "Unexpected response from the api: (#{api_method}) :: #{response}"
183
179
  end
184
180
  return response
@@ -193,17 +189,17 @@ module KynetxAmApi
193
189
  headers.merge!(additional_headers)
194
190
  end
195
191
  api_call = "/0.1/#{api_method}"
196
- puts "---------POST--------------"
197
- puts api_call
198
- puts data.inspect if RAILS_ENV == 'development'
192
+ puts "---------POST--------------" if $DEBUG
193
+ puts api_call if $DEBUG
194
+ puts data.inspect if $DEBUG
199
195
  puts "___________________________"
200
196
  response = @oauth.get_access_token.post(api_call, data, headers).body
201
- puts response.inspect if RAILS_ENV == 'development'
197
+ puts response.inspect if $DEBUG
202
198
  puts "---------------------------"
203
199
  begin
204
200
  response = JSON.parse(response) if format == :json
205
201
  rescue
206
- puts $!
202
+ puts $! if $DEBUG
207
203
  raise "Unexpected response from the api: (#{api_method}) :: #{response}"
208
204
  end
209
205
  return response
@@ -1,10 +1,8 @@
1
1
  module KynetxAmApi
2
2
  require 'oauth'
3
3
  require 'json'
4
- require 'pp'
5
4
 
6
5
  class Oauth
7
-
8
6
  cattr_accessor :accounts_server_url
9
7
  cattr_accessor :api_server_url
10
8
  cattr_accessor :consumer_key
@@ -50,14 +48,7 @@ module KynetxAmApi
50
48
  private
51
49
 
52
50
  def get_account_consumer
53
- # puts Oauth.consumer_key
54
- # puts Oauth.consumer_secret
55
- # puts Oauth.accounts_server_url
56
-
57
51
  return @account_consumer if @account_consumer
58
-
59
- # TODO: Accounts url must come form settings.
60
-
61
52
  return @account_consumer = OAuth::Consumer.new(Oauth.consumer_key, Oauth.consumer_secret, {
62
53
  :site => Oauth.accounts_server_url,
63
54
  :scheme => :header,
@@ -74,14 +65,6 @@ module KynetxAmApi
74
65
 
75
66
  def get_api_consumer
76
67
  return @api_consumer if @api_consumer
77
-
78
- # TODO: Accounts url must come form settings.
79
-
80
- # puts Oauth.consumer_key
81
- # puts Oauth.consumer_secret
82
- # puts Oauth.api_server_url
83
-
84
-
85
68
  return @api_consumer = OAuth::Consumer.new(Oauth.consumer_key, Oauth.consumer_secret, {
86
69
  :site => Oauth.api_server_url,
87
70
  :scheme => :header,
@@ -12,7 +12,7 @@ module KynetxAmApi
12
12
  attr_accessor :oauth_verifier
13
13
  # OAuth Access Token
14
14
  attr_accessor :access_token
15
- # OAuth Acces sSecret
15
+ # OAuth Access Secret
16
16
  attr_accessor :access_secret
17
17
  # Kynetx User name
18
18
  attr_accessor :username
@@ -79,14 +79,11 @@ module KynetxAmApi
79
79
  options[:version] ||= "development"
80
80
  raise "Expecting :application_id" unless options[:application_id]
81
81
 
82
- puts "Creating a new Application object."
83
82
  if @current_application && @current_application.application_id != options[:application_id]
84
83
  @current_application = KynetxAmApi::Application.new(self, options[:application_id], options[:version])
85
84
  else
86
85
  @current_application ||= KynetxAmApi::Application.new(self, options[:application_id], options[:version])
87
86
  end
88
- # rst = api.get_app_source(options[:application_id],options[:version], :krl);
89
- # app.source = rst;
90
87
  return @current_application
91
88
  end
92
89
 
@@ -106,9 +103,7 @@ module KynetxAmApi
106
103
  end
107
104
 
108
105
  def owns_current?
109
- puts "OWNER / CURRENT_APP: #{@current_application.name}"
110
106
  return false unless @current_application
111
- puts "ME: #{self.userid.to_i} OWNER: #{@current_application.owner["kynetxuserid"].to_i}"
112
107
  return @current_application.owner["kynetxuserid"].to_i == self.userid.to_i
113
108
  end
114
109
 
data/lib/kynetx_am_api.rb CHANGED
@@ -5,37 +5,37 @@ require File.dirname(__FILE__) + '/kynetx_am_api/application.rb'
5
5
 
6
6
 
7
7
  DEFAULT_META = <<-KRL
8
- meta {
9
- name "<<NAME>>"
10
- description <<
11
- <<DESCRIPTION>>
12
- >>
13
- author ""
14
- // Uncomment this line to require Markeplace purchase to use this app.
15
- // authz require user
16
- logging off
17
- }
8
+ meta {
9
+ name "<<NAME>>"
10
+ description <<
11
+ <<DESCRIPTION>>
12
+ >>
13
+ author ""
14
+ // Uncomment this line to require Markeplace purchase to use this app.
15
+ // authz require user
16
+ logging off
17
+ }
18
18
  KRL
19
19
 
20
20
  DEFAULT_GLOBAL = <<-KRL
21
- global {
21
+ global {
22
22
 
23
- }
23
+ }
24
24
  KRL
25
25
 
26
26
  DEFAULT_DISPATCH = <<-KRL
27
- dispatch {
28
- // Some example dispatch domains
29
- // www.exmple.com
30
- // other.example.com
31
- }
27
+ dispatch {
28
+ // Some example dispatch domains
29
+ // www.exmple.com
30
+ // other.example.com
31
+ }
32
32
  KRL
33
33
 
34
34
  DEFAULT_RULE = <<-KRL
35
- rule <<NAME>> is active {
36
- select using "" setting ()
37
- // pre { }
38
- // notify("Hello World", "This is a sample rule.");
39
- noop();
40
- }
35
+ rule <<NAME>> is active {
36
+ select using "" setting ()
37
+ // pre { }
38
+ // notify("Hello World", "This is a sample rule.");
39
+ noop();
40
+ }
41
41
  KRL
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 11
9
- version: 0.1.11
8
+ - 12
9
+ version: 0.1.12
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Farmer, Cid Dennis