kynetx_am_api 0.1.2 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,21 +1,18 @@
1
- The MIT License
1
+ Permission is hereby granted, free of charge, to any person obtaining
2
+ a copy of this software and associated documentation files (the
3
+ "Software"), to deal in the Software without restriction, including
4
+ without limitation the rights to use, copy, modify, merge, publish,
5
+ distribute, sublicense, and/or sell copies of the Software, and to
6
+ permit persons to whom the Software is furnished to do so, subject to
7
+ the following conditions:
2
8
 
3
- Copyright (c) 2010 Kynetx Inc.
9
+ The above copyright notice and this permission notice shall be
10
+ included in all copies or substantial portions of the Software.
4
11
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -158,7 +158,7 @@ module KynetxAmApi
158
158
  options = {
159
159
  "extname" => name,
160
160
  "extdesc" => description,
161
- "extauthor" => author.to_s.empty? ? @user.name : author
161
+ "extauthor" => author.blank? ? @user.name : author
162
162
  }
163
163
  options["appguid"] = @guid if type == :ie
164
164
  return @api.post_app_generate(@application_id, type.to_s, options)
@@ -174,10 +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}" if $DEBUG
178
- if app_details["error"]
179
- raise app_details["error"]
180
- end
177
+ puts "APPDETAILS: #{app_details.inspect}"
181
178
  @name = app_details["name"]
182
179
  @application_id = app_details["appid"]
183
180
  @guid = app_details["guid"]
@@ -200,7 +197,7 @@ module KynetxAmApi
200
197
 
201
198
  def load_versions
202
199
  app_info = @api.get_app_info(@application_id)
203
- puts "APPINFO: #{app_info.inspect}" if $DEBUG
200
+ puts "APPINFO: #{app_info.inspect}"
204
201
  @production_version = app_info["production"]["version"] if app_info["production"]
205
202
  @development_version = app_info["development"]["version"] if app_info["development"]
206
203
  @application_id = app_info["appid"]
@@ -210,7 +207,7 @@ module KynetxAmApi
210
207
  def set_krl(krl)
211
208
  # ensure that the ruleset_id is correct.
212
209
  krl.gsub!(/ruleset.*?\{/m, "ruleset #{@application_id} {")
213
- puts "NEW KRL: #{krl}" if $DEBUG
210
+ puts "NEW KRL: #{krl}"
214
211
  response = @api.post_app_source(@application_id, krl, "krl")
215
212
  response = JSON.parse(response)
216
213
  if response["valid"]
@@ -1,7 +1,7 @@
1
1
  module KynetxAmApi
2
- require 'rubygems'
3
2
  require 'oauth'
4
3
  require 'json'
4
+ require 'pp'
5
5
  require 'net/http/post/multipart'
6
6
 
7
7
  class DirectApi
@@ -128,9 +128,13 @@ module KynetxAmApi
128
128
  end
129
129
 
130
130
  def post_app_updateappimage(application_id, filename, content_type, image_data)
131
- # TODO: Make this go through the APIß
132
- response = ""
133
- url = URI.parse('https://accounts.kynetx.com/api/0.1/updateAppInfo')
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
+
134
138
  StringIO.open(image_data) do |i|
135
139
  req = Net::HTTP::Post::Multipart.new url.path,
136
140
  "image" => UploadIO.new(i, content_type, filename),
@@ -149,7 +153,7 @@ module KynetxAmApi
149
153
 
150
154
  def get_user_info
151
155
  user = @oauth.user
152
- if user.username.to_s.empty?
156
+ if user.username.blank?
153
157
  user_info = get_response("userinfo", :json)
154
158
  user.username = user_info["username"]
155
159
  user.userid = user_info["userid"]
@@ -165,16 +169,16 @@ module KynetxAmApi
165
169
  headers = {'Accept'=>'application/json'}
166
170
  end
167
171
  api_call = "/0.1/#{api_method}"
168
- puts "---------GET---------------" if $DEBUG
169
- puts api_call if $DEBUG
170
- puts "___________________________" if $DEBUG
172
+ puts "---------GET---------------"
173
+ puts api_call
174
+ puts "___________________________"
171
175
  response = @oauth.get_access_token.get(api_call, headers).body
172
- puts response.inspect if $DEBUG
173
- puts "___________________________" if $DEBUG
176
+ puts response.inspect if RAILS_ENV == 'development'
177
+ puts "___________________________"
174
178
  begin
175
179
  response = JSON.parse(response) if format == :json
176
180
  rescue
177
- puts $! if $DEBUG
181
+ puts $!
178
182
  raise "Unexpected response from the api: (#{api_method}) :: #{response}"
179
183
  end
180
184
  return response
@@ -189,17 +193,17 @@ module KynetxAmApi
189
193
  headers.merge!(additional_headers)
190
194
  end
191
195
  api_call = "/0.1/#{api_method}"
192
- puts "---------POST--------------" if $DEBUG
193
- puts api_call if $DEBUG
194
- puts data.inspect if $DEBUG
195
- puts "___________________________" if $DEBUG
196
+ puts "---------POST--------------"
197
+ puts api_call
198
+ puts data.inspect if RAILS_ENV == 'development'
199
+ puts "___________________________"
196
200
  response = @oauth.get_access_token.post(api_call, data, headers).body
197
- puts response.inspect if $DEBUG
198
- puts "---------------------------" if $DEBUG
201
+ puts response.inspect if RAILS_ENV == 'development'
202
+ puts "---------------------------"
199
203
  begin
200
204
  response = JSON.parse(response) if format == :json
201
205
  rescue
202
- puts $! if $DEBUG
206
+ puts $!
203
207
  raise "Unexpected response from the api: (#{api_method}) :: #{response}"
204
208
  end
205
209
  return response
@@ -1,9 +1,15 @@
1
1
  module KynetxAmApi
2
2
  require 'oauth'
3
3
  require 'json'
4
+ require 'pp'
4
5
 
5
6
  class Oauth
6
7
 
8
+ cattr_accessor :accounts_server_url
9
+ cattr_accessor :api_server_url
10
+ cattr_accessor :consumer_key
11
+ cattr_accessor :consumer_secret
12
+
7
13
  attr_accessor :request_token
8
14
  attr_accessor :account_consumer
9
15
  attr_accessor :api_consumer
@@ -29,22 +35,6 @@ module KynetxAmApi
29
35
  end
30
36
 
31
37
 
32
- def self.accounts_server_url=(v)
33
- @@accounts_server_url = v
34
- end
35
-
36
- def self.api_server_url=(v)
37
- @@api_server_url = v
38
- end
39
-
40
- def self.consumer_key=(v)
41
- @@consumer_key = v
42
- end
43
-
44
- def self.consumer_secret=(v)
45
- @@consumer_secret = v
46
- end
47
-
48
38
  private
49
39
 
50
40
 
@@ -56,10 +46,20 @@ module KynetxAmApi
56
46
 
57
47
  end
58
48
 
49
+
50
+ private
51
+
59
52
  def get_account_consumer
53
+ # puts Oauth.consumer_key
54
+ # puts Oauth.consumer_secret
55
+ # puts Oauth.accounts_server_url
56
+
60
57
  return @account_consumer if @account_consumer
61
- return @account_consumer = OAuth::Consumer.new(@@consumer_key, @@consumer_secret, {
62
- :site => @@accounts_server_url,
58
+
59
+ # TODO: Accounts url must come form settings.
60
+
61
+ return @account_consumer = OAuth::Consumer.new(Oauth.consumer_key, Oauth.consumer_secret, {
62
+ :site => Oauth.accounts_server_url,
63
63
  :scheme => :header,
64
64
  :method => :get,
65
65
  :request_token_path => "/oauth/request_token",
@@ -74,8 +74,16 @@ module KynetxAmApi
74
74
 
75
75
  def get_api_consumer
76
76
  return @api_consumer if @api_consumer
77
- return @api_consumer = OAuth::Consumer.new(@@consumer_key, @@consumer_secret, {
78
- :site => @@api_server_url,
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
+ return @api_consumer = OAuth::Consumer.new(Oauth.consumer_key, Oauth.consumer_secret, {
86
+ :site => Oauth.api_server_url,
79
87
  :scheme => :header,
80
88
  :method => :get,
81
89
  :request_token_path => "/oauth/request_token",
@@ -1,40 +1,17 @@
1
1
  module KynetxAmApi
2
- #
3
- # Simple wrapper to allow access to the OAuth user information. This also hold some basic user data like
4
- # username, name and user id.
5
- #
6
2
  class User
7
- # OAuth Request Token
8
3
  attr_accessor :request_token
9
- # OAuth Secret Token
10
4
  attr_accessor :request_secret
11
- # OAuth Verifieer
12
5
  attr_accessor :oauth_verifier
13
- # OAuth Access Token
14
6
  attr_accessor :access_token
15
- # OAuth Access Secret
16
7
  attr_accessor :access_secret
17
- # Kynetx User name
18
8
  attr_accessor :username
19
- # Kynetx User ID
20
9
  attr_accessor :userid
21
- # Full name of user
22
10
  attr_accessor :name
23
- # Current Application context.
24
11
  attr_reader :current_application
25
12
 
26
-
27
- #
28
- # Accepts a hash that has the following entries.
29
- # - :request_token
30
- # - :request_secret
31
- # - :oauth_verifier
32
- # - :access_token
33
- # - :access_secret
34
- # - :username
35
- # - :userid
36
- # - :name
37
- #
13
+ # attr :api
14
+ # attr :applications
38
15
 
39
16
  def initialize(attributes)
40
17
  @request_token = attributes[:request_token]
@@ -48,9 +25,7 @@ module KynetxAmApi
48
25
  @current_applicaion = nil
49
26
  end
50
27
 
51
- #
52
- # Returns the direct api to the Kynetx Application Manager.
53
- #
28
+
54
29
  def api
55
30
  @api ||= KynetxAmApi::DirectApi.new({:access_token => @access_token, :access_secret => @access_secret})
56
31
  return @api
@@ -59,12 +34,12 @@ module KynetxAmApi
59
34
  #
60
35
  # Read applications list
61
36
  #
62
- # - :offset => Start in list (not implemented)
63
- # - :size => Number of application to list (not implemented)
37
+ # :offset => Start in list (not implemented)
38
+ # :size => Number of application to list (not implemented)
64
39
  #
65
40
  # Returns a has with two keys
66
- # - "apps" => Array Off Hashes with :appid , :role, :name, :created
67
- # - "valid" => true
41
+ # "apps" => Array Off Hashes with :appid , :role, :name, :created
42
+ # "valid" => true
68
43
  #
69
44
  def applications(options = {})
70
45
  @applications = api.get_applist if !@applications
@@ -72,18 +47,21 @@ module KynetxAmApi
72
47
  end
73
48
 
74
49
  #
75
- # - :application_id => application_id
76
- # - :version => Version of application to obtain
50
+ # :application_id => application_id
51
+ # :version => Version of application to obtain
77
52
  #
78
53
  def find_application(options = {})
79
54
  options[:version] ||= "development"
80
55
  raise "Expecting :application_id" unless options[:application_id]
81
56
 
57
+ puts "Creating a new Application object."
82
58
  if @current_application && @current_application.application_id != options[:application_id]
83
59
  @current_application = KynetxAmApi::Application.new(self, options[:application_id], options[:version])
84
60
  else
85
61
  @current_application ||= KynetxAmApi::Application.new(self, options[:application_id], options[:version])
86
62
  end
63
+ # rst = api.get_app_source(options[:application_id],options[:version], :krl);
64
+ # app.source = rst;
87
65
  return @current_application
88
66
  end
89
67
 
@@ -97,28 +75,17 @@ module KynetxAmApi
97
75
 
98
76
  def duplicate_application(application_id)
99
77
  old_app = KynetxAmApi::Application.new(self, application_id)
100
- new_app = create_application(old_app.name || "", "")
78
+ new_app = create_application(old_app.name, "")
101
79
  new_app.krl = old_app.krl
102
80
  return new_app
103
81
  end
104
82
 
105
83
  def owns_current?
84
+ puts "OWNER / CURRENT_APP: #{@current_application.name}"
106
85
  return false unless @current_application
86
+ puts "ME: #{self.userid.to_i} OWNER: #{@current_application.owner["kynetxuserid"].to_i}"
107
87
  return @current_application.owner["kynetxuserid"].to_i == self.userid.to_i
108
88
  end
109
-
110
- def to_h
111
- return {
112
- :access_secret => @access_secret,
113
- :access_token => @access_token,
114
- :request_token => @request_token,
115
- :request_secret => @request_secret,
116
- :oauth_verifier => @oauth_verifier,
117
- :name => @name,
118
- :userid => @userid,
119
- :username => @username
120
- }
121
- end
122
89
 
123
90
 
124
91
  end
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
- - 2
9
- version: 0.1.2
8
+ - 10
9
+ version: 0.1.10
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Farmer, Cid Dennis