dmm 0.0.1 → 0.0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +31 -2
- data/dmm.gemspec +1 -0
- data/lib/dmm/client.rb +1 -1
- data/lib/dmm/core_ext/hash.rb +23 -9
- data/lib/dmm/version.rb +1 -1
- metadata +18 -2
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Dmm
|
2
2
|
|
3
|
-
|
3
|
+
Ruby wrapper for DMM Web Service API ver2
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -16,9 +16,38 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install dmm
|
18
18
|
|
19
|
+
## ChnageLog
|
20
|
+
|
21
|
+
### Version 0.0.2
|
22
|
+
|
23
|
+
XMLのパーサーをNokogiriに変更しました。処理が速くなってます。
|
24
|
+
|
19
25
|
## Usage
|
20
26
|
|
21
|
-
|
27
|
+
### 商品情報を取得する
|
28
|
+
```ruby
|
29
|
+
require 'dmm'
|
30
|
+
|
31
|
+
client = Dmm.new(:api_id => 'your_api_id', :affiliate_id => 'your_affiliate_id')
|
32
|
+
|
33
|
+
response = client.item_list(
|
34
|
+
:service => 'digital',
|
35
|
+
:floor => 'videoa',
|
36
|
+
:hits => 5,
|
37
|
+
:sort => 'rank',
|
38
|
+
:keyword => '検索ワード')
|
39
|
+
|
40
|
+
response.items each do |item|
|
41
|
+
puts item.title #=> 商品名
|
42
|
+
puts item.affiliate_url #=> アフィリエイトURL
|
43
|
+
puts item.sample_image_url #=> サンプル画像URL
|
44
|
+
puts item.price_download #=> 価格(ダウンロード)
|
45
|
+
puts item.price_stream #=> 価格(ストリーミング)
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
その他のパラメータや、他に取れそうな情報についてはこちらのサイトを参考にしてください。
|
50
|
+
https://affiliate.dmm.com/api/reference/r18/all/
|
22
51
|
|
23
52
|
## Contributing
|
24
53
|
|
data/dmm.gemspec
CHANGED
data/lib/dmm/client.rb
CHANGED
data/lib/dmm/core_ext/hash.rb
CHANGED
@@ -1,22 +1,36 @@
|
|
1
|
-
require '
|
1
|
+
require 'nokogiri'
|
2
2
|
|
3
3
|
class Hash
|
4
4
|
class << self
|
5
5
|
def from_xml(xml)
|
6
|
-
|
6
|
+
result = Nokogiri::XML(xml)
|
7
|
+
{ result.root.name.to_s.to_sym => xml_elem_to_hash(result.root) }
|
7
8
|
end
|
8
9
|
|
9
10
|
private
|
10
11
|
|
11
|
-
def
|
12
|
-
return
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
def xml_elem_to_hash(node)
|
13
|
+
return node.content.to_s unless node.element?
|
14
|
+
return nil if node.children.nil?
|
15
|
+
|
16
|
+
result_hash = {}
|
17
|
+
|
18
|
+
node.children.each do |child|
|
19
|
+
result = xml_elem_to_hash(child)
|
20
|
+
|
21
|
+
if child.name == "text"
|
22
|
+
return result if child.next_element.nil? && child.previous_element.nil?
|
23
|
+
elsif result_hash[child.name.to_sym]
|
24
|
+
if result_hash[child.name.to_sym].is_a? Object::Array
|
25
|
+
result_hash[child.name.to_sym] << result
|
26
|
+
else
|
27
|
+
result_hash[child.name.to_sym] = [result_hash[child.name.to_sym]] << result
|
28
|
+
end
|
29
|
+
else
|
30
|
+
result_hash[child.name.to_sym] = result
|
17
31
|
end
|
18
32
|
end
|
19
|
-
|
33
|
+
result_hash
|
20
34
|
end
|
21
35
|
end
|
22
36
|
end
|
data/lib/dmm/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dmm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
4
|
+
version: 0.0.2.1
|
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: 2013-02-
|
12
|
+
date: 2013-02-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0.8'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: nokogiri
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.5.6
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.5.6
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: rspec
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|