vidsy-data-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +3 -0
- data/README.md +23 -0
- data/Rakefile +6 -0
- data/lib/vidsy/data/api/client.rb +80 -0
- data/lib/vidsy/data/api/user.rb +19 -0
- data/lib/vidsy/data/api/version.rb +7 -0
- data/lib/vidsy/data/api/video.rb +22 -0
- data/lib/vidsy/data/api.rb +9 -0
- data/vidsy-data-api.gemspec +26 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 36c31358e29bc70cfc60549b209ab90df2b2b0cd
|
4
|
+
data.tar.gz: 54cede5df06c661cfe98dad3192e69b442c6b351
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e00f1f796320bf6a9ed8ec7135a16617f21721212b0dcdedde8424d0d5f2b28dac389d7e4eb2534f9c206bda58ad08f854a1784d461d8ac85592dd7d622be13c
|
7
|
+
data.tar.gz: f04ad4e88d94bfbfd8dd293b378aa2af35d317ab5b4d9f096f98e0905867d86b43ea0a811f1f26197078006b9d2577dcd5a4f9cbcfded1163c1cbc196740c2f7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
<h1 align="center">Vidsy Data API</h1>
|
2
|
+
|
3
|
+
<p align="center">
|
4
|
+
Ruby gem which wraps the Vidsy Data API.
|
5
|
+
</p>
|
6
|
+
|
7
|
+
### Config
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require "vidsy/data/api"
|
11
|
+
|
12
|
+
routes = {
|
13
|
+
:user => "/user",
|
14
|
+
:video => "/video"
|
15
|
+
}
|
16
|
+
|
17
|
+
Vidsy::Data::API::Client.tap do |c|
|
18
|
+
c.set_api_key "xxx"
|
19
|
+
c.set_endpoint "http://default.docker.vm:5001"
|
20
|
+
c.set_routes routes
|
21
|
+
c.set_version "v1"
|
22
|
+
end
|
23
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "json"
|
3
|
+
require "ostruct"
|
4
|
+
|
5
|
+
module Vidsy
|
6
|
+
module Data
|
7
|
+
module API
|
8
|
+
class Client
|
9
|
+
@@config = OpenStruct.new
|
10
|
+
|
11
|
+
def self.set_api_key(s)
|
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
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.version
|
60
|
+
@@config.version || "v1"
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def self.connection
|
66
|
+
@connection ||= Faraday.new(:url => endpoint) do |f|
|
67
|
+
f.response :logger
|
68
|
+
f.adapter Faraday.default_adapter
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.parse(response)
|
73
|
+
JSON.parse(response.body)["data"].map do |result|
|
74
|
+
OpenStruct.new result
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "vidsy/data/api/client"
|
2
|
+
|
3
|
+
module Vidsy
|
4
|
+
module Data
|
5
|
+
module API
|
6
|
+
class User < Client
|
7
|
+
def self.find(id)
|
8
|
+
users = get "#{routes.user}/#{id}"
|
9
|
+
users.size == 0 ? nil : users.first
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.create(params)
|
13
|
+
users = post(routes.user, params)
|
14
|
+
users.first.id
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "vidsy/data/api/client"
|
2
|
+
|
3
|
+
module Vidsy
|
4
|
+
module Data
|
5
|
+
module API
|
6
|
+
class Video < Client
|
7
|
+
def self.create(params, user_id)
|
8
|
+
videos = post(routes.video, post_params(user_id))
|
9
|
+
videos.first.id
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def self.post_params(user_id)
|
15
|
+
{
|
16
|
+
:user_id => user_id.to_i
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "vidsy/data/api/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vidsy-data-api"
|
8
|
+
spec.version = Vidsy::Data::API::VERSION
|
9
|
+
spec.authors = ["Charlie Revett"]
|
10
|
+
spec.email = ["charlie@vidsy.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{We"re hiring! http://vidsy.co/jobs}
|
13
|
+
spec.homepage = "http://vidsy.co/jobs"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
|
24
|
+
spec.add_dependency "faraday"
|
25
|
+
spec.add_dependency "json"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vidsy-data-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Charlie Revett
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- charlie@vidsy.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- lib/vidsy/data/api.rb
|
95
|
+
- lib/vidsy/data/api/client.rb
|
96
|
+
- lib/vidsy/data/api/user.rb
|
97
|
+
- lib/vidsy/data/api/version.rb
|
98
|
+
- lib/vidsy/data/api/video.rb
|
99
|
+
- vidsy-data-api.gemspec
|
100
|
+
homepage: http://vidsy.co/jobs
|
101
|
+
licenses: []
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.5.1
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: We"re hiring! http://vidsy.co/jobs
|
123
|
+
test_files: []
|