wes-data-api 3.5.0 → 4.0.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: 606729653ad9bae7a4999e9eb0e09407b5dffdf0
4
- data.tar.gz: 8ee3f5734be6d44e0cdf47b44215cd88d3a4455a
3
+ metadata.gz: 023c6f11132ce8f89854c1e0ee9b1e825bc6011c
4
+ data.tar.gz: 10f92314070fe552e5a6e3f7509f3bea8d26508f
5
5
  SHA512:
6
- metadata.gz: 5a007f038b340a1579df1af88a44fec721cb1e17cf535bc88c3736b98e74043dc880e9e5fd830a1a58568a363ccde8a82dbc4596af34ddface88cbc9f8b3e32e
7
- data.tar.gz: 7dd9adbc5e419267185a412212ce82724f6a0ef2910a240f4484ae7469dbc2980fe8d68bf5035379de0602886ab522a375f057c06b82eb66ff90e3e4b199803b
6
+ metadata.gz: da26e0f3cff0d69a526487a409cdf0d111bd9ebf7184e5fd037fb0c34f0086fa3a4103292a9ef20c4bf94f96e0f4c028ad5d86df59500ce4d80ff3aa109884e5
7
+ data.tar.gz: e2ab74fcca14e06caca472450070652e383188edcb46d73e9d3574777f95cb48a836ffe5c78b32f0bb06877fa4221614b9e0dc9d02992ee2b2ae326932bb0398
data/lib/wes/data/api.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require "json"
2
2
  require "ostruct"
3
3
  require "wes/data/api/configuration"
4
- require "wes/data/api/version"
5
4
 
6
5
  module Wes
7
6
  module Data
8
7
  module API
8
+ VERSION = "4.0.0".freeze
9
9
  end
10
10
  end
11
11
  end
@@ -4,77 +4,26 @@ require "wes/data/api/configuration"
4
4
  module Wes
5
5
  module Data
6
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?
7
+ module Base
8
+ def add_state(route, state = nil)
9
+ return route unless state
10
+ "#{route}/#{state}"
44
11
  end
45
12
 
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?
13
+ def client
14
+ Client.new
62
15
  end
63
16
 
64
- def id
65
- attributes.id
17
+ def configuration
18
+ Configuration
66
19
  end
67
20
 
68
- def client
69
- self.class.client
21
+ def map_objects(records, klass)
22
+ records.map { |r| klass.new(r) }
70
23
  end
71
24
 
72
25
  def routes
73
- self.class.routes
74
- end
75
-
76
- def mapped_objects(route)
77
- self.class.mapped_objects(route)
26
+ configuration.routes
78
27
  end
79
28
  end
80
29
  end
@@ -1,27 +1,37 @@
1
1
  require "wes/data/api/base"
2
+ require "wes/data/api/model/billing"
2
3
 
3
4
  module Wes
4
5
  module Data
5
6
  module API
6
- class Billing < Base
7
+ class Billing
7
8
  class << self
9
+ include Base
10
+
8
11
  def create(data)
9
- attributes = client.post("#{routes.billing}", data).first
10
- new(attributes)
12
+ attributes = client.post(routes.billing, data).first
13
+ model_klass.new(attributes)
11
14
  end
12
15
 
13
16
  def find(key, value)
17
+ attributes = client.get(find_route(key, value)).first
18
+ model_klass.new(attributes)
19
+ end
20
+
21
+ private
22
+
23
+ def find_route(key, value)
14
24
  case key
15
25
  when :id
16
- super("#{routes.billing}/#{value}")
26
+ [routes.billing, value].join("/")
17
27
  when :user_id
18
- super("#{routes.user}/#{value}/billing")
28
+ [routes.billing, value, routes.billing].join("/")
19
29
  end
20
30
  end
21
- end
22
31
 
23
- def update(changes)
24
- super("#{routes.billing}/#{id}", changes)
32
+ def model_klass
33
+ Wes::Data::API::Model::Billing
34
+ end
25
35
  end
26
36
  end
27
37
  end
@@ -1,49 +1,28 @@
1
- require "wes/data/api/client"
2
- require "wes/data/api/configuration"
1
+ require "wes/data/api/base"
2
+ require "wes/data/api/model/brand"
3
3
 
4
4
  module Wes
5
5
  module Data
6
6
  module API
7
7
  class Brand
8
- def initialize(id = nil)
9
- @id = id
10
- end
11
-
12
- def self.all
13
- new.all
14
- end
15
-
16
- def self.find(id)
17
- new.find id
18
- end
19
-
20
- def all
21
- client.get "#{routes.brands}"
22
- end
8
+ class << self
9
+ include Base
23
10
 
24
- def challenges
25
- raise(ArgumentError, "ID not set for Brand") if id.nil?
26
- client.get "#{routes.brand}/#{id}#{routes.challenges}"
27
- end
28
-
29
- def find(id)
30
- client.get("#{routes.brand}/#{id}").first
31
- end
32
-
33
- private
11
+ def all
12
+ map_objects(client.get(routes.brands), model_klass)
13
+ end
34
14
 
35
- attr_reader :id
15
+ def find(_key, value)
16
+ route = [routes.brand, value].join("/")
17
+ attributes = client.get(route).first
18
+ model_klass.new(attributes)
19
+ end
36
20
 
37
- def client
38
- Client.new
39
- end
40
-
41
- def configuration
42
- Configuration
43
- end
21
+ private
44
22
 
45
- def routes
46
- configuration.routes
23
+ def model_klass
24
+ Wes::Data::API::Model::Brand
25
+ end
47
26
  end
48
27
  end
49
28
  end
@@ -1,52 +1,32 @@
1
1
  require "wes/data/api/base"
2
+ require "wes/data/api/model/challenge"
2
3
 
3
4
  module Wes
4
5
  module Data
5
6
  module API
6
- class Challenge < Base
7
+ class Challenge
7
8
  class << self
8
- def find(id)
9
- super("#{routes.challenge}/#{id}")
10
- end
9
+ include Base
11
10
 
12
- def all
13
- mapped_objects(routes.challenges)
11
+ def find(_key, value)
12
+ route = [routes.challenge, value].join("/")
13
+ attributes = client.get(route).first
14
+ model_klass.new(attributes)
14
15
  end
15
16
 
16
- def closed
17
- mapped_objects("#{routes.challenges}/closed")
17
+ def all(state = nil)
18
+ route = add_state(routes.challenges, state)
19
+ map_objects(
20
+ client.get(route), model_klass
21
+ )
18
22
  end
19
23
 
20
- def drafts
21
- mapped_objects("#{routes.challenges}/drafts")
22
- end
24
+ private
23
25
 
24
- def open
25
- mapped_objects("#{routes.challenges}/open")
26
+ def model_klass
27
+ Wes::Data::API::Model::Challenge
26
28
  end
27
29
  end
28
-
29
- def purchased_videos
30
- id_set?
31
- mapped_objects("#{routes.challenge}/#{id}#{routes.videos}/purchased")
32
- end
33
-
34
- def rewards
35
- id_set?
36
- mapped_objects("#{routes.challenge}/#{id}/rewards")
37
- end
38
-
39
- def users(state = nil)
40
- id_set?
41
- route = state ? "#{routes.challenge}/#{id}/users/#{state}"
42
- : "#{routes.challenge}/#{id}/users"
43
- mapped_objects(route)
44
- end
45
-
46
- def videos
47
- id_set?
48
- mapped_objects("#{routes.challenge}/#{id}#{routes.videos}")
49
- end
50
30
  end
51
31
  end
52
32
  end
@@ -27,7 +27,7 @@ module Wes
27
27
  end
28
28
 
29
29
  def response(api_response)
30
- Response.build api_response
30
+ Response.new(api_response).build
31
31
  end
32
32
  end
33
33
  end
@@ -1,32 +1,25 @@
1
- require "wes/data/api/client"
2
- require "wes/data/api/configuration"
1
+ require "wes/data/api/base"
2
+ require "wes/data/api/model/collective"
3
3
 
4
4
  module Wes
5
5
  module Data
6
6
  module API
7
7
  class Collective
8
- def self.all
9
- new.all
10
- end
11
-
12
- def all
13
- client.get "#{routes.collectives}"
14
- end
15
-
16
- private
8
+ class << self
9
+ include Base
17
10
 
18
- attr_reader :id
11
+ def all
12
+ map_objects(
13
+ client.get(routes.collectives),
14
+ model_klass
15
+ )
16
+ end
19
17
 
20
- def client
21
- Client.new
22
- end
23
-
24
- def configuration
25
- Configuration
26
- end
18
+ private
27
19
 
28
- def routes
29
- configuration.routes
20
+ def model_klass
21
+ Wes::Data::API::Model::Collective
22
+ end
30
23
  end
31
24
  end
32
25
  end
@@ -1,3 +1,5 @@
1
+ require "wes/data/api/routes"
2
+
1
3
  module Wes
2
4
  module Data
3
5
  module API
@@ -6,7 +8,7 @@ module Wes
6
8
 
7
9
  class << self
8
10
  attr_accessor :endpoint
9
- attr_writer :routes, :version
11
+ attr_writer :version
10
12
 
11
13
  def configure(&block)
12
14
  yield self
@@ -14,7 +16,7 @@ module Wes
14
16
  end
15
17
 
16
18
  def routes
17
- OpenStruct.new @routes
19
+ Routes.hash
18
20
  end
19
21
 
20
22
  def version
@@ -0,0 +1,57 @@
1
+ module Wes
2
+ module Data
3
+ module API
4
+ module Model
5
+ class Base
6
+ protected
7
+
8
+ attr_reader :attributes
9
+
10
+ def initialize(attributes)
11
+ @attributes = attributes
12
+ id_set?
13
+ end
14
+
15
+ def add_state(route, state)
16
+ return route unless state
17
+ "#{route}/#{state}"
18
+ end
19
+
20
+ def client
21
+ Client.new
22
+ end
23
+
24
+ def configuration
25
+ Configuration
26
+ end
27
+
28
+ def exist?
29
+ !attributes.nil?
30
+ end
31
+
32
+ def id
33
+ attributes.id
34
+ end
35
+
36
+ def map_objects(records, klass)
37
+ records.map { |r| klass.new(r) }
38
+ end
39
+
40
+ def method_missing(sym, *_args, &_block)
41
+ attributes.to_h.fetch(sym, nil)
42
+ end
43
+
44
+ def routes
45
+ configuration.routes
46
+ end
47
+
48
+ private
49
+
50
+ def id_set?
51
+ raise(ArgumentError, "ID not set for #{self.class.name}") if id.nil?
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,20 @@
1
+ require "wes/data/api/model/base"
2
+
3
+ module Wes
4
+ module Data
5
+ module API
6
+ module Model
7
+ class Billing < Base
8
+ def update(changes)
9
+ route = [routes.billing, id].join("/")
10
+ attributes = client.put(
11
+ route, attributes.to_h.merge(changes)
12
+ ).first
13
+
14
+ self
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ require "wes/data/api/model/base"
2
+ require "wes/data/api/model/challenge"
3
+
4
+ module Wes
5
+ module Data
6
+ module API
7
+ module Model
8
+ class Brand < Base
9
+ def challenges
10
+ route = [routes.brand, id, routes.challenges].join("/")
11
+ map_objects(
12
+ client.get(route), Wes::Data::API::Model::Challenge
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ require "wes/data/api/model/base"
2
+ require "wes/data/api/model/challenge_reward"
3
+ require "wes/data/api/model/user"
4
+ require "wes/data/api/model/video"
5
+
6
+ module Wes
7
+ module Data
8
+ module API
9
+ module Model
10
+ class Challenge < Base
11
+ def rewards
12
+ route = [routes.challenge, id, routes.rewards].join("/")
13
+ map_objects(
14
+ client.get(route), Wes::Data::API::Model::ChallengeReward
15
+ )
16
+ end
17
+
18
+ def users(state = nil)
19
+ route = add_state(
20
+ [routes.challenge, id, routes.users].join("/"), state
21
+ )
22
+ map_objects(
23
+ client.get(route), Wes::Data::API::Model::User
24
+ )
25
+ end
26
+
27
+ def videos(state = nil)
28
+ route = add_state(
29
+ [routes.challenge, id, routes.videos].join("/"), state
30
+ )
31
+ map_objects(
32
+ client.get(route), Wes::Data::API::Model::Video
33
+ )
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,12 @@
1
+ require "wes/data/api/model/base"
2
+
3
+ module Wes
4
+ module Data
5
+ module API
6
+ module Model
7
+ class ChallengeReward < Base
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require "wes/data/api/model/base"
2
+
3
+ module Wes
4
+ module Data
5
+ module API
6
+ module Model
7
+ class Collective < Base
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ require "wes/data/api/model/base"
2
+ require "wes/data/api/model/video"
3
+
4
+ module Wes
5
+ module Data
6
+ module API
7
+ module Model
8
+ class Submission < Base
9
+ def videos
10
+ route = [routes.submission, id, routes.videos].join("/")
11
+ map_objects(
12
+ client.get(route), Wes::Data::API::Model::Video
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,67 @@
1
+ require "wes/data/api/model/base"
2
+ require "wes/data/api/model/collective"
3
+ require "wes/data/api/model/submission"
4
+ require "wes/data/api/model/video"
5
+
6
+ module Wes
7
+ module Data
8
+ module API
9
+ module Model
10
+ class User < Base
11
+ def submissions(state = nil)
12
+ route = add_state(
13
+ [routes.user, id, routes.submissions].join("/"), state
14
+ )
15
+ map_objects(
16
+ client.get(route), Wes::Data::API::Model::Submission
17
+ )
18
+ end
19
+
20
+ def update(changes)
21
+ route = [routes.user, id].join("/")
22
+ attributes = client.put(
23
+ route, attributes.to_h.merge(changes)
24
+ ).first
25
+
26
+ self
27
+ end
28
+
29
+ def videos
30
+ route = [routes.user, id, routes.videos].join("/")
31
+ map_objects(
32
+ client.get(route), Wes::Data::API::Model::Video
33
+ )
34
+ end
35
+
36
+ def assign_collectives(collective_ids)
37
+ validate_collectives(collective_ids)
38
+ records = create_collectives(collective_ids)
39
+ map_objects(records, Wes::Data::API::Model::Collective)
40
+ end
41
+
42
+ protected
43
+
44
+ def create_collectives(collective_ids)
45
+ client.post(
46
+ [routes.user, id, routes.collectives].join("/"),
47
+ collective_ids
48
+ )
49
+ end
50
+
51
+ def id
52
+ attributes.auth0_id
53
+ end
54
+
55
+ def validate_collectives(input)
56
+ 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"
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,12 @@
1
+ require "wes/data/api/model/base"
2
+
3
+ module Wes
4
+ module Data
5
+ module API
6
+ module Model
7
+ class Video < Base
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -6,69 +6,59 @@ module Wes
6
6
  module Data
7
7
  module API
8
8
  class Request
9
- def self.get(path)
10
- new.get path
11
- end
12
-
13
- def self.post(path, options = {})
14
- new.post(path, options)
15
- end
16
-
17
- def self.put(path, options = {})
18
- new.put(path, options)
19
- end
20
-
21
- def get(path)
22
- connection.get do |r|
23
- r.url complete_path(path)
24
- r.options.timeout = TIMEOUT
9
+ class << self
10
+ def get(path)
11
+ connection.get do |r|
12
+ r.options.timeout = TIMEOUT
13
+ r.url complete_path(path)
14
+ end
25
15
  end
26
- end
27
16
 
28
- def post(path, options)
29
- connection.post do |r|
30
- r.body = options.to_json
31
- r.headers["Content-Type"] = "application/json"
32
- r.url complete_path(path)
33
- r.options.timeout = TIMEOUT
17
+ def post(path, options)
18
+ connection.post do |r|
19
+ r.body = options.to_json
20
+ r.headers["Content-Type"] = "application/json"
21
+ r.options.timeout = TIMEOUT
22
+ r.url complete_path(path)
23
+ end
34
24
  end
35
- end
36
25
 
37
- def put(path, options)
38
- connection.put do |r|
39
- r.body = options.to_json
40
- r.headers["Content-Type"] = "application/json"
41
- r.url complete_path(path)
42
- r.options.timeout = TIMEOUT
26
+ def put(path, options)
27
+ connection.put do |r|
28
+ r.body = options.to_json
29
+ r.headers["Content-Type"] = "application/json"
30
+ r.options.timeout = TIMEOUT
31
+ r.url complete_path(path)
32
+ end
43
33
  end
44
- end
45
34
 
46
- private
35
+ private
47
36
 
48
- TIMEOUT = 2
37
+ TIMEOUT = 2
49
38
 
50
- def complete_path(path)
51
- "/#{version}#{path}"
52
- end
39
+ def complete_path(path)
40
+ ["/", version, path].join("/")
41
+ end
53
42
 
54
- def configuration
55
- Configuration
56
- end
43
+ def configuration
44
+ Configuration
45
+ end
57
46
 
58
- def connection
59
- Faraday.new(:url => endpoint) do |c|
60
- c.adapter Faraday.default_adapter
61
- c.use Faraday::Response::RaiseError
62
- c.response :json, :content_type => /\bjson$/
47
+ def connection
48
+ Faraday.new(:url => endpoint) do |c|
49
+ c.adapter Faraday.default_adapter
50
+ c.use Faraday::Response::RaiseError
51
+ c.response :json, :content_type => /\bjson$/
52
+ end
63
53
  end
64
- end
65
54
 
66
- def endpoint
67
- configuration.endpoint
68
- end
55
+ def endpoint
56
+ configuration.endpoint
57
+ end
69
58
 
70
- def version
71
- configuration.version
59
+ def version
60
+ configuration.version
61
+ end
72
62
  end
73
63
  end
74
64
  end
@@ -5,15 +5,11 @@ module Wes
5
5
  module Data
6
6
  module API
7
7
  class Response
8
- def self.build(response)
9
- new(response).data
10
- end
11
-
12
8
  def initialize(response)
13
9
  @response = response
14
10
  end
15
11
 
16
- def data
12
+ def build
17
13
  raise unexpected_error unless response.body
18
14
  data = response.body["data"] || raise(response_error)
19
15
  data.map { |e| OpenStruct.new e }
@@ -0,0 +1,27 @@
1
+ module Wes
2
+ module Data
3
+ module API
4
+ class Routes
5
+ class << self
6
+ def hash
7
+ OpenStruct.new(
8
+ :billing => "billing",
9
+ :brand => "brand",
10
+ :brands => "brands",
11
+ :challenge => "challenge",
12
+ :challenges => "challenges",
13
+ :collectives => "collectives",
14
+ :rewards => "rewards",
15
+ :submission => "submission",
16
+ :submissions => "submissions",
17
+ :user => "user",
18
+ :users => "users",
19
+ :video => "video",
20
+ :videos => "videos"
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,49 +1,29 @@
1
- require "wes/data/api/client"
2
- require "wes/data/api/configuration"
1
+ require "wes/data/api/base"
2
+ require "wes/data/api/model/submission"
3
3
 
4
4
  module Wes
5
5
  module Data
6
6
  module API
7
7
  class Submission
8
- def initialize(id = nil)
9
- @id = id
10
- end
11
-
12
- def self.create(options)
13
- new.create options
14
- end
15
-
16
- def self.find(id)
17
- new.find id
18
- end
19
-
20
- def create(options)
21
- client.post(routes.submission, options).first
22
- end
8
+ class << self
9
+ include Base
23
10
 
24
- def find(id)
25
- client.get("#{routes.submission}/#{id}").first
26
- end
27
-
28
- def videos
29
- raise(ArgumentError, "ID not set for Submission") if id.nil?
30
- client.get "#{routes.submission}/#{id}#{routes.videos}"
31
- end
32
-
33
- private
11
+ def create(options)
12
+ attributes = client.post(routes.submission, options).first
13
+ model_klass.new(attributes)
14
+ end
34
15
 
35
- attr_reader :id
16
+ def find(_key, value)
17
+ route = [routes.submission, value].join("/")
18
+ attributes = client.get(route).first
19
+ model_klass.new(attributes)
20
+ end
36
21
 
37
- def client
38
- Client.new
39
- end
40
-
41
- def configuration
42
- Configuration
43
- end
22
+ private
44
23
 
45
- def routes
46
- configuration.routes
24
+ def model_klass
25
+ Wes::Data::API::Model::Submission
26
+ end
47
27
  end
48
28
  end
49
29
  end
@@ -1,67 +1,48 @@
1
1
  require "wes/data/api/base"
2
+ require "wes/data/api/model/user"
2
3
 
3
4
  module Wes
4
5
  module Data
5
6
  module API
6
- class User < Base
7
+ class User
7
8
  class << self
9
+ include Base
10
+
8
11
  def all
9
- mapped_objects(routes.users)
12
+ map_objects(
13
+ client.get(routes.users), model_klass
14
+ )
10
15
  end
11
16
 
12
17
  def create(id)
13
- super("#{routes.user}/#{id}")
18
+ route = [routes.user, id].join("/")
19
+ attributes = client.post(route).first
20
+ model_klass.new(attributes)
14
21
  end
15
22
 
16
23
  def find(key, value)
24
+ attributes = client.get(find_route(key, value)).first
25
+ model_klass.new(attributes)
26
+ end
27
+
28
+ private
29
+
30
+ def find_route(key, value)
17
31
  case key
18
32
  when :id
19
- super("#{routes.user}/#{value}")
33
+ [routes.user, value].join("/")
20
34
  else
21
- super("#{routes.user}?#{key}=#{value}")
35
+ "#{routes.user}?#{key}=#{value}"
22
36
  end
23
37
  end
24
- end
25
38
 
26
- def closed_submissions
27
- mapped_objects("#{routes.user}/#{id}#{routes.submissions}/closed")
28
- end
29
-
30
- def open_submissions
31
- mapped_objects("#{routes.user}/#{id}#{routes.submissions}/open")
32
- end
33
-
34
- def submissions
35
- mapped_objects("#{routes.user}/#{id}#{routes.submissions}")
36
- end
37
-
38
- def videos
39
- mapped_objects("#{routes.user}/#{id}#{routes.videos}")
40
- end
41
-
42
- def update(changes)
43
- super("#{routes.user}/#{id}", changes)
44
- end
45
-
46
- def assign_collectives(collective_ids)
47
- unless collective_ids.kind_of?(Array)
48
- raise ArgumentError, "List of collective ids must be an array"
39
+ def id
40
+ attributes.auth0_id
49
41
  end
50
42
 
51
- if collective_ids.empty?
52
- raise StandardError, "At least one collective_id must be specified"
43
+ def model_klass
44
+ Wes::Data::API::Model::User
53
45
  end
54
-
55
- client.post(
56
- [routes.user, id, "collectives"].join("/"),
57
- collective_ids
58
- )
59
- end
60
-
61
- private
62
-
63
- def id
64
- attributes.auth0_id
65
46
  end
66
47
  end
67
48
  end
@@ -1,30 +1,23 @@
1
- require "wes/data/api/client"
2
- require "wes/data/api/configuration"
1
+ require "wes/data/api/base"
2
+ require "wes/data/api/model/video"
3
3
 
4
4
  module Wes
5
5
  module Data
6
6
  module API
7
7
  class Video
8
- def self.create(options)
9
- new.create options
10
- end
11
-
12
- def create(options)
13
- client.post(routes.video, options).first
14
- end
8
+ class << self
9
+ include Base
15
10
 
16
- private
11
+ def create(options)
12
+ attributes = client.post(routes.video, options).first
13
+ model_klass.new(attributes)
14
+ end
17
15
 
18
- def client
19
- Client.new
20
- end
21
-
22
- def configuration
23
- Configuration
24
- end
16
+ private
25
17
 
26
- def routes
27
- configuration.routes
18
+ def model_klass
19
+ Wes::Data::API::Model::Video
20
+ end
28
21
  end
29
22
  end
30
23
  end
data/wes-data-api.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "wes/data/api/version"
4
+ require "wes/data/api"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "wes-data-api"
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.5.0
4
+ version: 4.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-05 00:00:00.000000000 Z
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,11 +126,20 @@ files:
126
126
  - lib/wes/data/api/configuration.rb
127
127
  - lib/wes/data/api/error/response.rb
128
128
  - lib/wes/data/api/error/unexpected.rb
129
+ - lib/wes/data/api/model/base.rb
130
+ - lib/wes/data/api/model/billing.rb
131
+ - lib/wes/data/api/model/brand.rb
132
+ - lib/wes/data/api/model/challenge.rb
133
+ - lib/wes/data/api/model/challenge_reward.rb
134
+ - lib/wes/data/api/model/collective.rb
135
+ - lib/wes/data/api/model/submission.rb
136
+ - lib/wes/data/api/model/user.rb
137
+ - lib/wes/data/api/model/video.rb
129
138
  - lib/wes/data/api/request.rb
130
139
  - lib/wes/data/api/response.rb
140
+ - lib/wes/data/api/routes.rb
131
141
  - lib/wes/data/api/submission.rb
132
142
  - lib/wes/data/api/user.rb
133
- - lib/wes/data/api/version.rb
134
143
  - lib/wes/data/api/video.rb
135
144
  - wes-data-api.gemspec
136
145
  homepage: ''
@@ -1,7 +0,0 @@
1
- module Wes
2
- module Data
3
- module API
4
- VERSION = "3.5.0".freeze
5
- end
6
- end
7
- end