Completed
Push — master ( 13432f...78215f )
by John
59s
created

Client.load_groups_cache()   A

Complexity

Conditions 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 3
1
require 'multi_json'
2
3
require 'glip_sdk/rest/cache/groups'
4
5
module GlipSdk
6
  module REST
7
    class Client
8
      attr_accessor :api
9
      attr_accessor :logger
10
      attr_accessor :groups
11
      attr_accessor :groups_cache
12
      attr_accessor :persons
13
      attr_accessor :posts
14
15
      def initialize(rc_sdk)
16
        @api = rc_sdk
17
        @logger = @api.config.logger
18
19
        @groups_cache = GlipSdk::REST::Cache::Groups.new
20
21
        @groups = GlipSdk::REST::Groups.new @api
22
        @persons = GlipSdk::REST::Persons.new @api
23
        @posts = GlipSdk::REST::Posts.new @api
24
      end
25
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
36
      end
37
    end
38
  end
39
end
40