botr 0.1.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 +7 -0
- data/.document +3 -0
- data/.gitignore +31 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +4 -0
- data/LICENSE.txt +20 -0
- data/README.md +278 -0
- data/Rakefile +43 -0
- data/botr.gemspec +24 -0
- data/botr.watchr +3 -0
- data/certs/cacert.pem +3554 -0
- data/lib/botr.rb +34 -0
- data/lib/botr/api/api.rb +83 -0
- data/lib/botr/api/authentication.rb +24 -0
- data/lib/botr/channels/channel.rb +137 -0
- data/lib/botr/channels/channel_thumbnail.rb +88 -0
- data/lib/botr/channels/channel_video.rb +130 -0
- data/lib/botr/channels/channel_view.rb +88 -0
- data/lib/botr/common/logger.rb +31 -0
- data/lib/botr/configuration.rb +18 -0
- data/lib/botr/http/http.rb +88 -0
- data/lib/botr/http/http_backend.rb +66 -0
- data/lib/botr/http/http_response.rb +48 -0
- data/lib/botr/http/multipart.rb +84 -0
- data/lib/botr/http/uri_ext.rb +28 -0
- data/lib/botr/object.rb +20 -0
- data/lib/botr/players/player.rb +149 -0
- data/lib/botr/players/player_view.rb +88 -0
- data/lib/botr/version.rb +3 -0
- data/lib/botr/videos/video.rb +187 -0
- data/lib/botr/videos/video_caption.rb +154 -0
- data/lib/botr/videos/video_conversion.rb +114 -0
- data/lib/botr/videos/video_engagement.rb +51 -0
- data/lib/botr/videos/video_tag.rb +52 -0
- data/lib/botr/videos/video_thumbnail.rb +87 -0
- data/lib/botr/videos/video_view.rb +89 -0
- data/spec/authentication_spec.rb +31 -0
- data/spec/botr_spec.rb +8 -0
- data/spec/http_backend_spec.rb +93 -0
- data/spec/http_response_spec.rb +48 -0
- data/spec/multipart_spec.rb +35 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/test.txt +1 -0
- metadata +150 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
module BOTR
|
2
|
+
|
3
|
+
class VideoView < BOTR::Object
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
attr_reader :last_status
|
8
|
+
|
9
|
+
def show(key, **options)
|
10
|
+
json = get_request(options.merge(:method => 'show',
|
11
|
+
:video_key => key))
|
12
|
+
res = JSON.parse(json.body)
|
13
|
+
|
14
|
+
if json.status == 200
|
15
|
+
params = process_show_response(res)
|
16
|
+
else
|
17
|
+
raise "HTTP Error #{json.status}: #{json.body}"
|
18
|
+
end
|
19
|
+
|
20
|
+
return new(params)
|
21
|
+
end
|
22
|
+
|
23
|
+
alias :find :show
|
24
|
+
|
25
|
+
def list(**options)
|
26
|
+
json = get_request(options.merge(:method => 'list'))
|
27
|
+
res = JSON.parse(json.body)
|
28
|
+
|
29
|
+
if json.status == 200
|
30
|
+
results = process_list_response(res)
|
31
|
+
else
|
32
|
+
raise "HTTP Error #{json.status}: #{json.body}"
|
33
|
+
end
|
34
|
+
|
35
|
+
return results
|
36
|
+
end
|
37
|
+
|
38
|
+
def all
|
39
|
+
list({})
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def process_show_response(body)
|
45
|
+
@last_status = body["status"]
|
46
|
+
|
47
|
+
return body["video"]
|
48
|
+
end
|
49
|
+
|
50
|
+
def process_list_response(body)
|
51
|
+
@last_status = body["status"]
|
52
|
+
res = []
|
53
|
+
|
54
|
+
if body["videos"]
|
55
|
+
body["videos"].each do |video|
|
56
|
+
res << new(video)
|
57
|
+
end
|
58
|
+
elsif body["days"]
|
59
|
+
body["days"].each do |day|
|
60
|
+
res << new(day)
|
61
|
+
end
|
62
|
+
elsif body["years"]
|
63
|
+
body["years"].each do |year|
|
64
|
+
res << new(year)
|
65
|
+
end
|
66
|
+
else
|
67
|
+
res << new(body)
|
68
|
+
end
|
69
|
+
|
70
|
+
return res
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
attr_reader :last_status, :key, :streams, :downloads, :views, :pageviews,
|
76
|
+
:viewed, :title, :status, :date, :timestamp, :number, :total,
|
77
|
+
:months, :days, :year
|
78
|
+
|
79
|
+
def initialize(params = {})
|
80
|
+
params.each do |key, val|
|
81
|
+
param = "@#{key.to_s}"
|
82
|
+
next unless methods.include? key.to_sym
|
83
|
+
instance_variable_set(param, val)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'botr/api/authentication'
|
3
|
+
|
4
|
+
class DummyClient
|
5
|
+
|
6
|
+
def api_secret_key
|
7
|
+
"uA96CFtJa138E2T5GhKfngml"
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
describe BOTR::Authentication do
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
@dummy_client = DummyClient.new
|
16
|
+
@dummy_client.extend(BOTR::Authentication)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#signature" do
|
20
|
+
|
21
|
+
it "should generature signature" do
|
22
|
+
params = {:text => "démo",
|
23
|
+
:api_format => "xml",
|
24
|
+
:api_key => "XOqEAfxj",
|
25
|
+
:api_nonce => "80684843",
|
26
|
+
:api_timestamp => "1237387851"}
|
27
|
+
@dummy_client.signature(params).should eql "fbdee51a45980f9876834dc5ee1ec5e93f67cb89"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/spec/botr_spec.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'botr/http/http_backend'
|
3
|
+
|
4
|
+
RSpec::Matchers.define :a_uri_path_of do |expected|
|
5
|
+
match do |actual|
|
6
|
+
(actual.should be_a_kind_of URI) && (actual.request_uri.should eql expected)
|
7
|
+
end
|
8
|
+
description do
|
9
|
+
"a URI with path '#{expected}'"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec::Matchers.define :a_POST_request_with_path do |expected|
|
14
|
+
match do |actual|
|
15
|
+
(actual.should be_a_kind_of Net::HTTP::Post) && (actual.instance_variable_get('@path').should eql expected)
|
16
|
+
end
|
17
|
+
description do
|
18
|
+
"a Net::HTTP::Post request with path '#{expected}'"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe BOTR::HTTPBackend do
|
23
|
+
|
24
|
+
before :each do
|
25
|
+
@http = mock("http")
|
26
|
+
@resp = mock("response")
|
27
|
+
|
28
|
+
Net::HTTP.stub!(:start).and_yield(@http)
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#get" do
|
32
|
+
|
33
|
+
before :each do
|
34
|
+
@http.stub!(:request_get).and_return(@resp)
|
35
|
+
@resp.stub!(:code).and_return(200)
|
36
|
+
@resp.stub!(:body).and_return("")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should send HTTP GET request" do
|
40
|
+
@http.should_receive(:request_get).with(an_instance_of(URI::HTTP))
|
41
|
+
subject.get('http://www.example.com/')
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should send HTTP GET request with params" do
|
45
|
+
@http.should_receive(:request_get).with(a_uri_path_of("/?field1=value1&field2=value2"))
|
46
|
+
subject.get('http://www.example.com/',
|
47
|
+
{:field1 => "value1", :field2 => "value2"})
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return HTTP response" do
|
51
|
+
res = subject.get('http://www.example.com')
|
52
|
+
res.should be_an_instance_of BOTR::HTTPResponse
|
53
|
+
res.status.should eql 200
|
54
|
+
res.body.should be_empty
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#post" do
|
59
|
+
|
60
|
+
before :each do
|
61
|
+
@http.stub!(:post_form).and_return(@resp)
|
62
|
+
@http.stub!(:request).and_return(@resp)
|
63
|
+
@resp.stub!(:code).and_return(200)
|
64
|
+
@resp.stub!(:body).and_return("")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should send HTTP POST request" do
|
68
|
+
@http.should_receive(:request).with(an_instance_of(Net::HTTP::Post))
|
69
|
+
subject.post('http://www.example.com/')
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should send HTTP POST request with params" do
|
73
|
+
@http.should_receive(:request).with(a_POST_request_with_path("/?field1=value1&field2=value2"))
|
74
|
+
subject.post('http://www.example.com/',
|
75
|
+
{:field1 => "value1", :field2 => "value2"})
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should send HTTP POST request with data" do
|
79
|
+
@http.should_receive(:request).with(an_instance_of(Net::HTTP::Post))
|
80
|
+
test_path = __dir__ + "/test.txt"
|
81
|
+
subject.post('http://www.example.com/', {}, test_path)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return HTTP response" do
|
85
|
+
res = subject.post('http://www.example.com')
|
86
|
+
res.should be_an_instance_of BOTR::HTTPResponse
|
87
|
+
res.status.should eql 200
|
88
|
+
res.body.should be_empty
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'botr/http/http_response'
|
3
|
+
|
4
|
+
describe BOTR::HTTPResponse do
|
5
|
+
|
6
|
+
describe "OKResponse" do
|
7
|
+
it "should return status 200" do
|
8
|
+
resp = BOTR::OKResponse.new
|
9
|
+
resp.status.should eql 200
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "BadRequestResponse" do
|
14
|
+
it "should return status 400" do
|
15
|
+
resp = BOTR::BadRequestResponse.new
|
16
|
+
resp.status.should eql 400
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "UnauthorizedResponse" do
|
21
|
+
it "should return status 401" do
|
22
|
+
resp = BOTR::UnauthorizedResponse.new
|
23
|
+
resp.status.should eql 401
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "ForbiddenResponse" do
|
28
|
+
it "should return status 403" do
|
29
|
+
resp = BOTR::ForbiddenResponse.new
|
30
|
+
resp.status.should eql 403
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "NotFoundResponse" do
|
35
|
+
it "should return status 404" do
|
36
|
+
resp = BOTR::NotFoundResponse.new
|
37
|
+
resp.status.should eql 404
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "NotAllowedResponse" do
|
42
|
+
it "should return status 405" do
|
43
|
+
resp = BOTR::NotAllowedResponse.new
|
44
|
+
resp.status.should eql 405
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'botr/http/multipart'
|
3
|
+
|
4
|
+
describe BOTR::Multipart do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
path = __dir__ + '/test.txt'
|
8
|
+
@expected_response = "--753536\r\nContent-Disposition: form-data; name=\"file\"; filename=\"test.txt\"\r\nContent-Length: 15\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: binary\r\n\r\nThis is a test.\r\n--753536--\r\n"
|
9
|
+
@multipart = BOTR::Multipart.new(path, '753536')
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#read" do
|
13
|
+
it "should return a string of content" do
|
14
|
+
res = @multipart.read
|
15
|
+
res.should be_kind_of String
|
16
|
+
res.should eql @expected_response
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#size" do
|
21
|
+
it "should return the number of bytes in content" do
|
22
|
+
bytesize = @expected_response.bytesize
|
23
|
+
@multipart.size.should eql bytesize
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#close" do
|
28
|
+
it "should close the IO stream" do
|
29
|
+
@multipart.should_not be_closed
|
30
|
+
@multipart.close
|
31
|
+
@multipart.should be_closed
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/test.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
This is a test.
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: botr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- bertrandk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.4'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubygems-tasks
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: watchr
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.8'
|
69
|
+
description: A ruby API kit that manages the authentication, serialization and sending
|
70
|
+
of API calls to the Bits on the Run online video platform.
|
71
|
+
email: b.karerangabo@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .document
|
77
|
+
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- .yardopts
|
80
|
+
- ChangeLog.md
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- botr.gemspec
|
85
|
+
- botr.watchr
|
86
|
+
- certs/cacert.pem
|
87
|
+
- lib/botr.rb
|
88
|
+
- lib/botr/api/api.rb
|
89
|
+
- lib/botr/api/authentication.rb
|
90
|
+
- lib/botr/channels/channel.rb
|
91
|
+
- lib/botr/channels/channel_thumbnail.rb
|
92
|
+
- lib/botr/channels/channel_video.rb
|
93
|
+
- lib/botr/channels/channel_view.rb
|
94
|
+
- lib/botr/common/logger.rb
|
95
|
+
- lib/botr/configuration.rb
|
96
|
+
- lib/botr/http/http.rb
|
97
|
+
- lib/botr/http/http_backend.rb
|
98
|
+
- lib/botr/http/http_response.rb
|
99
|
+
- lib/botr/http/multipart.rb
|
100
|
+
- lib/botr/http/uri_ext.rb
|
101
|
+
- lib/botr/object.rb
|
102
|
+
- lib/botr/players/player.rb
|
103
|
+
- lib/botr/players/player_view.rb
|
104
|
+
- lib/botr/version.rb
|
105
|
+
- lib/botr/videos/video.rb
|
106
|
+
- lib/botr/videos/video_caption.rb
|
107
|
+
- lib/botr/videos/video_conversion.rb
|
108
|
+
- lib/botr/videos/video_engagement.rb
|
109
|
+
- lib/botr/videos/video_tag.rb
|
110
|
+
- lib/botr/videos/video_thumbnail.rb
|
111
|
+
- lib/botr/videos/video_view.rb
|
112
|
+
- spec/authentication_spec.rb
|
113
|
+
- spec/botr_spec.rb
|
114
|
+
- spec/http_backend_spec.rb
|
115
|
+
- spec/http_response_spec.rb
|
116
|
+
- spec/multipart_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
- spec/test.txt
|
119
|
+
homepage: https://rubygems.org/gems/botr
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.0.6
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: A ruby API kit for Bits on the Run.
|
143
|
+
test_files:
|
144
|
+
- spec/authentication_spec.rb
|
145
|
+
- spec/botr_spec.rb
|
146
|
+
- spec/http_backend_spec.rb
|
147
|
+
- spec/http_response_spec.rb
|
148
|
+
- spec/multipart_spec.rb
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
- spec/test.txt
|