coach_client 0.2.0 → 0.3.0

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: 2805cca046500eb765764e207fc3a7e843346d1c
4
- data.tar.gz: cdb44876983b95577e726c7edea17551caca7a9f
3
+ metadata.gz: f56caba59cad3e4f6b474404f424f6aceb7bf122
4
+ data.tar.gz: a5f0daf07795f2dba5e4d1ed971c255aee38bcfb
5
5
  SHA512:
6
- metadata.gz: 259446f6fdfc66499a6bc45634a6c8db5d40f1f2c264f6ea3153e7e1c95261b90194fa28472a470aff18c91c2790245e9534384a3e45db48595fa6a546acf21c
7
- data.tar.gz: 0efc7375b3d25d7589276123d0756d683af2cc31ffce6774f6a5efb5e4ea61231a3135e8772757bd7bac69e49f30dd5bf95fcb664a933d5bbf34afb0f5618d60
6
+ metadata.gz: 4ce465fa9b72cf70969cfe6d32d5b59f5aba3fce72c2ac59e5d83793ad35d6b38b2524dc765fd06b6c8fd401a022188cb0c5ecc236223afafe4b53951058edea
7
+ data.tar.gz: e60dcef34395f31f26221a4a6bd407596751c2da537e3b1839b293a61d7081e9f42b115652617d1c573d7c4a0131cf3525550d2470c58da3c10f6e25a74f91d4
@@ -3,11 +3,11 @@ engines:
3
3
  fixme:
4
4
  enabled: true
5
5
  exclude_fingerprints:
6
- - cdc1cac1f5cb7afe72dca9f9bca8a237
7
- - c42b72af850c2590419dfa0bb4d15004
8
- - ee0a31701f95b21db4aff40647a56a3d
9
- - b86af833d6b2b1fa18da63471e2278d9
10
- - 8084d978e026eb97e18591af98ff5572
6
+ - cdc1cac1f5cb7afe72dca9f9bca8a237
7
+ - c42b72af850c2590419dfa0bb4d15004
8
+ - ee0a31701f95b21db4aff40647a56a3d
9
+ - b86af833d6b2b1fa18da63471e2278d9
10
+ - 8084d978e026eb97e18591af98ff5572
11
11
  rubocop:
12
12
  enabled: true
13
13
  ratings:
@@ -70,7 +70,7 @@ Style/Attr:
70
70
  Style/BeginBlock:
71
71
  Description: 'Avoid the use of BEGIN blocks.'
72
72
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-BEGIN-blocks'
73
- Enabled: false
73
+ Enabled: true
74
74
 
75
75
  Style/BarePercentLiterals:
76
76
  Description: 'Checks if usage of %() or %Q() matches configuration.'
@@ -111,7 +111,7 @@ Style/CaseIndentation:
111
111
  Style/CharacterLiteral:
112
112
  Description: 'Checks for uses of character literals.'
113
113
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-character-literals'
114
- Enabled: false
114
+ Enabled: true
115
115
 
116
116
  Style/ClassAndModuleCamelCase:
117
117
  Description: 'Use CamelCase for classes and modules.'
@@ -120,7 +120,7 @@ Style/ClassAndModuleCamelCase:
120
120
 
121
121
  Style/ClassAndModuleChildren:
122
122
  Description: 'Checks style of children classes and modules.'
123
- Enabled: false
123
+ Enabled: true
124
124
 
125
125
  Style/ClassCheck:
126
126
  Description: 'Enforces consistent use of `Object#is_a?` or `Object#kind_of?`.'
@@ -213,23 +213,23 @@ Style/EmptyLines:
213
213
 
214
214
  Style/EmptyLinesAroundAccessModifier:
215
215
  Description: "Keep blank lines around access modifiers."
216
- Enabled: false
216
+ Enabled: true
217
217
 
218
218
  Style/EmptyLinesAroundBlockBody:
219
219
  Description: "Keeps track of empty lines around block bodies."
220
- Enabled: false
220
+ Enabled: true
221
221
 
222
222
  Style/EmptyLinesAroundClassBody:
223
223
  Description: "Keeps track of empty lines around class bodies."
224
- Enabled: false
224
+ Enabled: true
225
225
 
226
226
  Style/EmptyLinesAroundModuleBody:
227
227
  Description: "Keeps track of empty lines around module bodies."
228
- Enabled: false
228
+ Enabled: true
229
229
 
230
230
  Style/EmptyLinesAroundMethodBody:
231
231
  Description: "Keeps track of empty lines around method bodies."
232
- Enabled: false
232
+ Enabled: true
233
233
 
234
234
  Style/EmptyLiteral:
235
235
  Description: 'Prefer literals to Array.new/Hash.new/String.new.'
@@ -282,7 +282,7 @@ Style/For:
282
282
  Style/FormatString:
283
283
  Description: 'Enforce the use of Kernel#sprintf, Kernel#format or String#%.'
284
284
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#sprintf'
285
- Enabled: false
285
+ Enabled: true
286
286
 
287
287
  Style/GlobalVars:
288
288
  Description: 'Do not introduce global variables.'
@@ -341,12 +341,12 @@ Style/InfiniteLoop:
341
341
  Style/Lambda:
342
342
  Description: 'Use the new lambda literal syntax for single-line blocks.'
343
343
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#lambda-multi-line'
344
- Enabled: false
344
+ Enabled: true
345
345
 
346
346
  Style/LambdaCall:
347
347
  Description: 'Use lambda.call(...) instead of lambda.(...).'
348
348
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#proc-call'
349
- Enabled: false
349
+ Enabled: true
350
350
 
351
351
  Style/LeadingCommentSpace:
352
352
  Description: 'Comments should start with a space.'
@@ -388,7 +388,7 @@ Style/MultilineBlockChain:
388
388
 
389
389
  Style/MultilineBlockLayout:
390
390
  Description: 'Ensures newlines after multiline block do statements.'
391
- Enabled: false
391
+ Enabled: true
392
392
 
393
393
  Style/MultilineIfThen:
394
394
  Description: 'Do not use then for multi-line if/unless.'
@@ -457,7 +457,7 @@ Style/OneLineConditional:
457
457
  Favor the ternary operator(?:) over
458
458
  if/then/else/end constructs.
459
459
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#ternary-operator'
460
- Enabled: false
460
+ Enabled: true
461
461
 
462
462
  Style/OpMethod:
463
463
  Description: 'When defining binary operators, name the argument other.'
@@ -479,7 +479,7 @@ Style/ParallelAssignment:
479
479
  This also provides performance benefits
480
480
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parallel-assignment'
481
481
  Reference: 'https://github.com/JuanitoFatas/fast-ruby#parallel-assignment-vs-sequential-assignment-code'
482
- Enabled: false
482
+ Enabled: true
483
483
 
484
484
  Style/ParenthesesAroundCondition:
485
485
  Description: >-
@@ -491,7 +491,7 @@ Style/ParenthesesAroundCondition:
491
491
  Style/PercentLiteralDelimiters:
492
492
  Description: 'Use `%`-literal delimiters consistently'
493
493
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-literal-braces'
494
- Enabled: false
494
+ Enabled: true
495
495
 
496
496
  Style/PercentQLiterals:
497
497
  Description: 'Checks if uses of %Q/%q match the configured preference.'
@@ -515,7 +515,7 @@ Style/Proc:
515
515
  Style/RaiseArgs:
516
516
  Description: 'Checks the arguments passed to raise/fail.'
517
517
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#exception-class-messages'
518
- Enabled: false
518
+ Enabled: true
519
519
 
520
520
  Style/RedundantBegin:
521
521
  Description: "Don't use begin blocks when they are not needed."
@@ -549,7 +549,7 @@ Style/RescueEnsureAlignment:
549
549
  Style/RescueModifier:
550
550
  Description: 'Avoid using rescue in its modifier form.'
551
551
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers'
552
- Enabled: false
552
+ Enabled: true
553
553
 
554
554
  Style/SelfAssignment:
555
555
  Description: >-
@@ -613,13 +613,13 @@ Style/SpaceAfterNot:
613
613
  Style/SpaceAfterSemicolon:
614
614
  Description: 'Use spaces after semicolons.'
615
615
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators'
616
- Enabled: false
616
+ Enabled: true
617
617
 
618
618
  Style/SpaceBeforeBlockBraces:
619
619
  Description: >-
620
620
  Checks that the left block brace has or doesn't have space
621
621
  before it.
622
- Enabled: false
622
+ Enabled: true
623
623
 
624
624
  Style/SpaceBeforeComma:
625
625
  Description: 'No spaces before commas.'
@@ -640,7 +640,7 @@ Style/SpaceInsideBlockBraces:
640
640
  Checks that block braces have or don't have surrounding space.
641
641
  For blocks taking parameters, checks that the left brace has
642
642
  or doesn't have trailing space.
643
- Enabled: false
643
+ Enabled: true
644
644
 
645
645
  Style/SpaceAroundBlockParameters:
646
646
  Description: 'Checks the spacing inside and after block parameters pipes.'
@@ -661,7 +661,7 @@ Style/SpaceAroundOperators:
661
661
 
662
662
  Style/SpaceBeforeModifierKeyword:
663
663
  Description: 'Put a space before the modifier keyword.'
664
- Enabled: false
664
+ Enabled: true
665
665
 
666
666
  Style/SpaceInsideBrackets:
667
667
  Description: 'No spaces after [ or before ].'
@@ -711,11 +711,11 @@ Style/StructInheritance:
711
711
 
712
712
  Style/SymbolLiteral:
713
713
  Description: 'Use plain symbols instead of string symbols when possible.'
714
- Enabled: false
714
+ Enabled: true
715
715
 
716
716
  Style/SymbolProc:
717
717
  Description: 'Use symbols as procs instead of blocks when possible.'
718
- Enabled: false
718
+ Enabled: true
719
719
 
720
720
  Style/Tab:
721
721
  Description: 'No hard tabs.'
@@ -725,7 +725,7 @@ Style/Tab:
725
725
  Style/TrailingBlankLines:
726
726
  Description: 'Checks trailing blank lines and final newline.'
727
727
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#newline-eof'
728
- Enabled: false
728
+ Enabled: true
729
729
 
730
730
  Style/TrailingComma:
731
731
  Description: 'Checks for trailing comma in parameter lists and literals.'
@@ -751,12 +751,12 @@ Style/UnlessElse:
751
751
 
752
752
  Style/UnneededCapitalW:
753
753
  Description: 'Checks for %W when interpolation is not needed.'
754
- Enabled: false
754
+ Enabled: true
755
755
 
756
756
  Style/UnneededPercentQ:
757
757
  Description: 'Checks for %q/%Q when single quotes or double quotes would do.'
758
758
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-q'
759
- Enabled: false
759
+ Enabled: true
760
760
 
761
761
  Style/TrailingUnderscoreVariable:
762
762
  Description: >-
@@ -796,7 +796,7 @@ Style/WhileUntilModifier:
796
796
  Style/WordArray:
797
797
  Description: 'Use %w or %W for arrays of words.'
798
798
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-w'
799
- Enabled: false
799
+ Enabled: true
800
800
 
801
801
  ##########################################################
802
802
  Metrics/AbcSize:
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Michael Jungo", "Amanda Karavolia", "Andrea Liechti", "Jocelyn Thode", "Simon Brulhart"]
10
10
  spec.email = ["michael.jungo@unifr.ch"]
11
11
 
12
- spec.summary = %q{A wrapper around the CyberCoach API of the University of Fribourg}
12
+ spec.summary = "A wrapper around the CyberCoach API of the University of Fribourg"
13
13
  spec.homepage = "https://github.com/jungomi/coach_client"
14
14
  spec.license = "MIT"
15
15
 
@@ -18,4 +18,3 @@ require 'coach_client/version'
18
18
  # A wrapper around the CyberCoach service of the University of Fribourg
19
19
  module CoachClient
20
20
  end
21
-
@@ -6,13 +6,20 @@ module CoachClient
6
6
  # @return [String]
7
7
  attr_reader :url
8
8
 
9
+ # The maximum size of the requests
10
+ #
11
+ # @return [Integer]
12
+ attr_accessor :max_size
13
+
9
14
  # Creates a new client with the CyberCoach informations.
10
15
  #
11
16
  # @param [String] host the host address
12
17
  # @param [String] path the path to the resources
18
+ # @param [Integer] max_size the maximum size of requests
13
19
  # @return [CoachClient::Client]
14
- def initialize(host, path = '/')
20
+ def initialize(host, path = '/', max_size = 1000)
15
21
  @url = host + path
22
+ @max_size = max_size
16
23
  end
17
24
 
18
25
  # Returns whether the given credentials are valid.
@@ -81,4 +88,3 @@ module CoachClient
81
88
  end
82
89
  end
83
90
  end
84
-
@@ -226,4 +226,3 @@ module CoachClient
226
226
  end
227
227
  end
228
228
  end
229
-
@@ -75,4 +75,3 @@ module CoachClient
75
75
  end
76
76
  end
77
77
  end
78
-
@@ -1,9 +1,6 @@
1
1
  module CoachClient
2
2
  # A partnership resource of the CyberCoach service.
3
3
  class Partnership < CoachClient::Resource
4
- # The size of the requests for the {.list} with all = true
5
- LIST_ALL_SIZE = 1000
6
-
7
4
  # @return [Integer]
8
5
  attr_reader :id, :datecreated
9
6
 
@@ -62,7 +59,7 @@ module CoachClient
62
59
  if all
63
60
  total = self.total(client)
64
61
  start = 0
65
- size = LIST_ALL_SIZE
62
+ size = client.max_size
66
63
  end
67
64
  loop do
68
65
  response = CoachClient::Request.get(client.url + path,
@@ -283,4 +280,3 @@ module CoachClient
283
280
  end
284
281
  end
285
282
  end
286
-
@@ -35,15 +35,18 @@ module CoachClient
35
35
  # Updates the partnership subscription with the data from the CyberCoach
36
36
  # service.
37
37
  #
38
+ # @param [Integer] size the number of entries
39
+ # @param [Integer] start the start of entries list
40
+ # @param [Boolean] all whether all entries are retrieved
38
41
  # @raise [CoachClient::NotFound] if the partnership subscription does not
39
42
  # exist
40
43
  # @return [CoachClient::PartnershipSubscription] the updated partnership
41
44
  # subscription
42
- def update
45
+ def update(size: 20, start: 0, all: false)
43
46
  begin
44
- super(@partnership.user1)
47
+ super(@partnership.user1, size: size, start: start, all: all)
45
48
  rescue CoachClient::Exception
46
- super(@partnership.user2)
49
+ super(@partnership.user2, size: size, start: start, all: all)
47
50
  end
48
51
  end
49
52
 
@@ -96,4 +99,3 @@ module CoachClient
96
99
  end
97
100
  end
98
101
  end
99
-
@@ -101,4 +101,3 @@ module CoachClient
101
101
  end
102
102
  end
103
103
  end
104
-
@@ -43,6 +43,12 @@ module CoachClient
43
43
  end
44
44
  hash
45
45
  end
46
+
47
+ private
48
+
49
+ def next?(links)
50
+ return false if links.nil?
51
+ links.any? { |link| link[:description] == "next" }
52
+ end
46
53
  end
47
54
  end
48
-
@@ -34,4 +34,3 @@ module CoachClient
34
34
  end
35
35
  end
36
36
  end
37
-
@@ -84,4 +84,3 @@ module CoachClient
84
84
  end
85
85
  end
86
86
  end
87
-
@@ -37,22 +37,34 @@ module CoachClient
37
37
  #
38
38
  # @raise [CoachClient::NotFound] if the subscription does not exist
39
39
  # @param [CoachClient::User] user
40
+ # @param [Integer] size the number of entries
41
+ # @param [Integer] start the start of entries list
42
+ # @param [Boolean] all whether all entries are retrieved
40
43
  # @return [CoachClient::Subscription] the updated subscription
41
- def update(user)
42
- response = CoachClient::Request.get(url, username: user.username,
43
- password: user.password)
44
- response = response.to_h
45
- @id = response[:id]
46
- @datesubscribed = response[:datesubscribed]
47
- @publicvisible = response[:publicvisible]
44
+ def update(user, size: 20, start: 0, all: false)
45
+ response = {}
46
+ if all
47
+ start = 0
48
+ size = @client.max_size
49
+ end
48
50
  @entries = []
49
- unless response[:entries].nil?
51
+ loop do
52
+ response = CoachClient::Request.get(url, username: user.username,
53
+ password: user.password,
54
+ params: { start: start, size: size })
55
+ response = response.to_h
56
+ break if response[:entries].nil?
50
57
  response[:entries].each do |e|
51
58
  tag = "entry#{@sport}"
52
59
  id = CoachClient::Entry.extract_id_from_uri(e[tag.to_sym][:uri])
53
60
  @entries << CoachClient::Entry.new(client, self, id: id)
54
61
  end
62
+ break unless all && next?(response[:links])
63
+ start += size
55
64
  end
65
+ @id = response[:id]
66
+ @datesubscribed = response[:datesubscribed]
67
+ @publicvisible = response[:publicvisible]
56
68
  self
57
69
  end
58
70
 
@@ -97,4 +109,3 @@ module CoachClient
97
109
  end
98
110
  end
99
111
  end
100
-
@@ -1,9 +1,6 @@
1
1
  module CoachClient
2
2
  # A user resource of the CyberCoach service.
3
3
  class User < CoachClient::Resource
4
- # The size of the requests for the {.list} with all = true
5
- LIST_ALL_SIZE = 1000
6
-
7
4
  # @return [String]
8
5
  attr_reader :username
9
6
 
@@ -56,7 +53,7 @@ module CoachClient
56
53
  if all
57
54
  total = self.total(client)
58
55
  start = 0
59
- size = LIST_ALL_SIZE
56
+ size = client.max_size
60
57
  end
61
58
  loop do
62
59
  response = CoachClient::Request.get(client.url + path,
@@ -93,24 +90,36 @@ module CoachClient
93
90
 
94
91
  # Updates the user with the data from the CyberCoach service.
95
92
  #
93
+ # @param [Integer] size the number of partnerships
94
+ # @param [Integer] start the start of partnerships list
95
+ # @param [Boolean] all whether all partnerships are retrieved
96
96
  # @raise [CoachClient::NotFound] if the user does not exist
97
97
  # @return [CoachClient::User] the updated user
98
- def update
99
- response = CoachClient::Request.get(url, username: @username,
100
- password: @password)
101
- response = response.to_h
102
- @realname = response[:realname]
103
- @email = response[:email]
104
- @publicvisible = response[:publicvisible]
105
- @datecreated = response[:datecreated]
98
+ def update(size: 20, start: 0, all: false)
99
+ response = {}
100
+ if all
101
+ start = 0
102
+ size = @client.max_size
103
+ end
106
104
  @partnerships = []
107
- unless response[:partnerships].nil?
105
+ loop do
106
+ response = CoachClient::Request.get(url, username: @username,
107
+ password: @password,
108
+ params: { start: start, size: size })
109
+ response = response.to_h
110
+ break if response[:partnerships].nil?
108
111
  response[:partnerships].each do |p|
109
112
  users = CoachClient::Partnership.extract_users_from_uri(p[:uri])
110
113
  users.reject! { |username| username == @username }
111
114
  @partnerships << CoachClient::Partnership.new(client, self, users.first)
112
115
  end
116
+ break unless all && next?(response[:links])
117
+ start += size
113
118
  end
119
+ @realname = response[:realname]
120
+ @email = response[:email]
121
+ @publicvisible = response[:publicvisible]
122
+ @datecreated = response[:datecreated]
114
123
  @subscriptions = []
115
124
  unless response[:subscriptions].nil?
116
125
  response[:subscriptions].each do |s|
@@ -183,4 +192,3 @@ module CoachClient
183
192
  end
184
193
  end
185
194
  end
186
-
@@ -32,10 +32,13 @@ module CoachClient
32
32
 
33
33
  # Updates the user subscription with the data from the CyberCoach service.
34
34
  #
35
+ # @param [Integer] size the number of entries
36
+ # @param [Integer] start the start of entries list
37
+ # @param [Boolean] all whether all entries are retrieved
35
38
  # @raise [CoachClient::NotFound] if the user subscription does not exist
36
39
  # @return [CoachClient::UserSubscription] the updated user subscription
37
- def update
38
- super(@user)
40
+ def update(size: 20, start: 0, all: false)
41
+ super(@user, size: size, start: start, all: all)
39
42
  end
40
43
 
41
44
  # Saves the user subscription to the CyberCoach service.
@@ -76,4 +79,3 @@ module CoachClient
76
79
  end
77
80
  end
78
81
  end
79
-
@@ -1,5 +1,4 @@
1
1
  module CoachClient
2
2
  # The version of the gem
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coach_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Jungo
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-12-10 00:00:00.000000000 Z
15
+ date: 2015-12-11 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bundler