cliskip2 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,7 +22,7 @@ A Ruby wrapper for the SKIP2 REST APIs
22
22
 
23
23
  ### create new user
24
24
  client = Cliskip2::Client.new
25
- client.post_user :user => {:name => 'hoge', :email => 'hoge@hoge.com'}
25
+ client.create_user :user => {:name => 'hoge', :email => 'hoge@hoge.com'}
26
26
 
27
27
  ### get the user by email
28
28
  client = Cliskip2::Client.new
@@ -30,4 +30,24 @@ A Ruby wrapper for the SKIP2 REST APIs
30
30
 
31
31
  ### update the user by email
32
32
  client = Cliskip2::Client.new
33
- client.put_user :user => {:name => 'foobar', :email => 'hoge@hoge.com'}
33
+ client.update_user :user => {:name => 'foobar', :email => 'hoge@hoge.com'}
34
+
35
+ ### search communities by the community-name
36
+ client = Cliskip2::Client.new
37
+ client.search_communities({:search => {:name => 'I love ruby'} })
38
+
39
+ ### get a community member
40
+ client = Cliskip2::Client.new
41
+ client.get_community_member(community, {:email => 'hoge@hoge.com'})
42
+
43
+ ### join new member to the community
44
+ client = Cliskip2::Client.new
45
+ community = client.search_communities({:search => {:name => 'I love ruby'} }).first
46
+ user = client.get_user :email => 'hoge@hoge.com'
47
+ client.join_community(community, user)
48
+
49
+ ### leave the member from the community
50
+ client = Cliskip2::Client.new
51
+ community = client.search_communities({:search => {:name => 'I love ruby'} }).first
52
+ member = client.get_community_member(community, {:email => 'hoge@hoge.com'})
53
+ client.leave_community(community, member)
@@ -2,6 +2,8 @@
2
2
  require 'cliskip2/connection'
3
3
  require 'cliskip2/request'
4
4
  require 'cliskip2/user'
5
+ require 'cliskip2/community'
6
+ require 'cliskip2/community_participation'
5
7
  require 'cliskip2/config'
6
8
 
7
9
  module Cliskip2
@@ -27,9 +29,13 @@ module Cliskip2
27
29
  @current_user ||= Cliskip2::User.new(user_attr['user'])
28
30
  end
29
31
 
32
+ # ========================================
33
+ # User APIs
34
+ # ========================================
35
+
30
36
  # Create new user by params
31
37
  # @return [Cliskip2::User]
32
- def post_user params
38
+ def create_user params
33
39
  user_attr = post("/admin/tenants/#{current_user.tenant_id}/users.json", params)
34
40
  Cliskip2::User.new(user_attr['user'])
35
41
  end
@@ -37,16 +43,52 @@ module Cliskip2
37
43
  # Get the user by params
38
44
  # @return [Cliskip2::User]
39
45
  def get_user params
40
- user_attr = get("/admin/tenants/#{current_user.tenant_id}/users/show_by_params.json", params)
46
+ user_attr = get("/tenants/#{current_user.tenant_id}/users/show_by_params.json", params)
41
47
  Cliskip2::User.new(user_attr['user'])
48
+ rescue Faraday::Error::ResourceNotFound => e
49
+ nil
42
50
  end
43
51
 
44
52
  # Update the user by params
45
53
  # @return [Cliskip2::User]
46
- def put_user params
54
+ def update_user params
47
55
  user = get_user :email => params[:user][:email]
48
56
  user_attr = put("/admin/tenants/#{current_user.tenant_id}/users/#{user.id}.json", params)
49
57
  Cliskip2::User.new(user_attr['user'])
50
58
  end
59
+
60
+ # ========================================
61
+ # Community APIs
62
+ # ========================================
63
+
64
+ # Search communities by some conditions
65
+ # @return [Array<Cliskip2::Community>]
66
+ def search_communities params
67
+ community_attrs = get("/tenants/#{current_user.tenant_id}/communities.json", params)
68
+ community_attrs.map {|community_attr| Cliskip2::Community.new(community_attr['community']) }
69
+ end
70
+
71
+ # Get the community-member by params
72
+ # @return [Cliskip2::CommunityParticipation]
73
+ def get_community_member community, params
74
+ community_participation_attr = get("/tenants/#{current_user.tenant_id}/communities/#{community.id}/community_participations/show_by_params.json", params)
75
+ Cliskip2::CommunityParticipation.new(community_participation_attr['community_participation'])
76
+ rescue Faraday::Error::ResourceNotFound => e
77
+ nil
78
+ end
79
+
80
+ # Join the community by the target-community and params
81
+ # @return [Cliskip2::CommunityParticipation]
82
+ def join_community community, user
83
+ community_participation_attr = post("/tenants/#{current_user.tenant_id}/communities/#{community.id}/community_participations.json", {:community_participation => {:user_id => user.id}})
84
+ Cliskip2::CommunityParticipation.new(community_participation_attr['community_participation'])
85
+ end
86
+
87
+ # Leave from the community by the target-community and params
88
+ # @return [Cliskip2::CommunityParticipation]
89
+ def leave_community community, community_participation
90
+ community_participation_attr = delete("/tenants/#{current_user.tenant_id}/communities/#{community.id}/community_participations/#{community_participation.id}.json")
91
+ Cliskip2::CommunityParticipation.new(community_participation_attr['community_participation'])
92
+ end
51
93
  end
52
94
  end
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'cliskip2/base'
3
+
4
+ module Cliskip2
5
+ class Community < Cliskip2::Base
6
+ lazy_attr_reader :id, :name, :description, :image_file_name, :privacy
7
+ end
8
+ end
9
+
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'cliskip2/base'
3
+
4
+ module Cliskip2
5
+ class CommunityParticipation < Cliskip2::Base
6
+ lazy_attr_reader :id, :user_id, :community_id, :admin
7
+ end
8
+ end
9
+
@@ -1,3 +1,3 @@
1
1
  module Cliskip2
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cliskip2
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Naoki Maeda
@@ -15,10 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-04 00:00:00 +01:00
18
+ date: 2012-06-18 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
+ name: faraday_middleware
23
+ prerelease: false
22
24
  requirement: &id001 !ruby/object:Gem::Requirement
23
25
  none: false
24
26
  requirements:
@@ -31,10 +33,10 @@ dependencies:
31
33
  - 7
32
34
  version: 0.8.7
33
35
  type: :runtime
34
- name: faraday_middleware
35
- prerelease: false
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
+ name: simple_oauth
39
+ prerelease: false
38
40
  requirement: &id002 !ruby/object:Gem::Requirement
39
41
  none: false
40
42
  requirements:
@@ -47,10 +49,10 @@ dependencies:
47
49
  - 8
48
50
  version: 0.1.8
49
51
  type: :runtime
50
- name: simple_oauth
51
- prerelease: false
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
54
+ name: json
55
+ prerelease: false
54
56
  requirement: &id003 !ruby/object:Gem::Requirement
55
57
  none: false
56
58
  requirements:
@@ -63,10 +65,10 @@ dependencies:
63
65
  - 3
64
66
  version: 1.7.3
65
67
  type: :runtime
66
- name: json
67
- prerelease: false
68
68
  version_requirements: *id003
69
69
  - !ruby/object:Gem::Dependency
70
+ name: oauth
71
+ prerelease: false
70
72
  requirement: &id004 !ruby/object:Gem::Requirement
71
73
  none: false
72
74
  requirements:
@@ -78,10 +80,10 @@ dependencies:
78
80
  - 4
79
81
  version: "0.4"
80
82
  type: :runtime
81
- name: oauth
82
- prerelease: false
83
83
  version_requirements: *id004
84
84
  - !ruby/object:Gem::Dependency
85
+ name: rake
86
+ prerelease: false
85
87
  requirement: &id005 !ruby/object:Gem::Requirement
86
88
  none: false
87
89
  requirements:
@@ -92,10 +94,10 @@ dependencies:
92
94
  - 0
93
95
  version: "0"
94
96
  type: :development
95
- name: rake
96
- prerelease: false
97
97
  version_requirements: *id005
98
98
  - !ruby/object:Gem::Dependency
99
+ name: rake-compiler
100
+ prerelease: false
99
101
  requirement: &id006 !ruby/object:Gem::Requirement
100
102
  none: false
101
103
  requirements:
@@ -106,10 +108,10 @@ dependencies:
106
108
  - 0
107
109
  version: "0"
108
110
  type: :development
109
- name: rake-compiler
110
- prerelease: false
111
111
  version_requirements: *id006
112
112
  - !ruby/object:Gem::Dependency
113
+ name: rspec
114
+ prerelease: false
113
115
  requirement: &id007 !ruby/object:Gem::Requirement
114
116
  none: false
115
117
  requirements:
@@ -120,8 +122,6 @@ dependencies:
120
122
  - 2
121
123
  version: "2"
122
124
  type: :development
123
- name: rspec
124
- prerelease: false
125
125
  version_requirements: *id007
126
126
  description: A Ruby wrapper for the SKIP2 REST APIs
127
127
  email:
@@ -142,6 +142,8 @@ files:
142
142
  - lib/cliskip2.rb
143
143
  - lib/cliskip2/base.rb
144
144
  - lib/cliskip2/client.rb
145
+ - lib/cliskip2/community.rb
146
+ - lib/cliskip2/community_participation.rb
145
147
  - lib/cliskip2/config.rb
146
148
  - lib/cliskip2/connection.rb
147
149
  - lib/cliskip2/request.rb