arc_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/Rakefile +6 -0
- data/arc_api.gemspec +28 -0
- data/lib/arc_api.rb +2 -0
- data/lib/arc_api/client.rb +45 -0
- data/lib/arc_api/client/health_check.rb +10 -0
- data/lib/arc_api/client/media.rb +34 -0
- data/lib/arc_api/version.rb +3 -0
- data/spec/arc_api/client/health_check_spec.rb +7 -0
- data/spec/arc_api/client/media_spec.rb +25 -0
- data/spec/arc_api/client_spec.rb +9 -0
- data/spec/arc_api_spec.rb +5 -0
- data/spec/fixtures/health_check.json +1 -0
- data/spec/fixtures/media_create.json +7 -0
- data/spec/fixtures/media_initiate_upload.json +6 -0
- data/spec/fixtures/media_upload_completion.json +7 -0
- data/spec/fixtures/media_url.json +1 -0
- data/spec/spec_helper.rb +42 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dd563fb928d3234e0a67360b3a201de7fd2768866e5dc8e5c5b5d234db4b8c9e
|
4
|
+
data.tar.gz: c65c7cf0ef8f40e2e5fd8e3eb6fe3299a452be30495dfe4b04e71245c8e47833
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e37df832a1292bc320b22801d9eb394dbcff997d01a7884c2e239406b1bcec92e3014ddaf61d6669a7983aeee029223440e2603710a12ffafde3fa8243416d2
|
7
|
+
data.tar.gz: d56bea8a3e8915a9f80735e7646fc7aab5c6f5002f6e6159db4b22a227187d0cb76a747279761212a7497bc80bed3cfc5b7bbdf339a51886570dc967734aac7c
|
data/Rakefile
ADDED
data/arc_api.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# spec/fixtures/bearcat.jpg Attribution: TassiloRau at the German language Wikipedia
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'arc_api/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |gem|
|
8
|
+
gem.authors = ['Colin Cromar']
|
9
|
+
gem.email = ['colincromar@gmail.com']
|
10
|
+
gem.description = %q{Ruby interface for interacting with the Arc API}
|
11
|
+
gem.summary = %q{Canvas API}
|
12
|
+
|
13
|
+
gem.files = %w[Rakefile arc_api.gemspec]
|
14
|
+
gem.files += Dir.glob('lib/**/*.rb')
|
15
|
+
gem.files += Dir.glob('spec/**/*')
|
16
|
+
gem.test_files = Dir.glob('spec/**/*')
|
17
|
+
gem.name = 'arc_api'
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
gem.version = ArcApi::VERSION
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rake'
|
22
|
+
gem.add_development_dependency 'bundler', '>= 1.0.0'
|
23
|
+
gem.add_development_dependency 'rspec', '>= 3.0'
|
24
|
+
gem.add_development_dependency 'webmock'
|
25
|
+
gem.add_development_dependency 'pry'
|
26
|
+
|
27
|
+
gem.add_dependency 'footrest', '>= 0.5.1'
|
28
|
+
end
|
data/lib/arc_api.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'footrest/client'
|
2
|
+
module ArcApi
|
3
|
+
class Client < Footrest::Client
|
4
|
+
require 'arc_api/client/media'
|
5
|
+
require 'arc_api/client/health_check'
|
6
|
+
|
7
|
+
include Media
|
8
|
+
include HealthCheck
|
9
|
+
|
10
|
+
API_PATH = '/api/public/v1'.freeze
|
11
|
+
MEDIA_PATH = '/media'.freeze
|
12
|
+
UPLOADS_PATH = '/uploads'.freeze
|
13
|
+
COMPLETE_PATH = '/complete'.freeze
|
14
|
+
HEALTH_CHECK_PATH = '/ping'.freeze
|
15
|
+
|
16
|
+
def set_connection(config)
|
17
|
+
config[:logger] = config[:logging] if config[:logging]
|
18
|
+
raise 'No client prefix url provided - must provide prefix' if config[:prefix].nil? || config[:prefix].empty?
|
19
|
+
@connection = Faraday.new(url: config[:prefix]) do |faraday|
|
20
|
+
faraday.use Footrest::FollowRedirects, limit: 5 unless config[:follow_redirects] == false
|
21
|
+
faraday.use Footrest::ParseJson, content_type: /\bjson$/
|
22
|
+
faraday.use Footrest::RaiseFootrestErrors
|
23
|
+
faraday.use Footrest::Pagination
|
24
|
+
faraday.request :multipart
|
25
|
+
faraday.request :url_encoded
|
26
|
+
faraday.adapter Faraday.default_adapter
|
27
|
+
|
28
|
+
if config[:logger] == true
|
29
|
+
faraday.response :logger
|
30
|
+
elsif config[:logger]
|
31
|
+
faraday.use Faraday::Response::Logger, config[:logger]
|
32
|
+
end
|
33
|
+
|
34
|
+
faraday.headers[:accept] = 'application/json'
|
35
|
+
faraday.headers[:user_agent] = 'Footrest'
|
36
|
+
if config[:token] && config[:user_id]
|
37
|
+
faraday.headers[:authorization] = "Bearer user_id=\"#{config[:user_id]}\", token=\"#{config[:token]}\""
|
38
|
+
else
|
39
|
+
raise 'No api authorization provided - must provide token and user_id'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ArcApi
|
2
|
+
class Client < Footrest::Client
|
3
|
+
module Media
|
4
|
+
def initiate_media_upload(params = {})
|
5
|
+
post(API_PATH + MEDIA_PATH + UPLOADS_PATH, params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def upload_file(params = {})
|
9
|
+
ext = File.extname(params[:file_path]).gsub!('.', '')
|
10
|
+
conn = Faraday.new do |f|
|
11
|
+
f.headers['Content-Type'] = "video/#{ext}"
|
12
|
+
f.request :multipart
|
13
|
+
f.request :url_encoded
|
14
|
+
f.adapter :httpclient
|
15
|
+
end
|
16
|
+
|
17
|
+
file = Faraday::UploadIO.new(params[:file_path], "video/#{ext}")
|
18
|
+
response = conn.put(params[:url], file)
|
19
|
+
|
20
|
+
return response.to_hash[:url].to_s
|
21
|
+
rescue StandardError => e
|
22
|
+
raise "File upload failed - #{e}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_media(params = {})
|
26
|
+
post(API_PATH + MEDIA_PATH, params)
|
27
|
+
end
|
28
|
+
|
29
|
+
def complete_media_upload(params = {})
|
30
|
+
post(API_PATH + MEDIA_PATH + UPLOADS_PATH + "/#{params[:id]}" + COMPLETE_PATH, params)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
describe ArcApi::Client::Media do
|
2
|
+
before { set_client }
|
3
|
+
|
4
|
+
it 'initiates a media upload' do
|
5
|
+
resp = stub_post(@client, ('/media/uploads')).to_return(json_response('media_initiate_upload.json'))
|
6
|
+
data = JSON.parse(resp.response.body)
|
7
|
+
expect(data['upload']['id']).to eq(2890)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'creates a media object' do
|
11
|
+
resp = stub_post(@client, ('/media')).to_return(json_response('media_create.json'))
|
12
|
+
data = JSON.parse(resp.response.body)
|
13
|
+
expect(data['media']['id']).to eq(2893)
|
14
|
+
expect(data['media']['title']).to eq('Introduction to SAML')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'completes the media upload' do
|
18
|
+
media_id = 2892
|
19
|
+
resp = stub_post(@client, ("/media/uploads/#{media_id}/complete")).to_return(json_response('media_upload_completion.json'))
|
20
|
+
data = JSON.parse(resp.response.body)
|
21
|
+
expect(data['media']['id']).to eq(2892)
|
22
|
+
expect(data['media']['title']).to eq('OAuth Overview')
|
23
|
+
expect(data['media']['description']).to eq('A brief overview of how OAuth works')
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe ArcApi::Client do
|
3
|
+
it 'sets the params' do
|
4
|
+
client = ArcApi::Client.new(prefix: "http://canvas.instructure.com", token: "token", user_id: 5)
|
5
|
+
expect(client.config[:prefix]).to eq("http://canvas.instructure.com")
|
6
|
+
expect(client.config[:token]).to eq("token")
|
7
|
+
expect(client.config[:user_id]).to eq(5)
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
"pong"
|
@@ -0,0 +1,6 @@
|
|
1
|
+
{
|
2
|
+
"upload": {
|
3
|
+
"id": 2890,
|
4
|
+
"url": "https://instructure-signal-bogus.s3.amazonaws.com/public_api_v1/43-2890?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=aws_key%2F20181102%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=bogus&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Signature=bogus"
|
5
|
+
}
|
6
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
"https://instructure-signal-bogus.s3.amazonaws.com/public_api_v1/43-2892?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=bogus%bogus%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20181102T164343Z&X-Amz-Expires=86400&X-Amz-Signature=bogu&X-Amz-SignedHeaders=host"
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'arc_api'
|
3
|
+
require 'rspec'
|
4
|
+
require 'webmock/rspec'
|
5
|
+
require 'json'
|
6
|
+
require 'pry'
|
7
|
+
|
8
|
+
WebMock.disable_net_connect!
|
9
|
+
|
10
|
+
def fixture(*file)
|
11
|
+
File.new(File.join(File.expand_path("../fixtures", __FILE__), *file))
|
12
|
+
end
|
13
|
+
|
14
|
+
def stub_get(client, url)
|
15
|
+
stub_request(:get, "#{client.config[:prefix]}#{url}")
|
16
|
+
end
|
17
|
+
|
18
|
+
def stub_post(client, url)
|
19
|
+
stub_request(:post, "#{client.config[:prefix]}#{url}")
|
20
|
+
end
|
21
|
+
|
22
|
+
def stub_put(client, url)
|
23
|
+
stub_request(:put, "#{client.config[:prefix]}#{url}")
|
24
|
+
end
|
25
|
+
|
26
|
+
def stub_delete(client, url)
|
27
|
+
stub_request(:delete, "#{client.config[:prefix]}#{url}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def json_response(*file)
|
31
|
+
{
|
32
|
+
:body => fixture(*file),
|
33
|
+
:headers => {
|
34
|
+
:content_type => 'application/json; charset=utf-8'
|
35
|
+
}
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_client
|
40
|
+
@client = ArcApi::Client.new(prefix: "https://ccromar.instructuremedia.com",
|
41
|
+
token: "token", user_id: 5)
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arc_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Colin Cromar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.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: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
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: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: footrest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.5.1
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.5.1
|
97
|
+
description: Ruby interface for interacting with the Arc API
|
98
|
+
email:
|
99
|
+
- colincromar@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- Rakefile
|
105
|
+
- arc_api.gemspec
|
106
|
+
- lib/arc_api.rb
|
107
|
+
- lib/arc_api/client.rb
|
108
|
+
- lib/arc_api/client/health_check.rb
|
109
|
+
- lib/arc_api/client/media.rb
|
110
|
+
- lib/arc_api/version.rb
|
111
|
+
- spec/arc_api/client/health_check_spec.rb
|
112
|
+
- spec/arc_api/client/media_spec.rb
|
113
|
+
- spec/arc_api/client_spec.rb
|
114
|
+
- spec/arc_api_spec.rb
|
115
|
+
- spec/fixtures/health_check.json
|
116
|
+
- spec/fixtures/media_create.json
|
117
|
+
- spec/fixtures/media_initiate_upload.json
|
118
|
+
- spec/fixtures/media_upload_completion.json
|
119
|
+
- spec/fixtures/media_url.json
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
homepage:
|
122
|
+
licenses: []
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.7.7
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Canvas API
|
144
|
+
test_files:
|
145
|
+
- spec/spec_helper.rb
|
146
|
+
- spec/arc_api_spec.rb
|
147
|
+
- spec/fixtures/media_url.json
|
148
|
+
- spec/fixtures/media_create.json
|
149
|
+
- spec/fixtures/health_check.json
|
150
|
+
- spec/fixtures/media_upload_completion.json
|
151
|
+
- spec/fixtures/media_initiate_upload.json
|
152
|
+
- spec/arc_api/client_spec.rb
|
153
|
+
- spec/arc_api/client/media_spec.rb
|
154
|
+
- spec/arc_api/client/health_check_spec.rb
|