Class: PodioController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/podio_controller.rb

Constant Summary collapse

@@abbrErr =
"PCR"

Instance Method Summary collapse

Instance Method Details

#check_user_loginObject

Get authentication status of podio account Input from POST, POST Output json string



67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/podio_controller.rb', line 67

def 
  podioUser = params[:user]
  podioPass = params[:pass]
  status = AbstractApplication.test_authentication?(podioUser, podioPass)

  if (status)
    render :json => {:status => "success"}
  else
    render :json => {:status => "failure"}
  end
end

#get_abstract_items(appFieldsArray, appid, limit, offset, order) ⇒ Object



42
43
44
45
# File 'app/controllers/podio_controller.rb', line 42

def get_abstract_items(appFieldsArray, appid, limit, offset, order)
  data = AbstractItem.range(appid, appFieldsArray, {:order => order, :offset => offset, :limit => limit})
  return data
end

#get_list_of_apps_for_elementsObject

Get list of apps for elements Input Output json string



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'app/controllers/podio_controller.rb', line 137

def get_list_of_apps_for_elements
  # Get all apps
  curWorkspace = Metadata.find_by_key("currentWorkspace")
  if (!curWorkspace.nil?)
    appList = AbstractApplication.get_apps_list_by_space(curWorkspace.value.strip)

    tApps = Metadata.all({:conditions => ['cat = ?', 'app']})

    tAppsArray = Array.new
    appList.each do |al|
      tAppsArray << (defined?(al.id) ? al.id.to_s : (-1).to_s)
    end

    tAppsResult = Array.new
    tApps.each do |ta|
      if (tAppsArray.include?(ta.value.strip))
        tAppsResult << ta
      end
    end

    apps = tAppsResult
  else
    apps = []
  end

  render :json => apps
end

#get_list_of_apps_from_workspaceObject

Get list of workspaces of user Input Output



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'app/controllers/podio_controller.rb', line 111

def get_list_of_apps_from_workspace
  begin
    spaceid = params[:space]

    appsObj = AbstractApplication.get_apps_list_by_space(spaceid)

    apps = Array.new
    appsObj.each do |a|
      tHash = Hash.new
      tHash['id'] = defined?(a.id) ? a.id : -1
      tHash['name'] = defined?(a.config) ? a.config['name'] : ''
      tHash['description'] = defined?(a.config) ? a.config['description'] : ''
      tHash['icon'] = defined?(a.config) ? a.config['icon'] : ''

      apps << tHash
    end

    render :json => apps
  rescue
    render :json => []
  end
end

#get_list_of_organizations_of_userObject

Get list of organizations of user Input Output



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/controllers/podio_controller.rb', line 82

def get_list_of_organizations_of_user
  orgs = AbstractOrganization.get_list_of_organizations

  orgsArray = Array.new
  orgs.each do |o|
    tHash = Hash.new
    tArray = Array.new

    tHash[:id] = defined?(o.id) ? o.id : -1
    tHash[:name] = o[:name]

    o[:spaces].each do |s|
      tSpaceHash = Hash.new

      tSpaceHash[:id] = s['space_id']
      tSpaceHash[:name] = s['name']
      tArray << tSpaceHash
    end
    tHash[:spaces] = tArray

    orgsArray << tHash
  end

  render :json => orgsArray
end

#get_podio_app_statusObject

Get status of podio Input from GET Output json string



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/podio_controller.rb', line 50

def get_podio_app_status
  begin
    data = params[:appid]
    app = AbstractApplication.app_exists?(data.to_i)
    if (app == true)
      render :json => {:status => "success", :message => "online"}
    else
      render :json => {:status => "success", :message => "offline"}
    end
  rescue Exception => ex
    render :json => {:status => "failure", :message => "error"}
  end
end

#get_podio_itemsObject

Get items of apps from podio Inputs: podio application id, order, limit, offset and fields which have the forms described below Output: valid json string



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/podio_controller.rb', line 11

def get_podio_items

  appid = params[:appid].to_i
  order = params[:order].nil? ? "ASC" : params[:order].strip # string default = "ASC"
  limit = params[:limit].nil? ? 30 : params[:limit].to_i # numeric default = 30
  offset = params[:offset].nil? ? 0 : params[:offset].to_i # numeric default = 0
  fields = params[:fields].strip # title|money|summary

  appFields = fields.split("|")

  appFieldsArray = Array.new
  appFields.each do |t|
    tHash = Hash.new

    tHash[:external_id] = t
    tHash[:simple] = true

    appFieldsArray << tHash
  end

  data = nil

  data = get_abstract_items(appFieldsArray, appid, limit, offset, order)

  if (!data.nil?)
    render :json => {:status => "success", :data => JSON.parse(data.to_json)}
  else
    render :json => {:status => "failure"}
  end
end