netologiest 0.0.1 → 0.0.2
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/README.md +23 -1
- data/lib/netologiest.rb +1 -0
- data/lib/netologiest/resource.rb +11 -9
- data/lib/netologiest/resources/lesson.rb +51 -0
- data/lib/netologiest/version.rb +1 -1
- data/spec/fixtures/lesson_token.json +4 -0
- data/spec/helpers/webmock_helpers.rb +15 -0
- data/spec/lesson_spec.rb +25 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d4a464c0f9f259a1a0304671d6ddfac401644b6
|
4
|
+
data.tar.gz: 8ea14f2bdd955ae999b4f56cc95dbe38cecfc4a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06132c8c86005a92955c55f76448ea21e54f7f683b1570bfeeb51f2ab0977db9ede15d00f49f898ea6139dfbe724170122eb7d90bda9b9cb607f1f1680edc112
|
7
|
+
data.tar.gz: e7bf43ccc6a8f764b891f45634a65c676fe7614e9e60220bc194a61112d9e4101993d7b780e55b8c2349dcff0ba7fb5194803d3de9a9290408bf49cc99e18f03
|
data/README.md
CHANGED
@@ -25,7 +25,10 @@ For example (in your `secrets.yml`):
|
|
25
25
|
|
26
26
|
## Usage
|
27
27
|
|
28
|
-
|
28
|
+
#### Course
|
29
|
+
|
30
|
+
Netologiest having only one resource at moment. It is a course.
|
31
|
+
And you can get list of courses
|
29
32
|
|
30
33
|
To get a list of courses
|
31
34
|
|
@@ -78,6 +81,25 @@ Also you can get detailed information about any course:
|
|
78
81
|
}
|
79
82
|
```
|
80
83
|
|
84
|
+
#### Lesson's video
|
85
|
+
|
86
|
+
Lesson class is used to obtain iframe token or iframe url (with token)
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
# returns complete URL to video iframe
|
90
|
+
Netologiest::Lesson.video_url(course_id, lesson_id)
|
91
|
+
|
92
|
+
# OR
|
93
|
+
|
94
|
+
lesson = Netologiest::Lesson.new(course_id, lesson_id)
|
95
|
+
# makes request to API and refresh lesson_token
|
96
|
+
lesson.video_token
|
97
|
+
# returns token
|
98
|
+
lesson.lesson_token
|
99
|
+
# returns complete URL
|
100
|
+
lesson.video_url
|
101
|
+
```
|
102
|
+
|
81
103
|
## Contributing
|
82
104
|
|
83
105
|
1. Fork it ( https://github.com/[my-github-username]/netologiest/fork )
|
data/lib/netologiest.rb
CHANGED
data/lib/netologiest/resource.rb
CHANGED
@@ -69,21 +69,16 @@ module Netologiest
|
|
69
69
|
|
70
70
|
def handle_detail(_response); end
|
71
71
|
|
72
|
-
protected
|
73
|
-
|
74
|
-
def build_url(*args)
|
75
|
-
File.join(Netologiest.config.api_url, *args.map(&:to_s))
|
76
|
-
end
|
77
|
-
|
78
72
|
# rubocop:disable Metrics/MethodLength
|
79
73
|
def get(url, options = {})
|
80
|
-
params = { token: token }.merge!(options)
|
74
|
+
params = { token: (options[:token] || token) }.merge!(options)
|
75
|
+
|
76
|
+
auth_method = options[:auth_method] || :authorize!
|
81
77
|
|
82
78
|
RestClient.get(url, params: params) do |response, _request, _result|
|
83
79
|
if response.code == 401
|
84
80
|
begin
|
85
|
-
|
86
|
-
params[:token] = token
|
81
|
+
params[:token] = send(auth_method)
|
87
82
|
return RestClient.get(url, params: params)
|
88
83
|
rescue RestClient::Unauthorized
|
89
84
|
raise Netologiest::Unauthorized, response.body
|
@@ -93,5 +88,12 @@ module Netologiest
|
|
93
88
|
end
|
94
89
|
end
|
95
90
|
# rubocop:enable Metrics/MethodLength
|
91
|
+
|
92
|
+
protected
|
93
|
+
|
94
|
+
def build_url(*args)
|
95
|
+
File.join(Netologiest.config.api_url, *args.map(&:to_s))
|
96
|
+
end
|
97
|
+
|
96
98
|
end
|
97
99
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Netologiest
|
2
|
+
class Lesson < Netologiest::Resource
|
3
|
+
self.resource_name = 'lessons'
|
4
|
+
|
5
|
+
attr_reader :lesson_token, :lesson_token_expire,
|
6
|
+
:course_id, :id, :iframe_url
|
7
|
+
|
8
|
+
def initialize(course_id, lesson_id)
|
9
|
+
authorize!
|
10
|
+
@course_id = course_id
|
11
|
+
@id = lesson_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.video_url(course_id, lesson_id)
|
15
|
+
lesson = new(course_id, lesson_id)
|
16
|
+
lesson.video_token
|
17
|
+
lesson.video_url
|
18
|
+
end
|
19
|
+
|
20
|
+
def video_token
|
21
|
+
url = build_url(
|
22
|
+
Netologiest::Course.resource_name,
|
23
|
+
course_id,
|
24
|
+
self.class.resource_name,
|
25
|
+
id,
|
26
|
+
'gettoken'
|
27
|
+
)
|
28
|
+
|
29
|
+
handle_lesson_token(get(url))
|
30
|
+
end
|
31
|
+
|
32
|
+
def video_url
|
33
|
+
@iframe_url = build_url(
|
34
|
+
Netologiest::Course.resource_name,
|
35
|
+
course_id,
|
36
|
+
self.class.resource_name,
|
37
|
+
id,
|
38
|
+
"iframe?token=#{lesson_token}"
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def handle_lesson_token(response)
|
45
|
+
data = JSON.parse(response)
|
46
|
+
return unless data.present? || data.any?
|
47
|
+
@lesson_token_expire = data["expires_in"]
|
48
|
+
@lesson_token = data["access_token"]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/netologiest/version.rb
CHANGED
@@ -76,4 +76,19 @@ module NetologiestWebMock
|
|
76
76
|
body: File.read("spec/fixtures/course.json")
|
77
77
|
)
|
78
78
|
end
|
79
|
+
|
80
|
+
## Lessons methods
|
81
|
+
|
82
|
+
def lesson_token_stub(course_id, lesson_id)
|
83
|
+
token = "S3PBVG38O1209Y01X5LEK0PYH0MT3YDZ"
|
84
|
+
url = Netologiest.config.api_url
|
85
|
+
url += "/courses/#{course_id}/lessons/#{lesson_id}"
|
86
|
+
url += "/gettoken?token=#{token}"
|
87
|
+
stub_request(:get, url)
|
88
|
+
.to_return(
|
89
|
+
headers: { 'Content-Type' => 'application/json' },
|
90
|
+
status: 200,
|
91
|
+
body: File.read("spec/fixtures/lesson_token.json")
|
92
|
+
)
|
93
|
+
end
|
79
94
|
end
|
data/spec/lesson_spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Netologiest::Lesson do
|
4
|
+
describe "valid access token" do
|
5
|
+
before(:each) do
|
6
|
+
mock_api
|
7
|
+
lesson_token_stub(931, 2268)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "return token" do
|
11
|
+
lesson = described_class.new(931, 2268)
|
12
|
+
expect(lesson.video_token)
|
13
|
+
.to eq "26C1WYAIWT3LRX12W8H4DTA9FRF3NLH9"
|
14
|
+
expect(lesson.lesson_token_expire)
|
15
|
+
.to eq 600
|
16
|
+
end
|
17
|
+
|
18
|
+
it "return iframe url with token" do
|
19
|
+
url = described_class.video_url(931, 2268)
|
20
|
+
expected = "#{Netologiest.config.api_url}/courses/931/lessons/2268/"
|
21
|
+
expected += "iframe?token=26C1WYAIWT3LRX12W8H4DTA9FRF3NLH9"
|
22
|
+
expect(url).to eq expected
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netologiest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vlad Dem
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -161,14 +161,17 @@ files:
|
|
161
161
|
- lib/netologiest/exceptions.rb
|
162
162
|
- lib/netologiest/resource.rb
|
163
163
|
- lib/netologiest/resources/course.rb
|
164
|
+
- lib/netologiest/resources/lesson.rb
|
164
165
|
- lib/netologiest/version.rb
|
165
166
|
- netologiest.gemspec
|
166
167
|
- spec/course_spec.rb
|
167
168
|
- spec/fixtures/auth.json
|
168
169
|
- spec/fixtures/course.json
|
169
170
|
- spec/fixtures/courses.json
|
171
|
+
- spec/fixtures/lesson_token.json
|
170
172
|
- spec/fixtures/netologiest_test.yml
|
171
173
|
- spec/helpers/webmock_helpers.rb
|
174
|
+
- spec/lesson_spec.rb
|
172
175
|
- spec/resource_spec.rb
|
173
176
|
- spec/spec_helper.rb
|
174
177
|
homepage: ''
|
@@ -191,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
194
|
version: '0'
|
192
195
|
requirements: []
|
193
196
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.
|
197
|
+
rubygems_version: 2.2.2
|
195
198
|
signing_key:
|
196
199
|
specification_version: 4
|
197
200
|
summary: Ruby API client for Netology
|
@@ -200,8 +203,10 @@ test_files:
|
|
200
203
|
- spec/fixtures/auth.json
|
201
204
|
- spec/fixtures/course.json
|
202
205
|
- spec/fixtures/courses.json
|
206
|
+
- spec/fixtures/lesson_token.json
|
203
207
|
- spec/fixtures/netologiest_test.yml
|
204
208
|
- spec/helpers/webmock_helpers.rb
|
209
|
+
- spec/lesson_spec.rb
|
205
210
|
- spec/resource_spec.rb
|
206
211
|
- spec/spec_helper.rb
|
207
212
|
has_rdoc:
|