myanimelist_client 0.1.0 → 0.1.1
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 +4 -4
- data/.rubocop.yml +45 -0
- data/.rubocop_todo.yml +30 -0
- data/.yardopts +1 -1
- data/Gemfile +1 -0
- data/README.md +11 -5
- data/Rakefile +8 -4
- data/bin/console +4 -3
- data/lib/myanimelist_client.rb +1 -0
- data/lib/myanimelist_client/myanimelist_client.rb +36 -34
- data/lib/myanimelist_client/search_entry.rb +4 -4
- data/lib/myanimelist_client/search_response.rb +2 -1
- data/lib/myanimelist_client/user_response.rb +1 -0
- data/lib/myanimelist_client/version.rb +2 -1
- data/myanimelist_client.gemspec +18 -17
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fa4b21a58ead4a3db317a408fa16cd4c9458b8b
|
4
|
+
data.tar.gz: faa3237727a3e6e76f621a37a3e0355c6f193a22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4be1f706bda69b1026a75c6618946a27efba1aedcb3d08c02a406eff1cc09e43b1b0c3fcb4f6a839ae59505853bc128e432bca8fa174cf64b75baf017e0382a
|
7
|
+
data.tar.gz: c503f3de7a1206efc067fca1111f9ce3c6261bd3fe553b9d13838df5c7dcc9554649d604e3d41c98ad2c2ecdcfb5061bfd6b2088d8f4bdb4ffa6e29c6248ea7e
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.3
|
5
|
+
|
6
|
+
Metrics/BlockLength:
|
7
|
+
Include:
|
8
|
+
- 'lib/*'
|
9
|
+
|
10
|
+
Metrics/LineLength:
|
11
|
+
Include:
|
12
|
+
- 'lib/*'
|
13
|
+
|
14
|
+
Metrics/MethodLength:
|
15
|
+
Max: 25
|
16
|
+
|
17
|
+
Style/ClassAndModuleChildren:
|
18
|
+
EnforcedStyle: compact
|
19
|
+
|
20
|
+
Style/ColonMethodCall:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Style/DoubleNegation:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Style/MethodDefParentheses:
|
27
|
+
EnforcedStyle: require_no_parentheses
|
28
|
+
|
29
|
+
Style/MutableConstant:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/NestedParenthesizedCalls:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Style/Not:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Style/NumericPredicate:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Style/SpaceAroundEqualsInParameterDefault:
|
42
|
+
EnforcedStyle: no_space
|
43
|
+
|
44
|
+
Style/SpaceBeforeBlockBraces:
|
45
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2016-11-14 00:10:52 +0100 using RuboCop version 0.45.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
Lint/AmbiguousOperator:
|
11
|
+
Exclude:
|
12
|
+
- 'lib/myanimelist_client/search_response.rb'
|
13
|
+
|
14
|
+
# Offense count: 1
|
15
|
+
Metrics/AbcSize:
|
16
|
+
Max: 42
|
17
|
+
|
18
|
+
# Offense count: 1
|
19
|
+
# Cop supports --auto-correct.
|
20
|
+
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
|
21
|
+
Style/ExtraSpacing:
|
22
|
+
Exclude:
|
23
|
+
- 'myanimelist_client.gemspec'
|
24
|
+
|
25
|
+
# Offense count: 1
|
26
|
+
# Cop supports --auto-correct.
|
27
|
+
# Configuration parameters: AllowForAlignment.
|
28
|
+
Style/SpaceAroundOperators:
|
29
|
+
Exclude:
|
30
|
+
- 'myanimelist_client.gemspec'
|
data/.yardopts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
- LICENSE.txt
|
1
|
+
--private - LICENSE.txt
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# MyAnimeList Client
|
2
|
+
[](https://badge.fury.io/rb/myanimelist_client)
|
3
|
+
[](https://codeclimate.com/github/Oli4242/myanimelist_client)
|
4
|
+
|
2
5
|
A gem for the [MyAnimeList.net API](https://myanimelist.net/modules.php?go=api).
|
3
6
|
|
4
7
|
For now you can:
|
@@ -8,7 +11,6 @@ For now you can:
|
|
8
11
|
* [Verify credentials](https://myanimelist.net/modules.php?go=api#verifycred)
|
9
12
|
|
10
13
|
## Installation
|
11
|
-
|
12
14
|
Add this line to your application's Gemfile:
|
13
15
|
|
14
16
|
```ruby
|
@@ -155,6 +157,9 @@ end
|
|
155
157
|
|
156
158
|
```
|
157
159
|
|
160
|
+
## API Documentation
|
161
|
+
[The API documentation at rubydoc.info](http://www.rubydoc.info/github/Oli4242/myanimelist_client/master)
|
162
|
+
|
158
163
|
## Contributing
|
159
164
|
Report issues at https://github.com/Oli4242/myanimelist_client.
|
160
165
|
|
@@ -162,10 +167,11 @@ If you want to make a pull request:
|
|
162
167
|
|
163
168
|
1. Fork it
|
164
169
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
165
|
-
3. Write and
|
166
|
-
4.
|
167
|
-
5.
|
168
|
-
6.
|
170
|
+
3. Write specs and test your code (`rake spec`)
|
171
|
+
4. Try not to offend RuboCop (`rake rubocop`)
|
172
|
+
5. Commit your changes (`git commit -am 'Add some feature'`)
|
173
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
174
|
+
7. Create new Pull Request
|
169
175
|
|
170
176
|
## Thanks
|
171
177
|
Thanks to [harveyico](https://github.com/harveyico) for his [myanimelist gem](https://github.com/harveyico/myanimelist), it helped me (I was using it before and its code kinda influenced me).
|
data/Rakefile
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require 'rubocop/rake_task'
|
5
|
+
require 'yard'
|
4
6
|
|
5
7
|
RSpec::Core::RakeTask.new(:spec)
|
6
8
|
|
7
9
|
YARD::Rake::YardocTask.new
|
8
10
|
|
9
|
-
|
11
|
+
RuboCop::RakeTask.new(:rubocop)
|
12
|
+
|
13
|
+
task default: :spec
|
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'myanimelist_client'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "myanimelist_client"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start
|
data/lib/myanimelist_client.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# This is the main class. It represents a client that can consume the {https://myanimelist.net/modules.php?go=api MyAnimeList.net API}.
|
2
3
|
#
|
3
4
|
# It allows to search for anime and manga titles as well as verify your username / password.
|
@@ -52,17 +53,15 @@ class MyanimelistClient
|
|
52
53
|
# @return [UserResponse] The API response or the error message nicely wraped in an object.
|
53
54
|
#
|
54
55
|
def verify_credentials
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
UserResponse.new e.response.body
|
65
|
-
end
|
56
|
+
response = RestClient::Request.execute(
|
57
|
+
method: :get,
|
58
|
+
url: 'https://myanimelist.net/api/account/verify_credentials.xml',
|
59
|
+
user: @username,
|
60
|
+
password: @password
|
61
|
+
)
|
62
|
+
UserResponse.new response.body
|
63
|
+
rescue RestClient::ExceptionWithResponse => e
|
64
|
+
UserResponse.new e.response.body
|
66
65
|
end
|
67
66
|
|
68
67
|
# Allows to search anime titles.
|
@@ -71,18 +70,7 @@ class MyanimelistClient
|
|
71
70
|
# @return [SearchResponse] The API response or the error message nicely wraped in an object.
|
72
71
|
#
|
73
72
|
def search_anime query
|
74
|
-
|
75
|
-
escaped_query = CGI::escape query
|
76
|
-
response = RestClient::Request.execute(
|
77
|
-
method: :get,
|
78
|
-
url: "https://myanimelist.net/api/anime/search.xml?q=#{escaped_query}",
|
79
|
-
user: @username,
|
80
|
-
password: @password
|
81
|
-
)
|
82
|
-
SearchResponse.new response.body
|
83
|
-
rescue RestClient::ExceptionWithResponse => e
|
84
|
-
SearchResponse.new e.response.body, :error
|
85
|
-
end
|
73
|
+
search 'anime', query
|
86
74
|
end
|
87
75
|
|
88
76
|
# Allows to search manga titles.
|
@@ -91,17 +79,31 @@ class MyanimelistClient
|
|
91
79
|
# @return [SearchResponse] The API response or the error message nicely wraped in an object.
|
92
80
|
#
|
93
81
|
def search_manga query
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
82
|
+
search 'manga', query
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
# Search a manga or an anime depending on the provided type
|
88
|
+
# @param [String] type The search type (+'anime'+ or +'manga'+).
|
89
|
+
# @param [String] query The search query.
|
90
|
+
# @return [SearchResponse] The API response or the error message nicely wraped in an object.
|
91
|
+
#
|
92
|
+
def search type, query
|
93
|
+
if type != 'anime' && type != 'manga'
|
94
|
+
raise 'Invalid search type: must be anime or manga'
|
105
95
|
end
|
96
|
+
escaped_query = CGI::escape query
|
97
|
+
response = RestClient::Request.execute(
|
98
|
+
method: :get,
|
99
|
+
url: "https://myanimelist.net/api/#{type}/search.xml?q=#{escaped_query}",
|
100
|
+
user: @username,
|
101
|
+
password: @password
|
102
|
+
)
|
103
|
+
SearchResponse.new response.body
|
104
|
+
rescue RestClient::ExceptionWithResponse => e
|
105
|
+
SearchResponse.new e.response.body, :error
|
106
|
+
rescue RuntimeError => e
|
107
|
+
SearchResponse.new e.message, :error
|
106
108
|
end
|
107
109
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# This class is used to reprensent an entry within a {SearchResponse}. It can describe either an anime or a manga.
|
2
3
|
#
|
3
4
|
# @example
|
@@ -51,7 +52,6 @@
|
|
51
52
|
# @attr [String, nil] image Returns the image's URL.
|
52
53
|
#
|
53
54
|
class MyanimelistClient::SearchEntry
|
54
|
-
|
55
55
|
# The list of attributes defining the entry for internal usage.
|
56
56
|
ATTRIBUTES = %w(
|
57
57
|
id
|
@@ -83,7 +83,7 @@ class MyanimelistClient::SearchEntry
|
|
83
83
|
# Creates a hash representing the entry.
|
84
84
|
# @return [Hash]
|
85
85
|
def to_h
|
86
|
-
values = ATTRIBUTES.map{|attribute| send attribute }
|
86
|
+
values = ATTRIBUTES.map{ |attribute| send attribute }
|
87
87
|
Hash[ATTRIBUTES.zip values]
|
88
88
|
end
|
89
89
|
|
@@ -99,12 +99,12 @@ class MyanimelistClient::SearchEntry
|
|
99
99
|
|
100
100
|
# Returns +true+ when the entry describes an anime.
|
101
101
|
def anime?
|
102
|
-
|
102
|
+
@episodes.to_i > 0
|
103
103
|
end
|
104
104
|
|
105
105
|
# Returns +true+ when the entry describes a manga.
|
106
106
|
def manga?
|
107
|
-
|
107
|
+
@chapters.to_i > 0 || @volumes.to_i > 0
|
108
108
|
end
|
109
109
|
|
110
110
|
# Returns +true+ when the anime is not yet aired / when the manga is not yet published.
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# This class represents a response to a search request. It is returned by {#search_anime} and {#search_manga}.
|
2
3
|
#
|
3
4
|
# +SearchResponse+ is responsible for parsing and wraping the XML response from the myanimelist API (or the error message).
|
@@ -96,7 +97,7 @@ class MyanimelistClient::SearchResponse
|
|
96
97
|
@entries.size
|
97
98
|
end
|
98
99
|
|
99
|
-
|
100
|
+
alias size length
|
100
101
|
|
101
102
|
# Is it empty?
|
102
103
|
def empty?
|
data/myanimelist_client.gemspec
CHANGED
@@ -1,42 +1,43 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'myanimelist_client/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'myanimelist_client'
|
8
9
|
spec.version = MyanimelistClient::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
10
|
+
spec.authors = ['Oli4242']
|
11
|
+
spec.email = ['Oli4242@users.noreply.github.com']
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
-
|
14
|
-
spec.
|
15
|
-
spec.license = "MIT"
|
13
|
+
spec.summary = 'A client for the MyAnimeList.net API'
|
14
|
+
spec.homepage = 'https://github.com/Oli4242/myanimelist_client'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
18
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
19
|
if spec.respond_to?(:metadata)
|
20
20
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
21
|
else
|
22
|
-
raise
|
23
|
-
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
23
|
+
'public gem pushes.'
|
24
24
|
end
|
25
25
|
|
26
26
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
27
|
f.match(%r{^(test|spec|features)/})
|
28
28
|
end
|
29
|
-
spec.bindir =
|
29
|
+
spec.bindir = 'exe'
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = [
|
31
|
+
spec.require_paths = ['lib']
|
32
32
|
|
33
33
|
spec.required_ruby_version = '>= 2.3'
|
34
34
|
|
35
|
-
spec.add_development_dependency
|
36
|
-
spec.add_development_dependency
|
37
|
-
spec.add_development_dependency
|
38
|
-
spec.add_development_dependency
|
35
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
36
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
39
|
+
spec.add_development_dependency 'rubocop', '~> 0.45'
|
39
40
|
|
40
|
-
spec.add_dependency
|
41
|
-
spec.add_dependency
|
41
|
+
spec.add_dependency 'rest-client', '~> 2.0'
|
42
|
+
spec.add_dependency 'nokogiri', '~> 1.6'
|
42
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myanimelist_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oli4242
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.45'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.45'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rest-client
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,6 +117,8 @@ extra_rdoc_files: []
|
|
103
117
|
files:
|
104
118
|
- ".gitignore"
|
105
119
|
- ".rspec"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- ".rubocop_todo.yml"
|
106
122
|
- ".travis.yml"
|
107
123
|
- ".yardopts"
|
108
124
|
- Gemfile
|