vidsy-data-api 0.3.0 → 0.4.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 +4 -4
- data/lib/vidsy/data/api.rb +1 -1
- data/lib/vidsy/data/api/brand.rb +18 -11
- data/lib/vidsy/data/api/client.rb +12 -62
- data/lib/vidsy/data/api/configuration.rb +29 -0
- data/lib/vidsy/data/api/error/response.rb +9 -0
- data/lib/vidsy/data/api/error/unexpected.rb +9 -0
- data/lib/vidsy/data/api/request.rb +58 -0
- data/lib/vidsy/data/api/response.rb +46 -0
- data/lib/vidsy/data/api/user.rb +27 -6
- data/lib/vidsy/data/api/version.rb +1 -1
- data/lib/vidsy/data/api/video.rb +18 -8
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b630829b895f90fdfac65adee62b293654f69d50
|
4
|
+
data.tar.gz: 417e2cfb904fd6a102789aa854b40b82a557196b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81d0cf0afde69d3778fe5558683dabba24b18c8e9d1614875efa644f3dfb4c7ba1b54eeba42181af73bba3c190325a63fc9d8902c2bb9000b85e9421fdad434d
|
7
|
+
data.tar.gz: 8e308eeece5fe54c1af6663d3f53305edaeba907535d16597675cf7b8790c45b1590070e319ed88beea6def83d2e9b2134c09f366097aa18f26a2c2574c7a33f
|
data/lib/vidsy/data/api.rb
CHANGED
data/lib/vidsy/data/api/brand.rb
CHANGED
@@ -1,34 +1,41 @@
|
|
1
1
|
require "vidsy/data/api/client"
|
2
|
+
require "vidsy/data/api/configuration"
|
2
3
|
|
3
4
|
module Vidsy
|
4
5
|
module Data
|
5
6
|
module API
|
6
|
-
class Brand
|
7
|
+
class Brand
|
7
8
|
def initialize(id = nil)
|
8
9
|
@id = id
|
9
10
|
end
|
10
11
|
|
11
|
-
def
|
12
|
-
|
13
|
-
challenges = get "#{routes.brand}/#{id}/#{routes.challenges}"
|
14
|
-
challenges.size == 0 ? nil : challenges
|
12
|
+
def self.all
|
13
|
+
new.all
|
15
14
|
end
|
16
15
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
16
|
+
def all
|
17
|
+
client.get "#{routes.brands}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def challenges
|
21
|
+
raise(ArgumentError, "ID not set for Brand") if id.nil?
|
22
|
+
client.get "#{routes.brand}/#{id}/#{routes.challenges}"
|
20
23
|
end
|
21
24
|
|
22
25
|
private
|
23
26
|
|
24
27
|
attr_reader :id
|
25
28
|
|
26
|
-
def
|
27
|
-
|
29
|
+
def client
|
30
|
+
Vidsy::Data::API::Client.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def configuration
|
34
|
+
Vidsy::Data::API::Configuration
|
28
35
|
end
|
29
36
|
|
30
37
|
def routes
|
31
|
-
|
38
|
+
configuration.routes
|
32
39
|
end
|
33
40
|
end
|
34
41
|
end
|
@@ -1,78 +1,28 @@
|
|
1
|
-
require "
|
2
|
-
require "
|
3
|
-
require "ostruct"
|
1
|
+
require "vidsy/data/api/request"
|
2
|
+
require "vidsy/data/api/response"
|
4
3
|
|
5
4
|
module Vidsy
|
6
5
|
module Data
|
7
6
|
module API
|
8
7
|
class Client
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
raise(ArgumentError, "API key must be String") unless s.is_a? String
|
13
|
-
@@config.tap { |c| c.api_key = s }
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.set_endpoint(s)
|
17
|
-
raise(ArgumentError, "Endpoint must be String") unless s.is_a? String
|
18
|
-
@@config.tap { |c| c.endpoint = s }
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.set_routes(h)
|
22
|
-
raise(ArgumentError, "Routes must be Hash") unless h.is_a? Hash
|
23
|
-
@@config.tap { |c| c.routes = OpenStruct.new h }
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.set_version(s)
|
27
|
-
raise(ArgumentError, "Version must be String") unless s.is_a? String
|
28
|
-
@@config.tap { |c| c.version = s }
|
29
|
-
end
|
30
|
-
|
31
|
-
protected
|
32
|
-
|
33
|
-
def self.api_key
|
34
|
-
@@config.api_key
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.endpoint
|
38
|
-
@@config.endpoint
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.get(path)
|
42
|
-
parse connection.get("/#{version}#{path}")
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.post(path, params)
|
46
|
-
response = connection.post do |req|
|
47
|
-
req.url "/#{version}#{path}"
|
48
|
-
req.headers["Content-Type"] = "application/json"
|
49
|
-
req.body = params.to_json
|
50
|
-
end
|
51
|
-
|
52
|
-
parse response
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.routes
|
56
|
-
@@config.routes
|
8
|
+
def get(path)
|
9
|
+
api_response = request.get path
|
10
|
+
response api_response
|
57
11
|
end
|
58
12
|
|
59
|
-
def
|
60
|
-
|
13
|
+
def post(path, options)
|
14
|
+
api_response = request.post(path, options)
|
15
|
+
response api_response
|
61
16
|
end
|
62
17
|
|
63
18
|
private
|
64
19
|
|
65
|
-
def
|
66
|
-
|
67
|
-
f.response :logger
|
68
|
-
f.adapter Faraday.default_adapter
|
69
|
-
end
|
20
|
+
def request
|
21
|
+
Vidsy::Data::API::Request
|
70
22
|
end
|
71
23
|
|
72
|
-
def
|
73
|
-
|
74
|
-
OpenStruct.new result
|
75
|
-
end
|
24
|
+
def response(api_response)
|
25
|
+
Vidsy::Data::API::Response.build api_response
|
76
26
|
end
|
77
27
|
end
|
78
28
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
|
3
|
+
module Vidsy
|
4
|
+
module Data
|
5
|
+
module API
|
6
|
+
class Configuration
|
7
|
+
DEFAULT_VERSION = "v1"
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_accessor :endpoint
|
11
|
+
attr_writer :routes, :version
|
12
|
+
|
13
|
+
def configure(&block)
|
14
|
+
yield self
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def routes
|
19
|
+
OpenStruct.new @routes
|
20
|
+
end
|
21
|
+
|
22
|
+
def version
|
23
|
+
@version ||= DEFAULT_VERSION
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
require "json"
|
4
|
+
require "vidsy/data/api/configuration"
|
5
|
+
|
6
|
+
module Vidsy
|
7
|
+
module Data
|
8
|
+
module API
|
9
|
+
class Request
|
10
|
+
def self.get(path)
|
11
|
+
new.get path
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.post(path, options = {})
|
15
|
+
new.post(path, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(path)
|
19
|
+
connection.get complete_path(path)
|
20
|
+
end
|
21
|
+
|
22
|
+
def post(path, options)
|
23
|
+
connection.post do |r|
|
24
|
+
r.body = options.to_json
|
25
|
+
r.headers["Content-Type"] = "application/json"
|
26
|
+
r.url complete_path(path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def complete_path(path)
|
33
|
+
"/#{version}#{path}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def configuration
|
37
|
+
Vidsy::Data::API::Configuration
|
38
|
+
end
|
39
|
+
|
40
|
+
def connection
|
41
|
+
Faraday.new(:url => endpoint) do |c|
|
42
|
+
c.adapter Faraday.default_adapter
|
43
|
+
c.use Faraday::Response::RaiseError
|
44
|
+
c.response :json, :content_type => /\bjson$/
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def endpoint
|
49
|
+
configuration.endpoint
|
50
|
+
end
|
51
|
+
|
52
|
+
def version
|
53
|
+
configuration.version
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
require "vidsy/data/api/error/unexpected"
|
3
|
+
|
4
|
+
module Vidsy
|
5
|
+
module Data
|
6
|
+
module API
|
7
|
+
class Response
|
8
|
+
def self.build(response)
|
9
|
+
new(response).data
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(response)
|
13
|
+
@response = response
|
14
|
+
end
|
15
|
+
|
16
|
+
def data
|
17
|
+
raise unexpected_error unless response.body
|
18
|
+
data = response.body["data"] || raise(response_error)
|
19
|
+
data.map { |e| OpenStruct.new e }
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :response
|
25
|
+
|
26
|
+
def error_details
|
27
|
+
response.body.fetch "details"
|
28
|
+
end
|
29
|
+
|
30
|
+
def error_status
|
31
|
+
response.body.fetch "status"
|
32
|
+
end
|
33
|
+
|
34
|
+
def response_error
|
35
|
+
Vidsy::Data::API::Error::Response.new(
|
36
|
+
"#{error_status} - #{error_details}"
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def unexpected_error
|
41
|
+
Vidsy::Data::API::Error::Unexpected
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/vidsy/data/api/user.rb
CHANGED
@@ -1,17 +1,38 @@
|
|
1
1
|
require "vidsy/data/api/client"
|
2
|
+
require "vidsy/data/api/configuration"
|
2
3
|
|
3
4
|
module Vidsy
|
4
5
|
module Data
|
5
6
|
module API
|
6
|
-
class User
|
7
|
+
class User
|
8
|
+
def self.create(options)
|
9
|
+
new.create options
|
10
|
+
end
|
11
|
+
|
7
12
|
def self.find(id)
|
8
|
-
|
9
|
-
|
13
|
+
new.find id
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(options)
|
17
|
+
client.post(routes.user, options).first
|
18
|
+
end
|
19
|
+
|
20
|
+
def find(id)
|
21
|
+
client.get "#{routes.user}/#{id}"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def client
|
27
|
+
Vidsy::Data::API::Client.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def configuration
|
31
|
+
Vidsy::Data::API::Configuration
|
10
32
|
end
|
11
33
|
|
12
|
-
def
|
13
|
-
|
14
|
-
users.first.id
|
34
|
+
def routes
|
35
|
+
configuration.routes
|
15
36
|
end
|
16
37
|
end
|
17
38
|
end
|
data/lib/vidsy/data/api/video.rb
CHANGED
@@ -1,20 +1,30 @@
|
|
1
1
|
require "vidsy/data/api/client"
|
2
|
+
require "vidsy/data/api/configuration"
|
2
3
|
|
3
4
|
module Vidsy
|
4
5
|
module Data
|
5
6
|
module API
|
6
|
-
class Video
|
7
|
-
def self.create(
|
8
|
-
|
9
|
-
|
7
|
+
class Video
|
8
|
+
def self.create(options)
|
9
|
+
new.create params
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(options)
|
13
|
+
client.post(routes.video, options).first
|
10
14
|
end
|
11
15
|
|
12
16
|
private
|
13
17
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
def client
|
19
|
+
Vidsy::Data::API::Client.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def configuration
|
23
|
+
Vidsy::Data::API::Configuration
|
24
|
+
end
|
25
|
+
|
26
|
+
def routes
|
27
|
+
configuration.routes
|
18
28
|
end
|
19
29
|
end
|
20
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vidsy-data-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Revett
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01
|
11
|
+
date: 2016-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -105,6 +105,11 @@ files:
|
|
105
105
|
- lib/vidsy/data/api.rb
|
106
106
|
- lib/vidsy/data/api/brand.rb
|
107
107
|
- lib/vidsy/data/api/client.rb
|
108
|
+
- lib/vidsy/data/api/configuration.rb
|
109
|
+
- lib/vidsy/data/api/error/response.rb
|
110
|
+
- lib/vidsy/data/api/error/unexpected.rb
|
111
|
+
- lib/vidsy/data/api/request.rb
|
112
|
+
- lib/vidsy/data/api/response.rb
|
108
113
|
- lib/vidsy/data/api/user.rb
|
109
114
|
- lib/vidsy/data/api/version.rb
|
110
115
|
- lib/vidsy/data/api/video.rb
|