dmm-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 754a5872ad922af26290b436c675fcfb29fefd9e
4
+ data.tar.gz: 69b2ed65940ac0c05ecb973b88174a326153a215
5
+ SHA512:
6
+ metadata.gz: 03b80c6bac6e4e2d2aff98f1c7f3381b6cfbf15c8432542c0509d070201a09a9ca2873b22493c72ae5036a7bf87d32e6773e09495580b098677e462e7917570a
7
+ data.tar.gz: 6f7df22555e51edd4894b873c8ca9de17ca23ffc52c80541bf5d655e74b6078b5d687efb5956faf31b1e0c81c20f1f07f2a9dab2916a08a4b8215a254425b2d0
@@ -0,0 +1,20 @@
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
+ spec/*.yml
19
+ spec/fixtures/*.yml
20
+ example/*.yml
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dmm-api.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 shoprev
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.
@@ -0,0 +1,52 @@
1
+ # Dmm::Api
2
+
3
+ Ruby DMM Web Service API ver 2.0
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'dmm-api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install dmm-api
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require 'dmm/api'
23
+
24
+ # configure
25
+ Dmm::Api.configure do |options|
26
+ options[:api_id] = "your api id"
27
+ options[:affiliate_id] = "your affiliate id"
28
+ options[:site] = "DMM.com or DMM.co.jp"
29
+ ...
30
+ end
31
+
32
+ # dmm web service api 2.0
33
+ res = Dmm::Api.get({:service => 'lod',:floor => 'nmb48',:keyword => "山本彩"})
34
+ res.code # 200
35
+ res.message # "OK"
36
+ res["result"]["items"]["item"].each do |v|
37
+ title = v["title"]
38
+ ...
39
+ end
40
+ ```
41
+
42
+ See the [examples directory](https://github.com/shoprev/dmm-api/tree/master/example) for more usage.
43
+
44
+ Refer to [DMM Web API documentation](https://affiliate.dmm.com/api/guide/) for more infomation.
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dmm/api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dmm-api"
8
+ spec.version = Dmm::Api::VERSION
9
+ spec.authors = ["shoprev"]
10
+ spec.email = ["admin@shoprev.net"]
11
+ spec.description = %q{Ruby DMM Web Service API ver 2.0}
12
+ spec.summary = %q{Ruby DMM Web Service API ver 2.0}
13
+ spec.homepage = "https://github.com/shoprev/dmm-api"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "vcr"
25
+ spec.add_development_dependency "webmock", "1.11.0"
26
+ # spec.add_runtime_dependency "nokogiri"
27
+ spec.add_runtime_dependency "activesupport"
28
+ end
@@ -0,0 +1,20 @@
1
+ require "dmm/api"
2
+ require "yaml"
3
+ require "pp"
4
+
5
+ config = YAML.load_file(File.dirname(__FILE__)+'/config.yml')
6
+
7
+ Dmm::Api.configure do |options|
8
+ options[:api_id] = config["api_id"]
9
+ options[:affiliate_id] = config["affiliate_id"]
10
+ options[:site] = "DMM.com"
11
+ end
12
+
13
+ res = Dmm::Api.get({:service => 'lod',:floor => 'nmb48',:keyword => "山本彩",:hits => "1"})
14
+ pp res["result"]["result_count"]
15
+ pp res["result"]["items"]["item"]["title"]
16
+
17
+ res = Dmm::Api.get({:service => 'lod',:floor => 'nmb48',:keyword => "山本彩"})
18
+ res["result"]["items"]["item"].each do |v|
19
+ pp v["title"]
20
+ end
@@ -0,0 +1,20 @@
1
+ require "dmm/api"
2
+ require "yaml"
3
+ require "pp"
4
+
5
+ config = YAML.load_file(File.dirname(__FILE__)+'/config.yml')
6
+
7
+ Dmm::Api.configure do |options|
8
+ options[:api_id] = config["api_id"]
9
+ options[:affiliate_id] = config["affiliate_id"]
10
+ options[:site] = "DMM.co.jp"
11
+ end
12
+
13
+ res = Dmm::Api.get({:service => 'digital',:floor => 'videoa',:keyword => "菜月アンナ",:hits => "1"})
14
+ pp res["result"]["result_count"]
15
+ pp res["result"]["items"]["item"]["title"]
16
+
17
+ res = Dmm::Api.get({:service => 'digital',:floor => 'videoa',:keyword => "菜月アンナ"})
18
+ res["result"]["items"]["item"].each do |v|
19
+ pp v["title"]
20
+ end
@@ -0,0 +1,38 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require 'active_support/core_ext'
4
+ # require "nokogiri"
5
+ # require "dmm/api/hash"
6
+ require "dmm/api/version"
7
+ require "dmm/api/response"
8
+ require "dmm/api/request"
9
+
10
+ module Dmm
11
+
12
+ class Api
13
+
14
+ @@options = {}
15
+
16
+ class << self
17
+
18
+ def options
19
+ @@options
20
+ end
21
+
22
+ def configure(&proc)
23
+ raise ArgumentError, "Block is required." unless block_given?
24
+ yield @@options
25
+ end
26
+
27
+ def get(opts={})
28
+ opts[:operation] = 'ItemList' unless opts.key?(:operation)
29
+ opts[:version] = '2.00' unless opts.key?(:version)
30
+ opts[:timestamp] = Time.now.strftime("%Y-%m-%d %H:%M:%S") unless opts.key?(:timestamp)
31
+ Dmm::Request.get("http://affiliate-api.dmm.com/", @@options.merge(opts))
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+
38
+ end
File without changes
@@ -0,0 +1,12 @@
1
+ module Dmm
2
+
3
+ class Request
4
+
5
+ def self.get(path,opts)
6
+ uri = URI.escape("#{path}?#{opts.map{|k,v|"#{k}=#{v}"}.join('&')}".encode('euc-jp'))
7
+ Dmm::Response.new(Net::HTTP.get_response(URI.parse(uri)))
8
+ end
9
+
10
+ end
11
+
12
+ end
@@ -0,0 +1,28 @@
1
+ module Dmm
2
+
3
+ class Response
4
+ def initialize(response)
5
+ @response =response
6
+ @body = Hash.from_xml(@response.body)
7
+ @body = @body["response"] if @body.key?("response")
8
+ end
9
+
10
+ def code
11
+ @response.code.to_i
12
+ end
13
+
14
+ def message
15
+ @response.message
16
+ end
17
+
18
+ def method_missing(name, *args, &block)
19
+ if @body.respond_to?(name)
20
+ @body.send(name, *args, &block)
21
+ else
22
+ super
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,5 @@
1
+ module Dmm
2
+ class Api
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+
4
+ share_examples_for 'found items' do
5
+ context 'code' do
6
+ it { expect(res.code).to eq 200 }
7
+ end
8
+ context 'size' do
9
+ it { expect(res["result"]["result_count"].to_i).to be > 0 }
10
+ end
11
+ end
12
+
13
+ share_examples_for 'not found items' do
14
+ context 'code' do
15
+ it { expect(res.code).to eq 200 }
16
+ end
17
+ context 'size' do
18
+ it { expect(res["result"]["result_count"].to_i).to eq 0 }
19
+ end
20
+ end
21
+
22
+ describe "Dmm::Api.get" do
23
+
24
+ let(:res) {
25
+ VCR.use_cassette('get_' + service.to_s + '_' + floor.to_s + '_' + keyword.to_s) do
26
+ Dmm::Api.get({:service => service,:floor => floor,:keyword => keyword})
27
+ end
28
+ }
29
+
30
+ context 'found items' do
31
+ let(:service) { 'digital' }
32
+ let(:floor) { 'videoa' }
33
+ let(:keyword) { "au" }
34
+ it_should_behave_like 'found items'
35
+ end
36
+
37
+ context 'not found items' do
38
+ let(:service) { 'digital' }
39
+ let(:floor) { 'videoa' }
40
+ let(:keyword) { 'auaaaaaaaaaaaaaaaaaaaaa' }
41
+ it_should_behave_like 'not found items'
42
+ end
43
+
44
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ require 'webmock/rspec'
3
+ WebMock.disable_net_connect!
4
+ require 'vcr'
5
+
6
+ VCR.configure do |c|
7
+ c.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + '/fixtures')
8
+ c.hook_into :webmock
9
+ c.allow_http_connections_when_no_cassette = true
10
+ c.default_cassette_options = {
11
+ :match_requests_on => [:method,
12
+ VCR.request_matchers.uri_without_param(:timestamp)]
13
+ }
14
+ end
15
+
16
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/dmm/api')
17
+ config = YAML.load_file(File.dirname(__FILE__)+'/config.yml')
18
+
19
+ Dmm::Api.configure do |options|
20
+ options[:api_id] = config["api_id"]
21
+ options[:affiliate_id] = config["affiliate_id"]
22
+ options[:site] = config["site"]
23
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dmm-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - shoprev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: vcr
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
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.11.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.11.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Ruby DMM Web Service API ver 2.0
98
+ email:
99
+ - admin@shoprev.net
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - dmm-api.gemspec
110
+ - example/com.rb
111
+ - example/config.yml
112
+ - example/r18.rb
113
+ - lib/dmm/api.rb
114
+ - lib/dmm/api/hash.rb
115
+ - lib/dmm/api/request.rb
116
+ - lib/dmm/api/response.rb
117
+ - lib/dmm/api/version.rb
118
+ - spec/dmm/api_spec.rb
119
+ - spec/spec_helper.rb
120
+ homepage: https://github.com/shoprev/dmm-api
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.0.3
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Ruby DMM Web Service API ver 2.0
144
+ test_files:
145
+ - spec/dmm/api_spec.rb
146
+ - spec/spec_helper.rb