restpack-group-client 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ script: bundle exec rake test
@@ -4,9 +4,13 @@ module RestPack
4
4
  class GroupApi < RestPack::Client::Api
5
5
  def index(params)
6
6
  #TODO: GJ: require channel_id
7
- hydrate get('/api/v1/groups.json', params)
7
+ hydrate http_get('/api/v1/groups.json', params)
8
8
  end
9
-
9
+
10
+ def get(id)
11
+ hydrate http_get("/api/v1/groups/#{id}.json")
12
+ end
13
+
10
14
  private
11
15
 
12
16
  def hydrate(response)
@@ -17,9 +21,11 @@ module RestPack
17
21
  memberships = response[:memberships].map { |m| Membership.new(m) } if response[:memberships]
18
22
  invitations = response[:invitations].map { |i| Invitation.new(i) } if response[:invitations]
19
23
  groups = response[:groups].map {|g| Group.new(g, memberships, invitations) } if response[:groups]
24
+ group = Group.new(response[:group], memberships, invitations) if response[:group]
20
25
 
21
26
  {
22
27
  groups: groups,
28
+ group: group,
23
29
  memberships: memberships,
24
30
  invitations: invitations
25
31
  }
@@ -13,7 +13,7 @@ module RestPack
13
13
  }.merge options
14
14
  end
15
15
 
16
- def get(path, params = {})
16
+ def http_get(path, params = {})
17
17
  url = build_url(path)
18
18
  json = RestClient.get(url, params: params)
19
19
  JSON.parse(json, :symbolize_keys => true)
@@ -1,7 +1,7 @@
1
1
  module RestPack
2
2
  module Group
3
3
  module Client
4
- VERSION = "0.0.8"
4
+ VERSION = "0.0.9"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe RestPack::Group::Client::GroupApi do
4
+ let(:client) { client = RestPack::Group::Client::GroupApi.new(use_https: false, password: '1234') }
5
+
6
+ describe "#index" do
7
+ let(:params) { { channel_id: 1 } }
8
+
9
+ before(:each) do
10
+ RestClient.should_receive(:get)
11
+ .with('http://:1234@localhost:1113/api/v1/groups.json', params: params)
12
+ .and_return(json)
13
+ @response = client.index(params)
14
+ end
15
+
16
+ context "when there is data" do
17
+ let(:json) { File.read('./spec/fixtures/group/index.json') }
18
+ describe "#index" do
19
+ it "parses response correctly" do
20
+ @response[:groups].length.should == 2
21
+ @response[:memberships].length.should == 3
22
+ @response[:invitations].length.should == 2
23
+ end
24
+
25
+ it "returns hierarichal group, membership and invitation data" do
26
+ @response[:groups][0].memberships.length.should == 2
27
+ @response[:groups][1].memberships.length.should == 1
28
+
29
+ @response[:groups][0].invitations.length.should == 2
30
+ @response[:groups][1].invitations.length.should == 0
31
+ end
32
+ end
33
+ end
34
+
35
+ context "when there is no data" do
36
+ let(:json) { File.read('./spec/fixtures/group/index-empty.json') }
37
+ it "returns valid data" do
38
+ @response[:groups].length.should == 0
39
+ @response[:memberships].length.should == 0
40
+ @response[:invitations].length.should == 0
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "#get" do
46
+ before(:each) do
47
+ RestClient.should_receive(:get)
48
+ .with('http://:1234@localhost:1113/api/v1/groups/142857.json', params: {})
49
+ .and_return(json)
50
+
51
+ @response = client.get(142857)
52
+ end
53
+ context "valid request" do
54
+ let(:json) { File.read('./spec/fixtures/group/get.json') }
55
+
56
+ it "correctly parses response" do
57
+ @response[:group].name.should == 'The First Group'
58
+ @response[:invitations].length.should == 2
59
+ @response[:memberships].length.should == 2
60
+ end
61
+ end
62
+ end
63
+ end
data/spec/client_spec.rb CHANGED
@@ -20,44 +20,4 @@ describe RestPack::Group::Client do
20
20
  end
21
21
  end
22
22
 
23
- context "Group endpoint" do
24
- let(:client) { client = RestPack::Group::Client::Api.new(use_https: false, password: '1234') }
25
- let(:params) { { channel_id: 1 } }
26
- before(:each) do
27
- RestClient.should_receive(:get)
28
- .with('http://:1234@localhost:1113/api/v1/groups.json', params: params)
29
- .and_return(json)
30
-
31
- @response = client.groups.index(params)
32
- end
33
-
34
- context "with data" do
35
- let(:json) { File.read('./spec/fixtures/group/index.json') }
36
- describe "#index" do
37
- it "parses response correctly" do
38
- @response[:groups].length.should == 2
39
- @response[:memberships].length.should == 3
40
- @response[:invitations].length.should == 2
41
- end
42
-
43
- it "returns hierarichal group, membership and invitation data" do
44
- @response[:groups][0].memberships.length.should == 2
45
- @response[:groups][1].memberships.length.should == 1
46
-
47
- @response[:groups][0].invitations.length.should == 2
48
- @response[:groups][1].invitations.length.should == 0
49
- end
50
- end
51
- end
52
-
53
- context "with empty data" do
54
- let(:json) { File.read('./spec/fixtures/group/index-empty.json') }
55
- it "returns valid data" do
56
- @response[:groups].length.should == 0
57
- @response[:memberships].length.should == 0
58
- @response[:invitations].length.should == 0
59
- end
60
- end
61
- end
62
-
63
23
  end
@@ -0,0 +1,74 @@
1
+ {
2
+ "memberships": [
3
+ {
4
+ "id": 14,
5
+ "channel_id": 1,
6
+ "group_id": 14,
7
+ "user_id": 4,
8
+ "created_at": "2013-03-16T08:42:32Z",
9
+ "updated_at": "2013-03-16T08:42:32Z",
10
+ "url": "/api/v1/memberships/14.json",
11
+ "invitation_id": 23
12
+ },
13
+ {
14
+ "id": 12,
15
+ "channel_id": 1,
16
+ "group_id": 14,
17
+ "user_id": 3,
18
+ "created_at": "2013-03-16T08:36:04Z",
19
+ "updated_at": "2013-03-16T08:36:04Z",
20
+ "url": "/api/v1/memberships/12.json",
21
+ "invitation_id": null
22
+ }
23
+ ],
24
+ "invitations": [
25
+ {
26
+ "id": 23,
27
+ "channel_id": 1,
28
+ "group_id": 14,
29
+ "inviter_id": 3,
30
+ "invitee_id": 4,
31
+ "status": "accepted",
32
+ "email": null,
33
+ "access_key": "sHjSy",
34
+ "remaining_uses": null,
35
+ "expires_at": null,
36
+ "created_at": "2013-03-16T08:37:18Z",
37
+ "updated_at": "2013-03-16T08:42:32Z",
38
+ "url": "/api/v1/invitations/23.json"
39
+ },
40
+ {
41
+ "id": 22,
42
+ "channel_id": 1,
43
+ "group_id": 14,
44
+ "inviter_id": 3,
45
+ "invitee_id": 142857,
46
+ "status": "available",
47
+ "email": null,
48
+ "access_key": "Tt97X4Hx",
49
+ "remaining_uses": null,
50
+ "expires_at": null,
51
+ "created_at": "2013-03-16T08:36:57Z",
52
+ "updated_at": "2013-03-16T08:36:57Z",
53
+ "url": "/api/v1/invitations/22.json"
54
+ }
55
+ ],
56
+ "group": {
57
+ "id": 14,
58
+ "name": "The First Group",
59
+ "description": "This group is the first",
60
+ "channel_id": 1,
61
+ "created_by_user_id": 3,
62
+ "created_at": "2013-03-16T08:36:04Z",
63
+ "updated_at": "2013-03-16T08:36:04Z",
64
+ "url": "/api/v1/groups/14.json",
65
+ "membership_ids": [
66
+ 12,
67
+ 14
68
+ ],
69
+ "invitation_ids": [
70
+ 22,
71
+ 23
72
+ ]
73
+ }
74
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restpack-group-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -83,6 +83,7 @@ extensions: []
83
83
  extra_rdoc_files: []
84
84
  files:
85
85
  - .gitignore
86
+ - .travis.yml
86
87
  - Gemfile
87
88
  - LICENSE
88
89
  - README.md
@@ -96,7 +97,9 @@ files:
96
97
  - lib/restpack-group-client/restpack_client_api.rb
97
98
  - lib/restpack-group-client/version.rb
98
99
  - restpack-group-client.gemspec
100
+ - spec/apis/group_api_spec.rb
99
101
  - spec/client_spec.rb
102
+ - spec/fixtures/group/get.json
100
103
  - spec/fixtures/group/index-empty.json
101
104
  - spec/fixtures/group/index.json
102
105
  - spec/spec_helper.rb
@@ -125,7 +128,9 @@ signing_key:
125
128
  specification_version: 3
126
129
  summary: A simple client gem for restpack-group-service
127
130
  test_files:
131
+ - spec/apis/group_api_spec.rb
128
132
  - spec/client_spec.rb
133
+ - spec/fixtures/group/get.json
129
134
  - spec/fixtures/group/index-empty.json
130
135
  - spec/fixtures/group/index.json
131
136
  - spec/spec_helper.rb