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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Dmm
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
@@ -19,5 +19,6 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_dependency 'faraday', '~> 0.8'
21
21
  gem.add_dependency 'faraday_middleware', '~> 0.8'
22
+ gem.add_dependency 'nokogiri', '~> 1.5.6'
22
23
  gem.add_development_dependency 'rspec'
23
24
  end
data/lib/dmm/client.rb CHANGED
@@ -62,7 +62,7 @@ module Dmm
62
62
  :timestamp => Time.now.to_s,
63
63
  :site => 'DMM.co.jp',
64
64
  }
65
- options[:keyword].encode!("euc-jp") if options[:keyword]
65
+ options.each_value {|val| val.encode! 'euc-jp' if val.kind_of? String}
66
66
  params.merge!(options)
67
67
  end
68
68
 
@@ -1,22 +1,36 @@
1
- require 'rexml/document'
1
+ require 'nokogiri'
2
2
 
3
3
  class Hash
4
4
  class << self
5
5
  def from_xml(xml)
6
- xml_to_hash REXML::Document.new(xml).root
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 xml_to_hash(node)
12
- return { node.name.to_sym => node.text } unless node.has_elements?
13
- child = {}
14
- node.each_element do |e|
15
- child.merge!(xml_to_hash(e)) do |key, old_val, new_val|
16
- old_val.kind_of?(Array) ? old_val << new_val : [old_val, new_val]
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
- { node.name.to_sym => child }
33
+ result_hash
20
34
  end
21
35
  end
22
36
  end
data/lib/dmm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dmm
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2.1"
3
3
  end
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-02 00:00:00.000000000 Z
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