rdmm2 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c632d7b61fd65abd09d44865fad081b79c712d65
4
+ data.tar.gz: 5e12f53f0170b9a9c3391e3cbbe206f040a9b5dd
5
+ SHA512:
6
+ metadata.gz: fdbade54706b7e884079cf9c803d82f5b15d32716e26dd596e93f15680ce7b1598301c75ab98b1421b3c26ba791297a154b21bb51fcdc534052af9c237ffdd63
7
+ data.tar.gz: 8ee5b3ce3a636b95d9b5c98e29d9942eb799ded78e97152f7109d5201f6274282a4ae7b377b11b9ba48fd3a50226f7505d0ff858328178deb88a6d95a5446914
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # coding: utf-8
2
+ source 'https://rubygems.org'
3
+ # Specify your gem's dependencies in rdmm2.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 kinumi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # RDMM2
2
+
3
+ A Ruby client for DMM Web Service API 2.0
4
+
5
+ DMM Web Service 2.0の、Ruby用クライアントライブラリです。
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'rdmm2'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install rdmm2
21
+
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ ## クライアントの生成
27
+
28
+ client = RDMM2::ItemListOperation.new(YOUR_API_ID, YOUR_AFFILIATE_ID)
29
+
30
+
31
+ ## 検索の実行
32
+
33
+ # 設定できる検索条件はDMM Web Service 2.0仕様を参照してください。
34
+ # 下記は検索条件設定の一例です。
35
+
36
+ # 'DMM.com'を条件無しで検索 (デフォルト)
37
+ result = client.request.execute
38
+ # 'DMM.co.jp'をキーワード検索
39
+ result = client.request.site('DMM.co.jp').keyword('巨乳').execute
40
+ # 取得件数、オフセット、ソート条件の指定
41
+ result = client.request.hits(100).offset(:date).execute
42
+
43
+
44
+ ## 検索結果の取得
45
+
46
+ # 取得できる情報はDMM Web Service 2.0仕様を参照してください。
47
+ # 下記は一例です。
48
+
49
+ result.result_count # => 取得件数(String)
50
+ result.total_count # => 全体件数(String)
51
+ result.first_position # => 検索開始位置(String)
52
+
53
+ result.items.item[0].service_name # => サービス名(String)
54
+ result.items.item[0].floor_name # => フロア名(String)
55
+ result.items.item[0].category_name # => カテゴリ名(String)
56
+ result.items.item[0].content_id # => 商品ID(String)
57
+ result.items.item[0].product_id # => 品番(String)
58
+ result.items.item[0].title # => タイトル(String)
59
+ result.items.item[0].URL # => 商品ページURL(String)
60
+ result.items.item[0].affiliateURL # => アフィリエイトリンクURL(String)
61
+ result.items.item[0].URLsp # => スマホ向け商品ページURL(あればString, なければnil)
62
+ result.items.item[0].affiliateURLsp # => スマホ向けアフィリエイトリンクURL(あればString, なければnil)
63
+ result.items.item[0].imageURL.list # => 画像URLリスト用(String)
64
+ result.items.item[0].imageURL.small # => 画像URL末端用(小)(String)
65
+ result.items.item[0].imageURL.large # => 画像URL末端用(大)(String)
66
+ ```
67
+
68
+ specファイルも参照してください。
69
+
70
+
71
+ ## Contributing
72
+
73
+ 1. Fork it ( https://github.com/[my-github-username]/rdmm2/fork )
74
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
75
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
76
+ 4. Push to the branch (`git push origin my-new-feature`)
77
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task :default => :spec
8
+ rescue LoadError
9
+ end
data/lib/rdmm2.rb ADDED
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ require 'uri'
4
+ require 'open-uri'
5
+
6
+ require 'rubygems'
7
+ require 'nokogiri'
8
+
9
+ require File.dirname(__FILE__) + '/rdmm2/request'
10
+ require File.dirname(__FILE__) + '/rdmm2/version'
11
+
12
+ module RDMM2
13
+ API_URI = 'http://affiliate-api.dmm.com/?'
14
+ API_VERSION = '2.00'
15
+
16
+ class ItemListOperation
17
+
18
+ OPERATION = 'ItemList'
19
+
20
+ SITE_DMM_COM = 'DMM.com'
21
+ SITE_DMM_CO_JP = 'DMM.co.jp'
22
+ DEFAULT_SITE = SITE_DMM_COM
23
+
24
+ def initialize(account_id, affiliate_id)
25
+ @account_id = account_id
26
+ @affiliate_id = affiliate_id
27
+ end
28
+
29
+ def request(options = {})
30
+ params = {
31
+ :account_id => @account_id,
32
+ :affiliate_id => @affiliate_id,
33
+ :version => API_VERSION,
34
+ :operation => OPERATION,
35
+ :site => DEFAULT_SITE,
36
+ }
37
+ params.merge(options)
38
+ RDMM2::Request.new(params)
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/response'
4
+
5
+ module RDMM2
6
+ class Request
7
+
8
+ def initialize(parameters)
9
+ @parameters = parameters.dup
10
+ end
11
+
12
+ def execute
13
+ @parameters[:timestamp] = Time.now.strftime('%Y/%m/%d %H:%M:%S')
14
+ return RDMM2::Response.new(Nokogiri::XML(open("#{API_URI}#{URI.encode_www_form(@parameters)}"))).response.result
15
+ end
16
+
17
+ def method_missing(method_name, *args)
18
+ @parameters[method_name] = args.first.to_s.encode('EUC-JP')
19
+ return self
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,48 @@
1
+ # coding: utf-8
2
+
3
+ module RDMM2
4
+ class Response
5
+
6
+ def initialize(doc)
7
+ @doc = doc
8
+ end
9
+
10
+ def inspect
11
+ @doc.inspect
12
+ end
13
+
14
+ def to_s
15
+ @doc.to_s
16
+ end
17
+
18
+ def to_a
19
+ @doc.to_a.map{|v| RDMM2::Response.new(v)}
20
+ end
21
+
22
+ def size
23
+ @doc.size
24
+ end
25
+
26
+ def each(&block)
27
+ self.to_a.each do |elem|
28
+ yield elem
29
+ end
30
+ end
31
+
32
+ def [](index)
33
+ self.to_a[index]
34
+ end
35
+
36
+ def method_missing(elem_name)
37
+ elem = @doc.css("> #{elem_name}")
38
+ if elem.empty?
39
+ nil
40
+ elsif elem.size == 1 && elem.children.size == 1 && elem.children.first.text?
41
+ elem.text
42
+ else
43
+ RDMM2::Response.new(elem)
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ # coding: utf-8
2
+
3
+ module RDMM2
4
+ VERSION = "1.0.0"
5
+ end
data/rdmm2.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rdmm2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rdmm2"
8
+ spec.version = RDMM2::VERSION
9
+ spec.authors = ["kinumi"]
10
+ spec.email = ["kunimi.ikeda@gmail.com"]
11
+ spec.summary = %q{A ruby client for DMM Web Service API 2.0}
12
+ spec.description = %q{A ruby client for DMM Web Service API 2.0}
13
+ spec.homepage = "https://github.com/kinumi/rdmm2"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "nokogiri"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,145 @@
1
+ require File.dirname(__FILE__) + '/../lib/rdmm2'
2
+ require 'rspec'
3
+
4
+ describe 'ItemListOperation' do
5
+ before :all do
6
+ @test_info = eval(File.read(File.expand_path('~/.rdmm2_test')))
7
+ @client = RDMM2::ItemListOperation.new(@test_info[:api_id], @test_info[:affiliate_id])
8
+ end
9
+
10
+ describe '検索条件無し' do
11
+ let(:result) do
12
+ @client.request.execute
13
+ end
14
+
15
+ it '主要なレスポンスフィールドを持っている' do
16
+ # 取得件数
17
+ expect(result.result_count).to be_a(String)
18
+ # 全体件数
19
+ expect(result.total_count).to be_a(String)
20
+ # 検索開始位置
21
+ expect(result.first_position).to be_a(String)
22
+ # 商品情報
23
+ expect(result.items).to be_a(RDMM2::Response)
24
+ # |- 商品
25
+ expect(result.items.item).to be_a(RDMM2::Response)
26
+ begin
27
+ # |- サービス名
28
+ expect(result.items.item[0].service_name).to be_a(String)
29
+ # |- フロア名
30
+ expect(result.items.item[0].floor_name).to be_a(String)
31
+ # |- カテゴリ名
32
+ expect(result.items.item[0].category_name).to be_a(String)
33
+ # |- 商品ID
34
+ expect(result.items.item[0].content_id).to be_a(String)
35
+ # |- 品番
36
+ expect(result.items.item[0].product_id).to be_a(String)
37
+ # |- タイトル
38
+ expect(result.items.item[0].title).to be_a(String)
39
+ # |- 商品ページURL
40
+ expect(result.items.item[0].URL).to be_a(String)
41
+ # |- アフィリエイトリンクURL
42
+ expect(result.items.item[0].affiliateURL).to be_a(String)
43
+ # |- スマホ向け商品ページURL(ある場合)
44
+ # expect(result.items.item[0].URLsp).to be_a(String)
45
+ # |- スマホ向けアフィリエイトリンクURL(ある場合)
46
+ # expect(result.items.item[0].affiliateURLsp).to be_a(String)
47
+ # |- 画像URL
48
+ expect(result.items.item[0].imageURL).to be_a(RDMM2::Response)
49
+ begin
50
+ # |- リスト用
51
+ expect(result.items.item[0].imageURL.list).to be_a(String)
52
+ # |- 末端用(小)
53
+ expect(result.items.item[0].imageURL.small).to be_a(String)
54
+ # |- 末端用(大)
55
+ expect(result.items.item[0].imageURL.large).to be_a(String)
56
+ end
57
+ end
58
+ end
59
+
60
+ it '(おそらく) 20個の結果を持つ' do
61
+ expect(result.result_count).to eq('20')
62
+ expect(result.items.item.size).to eq(20)
63
+ end
64
+ end
65
+
66
+ describe 'DMM.com 通販(スマホ向けページが有る)' do
67
+ let(:result) do
68
+ @client.request.service(:mono).floor(:dvd).execute
69
+ end
70
+
71
+ it 'スマホ向けページが取得できる' do
72
+ # |- 商品
73
+ expect(result.items.item).to be_a(RDMM2::Response)
74
+ begin
75
+ # |- スマホ向け商品ページURL(ある場合)
76
+ expect(result.items.item[0].URLsp).to be_a(String)
77
+ # |- スマホ向けアフィリエイトリンクURL(ある場合)
78
+ expect(result.items.item[0].affiliateURLsp).to be_a(String)
79
+ end
80
+ end
81
+ end
82
+
83
+ describe 'DMM.com PCソフト(スマホ向けページが無い)' do
84
+ let(:result) do
85
+ @client.request.service(:pcsoft).floor(:pcgame).execute
86
+ end
87
+
88
+ it 'スマホ向けページが無い(nil)' do
89
+ # |- 商品
90
+ expect(result.items.item).to be_a(RDMM2::Response)
91
+ begin
92
+ # |- スマホ向け商品ページURL(ある場合)
93
+ expect(result.items.item[0].URLsp).to eq(nil)
94
+ # |- スマホ向けアフィリエイトリンクURL(ある場合)
95
+ expect(result.items.item[0].affiliateURLsp).to eq(nil)
96
+ end
97
+ end
98
+ end
99
+
100
+ describe '取得件数指定あり' do
101
+ let(:result) do
102
+ @client.request.site('DMM.com').keyword('AKB').hits(100).execute
103
+ end
104
+
105
+ it '検索結果が100個となる' do
106
+ expect(result.result_count).to eq('100')
107
+ expect(result.items.item.size).to eq(100)
108
+ end
109
+ end
110
+
111
+ describe '検索開始位置指定あり' do
112
+ let(:result) do
113
+ @client.request.site('DMM.com').keyword('AKB').offset(100).execute
114
+ end
115
+
116
+ it '検索開始位置が100となる' do
117
+ expect(result.first_position).to eq('100')
118
+ end
119
+ end
120
+
121
+ describe 'ソート条件あり' do
122
+ let(:result_not_ordered) do
123
+ @client.request.site('DMM.com').keyword('AKB').execute
124
+ end
125
+ let(:result_ordered) do
126
+ @client.request.site('DMM.com').keyword('AKB').sort(:date).execute
127
+ end
128
+
129
+ it '並び順が変更されている' do
130
+ expect(result_ordered.items.item[0].title).not_to eq(result_not_ordered.items.item[0].title)
131
+ end
132
+ end
133
+
134
+ describe 'eachで回せる' do
135
+ let(:result) do
136
+ @client.request.execute
137
+ end
138
+
139
+ it 'eachで回せる' do
140
+ result.items.item.each do |item|
141
+ expect(item.title).to be_a(String)
142
+ end
143
+ end
144
+ end
145
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdmm2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - kinumi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A ruby client for DMM Web Service API 2.0
70
+ email:
71
+ - kunimi.ikeda@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/rdmm2.rb
82
+ - lib/rdmm2/request.rb
83
+ - lib/rdmm2/response.rb
84
+ - lib/rdmm2/version.rb
85
+ - rdmm2.gemspec
86
+ - spec/rdmm2_spec.rb
87
+ homepage: https://github.com/kinumi/rdmm2
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.0.14
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: A ruby client for DMM Web Service API 2.0
111
+ test_files:
112
+ - spec/rdmm2_spec.rb