wes-data-api 5.8.1 → 6.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 722668ce5a55fbfe928eb3d5e02e6bae392563ac
4
- data.tar.gz: a66d15fd5a00300a2066a04f02fb4cd5a3a495d6
3
+ metadata.gz: 672ea7c8e8c570ec0592654e7108cadb251290d3
4
+ data.tar.gz: c6fcf8c72f4d727cd6149367b843d300fb85aa6f
5
5
  SHA512:
6
- metadata.gz: ed7715f6040de906ddf5d8eae019698f0c692cddb04577ef0f1410cb1d54f72fb01704081d4fb3589f4223371cb430d1be4f7a6aefbe22f4897be07d0f4c08b9
7
- data.tar.gz: 40537b35dd9e4824250e7d2f71d2347dc863bcd317ba30b30e1f46720abe397e4cc63d76df8593fb5485b921afcc36ef43c59c7ab96d38c4d1d6f035449df2e9
6
+ metadata.gz: ffe56aefcf0be912807a175be4ded8d0c7550ae7410eccdf7f98afec55c111c14c0df185a18c08f3a9916e930d21a567d70c9cacadfc23d85fdce4b21533f97a
7
+ data.tar.gz: 5faa6474b4c74271f5ff1edca9a6f77ad3e8f5aa74b61716a79d33b26a2c05a2f17c2424661c29555b34a9201380b31c033263e1c1acfaebbb3e6a3539f985ef
@@ -5,8 +5,9 @@ module Wes
5
5
  class Base
6
6
  attr_reader :attributes
7
7
 
8
- def initialize(attributes)
9
- @attributes = attributes
8
+ def initialize(attrs)
9
+ @attributes = attrs.is_a?(Hash) ? OpenStruct.new(attrs)
10
+ : attrs
10
11
  id_set?
11
12
  end
12
13
 
@@ -6,12 +6,19 @@ module Wes
6
6
  module API
7
7
  module Model
8
8
  class Brand < Base
9
- def challenges
10
- route = [routes.brand, id, routes.challenges].join("/")
9
+ def challenges(fetch: false)
10
+ records = fetch ? fetch_challenges : @attributes.challenges
11
11
  map_objects(
12
- client.get(route), Wes::Data::API::Model::Challenge
12
+ records, Wes::Data::API::Model::Challenge
13
13
  )
14
14
  end
15
+
16
+ private
17
+
18
+ def fetch_challenges
19
+ route = [routes.brand, id, routes.challenges].join("/")
20
+ client.get(route)
21
+ end
15
22
  end
16
23
  end
17
24
  end
@@ -15,11 +15,10 @@ module Wes
15
15
  self
16
16
  end
17
17
 
18
- def brands
19
- route = [routes.brand_user, id, routes.brands].join("/")
18
+ def brands(fetch: false)
19
+ records = fetch ? fetch_brands : @attributes.brands
20
20
  map_objects(
21
- client.get(route),
22
- Wes::Data::API::Model::Brand
21
+ records, Wes::Data::API::Model::Brand
23
22
  )
24
23
  end
25
24
 
@@ -28,6 +27,13 @@ module Wes
28
27
  def id
29
28
  attributes.auth0_id
30
29
  end
30
+
31
+ private
32
+
33
+ def fetch_brands
34
+ route = [routes.brand_user, id, routes.brands].join("/")
35
+ client.get(route)
36
+ end
31
37
  end
32
38
  end
33
39
  end
@@ -9,10 +9,10 @@ module Wes
9
9
  module API
10
10
  module Model
11
11
  class Challenge < Base
12
- def answers
12
+ def answers(fetch: false)
13
+ records = fetch ? client.get(answers_route) : @attributes.answers
13
14
  map_objects(
14
- client.get(answers_route),
15
- Wes::Data::API::Model::ChallengeAnswer
15
+ records, Wes::Data::API::Model::ChallengeAnswer
16
16
  )
17
17
  end
18
18
 
@@ -24,19 +24,18 @@ module Wes
24
24
  client.put(answers_route, answers)
25
25
  end
26
26
 
27
- def rewards
28
- route = [routes.challenge, id, routes.rewards].join("/")
27
+ def rewards(fetch: false)
28
+ records = fetch ? fetch_rewards : @attributes.rewards
29
29
  map_objects(
30
- client.get(route), Wes::Data::API::Model::Reward
30
+ records, Wes::Data::API::Model::Reward
31
31
  )
32
32
  end
33
33
 
34
- def users(state = nil)
35
- route = add_state(
36
- [routes.challenge, id, routes.creator_users].join("/"), state
37
- )
34
+ def users(state: nil, fetch: false)
35
+ records = fetch || !state.nil? ? fetch_users(state)
36
+ : @attributes.users
38
37
  map_objects(
39
- client.get(route), Wes::Data::API::Model::CreatorUser
38
+ records, Wes::Data::API::Model::CreatorUser
40
39
  )
41
40
  end
42
41
 
@@ -53,12 +52,11 @@ module Wes
53
52
  update(:status => s)
54
53
  end
55
54
 
56
- def videos(state = nil)
57
- route = add_state(
58
- [routes.challenge, id, routes.videos].join("/"), state
59
- )
55
+ def videos(state: nil, fetch: false)
56
+ records = fetch || !state.nil? ? fetch_videos(state)
57
+ : @attributes.videos
60
58
  map_objects(
61
- client.get(route), Wes::Data::API::Model::Video
59
+ records, Wes::Data::API::Model::Video
62
60
  )
63
61
  end
64
62
 
@@ -67,6 +65,25 @@ module Wes
67
65
  def answers_route
68
66
  [routes.challenge, id, routes.answers].join("/")
69
67
  end
68
+
69
+ def fetch_rewards
70
+ route = [routes.challenge, id, routes.rewards].join("/")
71
+ client.get(route)
72
+ end
73
+
74
+ def fetch_users(state)
75
+ route = add_state(
76
+ [routes.challenge, id, routes.creator_users].join("/"), state
77
+ )
78
+ client.get(route)
79
+ end
80
+
81
+ def fetch_videos(state)
82
+ route = add_state(
83
+ [routes.challenge, id, routes.videos].join("/"), state
84
+ )
85
+ client.get(route)
86
+ end
70
87
  end
71
88
  end
72
89
  end
@@ -12,7 +12,7 @@ module Wes
12
12
  private
13
13
 
14
14
  def ids_set?
15
- @attributes.challenge_id != nil && @attributes.question_id != nil
15
+ !@attributes.challenge_id.nil? && !@attributes.question_id.nil?
16
16
  end
17
17
 
18
18
  def id_hash
@@ -8,12 +8,11 @@ module Wes
8
8
  module API
9
9
  module Model
10
10
  class CreatorUser < Base
11
- def submissions(state = nil)
12
- route = add_state(
13
- [routes.creator_user, id, routes.submissions].join("/"), state
14
- )
11
+ def submissions(state: nil, fetch: false)
12
+ records = fetch || !state.nil? ? fetch_submissions(state)
13
+ : @attributes.submissions
15
14
  map_objects(
16
- client.get(route), Wes::Data::API::Model::Submission
15
+ records, Wes::Data::API::Model::Submission
17
16
  )
18
17
  end
19
18
 
@@ -26,10 +25,10 @@ module Wes
26
25
  self
27
26
  end
28
27
 
29
- def videos
30
- route = [routes.creator_user, id, routes.videos].join("/")
28
+ def videos(fetch: false)
29
+ records = fetch ? fetch_videos : @attributes.videos
31
30
  map_objects(
32
- client.get(route), Wes::Data::API::Model::Video
31
+ records, Wes::Data::API::Model::Video
33
32
  )
34
33
  end
35
34
 
@@ -48,17 +47,27 @@ module Wes
48
47
  )
49
48
  end
50
49
 
50
+ def fetch_submissions(state)
51
+ route = add_state(
52
+ [routes.creator_user, id, routes.submissions].join("/"), state
53
+ )
54
+ client.get(route)
55
+ end
56
+
57
+ def fetch_videos
58
+ route = [routes.creator_user, id, routes.videos].join("/")
59
+ client.get(route)
60
+ end
61
+
51
62
  def id
52
63
  attributes.auth0_id
53
64
  end
54
65
 
55
66
  def validate_collectives(input)
56
67
  unless input.is_a?(Array)
57
- raise ArgumentError, "List of collective IDs must be an array"
58
- end
59
- if input.empty?
60
- raise StandardError, "List of collective IDs is empty"
68
+ raise(ArgumentError, "List of collective IDs must be an array")
61
69
  end
70
+ raise(StandardError, "List of collective IDs empty") if input.empty?
62
71
  end
63
72
  end
64
73
  end
@@ -14,15 +14,20 @@ module Wes
14
14
  update(:state => "declined")
15
15
  end
16
16
 
17
- def videos
18
- route = [routes.submission, id, routes.videos].join("/")
17
+ def videos(fetch: false)
18
+ records = fetch ? fetch_videos : @attributes.videos
19
19
  map_objects(
20
- client.get(route), Wes::Data::API::Model::Video
20
+ records, Wes::Data::API::Model::Video
21
21
  )
22
22
  end
23
23
 
24
24
  private
25
25
 
26
+ def fetch_videos
27
+ route = [routes.submission, id, routes.videos].join("/")
28
+ client.get(route)
29
+ end
30
+
26
31
  def update(changes)
27
32
  route = [routes.submission, id].join("/")
28
33
  @attributes = client.put(
@@ -12,7 +12,7 @@ module Wes
12
12
  def build
13
13
  raise unexpected_error unless response.body
14
14
  raise api_error unless response.status == 200
15
- data = response.body["data"] || {}
15
+ data = response.body || {}
16
16
  data.map { |e| OpenStruct.new e }
17
17
  end
18
18
 
data/lib/wes/data/api.rb CHANGED
@@ -5,7 +5,7 @@ require "wes/data/api/configuration"
5
5
  module Wes
6
6
  module Data
7
7
  module API
8
- VERSION = "5.8.1".freeze
8
+ VERSION = "6.0.0".freeze
9
9
  end
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wes-data-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.8.1
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-18 00:00:00.000000000 Z
11
+ date: 2016-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler