ruby_duga 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9ade715b2fa211b9bfd2f6d2c0007356bfe717f6f75806ff4f0898980b90fa01
4
+ data.tar.gz: 2ce1146bb4deffac481c5517cff8a6b4db68267964d825bec81a2dbcceb35188
5
+ SHA512:
6
+ metadata.gz: e2cea55fbdd0fce21964f644f73aa646cff03fe7e391dac859f8f3d5c691515ea6abd99488a6c0a27a4a77a83652a559ab9c1f77b3a38b0ed701ba2327ababee
7
+ data.tar.gz: 2b566543bc1481c5f216b1fee9409feb85123da31b0e6a9f74676ae6cced71817de1587da81f574d31dc0284365f0e96b8c1659f0b97e94d32b7ca4f47e86e95
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Style/FrozenStringLiteralComment:
16
+ Enabled: false
17
+
18
+ Style/Documentation:
19
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-05-10
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in ruby_duga.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 lumiere
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # RubyDuga
2
+
3
+ Client for the DUGA Web Service API v1.2
4
+
5
+ ## DUGA API Account
6
+
7
+ If you do not have a DUGA API Application ID, you can register at [DUGA](https://click.duga.jp/aff/40413-01). You will get Application ID and Agent ID.
8
+
9
+ ## Installation
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add ruby_duga
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install ruby_duga
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ cli = RubyDuga.new(app_id: "YOUR_APP_ID", agent_id: "YOUR_AGENT_ID", banner_id: "YOUR_BANNER_ID")
23
+ response = cli.search(keyword: "コメディ", adult: 0)
24
+ response.body[:items].map {|x| x[:item][:title]}
25
+ => ["けっこう仮面 マングリフォンの逆襲", "古今亭駒次「公園のひかり号」", "けっこう仮面 フォーエバー", "けっこう仮面 RETURNS", "できる子の証明", "天然華汁さやか", "けっこう仮面 プレミアム", "18倫 アイドルを探せ!", "ビキニ★ラーメン", "18倫"]
26
+ ```
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dugabot0/ruby_duga.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,58 @@
1
+ require "faraday"
2
+ require_relative "response"
3
+ require_relative "version"
4
+
5
+ module RubyDuga
6
+ class Client
7
+ BASE_URL = "http://affapi.duga.jp/".freeze
8
+ DEFAULT_AGENT_ID = "40413".freeze
9
+ DEFAULT_BANNER_ID = "01".freeze
10
+ API_VERSION = "1.2".freeze
11
+
12
+ def initialize(options = {})
13
+ @appid = (ENV["DUGA_APP_ID"] || options[:app_id])
14
+ @agentid = (ENV["DUGA_AGENT_ID"] || options[:agent_id] || DEFAULT_AGENT_ID)
15
+ @bannerid = (ENV["DUGA_BANNER_AGENT"] || options[:banner_id] || DEFAULT_BANNER_ID)
16
+ end
17
+
18
+ API_MAP = {
19
+ search: "search"
20
+ }.freeze
21
+
22
+ API_MAP.each do |method, path|
23
+ define_method method do |params = {}|
24
+ get(path, must.merge(params))
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def must
31
+ {
32
+ appid: @appid,
33
+ agentid: @agentid,
34
+ bannerid: @bannerid,
35
+ version: API_VERSION,
36
+ format: "json"
37
+ }
38
+ end
39
+
40
+ def get(path, options = {})
41
+ Response.new(connection.get(path, options))
42
+ end
43
+
44
+ def connection
45
+ @connection ||= Faraday.new(faraday_options) do |faraday|
46
+ faraday.adapter :net_http
47
+ faraday.request :url_encoded
48
+ faraday.response :json
49
+ end
50
+ end
51
+
52
+ def faraday_options
53
+ {
54
+ url: BASE_URL
55
+ }
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,23 @@
1
+ require "active_support/core_ext/hash/keys"
2
+
3
+ module RubyDuga
4
+ class Response
5
+ def initialize(faraday_response)
6
+ @original_response = faraday_response
7
+ end
8
+
9
+ attr_reader :original_response
10
+
11
+ def body
12
+ @body ||= original_response.body.deep_symbolize_keys
13
+ end
14
+
15
+ def headers
16
+ original_response.headers
17
+ end
18
+
19
+ def status
20
+ original_response.status
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyDuga
4
+ VERSION = "0.1.0"
5
+ end
data/lib/ruby_duga.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ruby_duga/version"
4
+ require_relative "ruby_duga/client"
5
+
6
+ module RubyDuga
7
+ class Error < StandardError; end
8
+
9
+ def self.new(options = {})
10
+ RubyDuga::Client.new(options)
11
+ end
12
+ end
data/sig/ruby_duga.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module RubyDuga
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_duga
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - duga_bot
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-05-12 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
+ description: Client for the DUGA Web Service API v1.2
28
+ email:
29
+ - duga_bot@pm.me
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rubocop.yml"
35
+ - CHANGELOG.md
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - lib/ruby_duga.rb
41
+ - lib/ruby_duga/client.rb
42
+ - lib/ruby_duga/response.rb
43
+ - lib/ruby_duga/version.rb
44
+ - sig/ruby_duga.rbs
45
+ homepage: https://github.com/dugabot0/ruby_duga
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ homepage_uri: https://github.com/dugabot0/ruby_duga
50
+ source_code_uri: https://github.com/dugabot0/ruby_duga
51
+ changelog_uri: https://github.com/dugabot0/ruby_duga
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.6.0
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.3.20
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Client for the DUGA Web Service API v1.2
71
+ test_files: []