valanga 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30f3d50c38df00da1f3e548631ce0095ebc2d1f6
4
- data.tar.gz: fd5b7fa4a329dd838808372ed47a2fd664e86e37
3
+ metadata.gz: 0e04b358a187ccce5fa8743f643f117836f664f4
4
+ data.tar.gz: caaed27bae15172fcc4a6a7d3294054eb32bbf37
5
5
  SHA512:
6
- metadata.gz: d673cc1558adf2dfd5a07e3e9d88b74113b16674599eb9ec13bf651ebb6d67eb8449fb16c945c6651c8147fad1c62f9f563fb3119d89dcb95d80db64924353a3
7
- data.tar.gz: e2ec20c5b598f9974f3504f4d279e551c9b5dafb5b0e68d779114bb05a3cbf9a8f8c6bb18a3673866e1785ef41ddb3147f252528832d5ad11fd6e832c4d160d7
6
+ metadata.gz: 6b9c244a0c3c871f0f3f15c42f18bf191f46b214d0cfa4f2c42e336d28cc63ce86cea0dc9287f57d64c4822486bfc1ffa92b6d33e8ad3eecc72a78af58efb4af
7
+ data.tar.gz: 169a438a3e701a3c5d72cca6cd9574c58c8fe2c5f2b5cc494fd7b22c6e54ae8e190873accd09b139c1289205a6bc34847ceb00d49f249fbc567fc0a82dad766c
@@ -1,3 +1,7 @@
1
+ # Version 0.3.0
2
+ * Updates README.md
3
+ * Supports `Valanga::Client#musics_at`, `Valanga::Client#music_image_url`
4
+
1
5
  # Version 0.2.0
2
6
  * Supports environment variable login for `ENV['KONAMI_ID']` `ENV['KONAMI_PASSWORD']`.
3
7
  * Caches the search query and url, Second time result is directly access to cached url.
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # Valanga
2
+ [![Gem Version](https://badge.fury.io/rb/valanga.svg)](http://badge.fury.io/rb/valanga)
3
+ [![Gemnasium](https://gemnasium.com/mgi166/valanga.svg)](https://gemnasium.com/mgi166/valanga)
4
+ [![Code Climate](https://codeclimate.com/github/mgi166/valanga/badges/gpa.svg)](https://codeclimate.com/github/mgi166/valanga)
2
5
 
3
6
  A Ruby client for [REFLEC BEAT](http://p.eagate.573.jp/game/reflec/groovin/p/index.html)
4
7
 
@@ -12,9 +15,14 @@ A Ruby client for [REFLEC BEAT](http://p.eagate.573.jp/game/reflec/groovin/p/ind
12
15
  ### Prepare
13
16
  Create `Valanga::Client` instance.
14
17
  The arguments of `name_or_email` is `KONAMI ID` or `email` that you registered.
18
+
19
+ If you set environment variables `KONAMI_ID` and `KONAMI_PASSWORD`, Valanga::Client uses the values for credentials.
15
20
 
16
21
  ```ruby
17
22
  client = Valanga::Client.new(name_or_email, password)
23
+
24
+ # Use ENV['KONAMI_ID'], ENV['KONAMI_PASSWORD'] if client received no arguments.
25
+ client = Valanga::Client.new
18
26
  ```
19
27
 
20
28
  ### Fetch all music names
@@ -24,6 +32,16 @@ client.list_musics
24
32
  #=> ["Artifacter", "Army of Marionette", "RPG", "アイネクライネ", ....]
25
33
  ```
26
34
 
35
+ ### Fetch music names specified page, sorttype, and sort
36
+
37
+ ```ruby
38
+ client.musics_at(page: 3)
39
+ #=> ["踊るフィーバーロボ", "鬼天", "朧", ...]
40
+
41
+ client.musics_at(sorttype: :special, sort: :desc)
42
+ #=> ["Butter-Fly", "七転八起☆至上主義!", "嘘", ...]
43
+ ```
44
+
27
45
  ### Search music
28
46
  Specifies the music name, returns `Valanga::Music` instance.
29
47
 
@@ -7,7 +7,8 @@ module Valanga
7
7
 
8
8
  LOGIN_PAGE = "https://p.eagate.573.jp/gate/p/login.html"
9
9
 
10
- attr_reader :session, :pages
10
+ attr_reader :session
11
+ attr_accessor :music_ids
11
12
 
12
13
  def initialize(username = nil, password = nil)
13
14
  Capybara.register_driver :poltergeist do |app|
@@ -15,7 +16,7 @@ module Valanga
15
16
  end
16
17
 
17
18
  @session = Capybara::Session.new(:poltergeist)
18
- @pages = {}
19
+ @music_ids = {}
19
20
 
20
21
  login!(username, password)
21
22
  end
@@ -2,8 +2,15 @@ module Valanga
2
2
  class Music
3
3
  def initialize(document)
4
4
  @document = Nokogiri::HTML.parse(document, nil, 'Shift_JIS')
5
+ @music_bk = @document.css("div.music_bk dl")
6
+
7
+ unless @music_bk.size == 8 || @music_bk.size == 9
8
+ raise NoMusicInformationError, "Not found music informations"
9
+ end
5
10
  end
6
11
 
12
+ attr_reader :music_bk
13
+
7
14
  def basic
8
15
  Difficulty::Basic.new(self)
9
16
  end
@@ -53,17 +60,5 @@ module Valanga
53
60
  end
54
61
  end
55
62
  end
56
-
57
- def music_bk
58
- return @music_bk if defined? @music_bk
59
-
60
- music_bk = @document.css("div.music_bk dl")
61
-
62
- unless music_bk.size == 8 || music_bk.size == 9
63
- raise NoMusicInformationError, "Not found music informations"
64
- end
65
-
66
- @music_bk = music_bk
67
- end
68
63
  end
69
64
  end
@@ -11,50 +11,35 @@ module Valanga
11
11
 
12
12
  def basic
13
13
  if has_special?
14
- MusicAttribute.new(create_attr(6)).tap do |attr|
15
- attr.name = name
16
- attr.artist = artist
17
- end
14
+ MusicAttribute.new(create_attr(6))
18
15
  else
19
- MusicAttribute.new(create_attr(5)).tap do |attr|
20
- attr.name = name
21
- attr.artist = artist
22
- end
16
+ MusicAttribute.new(create_attr(5))
23
17
  end
24
18
  end
25
19
 
26
20
  def medium
27
21
  if has_special?
28
- MusicAttribute.new(create_attr(7)).tap do |attr|
29
- attr.name = name
30
- attr.artist = artist
31
- end
22
+ MusicAttribute.new(create_attr(7))
32
23
  else
33
- MusicAttribute.new(create_attr(6)).tap do |attr|
34
- attr.name = name
35
- attr.artist = artist
36
- end
24
+ MusicAttribute.new(create_attr(6))
37
25
  end
38
26
  end
39
27
 
40
28
  def hard
41
29
  if has_special?
42
- MusicAttribute.new(create_attr(8)).tap do |attr|
43
- attr.name = name
44
- attr.artist = artist
45
- end
30
+ MusicAttribute.new(create_attr(8))
46
31
  else
47
- MusicAttribute.new(create_attr(7)).tap do |attr|
48
- attr.name = name
49
- attr.artist = artist
50
- end
32
+ MusicAttribute.new(create_attr(7))
51
33
  end
52
34
  end
53
35
 
54
36
  private
55
37
 
56
38
  def create_attr(index)
57
- Hash[COLLETE_KEY.zip(music_info_box[index])]
39
+ Hash[COLLETE_KEY.zip(music_info_box[index])].merge(
40
+ 'name' => name,
41
+ 'artist' => artist,
42
+ )
58
43
  end
59
44
  end
60
45
  end
@@ -13,39 +13,30 @@ module Valanga
13
13
  )
14
14
 
15
15
  def basic
16
- Valanga::MusicAttribute.new(create_attr(1)).tap do |attr|
17
- attr.name = name
18
- attr.artist = artist
19
- end
16
+ Valanga::MusicAttribute.new(create_attr(1))
20
17
  end
21
18
 
22
19
  def medium
23
- Valanga::MusicAttribute.new(create_attr(2)).tap do |attr|
24
- attr.name = name
25
- attr.artist = artist
26
- end
20
+ Valanga::MusicAttribute.new(create_attr(2))
27
21
  end
28
22
 
29
23
  def hard
30
- Valanga::MusicAttribute.new(create_attr(3)).tap do |attr|
31
- attr.name = name
32
- attr.artist = artist
33
- end
24
+ Valanga::MusicAttribute.new(create_attr(3))
34
25
  end
35
26
 
36
27
  def special
37
28
  if has_special?
38
- Valanga::MusicAttribute.new(create_attr(4)).tap do |attr|
39
- attr.name = name
40
- attr.artist = artist
41
- end
29
+ Valanga::MusicAttribute.new(create_attr(4))
42
30
  end
43
31
  end
44
32
 
45
33
  private
46
34
 
47
35
  def create_attr(index)
48
- Hash[GROOVIN_KEY.zip(music_info_box[index])]
36
+ Hash[GROOVIN_KEY.zip(music_info_box[index])].merge(
37
+ 'name' => name,
38
+ 'artist' => artist,
39
+ )
49
40
  end
50
41
  end
51
42
  end
@@ -2,16 +2,10 @@ module Valanga
2
2
  module MusicSearch
3
3
  MUSIC_INDEX = "http://p.eagate.573.jp/game/reflec/groovin/p/music/index.html"
4
4
 
5
- def list_musics(page: nil, sorttype: nil, sort: nil)
5
+ def list_musics
6
6
  musics = []
7
7
 
8
- if [page, sorttype, sort].none?
9
- page_sessions do |session|
10
- html = Nokogiri::HTML.parse(session.html)
11
- musics << html.css("#music_table1 td.music_jkimg a").map(&:text).map(&:strip)
12
- end
13
- else
14
- session.visit(music_url(page: page, sorttype: sorttype, sort: sort))
8
+ page_sessions do |session|
15
9
  html = Nokogiri::HTML.parse(session.html)
16
10
  musics << html.css("#music_table1 td.music_jkimg a").map(&:text).map(&:strip)
17
11
  end
@@ -19,9 +13,15 @@ module Valanga
19
13
  musics.flatten
20
14
  end
21
15
 
16
+ def musics_at(page: nil, sorttype: nil, sort: nil)
17
+ session.visit(music_url(page: page, sorttype: sorttype, sort: sort))
18
+ html = Nokogiri::HTML.parse(session.html)
19
+ html.css("#music_table1 td.music_jkimg a").map(&:text).map(&:strip)
20
+ end
21
+
22
22
  def search(music_name)
23
- if url = pages[music_name]
24
- return create_music(url)
23
+ if music_id = music_ids[music_name]
24
+ return create_music(music_id)
25
25
  end
26
26
 
27
27
  page_sessions do |session|
@@ -30,10 +30,9 @@ module Valanga
30
30
  session.click_link(music_name)
31
31
  end
32
32
 
33
- src = session.find(:css, "iframe")['src']
34
- pages[music_name] = info_url(src)
33
+ music_ids[music_name] = music_id(session)
35
34
 
36
- return create_music(info_url(src))
35
+ return create_music(music_ids[music_name])
37
36
  rescue Capybara::ElementNotFound
38
37
  # if link is not found, go next page.
39
38
  end
@@ -42,10 +41,30 @@ module Valanga
42
41
  alias_method :[], :search
43
42
  alias_method :find_music, :search
44
43
 
44
+ def music_image_url(music_name)
45
+ if music_id = music_ids[music_name]
46
+ return image_url(music_id)
47
+ end
48
+
49
+ page_sessions do |session|
50
+ begin
51
+ session.within("#music_table1") do
52
+ on_click = session.find_link(music_name)['onClick']
53
+ music_id = $1 if on_click =~ /id=([\w%]+)/
54
+ music_ids[music_name] = music_id
55
+ return image_url(music_id)
56
+ end
57
+ rescue Capybara::ElementNotFound
58
+ # if link is not found, go next page.
59
+ end
60
+ end
61
+ end
62
+
45
63
  private
46
64
 
47
- def create_music(info_url)
48
- session.visit(info_url)
65
+ def create_music(music_id)
66
+ info = info_url(music_id)
67
+ session.visit(info)
49
68
  Music.new(session.html)
50
69
  end
51
70
 
@@ -67,8 +86,12 @@ module Valanga
67
86
  end
68
87
  end
69
88
 
70
- def info_url(src)
71
- "http://p.eagate.573.jp/game/reflec/groovin/p/music/#{src}"
89
+ def image_url(music_id)
90
+ "http://p.eagate.573.jp/game/reflec/groovin/p/images/binary.html?img=#{music_id}"
91
+ end
92
+
93
+ def info_url(music_id)
94
+ "http://p.eagate.573.jp/game/reflec/groovin/p/music/m_info.html?id=#{music_id}"
72
95
  end
73
96
 
74
97
  def music_url(page: nil, sorttype: nil, sort: nil)
@@ -93,6 +116,11 @@ module Valanga
93
116
  end
94
117
  end
95
118
 
119
+ def music_id(session)
120
+ src = session.find(:css, "iframe")['src']
121
+ src.to_s.split('=').last
122
+ end
123
+
96
124
  def valid_sorttypes
97
125
  { "music_name" => 0, "basic" => 1, "medium" => 2, "hard" => 3, "special" => 4 }
98
126
  end
@@ -1,3 +1,3 @@
1
1
  module Valanga
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valanga
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mgi166
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-09 00:00:00.000000000 Z
11
+ date: 2015-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler