scryfall_rb 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 01e384df2d2e8cdc58079f01f3d20106db0482effa52d0430b13dc19cd010849
4
+ data.tar.gz: 169e9a3975f5cedf55417458f73ad1f91d42b09e2e8008f49e54f9bb07dd0a3e
5
+ SHA512:
6
+ metadata.gz: b8f9086ad6e7d6308ee7c60fd189c02a4805c3542b50f90a9b16248254025e0050be8f5fa4d8988dfadff60ae005428d77fbb4b0a9b3f3abaf9067d295c8e892
7
+ data.tar.gz: 74561f8868c0326a4de5cc0cf926e226b0bb7f31dc1f0e972d411c810e7df26d4057ca06b3208bc78d7f984ecda5a7464866393cd61a4ad3a82d86847bd877d5
@@ -0,0 +1,120 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+
53
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
54
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
55
+
56
+ # User-specific stuff
57
+ .idea/**/workspace.xml
58
+ .idea/**/tasks.xml
59
+ .idea/**/usage.statistics.xml
60
+ .idea/**/dictionaries
61
+ .idea/**/shelf
62
+
63
+ # Generated files
64
+ .idea/**/contentModel.xml
65
+
66
+ # Sensitive or high-churn files
67
+ .idea/**/dataSources/
68
+ .idea/**/dataSources.ids
69
+ .idea/**/dataSources.local.xml
70
+ .idea/**/sqlDataSources.xml
71
+ .idea/**/dynamic.xml
72
+ .idea/**/uiDesigner.xml
73
+ .idea/**/dbnavigator.xml
74
+
75
+ # Gradle
76
+ .idea/**/gradle.xml
77
+ .idea/**/libraries
78
+
79
+ # Gradle and Maven with auto-import
80
+ # When using Gradle or Maven with auto-import, you should exclude module files,
81
+ # since they will be recreated, and may cause churn. Uncomment if using
82
+ # auto-import.
83
+ # .idea/modules.xml
84
+ # .idea/*.iml
85
+ # .idea/modules
86
+ # *.iml
87
+ # *.ipr
88
+
89
+ # CMake
90
+ cmake-build-*/
91
+
92
+ # Mongo Explorer plugin
93
+ .idea/**/mongoSettings.xml
94
+
95
+ # File-based project format
96
+ *.iws
97
+
98
+ # IntelliJ
99
+ out/
100
+
101
+ # mpeltonen/sbt-idea plugin
102
+ .idea_modules/
103
+
104
+ # JIRA plugin
105
+ atlassian-ide-plugin.xml
106
+
107
+ # Cursive Clojure plugin
108
+ .idea/replstate.xml
109
+
110
+ # Crashlytics plugin (for Android Studio and IntelliJ)
111
+ com_crashlytics_export_strings.xml
112
+ crashlytics.properties
113
+ crashlytics-build.properties
114
+ fabric.properties
115
+
116
+ # Editor-based Rest Client
117
+ .idea/httpRequests
118
+
119
+ # Android studio 3.1+ serialized cache file
120
+ .idea/caches/build_file_checksums.ser
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at walker@walkergriggs.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in scryfall.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Walker Griggs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,71 @@
1
+ <img alt="# scryfall_rb" src="./assets/scryfall_rb.png" width="50%">
2
+
3
+ scryfall_rb is an open source Ruby client library for [Scryfall's](https://scryfall.com/) [API](https://scryfall.com/docs/api)
4
+
5
+ Features
6
+ --------
7
+
8
+ * Card lookup with Scryfall's fulltext query.
9
+ * Full catalog support for cards, artists, and types
10
+ * Set details by name (set code) or id
11
+ * Extensible error handling with Scryfall specific details
12
+
13
+ Future Features
14
+ ---------------
15
+ * Card image querying with options for downloading to local filesystem.
16
+ * `.next()` for lists with a none-null `has-next` value.
17
+ * Improved support for fulltext queries, including argument parsing. Currently, oracle text must be split by whitespace (ie. `"oracle:draw oracle:a oracle:card" => "oracle%3Adraw%20oracle%3Aa%20oracle%3Acard"`. That process can be further simplified.
18
+
19
+ Stretch Features
20
+ ----------------
21
+ * OAuth for 3rd party applications. Currently this feature is in a closed beta and registration is closed to the general public. This feature will be tackles once OAuth support goes GA
22
+
23
+ All class/method names follow Scryfall's own naming convention, so their [API documenation](https://scryfall.com/docs/api) is the base place to look if you have any questions.
24
+
25
+ Examples
26
+ --------
27
+
28
+ All `card` fields returned by Scryfall are packed into the `Scryfall::Card` object (including all image URI's for download).
29
+ ```
30
+ card = Scryfall::Card.random
31
+
32
+ card.class
33
+ => Scryfall::Card
34
+
35
+ card.inspect
36
+ => "#<Scryfall::Card:0x00005624429b77f8 @attributes=#<OpenStruct object=\"card\", id=\"442b8c31-f346-4984-9159-2dce6a7485ac\", oracle_id=\"d0f06250-25a5-4003-8f3a-6d85ef32ea10\", name=\"Keening Stone\", lang=\"en\", released_at=\"2016-11-11\", mana_cost=\"{6}\", cmc=6.0, type_line=\"Artifact\", oracle_text=\"{5}, {T}: Target player puts the top X cards of their library...
37
+
38
+ ```
39
+
40
+ Full text queries are done in plain text -- no need to [properly encoding](https://en.wikipedia.org/wiki/Percent-encoding) the query strings. For large query results, pagination is supported. Users are left to request 'next_page' values as needed.
41
+
42
+ ```
43
+ cards = Scryfall::Card.search("type:sorcery color:U")
44
+
45
+ cards.class
46
+ => Scryfall::List
47
+
48
+ cards.total_cards
49
+ => 422
50
+
51
+ cards.next_page
52
+ => "https://api.scryfall.com/cards/search?format=json&include_extras=false&include_multilingual=false&order=name&page=2&q=type%3Asorcery+color%3Au&unique=cards"
53
+ ```
54
+
55
+
56
+ License
57
+ -------
58
+ The scryfall_rb client is available under the terms of the MIT License.
59
+
60
+ Use of Scryfall/WoTC Data
61
+ --------------------
62
+
63
+ As per [Scryfall's own documentation](https://scryfall.com/docs/api), Scryfall provides their card data and image database free of charge for the primary purpose of creating additional Magic software, performing research, or creating community content (such as videos, set reviews, etc) about Magic and related products as part of the Wizards of the Coast Fan Content Policy,.
64
+
65
+ When using Scryfall data, you must adhere to the following guidelines:
66
+
67
+ * You may not use Scryfall logos or use the Scryfall name in a way that implies Scryfall has endorsed you, your work, or your product.
68
+ * You may not require anyone to make payments, take surveys, agree to subscriptions, rate your content, or create accounts in exchange for access to Scryfall data.
69
+ * You may not use Scryfall data to create new games, or to imply the information and images are from any other game besides Magic: The Gathering.
70
+
71
+ This software is not produced, endorsed, or supported by Wizards of the Coast or Scryfall.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
Binary file
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "scryfall"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ class Request
2
+ attr_accessor :params, :headers, :body
3
+
4
+ def initialize(params, headers=nil, body=nil)
5
+ @params = params
6
+ @headers = headers
7
+ @body = body
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ require "delegate"
2
+ require "httparty"
3
+
4
+ require "request/request"
5
+ require "scryfall/version"
6
+ require "scryfall/configuration"
7
+ require "scryfall/errors"
8
+ require "scryfall/client"
9
+ require "scryfall/connection"
10
+ require "scryfall/card"
11
+ require "scryfall/catalog"
12
+ require "scryfall/set"
13
+ require "scryfall/list"
14
+
15
+ module Scryfall
16
+ class << self
17
+ attr_accessor :configuration
18
+ end
19
+
20
+ def self.configuration
21
+ @configuration ||= Configuration.new
22
+ end
23
+
24
+ def self.configure
25
+ yield(configuration)
26
+ end
27
+ end
@@ -0,0 +1,145 @@
1
+ module Scryfall
2
+
3
+ class Card < Client
4
+
5
+ class << self
6
+
7
+ # Returns a List contained Cards found using a fulltext search string. This string supports the same fulltext
8
+ # search system that the main site uses. (https://scryfall.com/docs/syntax)
9
+ # https://scryfall.com/docs/api/cards/search
10
+ #
11
+ # @param q [String] A fulltext search query. Make sure that your parameter is properly encoded.
12
+ # @param unique [String] Specifies if Scryfall should remove "duplicate" results in your query. (cards, art
13
+ # prints)
14
+ # @param order [String] The method to sort returned cards. (name, set, released, rarity, color, usd, tix, eur,
15
+ # cmc, power, toughness, edhrec, artist)
16
+ # @param dir [String] The direction to sort cards. (auto, asc, desc)
17
+ # @param include_extras [Boolean] If true, extra cards (tokens, planes, etc.) will be included. Equivalent to
18
+ # adding include:extras to the fulltext search. Defaults to false.
19
+ # @param include_multilingual [Boolean] If true, cards in every language supported by Scryfall will be included.
20
+ # @param include_variations [Boolean] If true, rare care variations will be included. (Hairy Runesword, etc)
21
+ # @param page [Integer] The apge number to return
22
+ # @param format [String] The data format to return (json or csv)
23
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
24
+ def search(q, unique: "cards", order: "name", dir: "auto", include_extras: false, include_multilingual: false, include_variations: false, page: 1, format: "json", pretty: false)
25
+ params = {
26
+ q: q,
27
+ unique: unique,
28
+ order: order,
29
+ dir: dir,
30
+ include_extras: include_extras,
31
+ include_multilingual: include_multilingual,
32
+ include_variations: include_variations,
33
+ page: page,
34
+ format: format,
35
+ pretty: pretty
36
+ }
37
+
38
+ req = Request.new(params = params,
39
+ headers = nil,
40
+ body = nil)
41
+
42
+ Scryfall::Search.get("/cards/search", self, req)
43
+ end
44
+
45
+ # Returns a Card based on a name search string.
46
+ # https://scryfall.com/docs/api/cards/named
47
+ #
48
+ # @param name [String] Name of the card to retrieve
49
+ # @param mode [String] The level of search specificity ('exact' or 'fuzzy')
50
+ # @param set [String] A set code to limit the search to one set.
51
+ # @param format [String] The data format to return (json, text, or image)
52
+ # @param face [String] If using the image format and this parameter has the value 'back', the back of the card
53
+ # will be returned. Will return a 404 if this card has no back face.
54
+ # @param version [String] The image version to return when using the 'image' format (small, normal, large, png,
55
+ # art_crop, or border_crop)
56
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
57
+ def named(name, mode: "exact", set: nil, format: "json", face: nil, version: "large", pretty: false)
58
+ params = {
59
+ mode => name,
60
+ set: set,
61
+ format: format,
62
+ face: face,
63
+ version: version,
64
+ pretty: pretty
65
+ }
66
+
67
+ req = Request.new(params = params,
68
+ headers = nil,
69
+ body = nil)
70
+
71
+ Scryfall::Card.new JSON.parse(connection.get("/cards/named", req).body)
72
+ end
73
+
74
+ # Returns a Catalog object container up to 20 full English card names that could be auto-completions of the given
75
+ # string parameter
76
+ # https://scryfall.com/docs/api/cards/autocomplete
77
+ #
78
+ # @param q [String] The string to autocomplete
79
+ # @param format [String] The data format to return. This method only supports json.
80
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
81
+ def autocomplete(q, format: "json", pretty: false)
82
+ req = Request.new(
83
+ params = {q: q},
84
+ headers = nil,
85
+ body = nil)
86
+
87
+ Scryfall::Catalog.new JSON.parse(connection.get("/cards/autocomplete", req).body)
88
+ end
89
+
90
+ # Returns a single, random Card object.
91
+ # https://scryfall.com/docs/api/cards/random
92
+ #
93
+ # @param q [String] An optional fulltext search query to filter the pool of random cards. Make sure that
94
+ # your parameter is properly encoded (https://en.wikipedia.org/wiki/Percent-encoding)
95
+ # @param format [String] The data format to return (json, text, or image)
96
+ # @param face [String] If using the image format and this parameter has the value 'back', the back of the card
97
+ # will be returned. Will return a 404 if this card has no back face.
98
+ # @param version [String] The image version to return when using the 'image' format (small, normal, large, png,
99
+ # art_crop, or border_crop)
100
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code. # @param face [String]
101
+ def random(q: nil, format: "json", face: nil, version: "large", pretty: false)
102
+ params = {
103
+ q: q,
104
+ format: format,
105
+ face: face,
106
+ version: version,
107
+ pretty: pretty
108
+ }
109
+
110
+ req = Request.new(params = params,
111
+ headers = nil,
112
+ body = nil)
113
+
114
+ Scryfall::Card.new JSON.parse(connection.get("/cards/random", req).body)
115
+ end
116
+
117
+ # Accepts a JSON array of card identifiers, and returns a List object with the collection of requested cards.
118
+ # A maximum of 75 card references may be submitted per request.
119
+ # https://scryfall.com/docs/api/cards/collection
120
+ #
121
+ # @param identifiers [Array] An array of JSON objects, each one a card identifier.
122
+ # @param pretty [Boolean] If true, the returend JSON will be prettified. Avoid using for production code.
123
+ def collection(identifiers, pretty: false)
124
+ req = Request.new(params = nil,
125
+ headers = {'Content-Type' => 'application/json'},
126
+ body = identifiers)
127
+
128
+ Scryfall::Search.post("/cards/collection", self, req)
129
+ end
130
+
131
+ # Returns a single card with the given Scryfall ID.
132
+ # https://scryfall.com/docs/api/cards/id
133
+ #
134
+ # @param id [String] ID of the card to retrieve
135
+ # @return [Scryfall::Card] the card
136
+ def id(id)
137
+ req = Request.new(params = nil,
138
+ headers = nil,
139
+ body = nil)
140
+
141
+ Scryfall::Card.new JSON.parse(connection.get("/cards/#{id}", req).body)
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,146 @@
1
+ module Scryfall
2
+ class Catalog < Client
3
+
4
+ attr_reader :uri, :total_values, :data
5
+
6
+ def initialize(contents)
7
+ @uri = contents["uri"]
8
+ @total_values = contents["total_values"]
9
+ @data = contents["data"]
10
+ end
11
+
12
+ class << self
13
+
14
+ # Returns a Catalog of all nontoken English card names in Scryfall's database.V
15
+ # https://scryfall.com/docs/api/catalogs/card-names
16
+ #
17
+ # @param format [String] The data format to return. This method only supports json.
18
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
19
+ def card_names(format: "json", pretty: false)
20
+ request_catalogue("/catalog/card-names", format, pretty)
21
+ end
22
+
23
+ # Returns a Catalog of all canonical artist names in Scryfall's database.
24
+ # https://scryfall.com/docs/api/catalogs/artist-names
25
+ #
26
+ # @param format [String] The data format to return. This method only supports json.
27
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
28
+ def artist_names(format: "json", pretty: false)
29
+ request_catalogue("/catalog/artist-names", format, pretty)
30
+ end
31
+
32
+ # Returns a Catalog of all English words, of length 2 or more, that could appear in a card name.
33
+ # https://scryfall.com/docs/api/catalogs/word-bank
34
+ #
35
+ # @param format [String] The data format to return. This method only supports json.
36
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
37
+ def word_bank(format: "json", pretty: false)
38
+ request_catalogue("/catalog/word-bank", format, pretty)
39
+ end
40
+
41
+ # Returns a Catalog of all creature types in Scryfall's database.
42
+ # https://scryfall.com/docs/api/catalogs/creature-types
43
+ #
44
+ # @param format [String] The data format to return. This method only supports json.
45
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
46
+ def creature_types(format: "json", pretty: false)
47
+ request_catalogue("/catalog/creature-types", format, pretty)
48
+ end
49
+
50
+ # Returns a Catalog of all planeswalker types in Scryfall's database
51
+ # https://scryfall.com/docs/api/catalogs/planeswalker-types
52
+ #
53
+ # @param format [String] The data format to return. This method only supports json.
54
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
55
+ def planeswalker_types(format: "json", pretty: false)
56
+ request_catalogue("/catalog/planeswalker-types", format, pretty)
57
+ end
58
+
59
+ # Returns a Catalog of all land types in Scryfall's database
60
+ # https://scryfall.com/docs/api/catalogs/land-types
61
+ #
62
+ # @param format [String] The data format to return. This method only supports json.
63
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
64
+ def land_types(format: "json", pretty: false)
65
+ request_catalogue("/catalog/land-types", format, pretty)
66
+ end
67
+
68
+ # Returns a Catalog of all artifact types in Scryfall's database
69
+ # https://scryfall.com/docs/api/catalogs/artifact-types
70
+ #
71
+ # @param format [String] The data format to return. This method only supports json.
72
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
73
+ def artifact_types(format: "json", pretty: false)
74
+ request_catalogue("/catalog/artifact-types", format, pretty)
75
+ end
76
+
77
+ # Returns a Catalog of all enchantment types in Scryfall's database
78
+ # https://scryfall.com/docs/api/catalogs/enchantment-types
79
+ #
80
+ # @param format [String] The data format to return. This method only supports json.
81
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
82
+ def enchantment_types(format: "json", pretty: false)
83
+ request_catalogue("/catalog/enchantment-types", format, pretty)
84
+ end
85
+
86
+ # Returns a Catalog of all spell types in Scryfall's database
87
+ # https://scryfall.com/docs/api/catalogs/spell-types
88
+ #
89
+ # @param format [String] The data format to return. This method only supports json.
90
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
91
+ def spell_types(format: "json", pretty: false)
92
+ request_catalogue("/catalog/spell-types", format, pretty)
93
+ end
94
+
95
+ # Returns a Catalog of all possible values for a creature or vehicle's power in Scryfall's database
96
+ # https://scryfall.com/docs/api/catalogs/powers
97
+ #
98
+ # @param format [String] The data format to return. This method only supports json.
99
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
100
+ def powers(format: "json", pretty: false)
101
+ request_catalogue("/catalog/powers", format, pretty)
102
+ end
103
+
104
+ # Returns a Catalog of all possible values for a creature or vehicle's toughness in Scryfall's database
105
+ # https://scryfall.com/docs/api/catalogs/toughnesses
106
+ #
107
+ # @param format [String] The data format to return. This method only supports json.
108
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
109
+ def toughnesses(format: "json", pretty: false)
110
+ request_catalogue("/catalog/toughnesses", format, pretty)
111
+ end
112
+
113
+ # Returns a Catalog of all possible values for a planeswalker's loyalty in Scryfall's database
114
+ # https://scryfall.com/docs/api/catalogs/loyalties
115
+ #
116
+ # @param format [String] The data format to return. This method only supports json.
117
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
118
+ def loyalties(format: "json", pretty: false)
119
+ request_catalogue("/catalog/loyalties", format, pretty)
120
+ end
121
+
122
+ # Returns a Catalog of all watermarks in Scryfall's database
123
+ # https://scryfall.com/docs/api/catalogs/loyalties
124
+ #
125
+ # @param format [String] The data format to return. This method only supports json.
126
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
127
+ def watermarks(format: "json", pretty: false)
128
+ request_catalogue("/catalog/watermarks", format, pretty)
129
+ end
130
+
131
+ # Forms Request and calls connection. Used to DRY out the preceding catalog API.
132
+ #
133
+ # @param format [String] The data format to return. This method only supports json.
134
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
135
+ def request_catalogue(path, format, pretty)
136
+ req = Request.new(
137
+ params = {format: format, pretty: pretty},
138
+ headers = nil,
139
+ body = nil)
140
+
141
+ Scryfall::Catalog.new JSON.parse(connection.get(path, req).body)
142
+ end
143
+
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,34 @@
1
+ module Scryfall
2
+
3
+ class Client
4
+
5
+ def initialize(attrs = {})
6
+ @attributes = OpenStruct.new(attrs)
7
+ end
8
+
9
+ def to_h
10
+ @attributes.to_h
11
+ end
12
+
13
+ # @private
14
+ def method_missing(method, *args, &block)
15
+ attribute = @attributes.send(method, *args, &block)
16
+ attribute.is_a?(Hash) ? Client.new(attribute) : attribute
17
+ end
18
+
19
+ def connection
20
+ self.class.connection
21
+ end
22
+
23
+ class << self
24
+ def connection
25
+ @@connection ||= Connection.new
26
+ end
27
+
28
+ def connection=(conn)
29
+ @@connection = conn
30
+ end
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,8 @@
1
+ module Scryfall
2
+
3
+ class Configuration
4
+ def initialize
5
+ @logger = Logger.new(STDOUT)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,48 @@
1
+ module Scryfall
2
+
3
+ class Connection
4
+ include HTTParty
5
+
6
+ DEFAULT_VERSION = "v1"
7
+ DEFAULT_API_BASE_URI = "https://api.scryfall.com"
8
+
9
+ def initialize(version: DEFAULT_VERSION, api_base_uri: DEFAULT_API_BASE_URI)
10
+ @api_version = version
11
+ @api_base_uri = api_base_uri
12
+
13
+ Scryfall::Connection.base_uri @api_base_uri
14
+ end
15
+
16
+ def get(path, req)
17
+ request :get, path, req
18
+ end
19
+
20
+ def post(path, req)
21
+ request :post, path, req
22
+ end
23
+
24
+ def request(verb, path, req)
25
+ raise ArgumentError.new "Invalid HTTP verb #{verb}" unless [:get, :post].include?(verb)
26
+
27
+ response = begin
28
+ self.class.public_send verb, path, query: req.params, headers: req.headers, body: req.body # debug_output: $stdout
29
+ end
30
+
31
+ status = response.respond_to?(:status) ? response.status : response.code
32
+ case status
33
+ when 200..299
34
+ response
35
+ when 404
36
+ raise Scryfall::NotFoundError.new(error_details(response))
37
+ else
38
+ raise Scryfall::Error.new(error_details(response))
39
+ end
40
+
41
+ response
42
+ end
43
+
44
+ def error_details(response)
45
+ JSON.parse(response.body)["details"]
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,4 @@
1
+ module Scryfall
2
+ class Error < StandardError; end
3
+ class NotFoundError < Error; end
4
+ end
@@ -0,0 +1,35 @@
1
+ module Scryfall
2
+
3
+ class List < SimpleDelegator
4
+ attr_reader :has_more, :next_page, :total_cards, :warnings
5
+
6
+ def initialize(contents, klass)
7
+ @has_more = contents["has_more"]
8
+ @next_page = contents["next_page"]
9
+ @total_cards = contents["total_cards"]
10
+ @warnings = contents["warnings"]
11
+
12
+ data = contents["data"].map do |obj|
13
+ klass.new obj.to_hash
14
+ end
15
+
16
+ super(data)
17
+ end
18
+ end
19
+
20
+ class Search < Client
21
+
22
+ class << self
23
+
24
+ def get(url, klass, params)
25
+ data = JSON.parse(connection.get(url, params).body)
26
+ List.new(data, klass)
27
+ end
28
+
29
+ def post(url, klass, request)
30
+ data = JSON.parse(connection.post(url, request).body)
31
+ List.new(data, klass)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,52 @@
1
+ module Scryfall
2
+
3
+ class Set < Client
4
+
5
+ class << self
6
+
7
+ # Returns a List object of all Sets on Scryfall
8
+ # https://scryfall.com/docs/api/sets/all
9
+ #
10
+ # @param format [String] The data format to return. This method only supports json.
11
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
12
+ def all(format: "json", pretty: false)
13
+ req = Request.new(
14
+ params: {format: format, pretty: pretty},
15
+ headers: nil,
16
+ body: nil)
17
+
18
+ Scryfall::Search.get("/sets", self, req)
19
+ end
20
+
21
+ # Returns a Set with the given set code. The code can be either the code or the mtgo_code for the set.
22
+ # https://scryfall.com/docs/api/sets/code
23
+ #
24
+ # @param code [String] The three to five letter set code
25
+ # @param format [String] The data format to return. This method only supports json.
26
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
27
+ def code(code, format: "json", pretty: false)
28
+ req = Request.new(
29
+ params: {format: format, pretty: pretty},
30
+ headers: nil,
31
+ body: nil)
32
+
33
+ Scryfall::Set.new JSON.parse(connection.get("/sets/#{code}", req).body)
34
+ end
35
+
36
+ # Returns a Set with the given Scryfall ID.
37
+ # https://scryfall.com/docs/api/sets/id
38
+ #
39
+ # @param id [String] The Scryfall set ID
40
+ # @param format [String] The data format to return. This method only supports json.
41
+ # @param pretty [Boolean] If true, the returned JSON will be prettified. Avoid using for production code.
42
+ def id(id, format: "json", pretty: false)
43
+ req = Request.new(
44
+ params: {format: format, pretty: pretty},
45
+ headers: nil,
46
+ body: nil)
47
+
48
+ Scryfall::Set.new JSON.parse(connection.get("/sets/#{id}", req).body)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module Scryfall
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,36 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "scryfall/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "scryfall_rb"
8
+ spec.version = Scryfall::VERSION
9
+ spec.authors = ["Walker Griggs"]
10
+ spec.email = ["walker@walkergriggs.com"]
11
+
12
+ spec.summary = %q{A lightweight Ruby client for the Scryfall API.}
13
+ spec.homepage = "https://github.com/walkergriggs/scryfall_rb"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/walkergriggs/scryfall_rb"
20
+ spec.metadata["changelog_uri"] = "https://github.com/walkergriggs/scryfall_rb/CHANGELOG.md"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 2.0"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scryfall_rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Walker Griggs
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - walker@walkergriggs.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - assets/scryfall_rb.png
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/request/request.rb
74
+ - lib/scryfall.rb
75
+ - lib/scryfall/card.rb
76
+ - lib/scryfall/catalog.rb
77
+ - lib/scryfall/client.rb
78
+ - lib/scryfall/configuration.rb
79
+ - lib/scryfall/connection.rb
80
+ - lib/scryfall/errors.rb
81
+ - lib/scryfall/list.rb
82
+ - lib/scryfall/set.rb
83
+ - lib/scryfall/version.rb
84
+ - scryfall.gemspec
85
+ homepage: https://github.com/walkergriggs/scryfall_rb
86
+ licenses: []
87
+ metadata:
88
+ homepage_uri: https://github.com/walkergriggs/scryfall_rb
89
+ source_code_uri: https://github.com/walkergriggs/scryfall_rb
90
+ changelog_uri: https://github.com/walkergriggs/scryfall_rb/CHANGELOG.md
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubygems_version: 3.0.4
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: A lightweight Ruby client for the Scryfall API.
110
+ test_files: []