bremen 0.1.3 → 0.2.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.
- data/README.md +4 -2
- data/lib/bremen/mixcloud.rb +1 -1
- data/lib/bremen/nicovideo.rb +2 -2
- data/lib/bremen/soundcloud.rb +9 -7
- data/lib/bremen/version.rb +1 -1
- data/lib/bremen/youtube.rb +2 -2
- data/spec/bremen/base_spec.rb +11 -2
- data/spec/bremen/mixcloud_spec.rb +2 -0
- data/spec/bremen/nicovideo_spec.rb +2 -0
- data/spec/bremen/soundcloud_spec.rb +28 -11
- data/spec/bremen/youtube_spec.rb +2 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -18,9 +18,11 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Setting
|
20
20
|
|
21
|
-
As far as Soundcloud concerned, you need to set
|
21
|
+
As far as Soundcloud concerned, you need to set your app's client id before using.
|
22
22
|
|
23
|
-
Bremen::Soundcloud.
|
23
|
+
Bremen::Soundcloud.client_id = 'your_client_id'
|
24
|
+
|
25
|
+
Alternately, you can set 'SOUNDCLOUD_CLIENT_ID' environment variable.
|
24
26
|
|
25
27
|
## Usage
|
26
28
|
|
data/lib/bremen/mixcloud.rb
CHANGED
data/lib/bremen/nicovideo.rb
CHANGED
@@ -39,7 +39,7 @@ module Bremen
|
|
39
39
|
private
|
40
40
|
def convert_singly response
|
41
41
|
uid = response.scan(%r{<link rel="canonical" href="/watch/([^"]+)">}).flatten.first
|
42
|
-
created_at = Time.parse(response.scan(%r{<meta property="video:release_date" content="(.+)">}).flatten.first.to_s)
|
42
|
+
created_at = Time.parse(response.scan(%r{<meta property="video:release_date" content="(.+)">}).flatten.first.to_s).utc
|
43
43
|
new({
|
44
44
|
uid: uid,
|
45
45
|
url: "#{BASE_URL}watch/#{uid}",
|
@@ -60,7 +60,7 @@ module Bremen
|
|
60
60
|
response.scan(%r{<div class="thumb_col_1">\n<!---->\n(.*?)\n<!---->\n</div></div>}m).flatten.map do |html|
|
61
61
|
uid = html.scan(%r{<table [^>]+ summary="(.+)">}).flatten.first
|
62
62
|
min, sec = html.scan(%r{<p class="vinfo_length"><span>([\d:]+)</span></p>}).flatten.first.to_s.split(':')
|
63
|
-
created_at = Time.parse(html.scan(%r{<strong>(.+:\d\d)</strong>}).flatten.first.to_s.gsub(/\xE5\xB9\xB4|\xE6\x9C\x88|\xE6\x97\xA5/, ''))
|
63
|
+
created_at = Time.parse(html.scan(%r{<strong>(.+:\d\d)</strong>}).flatten.first.to_s.gsub(/\xE5\xB9\xB4|\xE6\x9C\x88|\xE6\x97\xA5/, '')).utc
|
64
64
|
new({
|
65
65
|
uid: uid,
|
66
66
|
url: "#{BASE_URL}watch/#{uid}",
|
data/lib/bremen/soundcloud.rb
CHANGED
@@ -13,11 +13,12 @@ module Bremen
|
|
13
13
|
}
|
14
14
|
|
15
15
|
class << self
|
16
|
-
attr_accessor :
|
16
|
+
attr_accessor :client_id
|
17
17
|
|
18
18
|
def build_query options = {}
|
19
|
-
|
20
|
-
|
19
|
+
self.client_id ||= ENV['SOUNDCLOUD_CLIENT_ID']
|
20
|
+
raise %Q{"#{self.name}.client_id" must be set} unless client_id
|
21
|
+
super(options.merge(client_id: client_id))
|
21
22
|
end
|
22
23
|
|
23
24
|
def find_url uid_or_url
|
@@ -41,20 +42,21 @@ module Bremen
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def from_api hash = {}
|
45
|
+
created_at = Time.parse(hash['created_at']).utc
|
44
46
|
new({
|
45
|
-
uid: hash['id'],
|
47
|
+
uid: hash['id'].to_s,
|
46
48
|
url: hash['permalink_url'],
|
47
49
|
title: hash['title'],
|
48
50
|
author: Bremen::Author.new({
|
49
|
-
uid: hash['user']['id'],
|
51
|
+
uid: hash['user']['id'].to_s,
|
50
52
|
url: hash['user']['permalink_url'],
|
51
53
|
name: hash['user']['username'],
|
52
54
|
thumbnail_url: hash['user']['avatar_url'].sub(%r{\?.*}, ''),
|
53
55
|
}),
|
54
56
|
length: (hash['duration'].to_i / 1000).round,
|
55
57
|
thumbnail_url: hash['artwork_url'] ? hash['artwork_url'].sub(%r{\?.*}, '') : nil,
|
56
|
-
created_at:
|
57
|
-
updated_at:
|
58
|
+
created_at: created_at,
|
59
|
+
updated_at: created_at,
|
58
60
|
})
|
59
61
|
end
|
60
62
|
|
data/lib/bremen/version.rb
CHANGED
data/lib/bremen/youtube.rb
CHANGED
@@ -47,8 +47,8 @@ module Bremen
|
|
47
47
|
}),
|
48
48
|
length: hash['media$group']['yt$duration']['seconds'].to_i,
|
49
49
|
thumbnail_url: hash['media$group']['media$thumbnail'][0]['url'],
|
50
|
-
created_at: Time.parse(hash['published']['$t']),
|
51
|
-
updated_at: Time.parse(hash['updated']['$t']),
|
50
|
+
created_at: Time.parse(hash['published']['$t']).utc,
|
51
|
+
updated_at: Time.parse(hash['updated']['$t']).utc,
|
52
52
|
})
|
53
53
|
end
|
54
54
|
|
data/spec/bremen/base_spec.rb
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
$:.unshift(File.expand_path('../../', __FILE__))
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
+
envfile = File.expand_path('../../../.env', __FILE__)
|
5
|
+
if File.exists?(envfile)
|
6
|
+
File.open(envfile, 'r').each do |line|
|
7
|
+
key, val = line.chomp.split('=', 2)
|
8
|
+
ENV[key] = val
|
9
|
+
end
|
10
|
+
end
|
11
|
+
SITES = ['Youtube', 'Mixcloud', 'Nicovideo']
|
12
|
+
SITES << 'Soundcloud' if ENV['SOUNDCLOUD_CLIENT_ID']
|
13
|
+
|
4
14
|
describe Bremen::Base do
|
5
15
|
describe '.search' do
|
6
|
-
|
7
|
-
['Youtube', 'Mixcloud', 'Nicovideo'].each do |site|
|
16
|
+
SITES.each do |site|
|
8
17
|
describe site do
|
9
18
|
let(:klass){ Bremen.const_get(site) }
|
10
19
|
|
@@ -41,6 +41,7 @@ describe Bremen::Mixcloud do
|
|
41
41
|
let(:response){ fixture('mixcloud_single.json') }
|
42
42
|
it 'convert successfully' do
|
43
43
|
subject.title.must_equal 'Title'
|
44
|
+
subject.created_at.zone.must_equal 'UTC'
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
@@ -49,6 +50,7 @@ describe Bremen::Mixcloud do
|
|
49
50
|
let(:response){ fixture('mixcloud_multi.json') }
|
50
51
|
it 'convert successfully' do
|
51
52
|
subject.first.title.must_equal 'Title'
|
53
|
+
subject.first.created_at.zone.must_equal 'UTC'
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|
@@ -41,6 +41,7 @@ describe Bremen::Nicovideo do
|
|
41
41
|
let(:response){ fixture('nicovideo_single.html') }
|
42
42
|
it 'convert successfully' do
|
43
43
|
subject.title.must_equal 'Title'
|
44
|
+
subject.created_at.zone.must_equal 'UTC'
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
@@ -49,6 +50,7 @@ describe Bremen::Nicovideo do
|
|
49
50
|
let(:response){ fixture('nicovideo_multi.html') }
|
50
51
|
it 'convert successfully' do
|
51
52
|
subject.first.title.must_equal 'Title'
|
53
|
+
subject.first.created_at.zone.must_equal 'UTC'
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|
@@ -2,54 +2,67 @@ $:.unshift(File.expand_path('../../', __FILE__))
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Bremen::Soundcloud do
|
5
|
+
after{ Bremen::Soundcloud.client_id = nil }
|
5
6
|
describe '.build_query' do
|
6
|
-
|
7
|
+
before do
|
8
|
+
Bremen::Soundcloud.client_id = nil
|
9
|
+
ENV['SOUNDCLOUD_CLIENT_ID'] = nil
|
10
|
+
end
|
11
|
+
describe 'not set client_id' do
|
7
12
|
it 'raise error' do
|
8
|
-
lambda{ Bremen::Soundcloud.
|
13
|
+
lambda{ Bremen::Soundcloud.build_query({a: 'b'}) }.must_raise RuntimeError
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'set client_id via ENV' do
|
18
|
+
before{ ENV['SOUNDCLOUD_CLIENT_ID'] = 'CID' }
|
19
|
+
subject{ Bremen::Soundcloud.build_query({a: 'b'}) }
|
20
|
+
it 'return query string' do
|
21
|
+
subject.must_equal 'a=b&client_id=CID'
|
9
22
|
end
|
10
23
|
end
|
11
24
|
|
12
|
-
describe 'set
|
13
|
-
before{ Bremen::Soundcloud.
|
25
|
+
describe 'set client_id directly' do
|
26
|
+
before{ Bremen::Soundcloud.client_id = 'CID' }
|
14
27
|
subject{ Bremen::Soundcloud.build_query({a: 'b'}) }
|
15
28
|
it 'return query string' do
|
16
|
-
subject.must_equal 'a=b&
|
29
|
+
subject.must_equal 'a=b&client_id=CID'
|
17
30
|
end
|
18
31
|
end
|
19
32
|
end
|
20
33
|
|
21
34
|
describe '.find_url' do
|
22
|
-
before{ Bremen::Soundcloud.
|
35
|
+
before{ Bremen::Soundcloud.client_id = 'CID' }
|
23
36
|
subject{ Bremen::Soundcloud.find_url(uid_or_url) }
|
24
37
|
describe 'given id' do
|
25
38
|
let(:uid_or_url){ 100 }
|
26
39
|
it 'generate directly' do
|
27
|
-
subject.must_equal 'http://api.soundcloud.com/tracks/100.json?
|
40
|
+
subject.must_equal 'http://api.soundcloud.com/tracks/100.json?client_id=CID'
|
28
41
|
end
|
29
42
|
end
|
30
43
|
|
31
44
|
describe 'given url' do
|
32
45
|
let(:uid_or_url){ 'http://soundcloud.com/author/permalink' }
|
33
46
|
it 'generate with resolve resource' do
|
34
|
-
subject.must_equal 'http://api.soundcloud.com/resolve.json?url=http%3A%2F%2Fsoundcloud.com%2Fauthor%2Fpermalink&
|
47
|
+
subject.must_equal 'http://api.soundcloud.com/resolve.json?url=http%3A%2F%2Fsoundcloud.com%2Fauthor%2Fpermalink&client_id=CID'
|
35
48
|
end
|
36
49
|
end
|
37
50
|
end
|
38
51
|
|
39
52
|
describe '.search_url' do
|
40
|
-
before{ Bremen::Soundcloud.
|
53
|
+
before{ Bremen::Soundcloud.client_id = 'CID' }
|
41
54
|
subject{ Bremen::Soundcloud.search_url(params) }
|
42
55
|
describe 'only keyword' do
|
43
56
|
let(:params){ {keyword: 'searchword'} }
|
44
57
|
it 'generate' do
|
45
|
-
subject.must_equal 'http://api.soundcloud.com/tracks.json?q=searchword&order=created_at&limit=50&offset=0&filter=&
|
58
|
+
subject.must_equal 'http://api.soundcloud.com/tracks.json?q=searchword&order=created_at&limit=50&offset=0&filter=&client_id=CID'
|
46
59
|
end
|
47
60
|
end
|
48
61
|
|
49
62
|
describe 'full params' do
|
50
63
|
let(:params){ {keyword: 'searchword', order: 'hotness', limit: 10, page: 2, filter: 'public'} }
|
51
64
|
it 'generate' do
|
52
|
-
subject.must_equal 'http://api.soundcloud.com/tracks.json?q=searchword&order=hotness&limit=10&offset=10&filter=public&
|
65
|
+
subject.must_equal 'http://api.soundcloud.com/tracks.json?q=searchword&order=hotness&limit=10&offset=10&filter=public&client_id=CID'
|
53
66
|
end
|
54
67
|
end
|
55
68
|
end
|
@@ -59,6 +72,8 @@ describe Bremen::Soundcloud do
|
|
59
72
|
let(:response){ fixture('soundcloud_single.json') }
|
60
73
|
it 'convert successfully' do
|
61
74
|
subject.title.must_equal 'Title'
|
75
|
+
subject.uid.must_equal '11111111'
|
76
|
+
subject.created_at.zone.must_equal 'UTC'
|
62
77
|
end
|
63
78
|
end
|
64
79
|
|
@@ -67,6 +82,8 @@ describe Bremen::Soundcloud do
|
|
67
82
|
let(:response){ fixture('soundcloud_multi.json') }
|
68
83
|
it 'convert successfully' do
|
69
84
|
subject.first.title.must_equal 'Title'
|
85
|
+
subject.first.uid.must_equal '11111111'
|
86
|
+
subject.first.created_at.zone.must_equal 'UTC'
|
70
87
|
end
|
71
88
|
end
|
72
89
|
end
|
data/spec/bremen/youtube_spec.rb
CHANGED
@@ -41,6 +41,7 @@ describe Bremen::Youtube do
|
|
41
41
|
let(:response){ fixture('youtube_single.json') }
|
42
42
|
it 'convert successfully' do
|
43
43
|
subject.title.must_equal 'Title'
|
44
|
+
subject.created_at.zone.must_equal 'UTC'
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
@@ -49,6 +50,7 @@ describe Bremen::Youtube do
|
|
49
50
|
let(:response){ fixture('youtube_multi.json') }
|
50
51
|
it 'convert successfully' do
|
51
52
|
subject.first.title.must_equal 'Title'
|
53
|
+
subject.first.created_at.zone.must_equal 'UTC'
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bremen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: guard-minitest
|