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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 322a8bcf59174eb6fc400792ec2d5217d034655f
4
- data.tar.gz: f93f47d5ff102dca9d61b94bc5838d7eab2dd083
3
+ metadata.gz: 1fa4b21a58ead4a3db317a408fa16cd4c9458b8b
4
+ data.tar.gz: faa3237727a3e6e76f621a37a3e0355c6f193a22
5
5
  SHA512:
6
- metadata.gz: 516a2cfacb909d01e1cdc2f3e92a1e79b519ea075e8f42e200fb10107cd8c9c0f9747142a9dec3eac8b3d3b6cd6ee70d5cf8ae88d99356df570f4a1da3ccc972
7
- data.tar.gz: a49ba46023cc1d23b66e85e468bc7fef4b6a7518dcd46c15dfbaedfccfd9760bd8e5f9fe7848954365a156aa58ab29f7e3b770331a83b8aa7d99969c3d582960
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  source 'https://rubygems.org'
2
3
 
3
4
  # Specify your gem's dependencies in myanimelist_client.gemspec
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # MyAnimeList Client
2
+ [![Gem Version](https://badge.fury.io/rb/myanimelist_client.svg)](https://badge.fury.io/rb/myanimelist_client)
3
+ [![Code Climate](https://codeclimate.com/github/Oli4242/myanimelist_client/badges/gpa.svg)](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 run the specs before you commit (`rake spec`)
166
- 4. Commit your changes (`git commit -am 'Add some feature'`)
167
- 5. Push to the branch (`git push origin my-new-feature`)
168
- 6. Create new Pull Request
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
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
- require "yard"
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
- task :default => :spec
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 "bundler/setup"
4
- require "myanimelist_client"
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 "irb"
14
+ require 'irb'
14
15
  IRB.start
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rest-client'
2
3
  require 'nokogiri'
3
4
 
@@ -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
- begin
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
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
- begin
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
- begin
95
- escaped_query = CGI::escape query
96
- response = RestClient::Request.execute(
97
- method: :get,
98
- url: "https://myanimelist.net/api/manga/search.xml?q=#{escaped_query}",
99
- user: @username,
100
- password: @password
101
- )
102
- SearchResponse.new response.body
103
- rescue RestClient::ExceptionWithResponse => e
104
- SearchResponse.new e.response.body, :error
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
- !!@episodes
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
- !!(@chapters && @volumes)
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
- alias_method :size, :length
100
+ alias size length
100
101
 
101
102
  # Is it empty?
102
103
  def empty?
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # This class represents a User. It is returned by {#verify_credentials}.
2
3
  #
3
4
  # +UserResponse+ is responsible for parsing and wraping the XML (or any error message) from the API.
@@ -1,4 +1,5 @@
1
+ # frozen_string_literal: true
1
2
  class MyanimelistClient
2
3
  # Versioning.
3
- VERSION = "0.1.0"
4
+ VERSION = '0.1.1'
4
5
  end
@@ -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 = "myanimelist_client"
8
+ spec.name = 'myanimelist_client'
8
9
  spec.version = MyanimelistClient::VERSION
9
- spec.authors = ["Oli4242"]
10
- spec.email = ["Oli4242@users.noreply.github.com"]
10
+ spec.authors = ['Oli4242']
11
+ spec.email = ['Oli4242@users.noreply.github.com']
11
12
 
12
- spec.summary = %q{A client for the MyAnimeList.net API}
13
- # spec.description = %q{TODO: Write a longer description or delete this line.}
14
- spec.homepage = "https://github.com/Oli4242/myanimelist_client"
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 "RubyGems 2.0 or newer is required to protect against " \
23
- "public gem pushes."
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 = "exe"
29
+ spec.bindir = 'exe'
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
31
+ spec.require_paths = ['lib']
32
32
 
33
33
  spec.required_ruby_version = '>= 2.3'
34
34
 
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"
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 "rest-client", "~> 2.0"
41
- spec.add_dependency "nokogiri", "~> 1.6"
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.0
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