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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 884254b7f4df26635bb8098700b93eedfcf4a6ed69dad3f314cf7855790b6f15
4
- data.tar.gz: 5e06821cc4cf777d05736387b43300b1d5b2132ee82fea63ac8195107c6e96c6
3
+ metadata.gz: 13abae40c7e882e8875a38cbd87148cbf62beab005f92a2ff36ff4e040f0ce26
4
+ data.tar.gz: cb5d3f78f66eea16fad77f26c21383d9db85c3ad4b410454212db1601ef394ea
5
5
  SHA512:
6
- metadata.gz: a5648630434e26a56a12e67b4f251e2b60cbbfbb5c899177454587ad8e097927e7a2cdbd609737a9a02286737fe9f32764ce9842eecb8471bf94cb9461940066
7
- data.tar.gz: fdf054939ce728736ea22c942fa8a281261f92a31e4a0b8e07fdde0802cd78ccca8d8c0cc093f0bac74d3d4ad4fb3c61d31b33245212111ec3aa7106a39b0a18
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 class will have class methods for each query on the Scryfall API. The methods will reflect their path on the official Scryfall API, following the logic of `Scryfall::<HTTP METHOD>_<PATH IN SNAKE CASE>_<VARIATION>`
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
- ## Cards Named (fuzzy and exact)
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::get_cards_named_fuzzy "aust commd"
34
+ Scryfall::Cards.named_fuzzy "aust commd"
34
35
 
35
36
  # Exact
36
- Scryfall::get_cards_named_exact "Counterspell"
37
+ Scryfall::Cards.named_exact "Counterspell"
37
38
  ```
38
39
 
39
- ## Search Query
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::get_cards_search "f:standard t:land id:UW"
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::get_cards_search "f:standard t:creature", page: 2
49
+ Scryfall::Cards.search "f:standard t:creature", page: 2
49
50
  ```
50
51
 
51
- # Response
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.
@@ -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,10 @@
1
+ module Scryfall
2
+ class Base
3
+ require "scryfall/api"
4
+
5
+ protected
6
+ def self.api
7
+ @api ||= API.new
8
+ end
9
+ end
10
+ 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
@@ -0,0 +1,15 @@
1
+ require 'json'
2
+
3
+ module ErrorHandler
4
+ def self.included(clazz)
5
+ clazz.class_eval do
6
+
7
+ end
8
+ end
9
+
10
+ private
11
+
12
+ def response_error(_e)
13
+ raise Scryfall::ResponseError
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ module Scryfall
2
+ class ResponseError < StandardError
3
+ end
4
+ 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.0.8
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