glip_sdk 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc1a035ca3a8a11081fe173c91f1e09867365cdd
4
- data.tar.gz: 7951602f8c911b26c7df8591bdc78e00b2fcd0c9
3
+ metadata.gz: aa6fdadf1797a32a45d0ead6b35d34d5af76a495
4
+ data.tar.gz: f2d083c1d2a0ed3660ac25c61f36d932c7562178
5
5
  SHA512:
6
- metadata.gz: 4f9b7f8bfc664a7cd4131c3a4d481b0bfedafd6abaadcc403124995284cc4036ce5301aa49e99203be98f9e0fabfb212d746fafdbf93df9542ccff704bd22e0f
7
- data.tar.gz: '0487a59cbc7759f8a329f64380b9fe6a3769921f7f5ef8a3ea062da13d5b6ee5d315ad0905b7f982eeaf1f01de461baa9bfb21498e909f45fd30c0d5981a5826'
6
+ metadata.gz: e799c4f6534d554d105db0cc66a26c97c26b5bef8c1cdcfdff746cf5f4053e02aae4c880746f21cf64f87703298f142f07d53226369bfa4ccefb3948d9f88c23
7
+ data.tar.gz: 67d0e063423dd4eb7973bf40d08d111711cb10fc34276fb429226a87f80d00845276b9abb553562d0fc8fb38e994e3f2148d5d448b2eb2d9d082c8e10bbea66e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  CHANGELOG
2
2
  ---------
3
+ - **2017-01-01**: 0.0.3
4
+ - Add get all groups
5
+ - Support Ruby 2.4.0
3
6
  - **2016-12-31**: 0.0.2
4
7
  - Update Rubydoc shield
5
8
  - **2016-12-31**: 0.0.1
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 John Wang
3
+ Copyright (c) 2016-2017 John Wang
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -49,7 +49,7 @@ Project Repo
49
49
 
50
50
  Glip SDK is available under the MIT license. See [LICENSE.md](LICENSE.md) for details.
51
51
 
52
- Glip SDK © 2016 by John Wang
52
+ Glip SDK © 2016-2017 by John Wang
53
53
 
54
54
  [gem-version-svg]: https://badge.fury.io/rb/glip_sdk.svg
55
55
  [gem-version-link]: http://badge.fury.io/rb/glip_sdk
data/lib/glip_sdk.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module GlipSdk
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
 
4
4
  autoload :REST, 'glip_sdk/rest'
5
5
 
@@ -12,7 +12,11 @@ module GlipSdk::REST::Cache
12
12
  end
13
13
 
14
14
  def load_groups(groups)
15
- groups.each { |g| load_group g }
15
+ if groups.is_a? Array
16
+ groups.each { |g| load_group g }
17
+ elsif groups.is_a? Hash
18
+ groups.each { |_, g| load_group g}
19
+ end
16
20
  end
17
21
 
18
22
  def load_group(group)
@@ -29,9 +33,25 @@ module GlipSdk::REST::Cache
29
33
  end
30
34
  end
31
35
 
36
+ def id_by_name(name)
37
+ group = by_name name
38
+ group.nil? ? nil : group['id']
39
+ end
40
+
41
+ def by_name(name)
42
+ team = team_by_name name
43
+ return team unless team.nil?
44
+ group_by_name name
45
+ end
46
+
32
47
  def team_by_name(name)
33
- # Innovation & Ops Extended Staff
34
- @teams[name.to_s]
48
+ team_id = @teams_name2id[name.to_s]
49
+ team_id ? @teams[team_id] : nil
50
+ end
51
+
52
+ def group_by_name(name)
53
+ group_id = @groups_name2id[name.to_s]
54
+ group_id ? @groups[group_id] : nil
35
55
  end
36
56
  end
37
57
  end
@@ -1,54 +1,39 @@
1
+ require 'multi_json'
2
+
3
+ require 'glip_sdk/rest/cache/groups'
4
+
1
5
  module GlipSdk
2
6
  module REST
3
7
  class Client
4
8
  attr_accessor :api
5
9
  attr_accessor :logger
6
10
  attr_accessor :groups
11
+ attr_accessor :groups_cache
7
12
  attr_accessor :persons
8
13
  attr_accessor :posts
9
14
 
10
15
  def initialize(rc_sdk)
11
16
  @api = rc_sdk
12
17
  @logger = @api.config.logger
18
+
19
+ @groups_cache = GlipSdk::REST::Cache::Groups.new
20
+
13
21
  @groups = GlipSdk::REST::Groups.new @api
14
22
  @persons = GlipSdk::REST::Persons.new @api
15
23
  @posts = GlipSdk::REST::Posts.new @api
16
24
  end
17
25
 
18
- def load_groups
19
- res = @groups.get.http.get 'glip/groups'
20
- @groups_cache = GlipSdk::REST::Cache::Groups.new
21
- @groups.load_groups(res.body['records'])
26
+ def load_groups_cache(filepath = nil)
27
+ if !filepath.nil? && File.exist?(filepath)
28
+ groups_json = IO.read filepath
29
+ all_groups = MultiJson.decode groups_json
30
+ @groups_cache.load_groups all_groups
31
+ else
32
+ @groups_cache.load_groups @groups.all_groups
33
+ end
34
+
35
+ @posts.groups_cache = @groups_cache
22
36
  end
23
37
  end
24
38
  end
25
39
  end
26
-
27
- =begin
28
- def post_message(opts = {})
29
- unless opts.key? :text
30
- fail "Text must be provided to post message"
31
- end
32
-
33
- unless opts.key?(:group_id) || opts.key?(:group_name)
34
- fail "Group Id or Group Name must be provided"
35
- end
36
-
37
- group_id = (opts.key?(:group_name) && !opts.key?(:group_id)) \
38
- ? @groups.groups_name2id[opts[:group_name]] : opts[:group_id]
39
-
40
- @api.http.post do |req|
41
- req.url 'glip/posts'
42
- req.headers['Content-Type'] = 'application/json'
43
- req.body = { groupId: group_id, text: opts[:text] }
44
- end
45
- end
46
-
47
- def observe(observer)
48
- @subscription = @api.create_subscription()
49
- @subscription.subscribe([
50
- "/restapi/v1.0/account/~/extension/~/glip/posts"
51
- ])
52
- @subscription.add_observer observer
53
- end
54
- =end
@@ -1,6 +1,7 @@
1
1
  module GlipSdk
2
2
  module REST
3
3
  class Groups
4
+ attr_accessor :cache
4
5
  attr_accessor :subscription
5
6
 
6
7
  def initialize(rc_sdk)
@@ -19,6 +20,23 @@ module GlipSdk
19
20
  @subscription.subscribe ['/restapi/v1.0/account/~/extension/~/glip/groups']
20
21
  @subscription.add_observer observer
21
22
  end
23
+
24
+ def all_groups(params = {})
25
+ groups = []
26
+ get_next = true
27
+ while get_next == true
28
+ res = get params
29
+ groups.concat(res.body['records']) if res.body['records'].length > 0
30
+
31
+ if res.body.key?('navigation') && res.body['navigation'].key?('prevPageToken')
32
+ params['pageToken'] = res.body['navigation']['prevPageToken']
33
+ @api.config.logger.info "PrevPageToken [#{res.body['navigation']['prevPageToken']}]"
34
+ else
35
+ get_next = false
36
+ end
37
+ end
38
+ return groups
39
+ end
22
40
  end
23
41
  end
24
42
  end
@@ -1,6 +1,10 @@
1
+ require 'multi_json'
2
+
1
3
  module GlipSdk
2
4
  module REST
3
5
  class Posts
6
+ attr_accessor :groups_cache
7
+
4
8
  def initialize(rc_sdk)
5
9
  @api = rc_sdk
6
10
  end
@@ -14,8 +18,14 @@ module GlipSdk
14
18
  raise ArgumentError, "Group Id or Group Name must be provided"
15
19
  end
16
20
 
17
- group_id = (opts.key?(:groupName) && !opts.key?(:groupId)) \
18
- ? @groups.groups_name2id[opts[:groupName]] : opts[:groupId]
21
+ group_id = opts[:groupId]
22
+
23
+ if group_id.nil? && @groups_cache && opts.key?(:groupName)
24
+ group_id = @groups_cache.id_by_name(opts[:groupName])
25
+ end
26
+
27
+ params = { groupId: group_id, text: opts[:text] }
28
+ puts MultiJson.encode params
19
29
 
20
30
  @api.http.post do |req|
21
31
  req.url 'glip/posts'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glip_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Wang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-31 00:00:00.000000000 Z
11
+ date: 2017-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ringcentral_sdk
@@ -114,7 +114,7 @@ dependencies:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
116
  version: '3'
117
- description: A Ruby SDK for the Glip collaboration solution
117
+ description: A Ruby SDK for the Glip collaboration solution (https://glip.com)
118
118
  email: johncwang@gmail.com
119
119
  executables: []
120
120
  extensions: []