mtg-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f2d3a1bd60084403db27e2e874982a957460c22
4
+ data.tar.gz: 13d6313a17b9cec8d5f1dd2c547a6bbe8ecb7fb9
5
+ SHA512:
6
+ metadata.gz: ea5a22404c45814428dfd73f8f389568febea198cddb41c87fc72cca2924636aca782175ab307e0935cea0621868285573da96f2999e949766c3b263fd2e5a7c
7
+ data.tar.gz: 6370dfe965e9a7721b4f7834730d8c4b2937c3861eb61f0d63c05e491962780d833dfa350f5eb0d9e0b132123b27d9c9768706a8f9e82c1af945313fcc1a7961
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ Gemfile.lock
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ tmp
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ notifications:
6
+ email:
7
+ on_failure: always
8
+ branches:
9
+ only:
10
+ - master
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mtg-api.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Musttache
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ mtg-api
2
+ ===========
3
+
4
+ Magic: The Gathering API Ruby Client - http://mtgapi.com
5
+
6
+ Documentation: http://mtgapi.com/docs
7
+
8
+ [![Build Status](https://travis-ci.org/musttache/mtg-api.png?branch=master)](https://travis-ci.org/musttache/mtg-api)
9
+ [![Dependency Status](https://gemnasium.com/musttache/mtg-api.png)](https://gemnasium.com/musttache/mtg-api)
10
+ [![Code Climate](https://codeclimate.com/github/musttache/mtg-api.png)](https://codeclimate.com/github/musttache/mtg-api)
11
+
12
+ Contributing
13
+ -----------
14
+
15
+ 1. Fork the project.
16
+ 2. Make your feature addition or bug fix.
17
+ 3. Add tests for it. This is important so I don't break it in a future version unintentionally.
18
+ 4. Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
19
+ 5. Send me a pull request. Bonus points for topic branches.
20
+
21
+ License
22
+ -----------
23
+
24
+ The MIT License (MIT) Copyright (c) 2013 Musttache. See LICENSE for details.
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
@@ -0,0 +1,8 @@
1
+ require 'httparty'
2
+ require 'hashie'
3
+ require 'json'
4
+
5
+ require 'mtg-api/version'
6
+ require 'mtg-api/config'
7
+ require 'mtg-api/request'
8
+ require 'mtg-api/card'
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ module MTG::API
4
+ class Card
5
+ class << self
6
+ def find_by_id(id)
7
+ Request.get("/id/#{id}")
8
+ end
9
+
10
+ def find_by_text(text)
11
+ Request.get("/search/#{text}")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module MTG::API
2
+ class Config
3
+ class << self
4
+ attr_accessor :token
5
+
6
+ def configure(&block)
7
+ yield(self)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ module MTG::API
4
+ class Request
5
+ class << self
6
+ def get(path, options = {}, &block)
7
+ response = HTTParty.get(base_uri + path, request_options(options), &block)
8
+
9
+ if response.code == 200
10
+ parsed_response(response)
11
+ else
12
+ raise "#{response.code} - #{response.message}"
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def base_uri
19
+ "http://mtgapi.com/api/v1/fetch"
20
+ end
21
+
22
+ def request_options(options)
23
+ options.merge!(query: { token: Config.token })
24
+ end
25
+
26
+ def parsed_response(response)
27
+ json = JSON.parse(response.body)
28
+
29
+ if json.is_a?(Hash)
30
+ Hashie::Mash.new(json)
31
+ elsif json.is_a?(Array)
32
+ json.map { |hash| Hashie::Mash.new(hash) }
33
+ else
34
+ raise "Unknown response kind."
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ module MTG
2
+ module API
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mtg-api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'mtg-api'
8
+ spec.version = MTG::API::VERSION
9
+ spec.authors = ['Eduardo Maia']
10
+ spec.email = ['eduvimaia@gmail.com']
11
+ spec.description = %q{Magic: The Gathering Ruby Client}
12
+ spec.summary = %q{Magic: The Gathering Ruby Client}
13
+ spec.homepage = 'http://github.com/musttache/mtg-api'
14
+ spec.license = 'MIT'
15
+
16
+ spec.required_ruby_version = '>= 1.9'
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'httparty', '~> 0.12.0'
24
+ spec.add_dependency 'hashie', '~> 2.0.5'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.3'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'pry'
29
+ spec.add_development_dependency 'rspec', '~> 2.14'
30
+ spec.add_development_dependency 'vcr', '~> 2.6.0'
31
+ spec.add_development_dependency 'webmock', '1.14'
32
+ end
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://mtgapi.com/api/v1/fetch/id/0?token=valid_token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - cloudflare-nginx
17
+ Date:
18
+ - Fri, 11 Oct 2013 03:19:58 GMT
19
+ Content-Type:
20
+ - text/html; charset=UTF-8
21
+ Transfer-Encoding:
22
+ - chunked
23
+ Connection:
24
+ - keep-alive
25
+ Set-Cookie:
26
+ - __cfduid=dbd27b6a3224dace4b15ea9d662bc705e1381461597992; expires=Mon, 23-Dec-2019
27
+ 23:50:00 GMT; path=/; domain=.mtgapi.com; HttpOnly
28
+ - laravel_session=ojir5li20k7kgb21jjjel4kgb1; expires=Fri, 11-Oct-2013 05:19:58
29
+ GMT; Max-Age=7200; path=/; HttpOnly
30
+ - laravel_session=ojir5li20k7kgb21jjjel4kgb1; expires=Fri, 11-Oct-2013 05:19:58
31
+ GMT; Max-Age=7200; path=/; httponly
32
+ X-Powered-By:
33
+ - PHP/5.5.4-1+debphp.org~precise+1
34
+ Cache-Control:
35
+ - no-cache
36
+ Cf-Ray:
37
+ - bb8696b7de80322
38
+ body:
39
+ encoding: UTF-8
40
+ string: '{"Error" : "Card Does Not Exist"}'
41
+ http_version:
42
+ recorded_at: Fri, 11 Oct 2013 03:19:58 GMT
43
+ recorded_with: VCR 2.6.0
@@ -0,0 +1,41 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://mtgapi.com/api/v1/fetch/search/invalid-name?token=valid_token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 500
13
+ message: Internal Server Error
14
+ headers:
15
+ Server:
16
+ - cloudflare-nginx
17
+ Date:
18
+ - Sat, 12 Oct 2013 01:53:19 GMT
19
+ Content-Type:
20
+ - text/html; charset=UTF-8
21
+ Transfer-Encoding:
22
+ - chunked
23
+ Connection:
24
+ - keep-alive
25
+ Set-Cookie:
26
+ - __cfduid=d82429af1fb886877fd080a98e17580791381542798470; expires=Mon, 23-Dec-2019
27
+ 23:50:00 GMT; path=/; domain=.mtgapi.com; HttpOnly
28
+ - laravel_session=26oecl8u0812mf77uhepp64vg7; expires=Sat, 12-Oct-2013 03:53:18
29
+ GMT; Max-Age=7200; path=/; HttpOnly
30
+ X-Powered-By:
31
+ - PHP/5.5.4-1+debphp.org~precise+1
32
+ Cache-Control:
33
+ - no-cache
34
+ Cf-Ray:
35
+ - bc027da783f0322
36
+ body:
37
+ encoding: UTF-8
38
+ string: '{"code":"500","error":"internal server error"}'
39
+ http_version:
40
+ recorded_at: Sat, 12 Oct 2013 01:53:19 GMT
41
+ recorded_with: VCR 2.6.0
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://mtgapi.com/api/v1/fetch/id/1?token=valid_token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - cloudflare-nginx
17
+ Date:
18
+ - Fri, 11 Oct 2013 03:19:57 GMT
19
+ Content-Type:
20
+ - text/html; charset=UTF-8
21
+ Transfer-Encoding:
22
+ - chunked
23
+ Connection:
24
+ - keep-alive
25
+ Set-Cookie:
26
+ - __cfduid=d2282cabe2e0a556c3ba8fbd0ec49e1731381461597568; expires=Mon, 23-Dec-2019
27
+ 23:50:00 GMT; path=/; domain=.mtgapi.com; HttpOnly
28
+ - laravel_session=9ibsuddnknunvno6pi42bl0dp3; expires=Fri, 11-Oct-2013 05:19:57
29
+ GMT; Max-Age=7200; path=/; HttpOnly
30
+ - laravel_session=9ibsuddnknunvno6pi42bl0dp3; expires=Fri, 11-Oct-2013 05:19:57
31
+ GMT; Max-Age=7200; path=/; httponly
32
+ X-Powered-By:
33
+ - PHP/5.5.4-1+debphp.org~precise+1
34
+ Cache-Control:
35
+ - no-cache
36
+ Cf-Ray:
37
+ - bb86968cb400322
38
+ body:
39
+ encoding: UTF-8
40
+ string: '{"id":"1","name":"Ankh of Mishra","mana":["2"],"cmc":"2","type":["Artifact"],"text":["Whenever
41
+ a land enters the battlefield, Ankh of Mishra deals 2 damage to that land''s
42
+ controller."],"flavor":[],"power":"","toughness":"","loyalty":"","watermark":"","set":"Limited
43
+ Edition Alpha","rarity":"Rare","prints":[{"set":"1E","id":"1"},{"set":"2E","id":"296"},{"set":"2U","id":"598"},{"set":"3E","id":"1094"},{"set":"4E","id":"2017"},{"set":"5E","id":"3760"},{"set":"6E","id":"14771"},{"set":"MED","id":"159251"}],"number":"","artist":"Amy
44
+ Weber"}'
45
+ http_version:
46
+ recorded_at: Fri, 11 Oct 2013 03:19:57 GMT
47
+ recorded_with: VCR 2.6.0
@@ -0,0 +1,55 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://mtgapi.com/api/v1/fetch/search/tundra?token=valid_token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - cloudflare-nginx
17
+ Date:
18
+ - Sat, 12 Oct 2013 01:53:20 GMT
19
+ Content-Type:
20
+ - text/html; charset=UTF-8
21
+ Transfer-Encoding:
22
+ - chunked
23
+ Connection:
24
+ - keep-alive
25
+ Set-Cookie:
26
+ - __cfduid=d348b1977d3407d3e7331460c3df6db4b1381542799574; expires=Mon, 23-Dec-2019
27
+ 23:50:00 GMT; path=/; domain=.mtgapi.com; HttpOnly
28
+ - laravel_session=l3l4kei3m8t6i8c8rlve2skao2; expires=Sat, 12-Oct-2013 03:53:19
29
+ GMT; Max-Age=7200; path=/; HttpOnly
30
+ - laravel_session=l3l4kei3m8t6i8c8rlve2skao2; expires=Sat, 12-Oct-2013 03:53:20
31
+ GMT; Max-Age=7200; path=/; httponly
32
+ X-Powered-By:
33
+ - PHP/5.5.4-1+debphp.org~precise+1
34
+ Cache-Control:
35
+ - no-cache
36
+ Cf-Ray:
37
+ - bc027e155080322
38
+ body:
39
+ encoding: UTF-8
40
+ string: '[{"id":"202424","name":"Tundra","mana":"","cmc":"","type":["Land ","Plains
41
+ Island"],"text":[],"flavor":[],"power":"","toughness":"","loyalty":"","watermark":"","set":"Masters
42
+ Edition IV","rarity":"Rare","prints":[{"set":"1E","id":"286"},{"set":"2E","id":"583"},{"set":"2U","id":"885"},{"set":"3E","id":"1383"},{"set":"ME2","id":"184751"},{"set":"ME4","id":"202424"}],"number":"255","artist":"Jesper
43
+ Myrfors"},{"id":"26805","name":"Tundra Kavu","mana":["2","R"],"cmc":"3","type":["Creature
44
+ ","Kavu"],"text":["{tap} : Target land becomes a Plains or an Island until
45
+ end of turn."],"flavor":[["A cross between a jaguar and an armadillo."]],"power":"2","toughness":"2","loyalty":"","watermark":"","set":"Apocalypse","rarity":"Common","prints":[],"number":"71","artist":"Matt
46
+ Cavotta"},{"id":"129604","name":"Tundra Wolves","mana":["W"],"cmc":"1","type":["Creature
47
+ ","Wolf"],"text":["First strike (This creature deals combat damage before
48
+ creatures without first strike.)"],"flavor":[["\"I heard their eerie howling,
49
+ the wolves calling their kindred across the frozen plains.\"","\u2014Onean
50
+ scout"]],"power":"1","toughness":"1","loyalty":"","watermark":"","set":"Tenth
51
+ Edition","rarity":"Common","prints":[{"set":"4E","id":"2368"},{"set":"5E","id":"4163"},{"set":"6E","id":"11543"},{"set":"8ED","id":"45167"},{"set":"10E","id":"129604"},{"set":"LE","id":"1638"}],"number":"54","artist":"Richard
52
+ Sardinha"}]'
53
+ http_version:
54
+ recorded_at: Sat, 12 Oct 2013 01:53:21 GMT
55
+ recorded_with: VCR 2.6.0
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://mtgapi.com/api/v1/fetch/id/1?token=invalid_token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 401
13
+ message: Unauthorized
14
+ headers:
15
+ Server:
16
+ - cloudflare-nginx
17
+ Date:
18
+ - Thu, 10 Oct 2013 03:33:14 GMT
19
+ Content-Type:
20
+ - application/json
21
+ Transfer-Encoding:
22
+ - chunked
23
+ Connection:
24
+ - keep-alive
25
+ Set-Cookie:
26
+ - __cfduid=d8ea748e60065c8d0d85445655ea1aa771381375994847; expires=Mon, 23-Dec-2019
27
+ 23:50:00 GMT; path=/; domain=.mtgapi.com
28
+ - laravel_session=csnig2rkejpdjbvc1544ip2mn5; expires=Thu, 10-Oct-2013 05:33:14
29
+ GMT; Max-Age=7200; path=/; HttpOnly
30
+ - laravel_session=csnig2rkejpdjbvc1544ip2mn5; expires=Thu, 10-Oct-2013 05:33:14
31
+ GMT; Max-Age=7200; path=/; httponly
32
+ X-Powered-By:
33
+ - PHP/5.5.4-1+debphp.org~precise+1
34
+ Cache-Control:
35
+ - no-cache
36
+ Cf-Ray:
37
+ - bb03f7fc65f0322
38
+ body:
39
+ encoding: UTF-8
40
+ string: '{"message":"API token error"}'
41
+ http_version:
42
+ recorded_at: Thu, 10 Oct 2013 03:33:15 GMT
43
+ recorded_with: VCR 2.6.0
@@ -0,0 +1,142 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://mtgapi.com/api/v1/fetch/invalid_url?token=valid_token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 404
13
+ message: Not Found
14
+ headers:
15
+ Server:
16
+ - cloudflare-nginx
17
+ Date:
18
+ - Fri, 11 Oct 2013 03:12:43 GMT
19
+ Content-Type:
20
+ - text/html; charset=UTF-8
21
+ Transfer-Encoding:
22
+ - chunked
23
+ Connection:
24
+ - keep-alive
25
+ Set-Cookie:
26
+ - __cfduid=d6b4fa30778611dd509c549112ecc46971381461163864; expires=Mon, 23-Dec-2019
27
+ 23:50:00 GMT; path=/; domain=.mtgapi.com; HttpOnly
28
+ Cf-Ray:
29
+ - bb85ed2247507d3
30
+ body:
31
+ encoding: UTF-8
32
+ string: |
33
+ <!DOCTYPE html>
34
+ <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
35
+ <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
36
+ <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
37
+ <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
38
+ <head>
39
+ <meta charset="utf-8">
40
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
41
+ <title>mtgapi.com | 404 - Page Cannot Be Found</title>
42
+ <meta name="robots" content="noindex, nofollow" />
43
+ <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
44
+ <link rel="stylesheet" href="/cdn-cgi/se/themes/core.css" />
45
+ <link rel="stylesheet" href="/cdn-cgi/se/themes/mountain-view/styles.css" />
46
+ <script src="/cdn-cgi/se/javascripts/modernizr.js"></script>
47
+ <script type="text/javascript">
48
+ //<![CDATA[
49
+ try{if (!window.CloudFlare) { var CloudFlare=[{verbose:0,p:1380869502,byc:0,owlid:"cf",bag2:1,mirage2:0,oracle:0,paths:{cloudflare:"/cdn-cgi/nexp/abv=1309062649/"},atok:"107150b695564d48a7a54874b39a0d9e",petok:"3ab877db569c0b77ba2b0e7893266c41-1381461163-1800",zone:"mtgapi.com",rocket:"0",apps:{}}];CloudFlare.push({"apps":{"ape":"61e19079e085ac75c6cbd7061298a9b7"}});var a=document.createElement("script"),b=document.getElementsByTagName("script")[0];a.async=!0;a.src="//ajax.cloudflare.com/cdn-cgi/nexp/abv=3224043168/cloudflare.min.js";b.parentNode.insertBefore(a,b);}}catch(e){};
50
+ //]]>
51
+ </script>
52
+
53
+ </head>
54
+ <body class="mountain-view simple">
55
+ <div class="smart-error">
56
+ <header>
57
+ <h1>The page you are looking for cannot be found.</h1>
58
+ <p>Similar results are provided below, or you can try another search</p>
59
+ </header>
60
+ <div class="main">
61
+ <div class="container search">
62
+ <form action="//blekko.com/ws/" method="GET" target="_blank">
63
+ <div class="query-input">
64
+ <input type="hidden" name="source" value="e8802460">
65
+ <input type="hidden" name="param1" value="mtgapi.com">
66
+ <input type="text" name="q">
67
+ </div>
68
+ <div class="buttons">
69
+ <div class="site button"><span>Search site</span></div>
70
+ <div class="web button"><input type="submit" value="Search web"></div>
71
+ </div>
72
+ </form>
73
+ </div>
74
+ <div class="container content">
75
+ <div class="fallback-content">
76
+ <h2>To find the missing content, try these steps:</h2>
77
+ <ol>
78
+ <li>Visit the domain home page</li>
79
+ <li><a rel="nofollow" href="." target="_self">Reload this page</a></li>
80
+ <li>Search for the missing content with the search box above</li>
81
+ </ol>
82
+ </div>
83
+ <div class="loading-indicator">
84
+ <h2>Loading...</h2>
85
+ </div>
86
+ </div>
87
+ </div>
88
+ <footer>
89
+ <p>SmartErrors powered by <span><a rel="nofollow" href="https://www.cloudflare.com/">CloudFlare</a></span><span><a rel="nofollow" href="https://www.cloudflare.com/security-policy">Privacy policy</a></span></p>
90
+ </footer>
91
+ </div>
92
+
93
+ <script type="text/javascript">
94
+ CloudFlare.push(function(require, define) {
95
+
96
+ window.require = require;
97
+ window.define = define;
98
+
99
+ define.amd.jQuery = 1;
100
+
101
+ define('handlebars', ['/cdn-cgi/se/javascripts/handlebars.js'], function() {
102
+
103
+ return Handlebars;
104
+ });
105
+
106
+ require(['cloudflare/config'], function(config) {
107
+
108
+
109
+ if(config.zone == 'cloudflare.com') {
110
+
111
+ var gaId = '_gaq',
112
+ ga = window[gaId] = window[gaId] || [];
113
+
114
+ ga.push(['_setAccount', 'UA-10218544-8']);
115
+ ga.push(['_setDomainName', 'cloudflare.com']);
116
+ ga.push(['_trackPageview']);
117
+
118
+ (function() {
119
+ var gs = document.createElement('script'); gs.type = 'text/javascript'; gs.async = true;
120
+ gs.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
121
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gs, s);
122
+ })();
123
+ }
124
+ });
125
+
126
+ require.paths.smarterror =
127
+ require.paths.backbone =
128
+ require.paths.underscore =
129
+ require.paths.handlebars =
130
+ require.paths.jquery = '/cdn-cgi/se/javascripts';
131
+
132
+ require(['smarterror']);
133
+ });
134
+ </script>
135
+ <noscript>
136
+ <img src="/cdn-cgi/ping?cf[action]=load&cf[location]=smarterror&cf[js]=0" width="0" height="0">
137
+ </noscript>
138
+ </body>
139
+ </html>
140
+ http_version:
141
+ recorded_at: Fri, 11 Oct 2013 03:12:44 GMT
142
+ recorded_with: VCR 2.6.0
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://mtgapi.com/api/v1/fetch/id/1?token=valid_token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - cloudflare-nginx
17
+ Date:
18
+ - Thu, 10 Oct 2013 03:33:15 GMT
19
+ Content-Type:
20
+ - text/html; charset=UTF-8
21
+ Transfer-Encoding:
22
+ - chunked
23
+ Connection:
24
+ - keep-alive
25
+ Set-Cookie:
26
+ - __cfduid=dc6f86023b133013af162b9026fda941d1381375995251; expires=Mon, 23-Dec-2019
27
+ 23:50:00 GMT; path=/; domain=.mtgapi.com
28
+ - laravel_session=cjva2ph8p1el6f47cmnj4hfp83; expires=Thu, 10-Oct-2013 05:33:15
29
+ GMT; Max-Age=7200; path=/; HttpOnly
30
+ - laravel_session=cjva2ph8p1el6f47cmnj4hfp83; expires=Thu, 10-Oct-2013 05:33:15
31
+ GMT; Max-Age=7200; path=/; httponly
32
+ X-Powered-By:
33
+ - PHP/5.5.4-1+debphp.org~precise+1
34
+ Cache-Control:
35
+ - no-cache
36
+ Cf-Ray:
37
+ - bb03f825c0b0322
38
+ body:
39
+ encoding: UTF-8
40
+ string: '{"id":"1","name":"Ankh of Mishra","mana":["2"],"cmc":"2","type":["Artifact"],"text":["Whenever
41
+ a land enters the battlefield, Ankh of Mishra deals 2 damage to that land''s
42
+ controller."],"flavor":[],"power":"","toughness":"","loyalty":"","watermark":"","set":"Limited
43
+ Edition Alpha","rarity":"Rare","prints":[{"set":"1E","id":"1"},{"set":"2E","id":"296"},{"set":"2U","id":"598"},{"set":"3E","id":"1094"},{"set":"4E","id":"2017"},{"set":"5E","id":"3760"},{"set":"6E","id":"14771"},{"set":"MED","id":"159251"}],"number":"","artist":"Amy
44
+ Weber"}'
45
+ http_version:
46
+ recorded_at: Thu, 10 Oct 2013 03:33:15 GMT
47
+ recorded_with: VCR 2.6.0
@@ -0,0 +1,86 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe MTG::API::Card do
6
+ subject { MTG::API::Card }
7
+
8
+ describe 'when search card' do
9
+ context 'by id' do
10
+ let(:valid_card) { subject.find_by_id(1) }
11
+ let(:invalid_card) { subject.find_by_id(0) }
12
+
13
+ it 'with invalid id', vcr: { cassette_name: 'find_by_invalid_id' } do
14
+ expect(invalid_card).to respond_to(:Error)
15
+ end
16
+
17
+ it 'with valid id', vcr: { cassette_name: 'find_by_valid_id' } do
18
+ expect(valid_card).to_not respond_to(:Error)
19
+
20
+ expect(valid_card.id).to eql "1"
21
+ expect(valid_card.name).to eql "Ankh of Mishra"
22
+ expect(valid_card.mana).to eql ["2"]
23
+ expect(valid_card.cmc).to eql "2"
24
+ expect(valid_card.type).to eql ["Artifact"]
25
+ expect(valid_card.text).to eql ["Whenever a land enters the battlefield, Ankh of Mishra deals 2 damage to that land's controller."]
26
+ expect(valid_card.flavor).to be_empty
27
+ expect(valid_card.power).to be_empty
28
+ expect(valid_card.toughness).to be_empty
29
+ expect(valid_card.loyalty).to be_empty
30
+ expect(valid_card.watermark).to be_empty
31
+ expect(valid_card.set).to eql "Limited Edition Alpha"
32
+ expect(valid_card.rarity).to eql "Rare"
33
+ expect(valid_card.number).to be_empty
34
+ expect(valid_card.artist).to eql "Amy Weber"
35
+ expect(valid_card.prints).to eql [{"set" => "1E", "id" => "1"},
36
+ {"set" => "2E", "id" => "296"},
37
+ {"set" => "2U", "id" => "598"},
38
+ {"set" => "3E", "id" => "1094"},
39
+ {"set" => "4E", "id" => "2017"},
40
+ {"set" => "5E", "id" => "3760"},
41
+ {"set" => "6E", "id" => "14771"},
42
+ {"set" => "MED", "id" => "159251"}]
43
+ end
44
+ end
45
+
46
+ context 'by text' do
47
+ let(:valid_cards) { subject.find_by_text('tundra') }
48
+ let(:invalid_card) { subject.find_by_text('invalid-name') }
49
+
50
+ it 'with invalid card name', vcr: { cassette_name: 'find_by_invalid_text' } do
51
+ pending 'API is raising {"code":"500","error":"internal server error"} so far :('
52
+ expect(invalid_card).to raise_error(/500 - Internal Server Error/)
53
+ end
54
+
55
+ it 'with valid card name', vcr: { cassette_name: 'find_by_valid_text' } do
56
+ valid_card = valid_cards.first
57
+
58
+ expect(valid_cards).to have(3).cards
59
+
60
+ expect(valid_card).to_not respond_to(:Error)
61
+
62
+ expect(valid_card.id).to eql "202424"
63
+ expect(valid_card.name).to eql "Tundra"
64
+ expect(valid_card.mana).to be_empty
65
+ expect(valid_card.cmc).to be_empty
66
+ expect(valid_card.type).to eql ["Land ", "Plains Island"]
67
+ expect(valid_card.text).to be_empty
68
+ expect(valid_card.flavor).to be_empty
69
+ expect(valid_card.power).to be_empty
70
+ expect(valid_card.toughness).to be_empty
71
+ expect(valid_card.loyalty).to be_empty
72
+ expect(valid_card.watermark).to be_empty
73
+ expect(valid_card.set).to eql "Masters Edition IV"
74
+ expect(valid_card.rarity).to eql "Rare"
75
+ expect(valid_card.number).to eql "255"
76
+ expect(valid_card.artist).to eql "Jesper Myrfors"
77
+ expect(valid_card.prints).to eql [{"set" => "1E", "id" => "286"},
78
+ {"set" => "2E", "id" => "583"},
79
+ {"set" => "2U", "id" => "885"},
80
+ {"set" => "3E", "id" => "1383"},
81
+ {"set" => "ME2", "id" => "184751"},
82
+ {"set" => "ME4", "id" => "202424"}]
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe MTG::API::Config do
6
+ subject { described_class }
7
+
8
+ it "set token" do
9
+ subject.configure { |c| c.token = "123token" }
10
+
11
+ expect(subject.token).to eql "123token"
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe MTG::API::Request do
6
+ subject { MTG::API::Request }
7
+
8
+ context 'requests' do
9
+ describe 'valid url' do
10
+ it 'respond with 200', vcr: { cassette_name: 'valid_token' } do
11
+ expect { subject.get('/id/1') }.to_not raise_error
12
+ end
13
+
14
+ it 'respond with 401', vcr: { cassette_name: 'invalid_token' } do
15
+ MTG::API::Config.configure { |c| c.token = 'invalid_token' }
16
+
17
+ expect { subject.get('/id/1') }.to raise_error(/401 - Unauthorized/)
18
+ end
19
+
20
+ it 'respond with 404', vcr: { cassette_name: 'invalid_url' } do
21
+ expect { subject.get('/invalid_url') }.to raise_error(/404 - Not Found/)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ require 'mtg-api'
2
+ require 'vcr'
3
+
4
+ Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+ config.order = 'random'
11
+
12
+ config.expect_with :rspec do |c|
13
+ c.syntax = :expect
14
+ end
15
+
16
+ config.before(:each) do
17
+ MTG::API::Config.configure do |c|
18
+ c.token = 'valid_token'
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ VCR.configure do |c|
2
+ c.configure_rspec_metadata!
3
+ c.cassette_library_dir = 'spec/fixtures/cassettes'
4
+ c.default_cassette_options = { :record => :once }
5
+ c.allow_http_connections_when_no_cassette = false
6
+ c.hook_into :webmock
7
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mtg-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eduardo Maia
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: hashie
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '2.14'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '2.14'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 2.6.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 2.6.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: '1.14'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: '1.14'
125
+ description: 'Magic: The Gathering Ruby Client'
126
+ email:
127
+ - eduvimaia@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .rspec
134
+ - .travis.yml
135
+ - Gemfile
136
+ - LICENSE
137
+ - README.md
138
+ - Rakefile
139
+ - lib/mtg-api.rb
140
+ - lib/mtg-api/card.rb
141
+ - lib/mtg-api/config.rb
142
+ - lib/mtg-api/request.rb
143
+ - lib/mtg-api/version.rb
144
+ - mtg-api.gemspec
145
+ - spec/fixtures/cassettes/find_by_invalid_id.yml
146
+ - spec/fixtures/cassettes/find_by_invalid_text.yml
147
+ - spec/fixtures/cassettes/find_by_valid_id.yml
148
+ - spec/fixtures/cassettes/find_by_valid_text.yml
149
+ - spec/fixtures/cassettes/invalid_token.yml
150
+ - spec/fixtures/cassettes/invalid_url.yml
151
+ - spec/fixtures/cassettes/valid_token.yml
152
+ - spec/mtg-api/card_spec.rb
153
+ - spec/mtg-api/config_spec.rb
154
+ - spec/mtg-api/request_spec.rb
155
+ - spec/spec_helper.rb
156
+ - spec/support/vcr.rb
157
+ homepage: http://github.com/musttache/mtg-api
158
+ licenses:
159
+ - MIT
160
+ metadata: {}
161
+ post_install_message:
162
+ rdoc_options: []
163
+ require_paths:
164
+ - lib
165
+ required_ruby_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '1.9'
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ requirements: []
176
+ rubyforge_project:
177
+ rubygems_version: 2.1.5
178
+ signing_key:
179
+ specification_version: 4
180
+ summary: 'Magic: The Gathering Ruby Client'
181
+ test_files:
182
+ - spec/fixtures/cassettes/find_by_invalid_id.yml
183
+ - spec/fixtures/cassettes/find_by_invalid_text.yml
184
+ - spec/fixtures/cassettes/find_by_valid_id.yml
185
+ - spec/fixtures/cassettes/find_by_valid_text.yml
186
+ - spec/fixtures/cassettes/invalid_token.yml
187
+ - spec/fixtures/cassettes/invalid_url.yml
188
+ - spec/fixtures/cassettes/valid_token.yml
189
+ - spec/mtg-api/card_spec.rb
190
+ - spec/mtg-api/config_spec.rb
191
+ - spec/mtg-api/request_spec.rb
192
+ - spec/spec_helper.rb
193
+ - spec/support/vcr.rb
194
+ has_rdoc: