wes-data-api 3.2.0 → 3.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: 2a765f6f56c692316cc7c0b0ac714e3d55169098
4
- data.tar.gz: 8233264fabc518241793426d56922ad2d6d8d712
3
+ metadata.gz: 36a4a4b4c62efac5afee29df5ba290bb91462d30
4
+ data.tar.gz: 12282a6060e9570f5053915b1a274e42b28055f8
5
5
  SHA512:
6
- metadata.gz: 98fb1ef00da31dd70b00f8516dde4c70c3aefba5551f2bd026742306fe9ae20d147b7f1ab554175355d7a288237e2de0563bed8820660416d2709c74dede016a
7
- data.tar.gz: e9250b3f2c6d4170bcf85c4e745da4270ec650165eaa49c581c2bc94b2fe8e1f72fb31faecd75c55cbbcb1bfe0f4ec7ccfc40c75090f67e518f4663f611ac3ef
6
+ metadata.gz: 11981dba3e27067f08598096a4512ba7a65cecbb43c8b7f5ae2f57fdc99ea0f04d88a631d5bc9d9861f5d16c1217e317f0757abb0288c871b44125649a8f7658
7
+ data.tar.gz: 1d79e4cbe105c0cd977e4a6dfa7a5c2b2ee88202c8381796b716d31d5aef9224d626803485f595bf98fb06300687b8fe3a80bb093b02b4425f7e25b5fdfaa23b
@@ -0,0 +1,82 @@
1
+ require "wes/data/api/client"
2
+ require "wes/data/api/configuration"
3
+
4
+ module Wes
5
+ module Data
6
+ module API
7
+ class Base
8
+ attr_reader :attributes
9
+
10
+ def initialize(attributes)
11
+ @attributes = attributes
12
+ end
13
+
14
+ class << self
15
+ def client
16
+ Client.new
17
+ end
18
+
19
+ def configuration
20
+ Configuration
21
+ end
22
+
23
+ def find(route)
24
+ new(client.get(route).first)
25
+ end
26
+
27
+ def create(route, payload = {})
28
+ new(client.post(route, payload).first)
29
+ end
30
+
31
+ def routes
32
+ configuration.routes
33
+ end
34
+
35
+ def mapped_objects(route)
36
+ client.get(route).map do |item|
37
+ new(item)
38
+ end
39
+ end
40
+ end
41
+
42
+ def exist?
43
+ !attributes.nil?
44
+ end
45
+
46
+ def method_missing(method_sym)
47
+ attributes.to_h.fetch(method_sym, nil)
48
+ end
49
+
50
+ def update(route, changes)
51
+ @attributes = client.put(
52
+ route,
53
+ @attributes.to_h.merge(changes)
54
+ ).first
55
+ self
56
+ end
57
+
58
+ protected
59
+
60
+ def id_set?
61
+ raise(ArgumentError, "ID not set for #{self.class.name}") if id.nil?
62
+ end
63
+
64
+ def id
65
+ attributes.id
66
+ end
67
+
68
+ def client
69
+ self.class.client
70
+ end
71
+
72
+ def routes
73
+ self.class.routes
74
+ end
75
+
76
+ def mapped_objects(route)
77
+ self.class.mapped_objects(route)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -1,73 +1,27 @@
1
- require "wes/data/api/client"
2
- require "wes/data/api/configuration"
1
+ require "wes/data/api/base"
3
2
 
4
3
  module Wes
5
4
  module Data
6
5
  module API
7
- class Billing
8
- attr_reader :attributes
9
-
10
- def initialize(attributes)
11
- @attributes = attributes
12
- end
13
-
6
+ class Billing < Base
14
7
  class << self
15
- def client
16
- Client.new
17
- end
18
-
19
- def configuration
20
- Configuration
21
- end
22
-
23
8
  def create(data)
24
9
  attributes = client.post("#{routes.billing}", data).first
25
10
  new(attributes)
26
11
  end
27
12
 
28
13
  def find(key, value)
29
- attrs = case key
14
+ case key
30
15
  when :id
31
- client.get("#{routes.billing}/#{value}")
16
+ super("#{routes.billing}/#{value}")
32
17
  when :user_id
33
- client.get("#{routes.user}/#{value}/billing")
18
+ super("#{routes.user}/#{value}/billing")
34
19
  end
35
- new(attrs.first)
36
20
  end
37
-
38
- def routes
39
- configuration.routes
40
- end
41
- end
42
-
43
- def exist?
44
- !@attributes.nil?
45
- end
46
-
47
- def method_missing(method_sym)
48
- attributes.send method_sym
49
21
  end
50
22
 
51
23
  def update(changes)
52
- @attributes = client.put(
53
- "#{routes.billing}/#{id}",
54
- @attributes.to_h.merge(changes)
55
- ).first
56
- self
57
- end
58
-
59
- private
60
-
61
- def client
62
- self.class.client
63
- end
64
-
65
- def id
66
- attributes.id
67
- end
68
-
69
- def routes
70
- self.class.routes
24
+ super("#{routes.billing}/#{id}", changes)
71
25
  end
72
26
  end
73
27
  end
@@ -1,86 +1,45 @@
1
- require "wes/data/api/client"
2
- require "wes/data/api/configuration"
1
+ require "wes/data/api/base"
3
2
 
4
3
  module Wes
5
4
  module Data
6
5
  module API
7
- class Challenge
8
- attr_reader :attributes
9
-
10
- def initialize(attributes)
11
- @attributes = attributes
12
- end
6
+ class Challenge < Base
13
7
 
14
8
  class << self
15
- def client
16
- Client.new
17
- end
18
-
19
- def configuration
20
- Configuration
21
- end
22
-
23
9
  def find(id)
24
- attributes = client.get("#{routes.challenge}/#{id}").first
25
- new(attributes)
10
+ super("#{routes.challenge}/#{id}")
26
11
  end
27
12
 
28
13
  def all
29
- client.get routes.challenges
14
+ mapped_objects(routes.challenges)
30
15
  end
31
16
 
32
17
  def closed
33
- client.get "#{routes.challenges}/closed"
18
+ mapped_objects("#{routes.challenges}/closed")
34
19
  end
35
20
 
36
21
  def drafts
37
- client.get "#{routes.challenges}/drafts"
22
+ mapped_objects("#{routes.challenges}/drafts")
38
23
  end
39
24
 
40
25
  def open
41
- client.get "#{routes.challenges}/open"
42
- end
43
-
44
- def routes
45
- configuration.routes
26
+ mapped_objects("#{routes.challenges}/open")
46
27
  end
47
28
  end
48
29
 
49
30
  def videos
50
31
  id_set?
51
- client.get "#{routes.challenge}/#{id}#{routes.videos}"
32
+ mapped_objects("#{routes.challenge}/#{id}#{routes.videos}")
52
33
  end
53
34
 
54
35
  def purchased_videos
55
36
  id_set?
56
- client.get "#{routes.challenge}/#{id}#{routes.videos}/purchased"
37
+ mapped_objects("#{routes.challenge}/#{id}#{routes.videos}/purchased")
57
38
  end
58
39
 
59
40
  def rewards
60
41
  id_set?
61
- client.get "#{routes.challenge}/#{id}/rewards"
62
- end
63
-
64
- def method_missing(method_sym)
65
- attributes.to_h.fetch(method_sym, nil)
66
- end
67
-
68
- private
69
-
70
- def id_set?
71
- raise(ArgumentError, "ID not set for Challenge") if id.nil?
72
- end
73
-
74
- def client
75
- self.class.client
76
- end
77
-
78
- def id
79
- attributes.id
80
- end
81
-
82
- def routes
83
- self.class.routes
42
+ mapped_objects("#{routes.challenge}/#{id}/rewards")
84
43
  end
85
44
  end
86
45
  end
@@ -1,71 +1,42 @@
1
- require "wes/data/api/client"
2
- require "wes/data/api/configuration"
1
+ require "wes/data/api/base"
3
2
 
4
3
  module Wes
5
4
  module Data
6
5
  module API
7
- class User
8
- attr_reader :attributes
9
-
10
- def initialize(attributes)
11
- @attributes = attributes
12
- end
13
-
6
+ class User < Base
14
7
  class << self
15
- def client
16
- Client.new
17
- end
18
-
19
- def configuration
20
- Configuration
21
- end
22
-
23
8
  def create(id)
24
- attributes = client.post("#{routes.user}/#{id}", {}).first
25
- new(attributes)
9
+ super("#{routes.user}/#{id}")
26
10
  end
27
11
 
28
12
  def find(key, value)
29
- attrs = key == :id ? client.get("#{routes.user}/#{value}")
30
- : client.get("#{routes.user}?#{key}=#{value}")
31
- new(attrs.first)
32
- end
33
-
34
- def routes
35
- configuration.routes
13
+ case key
14
+ when :id
15
+ super("#{routes.user}/#{value}")
16
+ else
17
+ super("#{routes.user}?#{key}=#{value}")
18
+ end
36
19
  end
37
20
  end
38
21
 
39
22
  def closed_submissions
40
- client.get "#{routes.user}/#{id}#{routes.submissions}/closed"
41
- end
42
-
43
- def exist?
44
- !@attributes.nil?
45
- end
46
-
47
- def method_missing(method_sym)
48
- attributes.send method_sym
23
+ mapped_objects("#{routes.user}/#{id}#{routes.submissions}/closed")
49
24
  end
50
25
 
51
26
  def open_submissions
52
- client.get("#{routes.user}/#{id}#{routes.submissions}/open")
27
+ mapped_objects("#{routes.user}/#{id}#{routes.submissions}/open")
53
28
  end
54
29
 
55
30
  def submissions
56
- client.get("#{routes.user}/#{id}#{routes.submissions}")
31
+ mapped_objects("#{routes.user}/#{id}#{routes.submissions}")
57
32
  end
58
33
 
59
34
  def videos
60
- client.get("#{routes.user}/#{id}#{routes.videos}")
35
+ mapped_objects("#{routes.user}/#{id}#{routes.videos}")
61
36
  end
62
37
 
63
38
  def update(changes)
64
- @attributes = client.put(
65
- "#{routes.user}/#{id}",
66
- @attributes.to_h.merge(changes)
67
- ).first
68
- self
39
+ super("#{routes.user}/#{id}", changes)
69
40
  end
70
41
 
71
42
  def assign_collectives(collective_ids)
@@ -85,17 +56,9 @@ module Wes
85
56
 
86
57
  private
87
58
 
88
- def client
89
- self.class.client
90
- end
91
-
92
59
  def id
93
60
  attributes.auth0_id
94
61
  end
95
-
96
- def routes
97
- self.class.routes
98
- end
99
62
  end
100
63
  end
101
64
  end
@@ -1,7 +1,7 @@
1
1
  module Wes
2
2
  module Data
3
3
  module API
4
- VERSION = "3.2.0".freeze
4
+ VERSION = "3.3.0".freeze
5
5
  end
6
6
  end
7
7
  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: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-26 00:00:00.000000000 Z
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -117,6 +117,7 @@ extra_rdoc_files: []
117
117
  files:
118
118
  - Gemfile
119
119
  - lib/wes/data/api.rb
120
+ - lib/wes/data/api/base.rb
120
121
  - lib/wes/data/api/billing.rb
121
122
  - lib/wes/data/api/brand.rb
122
123
  - lib/wes/data/api/challenge.rb