Commit c31fef048a61dff9ed08b65db64f6e3becd9e1a9
1 parent
529ab619
Exists in
master
and in
55 other branches
Add software communities endpoint to API
Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com> Signed-off-by: Simião Carvalho <simiaosimis@gmail.com>
Showing
4 changed files
with
72 additions
and
0 deletions
Show diff stats
src/noosfero-spb/software_communities/lib/software_communities_plugin.rb
@@ -17,6 +17,10 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | @@ -17,6 +17,10 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | ||
17 | _('Add Public Software and MPOG features.') | 17 | _('Add Public Software and MPOG features.') |
18 | end | 18 | end |
19 | 19 | ||
20 | + def self.api_mount_points | ||
21 | + [SoftwareCommunitiesPlugin::API] | ||
22 | + end | ||
23 | + | ||
20 | def profile_tabs | 24 | def profile_tabs |
21 | if context.profile.community? | 25 | if context.profile.community? |
22 | return profile_tabs_software if context.profile.software? | 26 | return profile_tabs_software if context.profile.software? |
src/noosfero-spb/software_communities/lib/software_communities_plugin/api.rb
0 → 100644
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../../lib/noosfero/api/helpers' | ||
2 | +require_relative 'api_entities' | ||
3 | + | ||
4 | +class SoftwareCommunitiesPlugin::API < Grape::API | ||
5 | + | ||
6 | + include Noosfero::API::APIHelpers | ||
7 | + | ||
8 | + resource :software_communities do | ||
9 | + get do | ||
10 | + authenticate! | ||
11 | + softwares = select_filtered_collection_of(environment,'communities',params).joins(:software_info) | ||
12 | + present softwares, :with => Entities::SoftwareCommunity | ||
13 | + end | ||
14 | + | ||
15 | + get ':id' do | ||
16 | + authenticate! | ||
17 | + software = SoftwareInfo.find_by_id(params[:id]) | ||
18 | + present software.community, :with => Entities::SoftwareCommunity | ||
19 | + end | ||
20 | + | ||
21 | + end | ||
22 | +end | ||
23 | + |
src/noosfero-spb/software_communities/lib/software_communities_plugin/api_entities.rb
0 → 100644
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +module Entities | ||
2 | + class SoftwareInfo < Noosfero::API::Entity | ||
3 | + expose :id, :finality, :repository_link, :public_software | ||
4 | + end | ||
5 | + | ||
6 | + class SoftwareCommunity < Noosfero::API::Entity | ||
7 | + root 'softwares', 'software' | ||
8 | + expose :community, :using => Noosfero::API::Entities::Community do |community, options| | ||
9 | + community | ||
10 | + end | ||
11 | + expose :software_info, :using => SoftwareInfo | ||
12 | + end | ||
13 | + | ||
14 | +end |
src/noosfero-spb/software_communities/test/unit/api_test.rb
0 → 100644
@@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../test/unit/api/test_helper' | ||
2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | ||
3 | + | ||
4 | +class SoftwareCommunitiesApiTest < ActiveSupport::TestCase | ||
5 | + | ||
6 | + include PluginTestHelper | ||
7 | + | ||
8 | + def setup | ||
9 | + login_api | ||
10 | + environment = Environment.default | ||
11 | + environment.enable_plugin(SoftwareCommunitiesPlugin) | ||
12 | + end | ||
13 | + | ||
14 | + should 'list all softwares' do | ||
15 | + @software_info = create_software_info("software_test") | ||
16 | + @software_info2 = create_software_info("software_test2") | ||
17 | + | ||
18 | + get "/api/v1/software_communities?#{params.to_query}" | ||
19 | + json = JSON.parse(last_response.body) | ||
20 | + assert_equivalent [@software_info.id, @software_info2.id], json['softwares'].map {|c| c['software_info']['id']} | ||
21 | + end | ||
22 | + | ||
23 | + should 'get software by id' do | ||
24 | + @software_info = create_software_info("software_test") | ||
25 | + get "/api/v1/software_communities/#{@software_info.id}?#{params.to_query}" | ||
26 | + | ||
27 | + json = JSON.parse(last_response.body) | ||
28 | + assert_equal @software_info.id, json["software"]['software_info']["id"] | ||
29 | + end | ||
30 | + | ||
31 | +end |