myanimelist 0.0.6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +80 -30
- data/lib/myanimelist.rb +9 -11
- data/lib/myanimelist/anime.rb +8 -23
- data/lib/myanimelist/api.rb +63 -0
- data/lib/myanimelist/credentials.rb +4 -2
- data/lib/myanimelist/manga.rb +9 -24
- data/lib/myanimelist/serializer.rb +8 -19
- data/lib/myanimelist/version.rb +2 -2
- data/myanimelist.gemspec +5 -5
- metadata +18 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36e2394e2cc00a68cf29f2a2f415c7d18496b2e6
|
4
|
+
data.tar.gz: de27746feff083309417341a421a3d93a5cdc5e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04ccd0576989e8c6db19870d5acfc86b6c68773464886d8082d1e1d27aff5d944eaec30658c0a751cc169050f50200968ce92692272077534ad886b1d1f15930
|
7
|
+
data.tar.gz: 496e664055f874ac4ef857c7f08e211bc2cab5e3bddbb7eee3b23e35bde8526243e026ef510daf319c7a9274b4499b1815f3950473a703206e160c17a5458d46
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# MyAnimeList
|
2
|
-
|
2
|
+
A gem wrapper for http://myanimelist.net that covers all the methods available on the current API
|
3
3
|
For additional documentation, visit: http://myanimelist.net/modules.php?go=api
|
4
|
+
|
4
5
|
## Installation
|
5
6
|
|
6
7
|
Add this line to your application's Gemfile:
|
7
8
|
|
8
|
-
gem 'myanimelist', '~>
|
9
|
+
gem 'myanimelist', '~> 1.0'
|
9
10
|
|
10
11
|
And then execute:
|
11
12
|
|
@@ -16,50 +17,94 @@ Or install it yourself as:
|
|
16
17
|
$ gem install myanimelist
|
17
18
|
|
18
19
|
### Configuration
|
19
|
-
MyAnimeList API requires authentication from the actual site, so you need to sign up first
|
20
|
-
<a href="http://myanimelist.net/register.php">here</a>
|
20
|
+
MyAnimeList API requires authentication from the actual site, so you need to sign up first [here](http://myanimelist.net/register.php).
|
21
21
|
|
22
22
|
After signing up and verifying your email, you need to assign the username and password on your respective myanimelist API,
|
23
|
-
here's what you need to do,
|
23
|
+
here's what you need to do,
|
24
24
|
If you are using Rails: setup `config/initializers/myanimelist.rb`:
|
25
25
|
```ruby
|
26
26
|
MyAnimeList.configure do |config|
|
27
|
-
config.username =
|
28
|
-
config.password =
|
27
|
+
config.username = ENV['username']
|
28
|
+
config.password = ENV['password']
|
29
29
|
end
|
30
30
|
```
|
31
31
|
If you are not using rails make sure to set this up before you can start searching.
|
32
32
|
|
33
33
|
## Usage
|
34
|
-
|
35
|
-
|
36
|
-
MyAnimeList.search_anime("Anime name here.")
|
34
|
+
#### Verify Credentials
|
35
|
+
Additional step for verifying credentials from myanimelist.
|
37
36
|
```
|
38
|
-
|
39
|
-
```ruby
|
40
|
-
MyAnimeList.search_manga("Manga name here.")
|
37
|
+
MyAnimeList.verify_crendetials
|
41
38
|
```
|
42
39
|
|
43
|
-
|
40
|
+
#### Search Anime/Manga
|
41
|
+
Returns an Array of Hashes for the result.
|
42
|
+
```
|
43
|
+
# Anime
|
44
|
+
> MyAnimeList.search_anime('Fairy Tail')
|
45
|
+
> MyAnimeList::Anime.search('Fairy Tail')
|
46
|
+
|
47
|
+
# Manga
|
48
|
+
> MyAnimeList.search_manga('Fairy Tail')
|
49
|
+
> MyAnimeList::Manga.search('Fairy Tail'
|
50
|
+
```
|
44
51
|
|
45
|
-
|
52
|
+
#### Add Anime/Manga
|
53
|
+
Adds anime/manga on your list. For additional `Anime` parameters, please refer [here](https://myanimelist.net/modules.php?go=api#animevalues). For `Manga`, please refer [here](https://myanimelist.net/modules.php?go=api#mangavalues).
|
54
|
+
Just imagine that the xml value would be the key:value pair in ruby, as seen below.
|
55
|
+
```
|
56
|
+
# Anime
|
57
|
+
> MyAnimeList::Anime.add(anime_id, { episode: 1, status: 2 })
|
58
|
+
=> true
|
59
|
+
|
60
|
+
# Manga
|
61
|
+
> MyAnimeList::Manga.add(manga_id, { chapter: 1 })
|
62
|
+
=> true
|
63
|
+
```
|
64
|
+
|
65
|
+
#### Update Anime/Manga
|
66
|
+
Updates anime/manga on your list. For additional `Anime` parameters, please refer [here](https://myanimelist.net/modules.php?go=api#animevalues). For `Manga`, please refer [here](https://myanimelist.net/modules.php?go=api#mangavalues).
|
67
|
+
Just imagine that the xml value would be the key:value pair in ruby, as seen below.
|
68
|
+
```
|
69
|
+
# Anime
|
70
|
+
> MyAnimeList::Anime.update(anime_id, { episode: 1, status: 2 })
|
71
|
+
=> true
|
72
|
+
|
73
|
+
# Manga
|
74
|
+
> MyAnimeList::Manga.update(manga_id, { chapter: 1 })
|
75
|
+
=> true
|
76
|
+
```
|
77
|
+
|
78
|
+
#### Remove Anime/Manga
|
79
|
+
Remove anime/manga on your list.
|
80
|
+
```
|
81
|
+
# Anime
|
82
|
+
> MyAnimeList::Anime.remove(anime_id)
|
83
|
+
=> true
|
84
|
+
|
85
|
+
# Manga
|
86
|
+
> MyAnimeList::Manga.remove(manga_id)
|
87
|
+
=> true
|
88
|
+
```
|
89
|
+
|
90
|
+
## Example
|
46
91
|
```ruby
|
47
92
|
MyAnimeList.search_anime('Fairy Tail')
|
48
|
-
|
49
|
-
#will result to the followinghash
|
50
|
-
|
51
|
-
=> [{"id"=>"6702",
|
52
|
-
"title"=>"Fairy Tail",
|
53
|
-
"english"=>nil,
|
54
|
-
"synonyms"=>nil,
|
55
|
-
"episodes"=>"175",
|
56
|
-
"score"=>"8.57",
|
57
|
-
"type"=>"TV",
|
58
|
-
"status"=>"Finished Airing",
|
59
|
-
"start_date"=>"2009-10-12",
|
60
|
-
"end_date"=>"2013-03-30",
|
93
|
+
|
94
|
+
# will result to the followinghash
|
95
|
+
|
96
|
+
=> [{"id"=>"6702",
|
97
|
+
"title"=>"Fairy Tail",
|
98
|
+
"english"=>nil,
|
99
|
+
"synonyms"=>nil,
|
100
|
+
"episodes"=>"175",
|
101
|
+
"score"=>"8.57",
|
102
|
+
"type"=>"TV",
|
103
|
+
"status"=>"Finished Airing",
|
104
|
+
"start_date"=>"2009-10-12",
|
105
|
+
"end_date"=>"2013-03-30",
|
61
106
|
"synopsis"=>
|
62
|
-
"Set in an imaginary world, the Earth Land, there exists a Mage Guild called Fairy Tail...",
|
107
|
+
"Set in an imaginary world, the Earth Land, there exists a Mage Guild called Fairy Tail...",
|
63
108
|
"image"=>"http://cdn.myanimelist.net/images/anime/5/18179.jpg"}
|
64
109
|
}]
|
65
110
|
|
@@ -74,4 +119,9 @@ Simple isn't it?
|
|
74
119
|
5. Create new Pull Request
|
75
120
|
|
76
121
|
|
77
|
-
##
|
122
|
+
## Thanks
|
123
|
+
[MyAnimeList](myanimelist.net) for the API.
|
124
|
+
|
125
|
+
**myanimelist** © 2013+, Harvey Ico. Released under the [MIT](http://mit-license.org/) License.
|
126
|
+
|
127
|
+
Authored and maintained by Harvey Ico with help from contributors ([list](https://github.com/harveyico/myanimelist/contributors)).
|
data/lib/myanimelist.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'xmlsimple'
|
1
3
|
require 'myanimelist/version'
|
2
|
-
require '
|
3
|
-
require 'active_support/core_ext/hash'
|
4
|
+
require 'myanimelist/api'
|
4
5
|
require 'myanimelist/anime'
|
5
6
|
require 'myanimelist/manga'
|
6
7
|
require 'myanimelist/credentials'
|
@@ -8,21 +9,18 @@ require 'myanimelist/serializer'
|
|
8
9
|
|
9
10
|
module MyAnimeList
|
10
11
|
def self.configure(&block)
|
11
|
-
|
12
|
-
|
13
|
-
@myanimelist_username = credentials.username
|
14
|
-
@myanimelist_password = credentials.password
|
12
|
+
block.call(Credentials) if block_given?
|
13
|
+
end
|
15
14
|
|
16
|
-
|
15
|
+
def self.verify_credentials
|
16
|
+
Api.new.verify_credentials!
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.search_anime(name)
|
20
|
-
|
21
|
-
animes.search name
|
20
|
+
MyAnimeList::Anime.search(name)
|
22
21
|
end
|
23
22
|
|
24
23
|
def self.search_manga(name)
|
25
|
-
|
26
|
-
manga.search name
|
24
|
+
MyAnimeList::Manga.search(name)
|
27
25
|
end
|
28
26
|
end
|
data/lib/myanimelist/anime.rb
CHANGED
@@ -1,34 +1,19 @@
|
|
1
1
|
module MyAnimeList
|
2
2
|
class Anime
|
3
|
-
|
4
|
-
|
5
|
-
@myanimelist_username = options[:username]
|
6
|
-
@myanimelist_password = options[:password]
|
3
|
+
def self.search(name)
|
4
|
+
Api.new.search('anime', name)
|
7
5
|
end
|
8
6
|
|
9
|
-
def
|
10
|
-
|
7
|
+
def self.add(id, params = {})
|
8
|
+
Api.new.add('anime', id, params)
|
11
9
|
end
|
12
10
|
|
13
|
-
def
|
14
|
-
|
15
|
-
method: :get,
|
16
|
-
url: "https://myanimelist.net/api/anime/search.xml?q=#{CGI::escape name}",
|
17
|
-
user: @myanimelist_username,
|
18
|
-
password: @myanimelist_password,
|
19
|
-
content_type: :xml ).execute
|
20
|
-
|
21
|
-
parse_xml response
|
11
|
+
def self.update(id, params = {})
|
12
|
+
Api.new.update('anime', id, params)
|
22
13
|
end
|
23
14
|
|
24
|
-
def
|
25
|
-
|
15
|
+
def self.remove(id)
|
16
|
+
Api.new.remove('anime', id)
|
26
17
|
end
|
27
|
-
|
28
|
-
def serialize(data)
|
29
|
-
result = MyAnimeList::Serializer.new data, 'anime'
|
30
|
-
result.fetch
|
31
|
-
end
|
32
|
-
|
33
18
|
end
|
34
19
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module MyAnimeList
|
2
|
+
class ApiException < Exception; end
|
3
|
+
class Api
|
4
|
+
BASE_URL = 'https://myanimelist.net/api'
|
5
|
+
|
6
|
+
def search(type, name)
|
7
|
+
body = request("#{BASE_URL}/#{type}/search.xml?q=#{CGI::escape name}")
|
8
|
+
|
9
|
+
Serializer.new(body).entry
|
10
|
+
end
|
11
|
+
|
12
|
+
def add(type, id, params = {})
|
13
|
+
request("#{BASE_URL}/#{type}list/add/#{id}.xml", params) == 'Created'
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(type, id, params = {})
|
17
|
+
request("#{BASE_URL}/#{type}list/update/#{id}.xml", params) == 'Updated'
|
18
|
+
end
|
19
|
+
|
20
|
+
def remove(type, id)
|
21
|
+
request("#{BASE_URL}/#{type}list/delete/#{id}.xml") == 'Deleted'
|
22
|
+
end
|
23
|
+
|
24
|
+
def verify_credentials!
|
25
|
+
body = request("#{BASE_URL}/account/verify_credentials.xml")
|
26
|
+
|
27
|
+
Serializer.new(body).call
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def request(url, params = {})
|
33
|
+
RestClient::Request.new( build_params(url, params) ).execute do |resp|
|
34
|
+
if resp.code == 200 || resp.code == 201
|
35
|
+
resp.body
|
36
|
+
else
|
37
|
+
raise ApiException.new(resp.body)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_params(url, params)
|
43
|
+
{
|
44
|
+
method: :get,
|
45
|
+
url: url,
|
46
|
+
user: Credentials.username,
|
47
|
+
password: Credentials.password,
|
48
|
+
content_type: :xml
|
49
|
+
}.merge( headers(params) )
|
50
|
+
end
|
51
|
+
|
52
|
+
def headers(params)
|
53
|
+
return {} if params.empty?
|
54
|
+
{
|
55
|
+
headers: {
|
56
|
+
params: {
|
57
|
+
data: XmlSimple.xml_out(params, rootname: 'entry', noattr: true, noindent: true, keeproot: false)
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/myanimelist/manga.rb
CHANGED
@@ -1,34 +1,19 @@
|
|
1
1
|
module MyAnimeList
|
2
|
-
class Manga
|
3
|
-
|
4
|
-
|
5
|
-
@myanimelist_username = options[:username]
|
6
|
-
@myanimelist_password = options[:password]
|
2
|
+
class Manga < Api
|
3
|
+
def self.search(name)
|
4
|
+
Api.new.search('manga', name)
|
7
5
|
end
|
8
6
|
|
9
|
-
def
|
10
|
-
|
7
|
+
def self.add(id, params = {})
|
8
|
+
Api.new.add('manga', id, params)
|
11
9
|
end
|
12
10
|
|
13
|
-
def
|
14
|
-
|
15
|
-
method: :get,
|
16
|
-
url: "https://myanimelist.net/api/manga/search.xml?q=#{CGI::escape name}",
|
17
|
-
user: @myanimelist_username,
|
18
|
-
password: @myanimelist_password,
|
19
|
-
content_type: :xml ).execute
|
20
|
-
|
21
|
-
parse_xml response
|
11
|
+
def self.update(id, params = {})
|
12
|
+
Api.new.update('manga', id, params)
|
22
13
|
end
|
23
14
|
|
24
|
-
def
|
25
|
-
|
15
|
+
def self.remove(id)
|
16
|
+
Api.new.remove('manga', id)
|
26
17
|
end
|
27
|
-
|
28
|
-
def serialize(data)
|
29
|
-
result = MyAnimeList::Serializer.new data, 'manga'
|
30
|
-
result.fetch
|
31
|
-
end
|
32
|
-
|
33
18
|
end
|
34
19
|
end
|
@@ -1,29 +1,18 @@
|
|
1
1
|
module MyAnimeList
|
2
2
|
class Serializer
|
3
|
-
|
4
|
-
@type = type
|
5
|
-
@animes = data || []
|
6
|
-
end
|
3
|
+
attr_accessor :response
|
7
4
|
|
8
|
-
def
|
9
|
-
|
5
|
+
def initialize(resp)
|
6
|
+
@response = resp
|
10
7
|
end
|
11
8
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
collection = []
|
16
|
-
data = @animes[@type]['entry']
|
17
|
-
if is_array? data
|
18
|
-
collection += data
|
19
|
-
else
|
20
|
-
collection << data
|
21
|
-
end
|
9
|
+
def entry
|
10
|
+
hash = XmlSimple.xml_in(response, force_array: false)
|
11
|
+
hash['entry']
|
22
12
|
end
|
23
13
|
|
24
|
-
def
|
25
|
-
|
14
|
+
def call
|
15
|
+
XmlSimple.xml_in(response, force_array: false)
|
26
16
|
end
|
27
|
-
|
28
17
|
end
|
29
18
|
end
|
data/lib/myanimelist/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = '0.0
|
1
|
+
module MyAnimeList
|
2
|
+
VERSION = '1.0.0'
|
3
3
|
end
|
data/myanimelist.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'myanimelist/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'myanimelist'
|
8
|
-
spec.version =
|
8
|
+
spec.version = MyAnimeList::VERSION
|
9
9
|
spec.authors = ['Harvey Ico']
|
10
10
|
spec.email = ['godstrikerharvey@gmail.com']
|
11
11
|
spec.description = %q{The API for MyAnimeList.net}
|
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency 'bundler', '
|
22
|
-
spec.add_development_dependency 'rake'
|
23
|
-
spec.add_dependency 'rest-client'
|
24
|
-
spec.add_dependency '
|
21
|
+
spec.add_development_dependency 'bundler', '1.3'
|
22
|
+
spec.add_development_dependency 'rake', '12.0.0'
|
23
|
+
spec.add_dependency 'rest-client', '2.0.2'
|
24
|
+
spec.add_dependency 'xml-simple', '1.1.5'
|
25
25
|
end
|
metadata
CHANGED
@@ -1,71 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myanimelist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harvey Ico
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.0.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rest-client
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 2.0.2
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 2.0.2
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: xml-simple
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 1.1.5
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 1.1.5
|
69
69
|
description: The API for MyAnimeList.net
|
70
70
|
email:
|
71
71
|
- godstrikerharvey@gmail.com
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- Rakefile
|
81
81
|
- lib/myanimelist.rb
|
82
82
|
- lib/myanimelist/anime.rb
|
83
|
+
- lib/myanimelist/api.rb
|
83
84
|
- lib/myanimelist/credentials.rb
|
84
85
|
- lib/myanimelist/manga.rb
|
85
86
|
- lib/myanimelist/serializer.rb
|