scryfall 0.0.8 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -9
- data/lib/scryfall/api.rb +29 -0
- data/lib/scryfall/base.rb +10 -0
- data/lib/scryfall/cards.rb +22 -0
- data/lib/scryfall/error_handler.rb +15 -0
- data/lib/scryfall/errors.rb +4 -0
- metadata +20 -2
- data/lib/scryfall.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13abae40c7e882e8875a38cbd87148cbf62beab005f92a2ff36ff4e040f0ce26
|
4
|
+
data.tar.gz: cb5d3f78f66eea16fad77f26c21383d9db85c3ad4b410454212db1601ef394ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b90b6859fb7548b7aee1e694f401ff0f3099af8c8f8da906ea9dee3c13d55e413ed81d6aa5a80656984ecfbf71eb94d123c8c2480bff8cfda77b94e9bcab3f00
|
7
|
+
data.tar.gz: 39496f61f0327badd1a1e9f9b1eecf28191ae2f52bde95434f7b50ebe70e4c0eb9b48d031ac28a4b4acaba8478e800d6dd3a33c5ccff6da5d4827f69dcdaa722
|
data/README.md
CHANGED
@@ -20,34 +20,35 @@ bundle install
|
|
20
20
|
|
21
21
|
# Usage
|
22
22
|
|
23
|
-
The Scryfall
|
23
|
+
The Scryfall module have classes for each query on the Scryfall API. Each class will reflect a module of query.
|
24
24
|
|
25
25
|
At first, there are only a few methods available:
|
26
26
|
|
27
|
-
|
27
|
+
# Cards
|
28
|
+
### Named (fuzzy and exact)
|
28
29
|
|
29
30
|
It searches for cards named almost as the string passed (fuzzy), or with the exact name as the string passed (exact)
|
30
31
|
|
31
32
|
```ruby
|
32
33
|
# Fuzzy
|
33
|
-
Scryfall::
|
34
|
+
Scryfall::Cards.named_fuzzy "aust commd"
|
34
35
|
|
35
36
|
# Exact
|
36
|
-
Scryfall::
|
37
|
+
Scryfall::Cards.named_exact "Counterspell"
|
37
38
|
```
|
38
39
|
|
39
|
-
|
40
|
+
### Search Query
|
40
41
|
|
41
42
|
It can search a list of cards using the Scryfall syntax
|
42
43
|
|
43
44
|
```ruby
|
44
45
|
# The search will return all the cards that fits on the query parameters
|
45
|
-
Scryfall::
|
46
|
+
Scryfall::Cards.search "f:standard t:land id:UW"
|
46
47
|
|
47
48
|
# It can be passed the page of the search. Each page of data has a maximum of 175 cards
|
48
|
-
Scryfall::
|
49
|
+
Scryfall::Cards.search "f:standard t:creature", page: 2
|
49
50
|
```
|
50
51
|
|
51
|
-
#
|
52
|
+
# Responses
|
52
53
|
|
53
|
-
The default response for all calls are JSON. If a `to_struct: true` is passed as argument, the return will be a `OpenStruct` Hash object.
|
54
|
+
The default response for all calls are JSON. If a `to_struct: true` is passed as argument, the return will be a `OpenStruct` Hash object.
|
data/lib/scryfall/api.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Scryfall
|
2
|
+
class API
|
3
|
+
require 'http'
|
4
|
+
require 'ostruct'
|
5
|
+
require 'json'
|
6
|
+
require 'error_handler'
|
7
|
+
require 'resolv-replace'
|
8
|
+
|
9
|
+
def initialize(url = 'https://api.scryfall.com');
|
10
|
+
@url = url
|
11
|
+
end
|
12
|
+
|
13
|
+
def get(path = "", params = {}, **args)
|
14
|
+
res = HTTP.get(mount_uri(path), params: params)
|
15
|
+
|
16
|
+
if args.has_key?(:to_struct) && args[:to_struct] == true
|
17
|
+
JSON.parse res, object_class: OpenStruct
|
18
|
+
else
|
19
|
+
JSON.parse res
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def mount_uri(path)
|
26
|
+
@url + path
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Scryfall
|
2
|
+
require 'scryfall/base'
|
3
|
+
class Cards < Base
|
4
|
+
def self.named_fuzzy(cardname, **args)
|
5
|
+
api.get '/cards/named', { fuzzy: cardname }, args
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.named_exact(cardname, **args)
|
9
|
+
api.get '/cards/named', { exact: cardname }, args
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.search(query, **args)
|
13
|
+
params = { q: query.encode }
|
14
|
+
|
15
|
+
if args.has_key?(:page) && args.page >= 1
|
16
|
+
params['page'] = args.page
|
17
|
+
end
|
18
|
+
|
19
|
+
api.get '/cards/search', params, args
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scryfall
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- João Lucas
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: http
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -32,7 +46,11 @@ extra_rdoc_files:
|
|
32
46
|
- README.md
|
33
47
|
files:
|
34
48
|
- README.md
|
35
|
-
- lib/scryfall.rb
|
49
|
+
- lib/scryfall/api.rb
|
50
|
+
- lib/scryfall/base.rb
|
51
|
+
- lib/scryfall/cards.rb
|
52
|
+
- lib/scryfall/error_handler.rb
|
53
|
+
- lib/scryfall/errors.rb
|
36
54
|
homepage: https://github.com/jlcarruda/scryfall-rails
|
37
55
|
licenses:
|
38
56
|
- MIT
|
data/lib/scryfall.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
|
2
|
-
class Scryfall
|
3
|
-
require 'http'
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
@url = 'https://api.scryfall.com'
|
7
|
-
|
8
|
-
def self.mount_uri(path)
|
9
|
-
@url + path
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.get(path, params = {}, **args)
|
13
|
-
res = HTTP.get(mount_uri(path), params: params)
|
14
|
-
|
15
|
-
if args.has_key?(:to_struct) && args[:to_struct] === true
|
16
|
-
JSON.parse res, object_class: OpenStruct
|
17
|
-
else
|
18
|
-
JSON.parse res
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.get_cards_named_fuzy(cardname, **args)
|
23
|
-
get '/cards/named', { fuzzy: cardname }, args
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.get_cards_named_exact(cardname, **args)
|
27
|
-
get '/cards/named', { exact: cardname }, args
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.get_cards_search(query, **args)
|
31
|
-
params = { q: query.encode }
|
32
|
-
|
33
|
-
if args.has_key?(:page) && args.page >= 1
|
34
|
-
params['page'] = args.page
|
35
|
-
end
|
36
|
-
|
37
|
-
get '/cards/search', params, args
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|