rdmm 0.0.1

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: 2fdf2276f123620c09e7985eaa349ae3aed3b946
4
+ data.tar.gz: 5179c7024474006ca8c2cf34fca0355f4b8cd26c
5
+ SHA512:
6
+ metadata.gz: 6d667c0451e4a6fadb17ae3b994134f09d3f459e9f3018f7c3bcb3dfd7fcf6e47fb456b3808231143118ea3dbc7d49abf706984f66d9476abd85fa4b3bfae706
7
+ data.tar.gz: 36bce25c65eb0dd6acf5965a01f58d19b7990d1cf3229bd4c32e157b1b9b5aa9b9f7114b14c3c069cc248260b2d16bba877fc6265ef4019c100843f6322972f3
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ## 0.0.1
2
+
3
+ - 1st Release :tada:
4
+ - Add `Rdmm::Client#list_items`
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rdmm.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 Ryo Nakamura
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,101 @@
1
+ # Rdmm
2
+
3
+ An API Client library for DMM written in Ruby.
4
+
5
+ ## Requirements
6
+
7
+ - Ruby 2.2.2 or higher
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem "rdmm"
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```bash
20
+ bundle
21
+ ```
22
+
23
+ Or install it yourself as:
24
+
25
+ ```bash
26
+ gem install rdmm
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ### Rdmm::Client.new
32
+
33
+ ```ruby
34
+ require "rdmm"
35
+ client = Rdmm::Client.new(affiliate_id: "dummy", api_id: "dummy")
36
+ ```
37
+
38
+ ### Rdmm::Client#list_items
39
+
40
+ Available options:
41
+
42
+ - `:article`
43
+ - `:article_id`
44
+ - `:content_id`
45
+ - `:floor`
46
+ - `:hits`
47
+ - `:keyword`
48
+ - `:mono_stock`
49
+ - `:offset`
50
+ - `:released_from`
51
+ - `:released_to`
52
+ - `:service`
53
+ - `:site`
54
+ - `:sort`
55
+
56
+ ```ruby
57
+ client.list_items(site: "DMM.com")
58
+ ```
59
+
60
+ `https://api.dmm.com/affiliate/v3/ItemList?affiliate_id=dummy&api_id=dummy&site=DMM.com`
61
+
62
+ ### Rdmm::Resources::ItemResource
63
+
64
+ Available attributes:
65
+
66
+ - `actors`
67
+ - `actresses`
68
+ - `affiliate_url`
69
+ - `authors`
70
+ - `category_name`
71
+ - `content_id`
72
+ - `directors`
73
+ - `floor_code`
74
+ - `floor_name`
75
+ - `genres`
76
+ - `labels`
77
+ - `makers`
78
+ - `prices`
79
+ - `product_id`
80
+ - `released_at`
81
+ - `review_avarage`
82
+ - `review_count`
83
+ - `series_list`
84
+ - `service_code`
85
+ - `service_name`
86
+ - `title`
87
+ - `url`
88
+ - `volume`
89
+
90
+ ```ruby
91
+ client.list_items(site: "DMM.com").first.title
92
+ ```
93
+
94
+ <details>
95
+ <summary>output</summary>
96
+
97
+ ```ruby
98
+ "キングダム"
99
+ ```
100
+
101
+ </details>
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/lib/rdmm.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "rdmm/client"
2
+ require "rdmm/queries/base_query"
3
+ require "rdmm/queries/list_items_query"
4
+ require "rdmm/resources/base_resource"
5
+ require "rdmm/resources/item_resource"
6
+ require "rdmm/responses/base_response"
7
+ require "rdmm/responses/list_items_response"
8
+ require "rdmm/version"
@@ -0,0 +1,52 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+
4
+ module Rdmm
5
+ class Client
6
+ BASE_URL = "https://api.dmm.com"
7
+ PATH_TO_LIST_ITEMS = "/affiliate/v3/ItemList"
8
+
9
+ # @param affiliate_id [String]
10
+ # @param api_id [String]
11
+ def initialize(affiliate_id:, api_id:)
12
+ @affiliate_id = affiliate_id
13
+ @api_id = api_id
14
+ end
15
+
16
+ # @return [Faraday::Connection]
17
+ def connection
18
+ @connection ||= ::Faraday::Connection.new(url: BASE_URL) do |connection|
19
+ connection.adapter :net_http
20
+ connection.response :json
21
+ connection.response :raise_error
22
+ end
23
+ end
24
+
25
+ # @param options [Hash]
26
+ # @return [Rdmm::Responses::ListItemsResponse]
27
+ def list_items(options = {})
28
+ query_options = default_query_options.merge(options)
29
+ query = ::Rdmm::Queries::ListItemsQuery.new(query_options)
30
+ faraday_response = get(PATH_TO_LIST_ITEMS, query.to_hash)
31
+ ::Rdmm::Responses::ListItemsResponse.new(faraday_response)
32
+ end
33
+
34
+ private
35
+
36
+ # @return [Hash]
37
+ def default_query_options
38
+ {
39
+ affiliate_id: @affiliate_id,
40
+ api_id: @api_id,
41
+ }
42
+ end
43
+
44
+ # @private
45
+ # @param path [String]
46
+ # @param query [Hash]
47
+ # @return [Faraday::Response]
48
+ def get(path, query)
49
+ connection.get(path, query)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,59 @@
1
+ module Rdmm
2
+ module Queries
3
+ class BaseQuery
4
+ class << self
5
+ attr_writer :property_names
6
+
7
+ # @note Override
8
+ def inherited(child_class)
9
+ child_class.property_names = property_names.clone
10
+ end
11
+
12
+ # @return [Array<Symbol>]
13
+ def property_names
14
+ @property_names ||= []
15
+ end
16
+
17
+ # @param property_name [Symbol]
18
+ def property(property_name)
19
+ property_names << property_name
20
+ end
21
+ end
22
+
23
+ property :affiliate_id
24
+ property :api_id
25
+
26
+ # @param options [Hash]
27
+ def initialize(options = {})
28
+ @options = options
29
+ end
30
+
31
+ # @return [String]
32
+ def affiliate_id
33
+ options[:affiliate_id]
34
+ end
35
+
36
+ # @return [String]
37
+ def api_id
38
+ options[:api_id]
39
+ end
40
+
41
+ # @return [Hash]
42
+ def to_hash
43
+ self.class.property_names.each_with_object({}) do |property_name, result|
44
+ value = send(property_name)
45
+ unless value.nil?
46
+ result[property_name.to_s] = value
47
+ end
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ # @return [Hash]
54
+ def options
55
+ @options
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,118 @@
1
+ module Rdmm
2
+ module Queries
3
+ class ListItemsQuery < BaseQuery
4
+ property :article
5
+ property :article_id
6
+ property :cid
7
+ property :floor
8
+ property :gte_date
9
+ property :hits
10
+ property :keyword
11
+ property :lte_date
12
+ property :mono_stock
13
+ property :offset
14
+ property :service
15
+ property :site
16
+ property :sort
17
+
18
+ # @note One of the following values:
19
+ # "actress"
20
+ # "author"
21
+ # "genre"
22
+ # "maker"
23
+ # "series"
24
+ # @return [String, nil]
25
+ def article
26
+ options[:article]
27
+ end
28
+
29
+ # @return [String, nil]
30
+ def article_id
31
+ options[:article_id]
32
+ end
33
+
34
+ # @return [String, nil]
35
+ def cid
36
+ options[:content_id]
37
+ end
38
+
39
+ # @note floor code
40
+ # @return [String, nil]
41
+ def floor
42
+ options[:floor]
43
+ end
44
+
45
+ # @return [String, nil]
46
+ def gte_date
47
+ if options[:released_from]
48
+ format_time(options[:released_from])
49
+ end
50
+ end
51
+
52
+ # @return [Integer, nil]
53
+ def hits
54
+ options[:hits]
55
+ end
56
+
57
+ # @return [String, nil]
58
+ def keyword
59
+ options[:keyword]
60
+ end
61
+
62
+ # @return [String, nil]
63
+ def lte_date
64
+ if options[:released_to]
65
+ format_time(options[:released_to])
66
+ end
67
+ end
68
+
69
+ # @note One of the following values:
70
+ # "dmp"
71
+ # "mono"
72
+ # "reserve"
73
+ # "stock"
74
+ # @return [String, nil]
75
+ def mono_stock
76
+ options[:mono_stock]
77
+ end
78
+
79
+ # @return [Integer, nil]
80
+ def offset
81
+ options[:offset]
82
+ end
83
+
84
+ # @note service code
85
+ # @return [String, nil]
86
+ def service
87
+ options[:service]
88
+ end
89
+
90
+ # @note One of the following values:
91
+ # "DMM.com"
92
+ # "DMM.R18"
93
+ # @return [String, nil]
94
+ def site
95
+ options[:site]
96
+ end
97
+
98
+ # @note One of the following values:
99
+ # "-price"
100
+ # "date"
101
+ # "price"
102
+ # "rank"
103
+ # "review"
104
+ # @return [String, nil]
105
+ def sort
106
+ options[:sort]
107
+ end
108
+
109
+ private
110
+
111
+ # @param time [Time]
112
+ # @return [String]
113
+ def format_time(time)
114
+ time.strftime("%Y-%m-%dT%H:%M:%S")
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,13 @@
1
+ module Rdmm
2
+ module Resources
3
+ class BaseResource
4
+ # @return [Hash]
5
+ attr_reader :source
6
+
7
+ # @param source [Hash]
8
+ def initialize(source)
9
+ @source = source
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,124 @@
1
+ require "time"
2
+
3
+ module Rdmm
4
+ module Resources
5
+ class ItemResource < BaseResource
6
+ # @return [Array]
7
+ def actresses
8
+ Array(source["iteminfo"]["actress"])
9
+ end
10
+
11
+ # @return [Array]
12
+ def actors
13
+ Array(source["iteminfo"]["actor"])
14
+ end
15
+
16
+ # @return [String, nil]
17
+ def affiliate_url
18
+ source["affiliate_url"]
19
+ end
20
+
21
+ # @return [Array]
22
+ def authors
23
+ Array(source["iteminfo"]["author"])
24
+ end
25
+
26
+ # @return [String, nil]
27
+ def category_name
28
+ source["category_name"]
29
+ end
30
+
31
+ # @return [String, nil]
32
+ def content_id
33
+ source["content_id"]
34
+ end
35
+
36
+ # @return [Array]
37
+ def directors
38
+ Array(source["iteminfo"]["director"])
39
+ end
40
+
41
+ # @return [String, nil]
42
+ def floor_code
43
+ source["floor_code"]
44
+ end
45
+
46
+ # @return [String, nil]
47
+ def floor_name
48
+ source["floor_name"]
49
+ end
50
+
51
+ # @return [Array]
52
+ def genres
53
+ Array(source["iteminfo"]["genre"])
54
+ end
55
+
56
+ # @return [Array]
57
+ def labels
58
+ Array(source["iteminfo"]["label"])
59
+ end
60
+
61
+ # @return [Array]
62
+ def makers
63
+ Array(source["iteminfo"]["maker"])
64
+ end
65
+
66
+ # @return [Hash, nil]
67
+ def prices
68
+ source["prices"]
69
+ end
70
+
71
+ # @return [String, nil]
72
+ def product_id
73
+ source["product_id"]
74
+ end
75
+
76
+ # @return [Time, nil]
77
+ def released_at
78
+ if source["date"]
79
+ ::Time.parse(source["date"])
80
+ end
81
+ end
82
+
83
+ # @return [Integer, nil]
84
+ def review_avarage
85
+ source["review"]["count"]
86
+ end
87
+
88
+ # @return [Float, nil]
89
+ def review_count
90
+ source["review"]["count"]
91
+ end
92
+
93
+ # @return [Array]
94
+ def series_list
95
+ Array(source["iteminfo"]["series"])
96
+ end
97
+
98
+ # @return [String, nil]
99
+ def service_code
100
+ source["service_code"]
101
+ end
102
+
103
+ # @return [String, nil]
104
+ def service_name
105
+ source["service_name"]
106
+ end
107
+
108
+ # @return [String, nil]
109
+ def title
110
+ source["title"]
111
+ end
112
+
113
+ # @return [String, nil]
114
+ def url
115
+ source["url"]
116
+ end
117
+
118
+ # @return [Integer, nil]
119
+ def volume
120
+ source["volume"]
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,44 @@
1
+ module Rdmm
2
+ module Responses
3
+ class BaseResponse
4
+ include ::Enumerable
5
+
6
+ # @param faraday_response [Faraday::Response]
7
+ def initialize(faraday_response)
8
+ @faraday_response = faraday_response
9
+ end
10
+
11
+ # @return [String]
12
+ def body
13
+ faraday_response.body
14
+ end
15
+
16
+ # @note Implementation for Enumerable
17
+ def each(&block)
18
+ resources.each(&block)
19
+ end
20
+
21
+ # @return [Faraday::Utils::Headers]
22
+ def headers
23
+ faraday_response.headers
24
+ end
25
+
26
+ # @return [Rdmm::Resources::BaseResource]
27
+ def resources
28
+ raise ::NotImplementedError
29
+ end
30
+
31
+ # @return [Integer]
32
+ def status
33
+ faraday_response.status
34
+ end
35
+
36
+ private
37
+
38
+ # @return [Faraday::Response]
39
+ def faraday_response
40
+ @faraday_response
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,12 @@
1
+ module Rdmm
2
+ module Responses
3
+ class ListItemsResponse < BaseResponse
4
+ # @note Override
5
+ def resources
6
+ body["result"]["items"].map do |source|
7
+ ::Rdmm::Resources::ItemResource.new(source)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Rdmm
2
+ VERSION = "0.0.1"
3
+ end
data/rdmm.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "rdmm/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rdmm"
7
+ spec.version = Rdmm::VERSION
8
+ spec.authors = ["Ryo Nakamura"]
9
+ spec.email = ["r7kamura@gmail.com"]
10
+ spec.summary = "An API Client library for DMM written in Ruby."
11
+ spec.homepage = "https://github.com/r7kamura/rdmm"
12
+
13
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
14
+ f.match(%r{^(test|spec|features)/})
15
+ end
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_dependency "faraday"
19
+ spec.add_dependency "faraday_middleware"
20
+ spec.add_development_dependency "bundler", "~> 1.14"
21
+ spec.add_development_dependency "pry"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdmm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
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: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description:
98
+ email:
99
+ - r7kamura@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - CHANGELOG.md
107
+ - Gemfile
108
+ - LICENSE
109
+ - README.md
110
+ - Rakefile
111
+ - lib/rdmm.rb
112
+ - lib/rdmm/client.rb
113
+ - lib/rdmm/queries/base_query.rb
114
+ - lib/rdmm/queries/list_items_query.rb
115
+ - lib/rdmm/resources/base_resource.rb
116
+ - lib/rdmm/resources/item_resource.rb
117
+ - lib/rdmm/responses/base_response.rb
118
+ - lib/rdmm/responses/list_items_response.rb
119
+ - lib/rdmm/version.rb
120
+ - rdmm.gemspec
121
+ homepage: https://github.com/r7kamura/rdmm
122
+ licenses: []
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.5.2
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: An API Client library for DMM written in Ruby.
144
+ test_files: []