mkmapi 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +53 -0
- data/Gemfile +13 -0
- data/LICENSE +21 -0
- data/README +50 -0
- data/Rakefile +25 -0
- data/lib/mkmapi.rb +29 -0
- data/lib/mkmapi/agent.rb +43 -0
- data/lib/mkmapi/base.rb +15 -0
- data/lib/mkmapi/marketplace.rb +80 -0
- data/lib/mkmapi/session.rb +11 -0
- data/lib/version.rb +3 -0
- data/mkmapi.gemspec +26 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eb509794597cb8728ac0d9b6e3b02ca6e03d8a73
|
4
|
+
data.tar.gz: 5d0795b70d3882b11c5eca1efbada41cb8727ba5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7ca71c199f0ffefd352bb8d12c54ffb69dabe02b09aa55c0fc4bc64f4461d700d0e80248aa41ffb17e93f05f9565db898d1d6d8def56ecf9b0a496379886bb83
|
7
|
+
data.tar.gz: b400116ef03ae6fb331e92d1a0385a447d9e196316266ee3dc6ec44365fe2899702e74001f22c0d87c9450a2ba8fe640883b1e7c29032072a98286b6057815ff
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
Gemfile.lock
|
2
|
+
|
3
|
+
# rcov generated
|
4
|
+
coverage
|
5
|
+
coverage.data
|
6
|
+
|
7
|
+
# rdoc generated
|
8
|
+
rdoc
|
9
|
+
|
10
|
+
# yard generated
|
11
|
+
doc
|
12
|
+
.yardoc
|
13
|
+
|
14
|
+
# bundler
|
15
|
+
.bundle
|
16
|
+
|
17
|
+
# jeweler generated
|
18
|
+
pkg
|
19
|
+
|
20
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
21
|
+
#
|
22
|
+
# * Create a file at ~/.gitignore
|
23
|
+
# * Include files you want ignored
|
24
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
25
|
+
#
|
26
|
+
# After doing this, these files will be ignored in all your git projects,
|
27
|
+
# saving you from having to 'pollute' every project you touch with them
|
28
|
+
#
|
29
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
30
|
+
#
|
31
|
+
# For MacOS:
|
32
|
+
#
|
33
|
+
#.DS_Store
|
34
|
+
|
35
|
+
# For TextMate
|
36
|
+
#*.tmproj
|
37
|
+
#tmtags
|
38
|
+
|
39
|
+
# For emacs:
|
40
|
+
#*~
|
41
|
+
#\#*
|
42
|
+
#.\#*
|
43
|
+
|
44
|
+
# For vim:
|
45
|
+
#*.swp
|
46
|
+
|
47
|
+
# For redcar:
|
48
|
+
#.redcar
|
49
|
+
|
50
|
+
# For rubinius:
|
51
|
+
#*.rbc
|
52
|
+
|
53
|
+
.gems
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Arjen
|
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.
|
data/README
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
= Mkmapi
|
2
|
+
|
3
|
+
Ruby interface to the magiccardmarket.eu API.
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
You'll need an OAuth credentials for a dedicated app from Mkmapi.
|
8
|
+
|
9
|
+
Use with bundler
|
10
|
+
|
11
|
+
gem 'mkmapi', github: 'cybey/mkmapi'
|
12
|
+
|
13
|
+
Create a session
|
14
|
+
|
15
|
+
session = Mkmapi.auth({
|
16
|
+
consumer_key: "xxxx",
|
17
|
+
consumer_secret: "xxxx",
|
18
|
+
token: "xxxx",
|
19
|
+
token_secret: "xxxx",
|
20
|
+
})
|
21
|
+
|
22
|
+
Retrieve your account's data
|
23
|
+
|
24
|
+
me = session.account # => Mkmapi::Account
|
25
|
+
me.id # => 1234
|
26
|
+
me.username # => 'your_user_name'
|
27
|
+
|
28
|
+
== TODO
|
29
|
+
|
30
|
+
* domain models
|
31
|
+
* documentation
|
32
|
+
* Account Management
|
33
|
+
* Market Place Information (partially)
|
34
|
+
* Order Management
|
35
|
+
* Shopping Cart Manipulation
|
36
|
+
* Stock Management
|
37
|
+
* Wants List Management
|
38
|
+
|
39
|
+
== Contributing to Mkmapi
|
40
|
+
|
41
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
42
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
43
|
+
* Fork the project.
|
44
|
+
* Start a feature/bugfix branch.
|
45
|
+
* Commit and push until you are happy with your contribution.
|
46
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
47
|
+
|
48
|
+
== Contributors
|
49
|
+
|
50
|
+
Based on the work done by knaveofdiamonds.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
|
6
|
+
begin
|
7
|
+
Bundler.setup(:default, :development)
|
8
|
+
rescue Bundler::BundlerError => e
|
9
|
+
$stderr.puts e.message
|
10
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
11
|
+
exit e.status_code
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
desc "Code coverage detail"
|
16
|
+
task :simplecov do
|
17
|
+
ENV['COVERAGE'] = "true"
|
18
|
+
Rake::Task['spec'].execute
|
19
|
+
end
|
20
|
+
|
21
|
+
task :console do
|
22
|
+
exec "irb -r mkmapi -I ./lib"
|
23
|
+
end
|
24
|
+
|
25
|
+
task :default => :spec
|
data/lib/mkmapi.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'faraday'
|
3
|
+
|
4
|
+
module Mkmapi
|
5
|
+
|
6
|
+
path = ->(basename) {
|
7
|
+
File.expand_path File.join('..', 'mkmapi', basename), __FILE__
|
8
|
+
}
|
9
|
+
autoload :Agent, path['agent']
|
10
|
+
autoload :Session, path['session']
|
11
|
+
autoload :Base, path['base']
|
12
|
+
autoload :Account, path['account']
|
13
|
+
autoload :Marketplace, path['marketplace']
|
14
|
+
|
15
|
+
def self.connect(url = 'https://www.mkmapi.eu/ws/v2.0')
|
16
|
+
@connection = Faraday.new url, ssl: { verify: false } do |faraday|
|
17
|
+
# faraday.response :logger
|
18
|
+
faraday.adapter Faraday.default_adapter
|
19
|
+
end
|
20
|
+
end
|
21
|
+
def self.connection
|
22
|
+
@connection ||= connect
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.auth(params)
|
26
|
+
Session.new connection, params
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/lib/mkmapi/agent.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'simple_oauth'
|
2
|
+
require 'oj'
|
3
|
+
|
4
|
+
module Mkmapi
|
5
|
+
class Agent < Struct.new(:connection, :auth)
|
6
|
+
|
7
|
+
attr_reader :last
|
8
|
+
|
9
|
+
def get(path)
|
10
|
+
process(:get, path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def put(path, body)
|
14
|
+
raise NotImplementedError
|
15
|
+
end
|
16
|
+
def post(path, body)
|
17
|
+
raise NotImplementedError
|
18
|
+
end
|
19
|
+
def delete(path)
|
20
|
+
raise NotImplementedError
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def process(method, path)
|
26
|
+
json_path = "output.json/#{ path }"
|
27
|
+
endpoint = connection.url_prefix.to_s + "/" + json_path
|
28
|
+
|
29
|
+
@last = connection.send(method, json_path, {}, authorization: oauth(method, endpoint))
|
30
|
+
Oj.load(@last.body)
|
31
|
+
end
|
32
|
+
|
33
|
+
def oauth(method, url, options = {}, query = {})
|
34
|
+
header = SimpleOAuth::Header.new(method, url, options, auth)
|
35
|
+
|
36
|
+
signed_attributes = { realm: url }.update(header.signed_attributes)
|
37
|
+
attributes = signed_attributes.map { |(k, v)| %(#{k}="#{v}") }
|
38
|
+
|
39
|
+
"OAuth #{ attributes * ', ' }"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/lib/mkmapi/base.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require 'zlib'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
module Mkmapi
|
6
|
+
class Marketplace < Struct.new(:agent)
|
7
|
+
|
8
|
+
def priceguide
|
9
|
+
json_data = agent.get("priceguide")
|
10
|
+
|
11
|
+
if (json_data && json_data["priceguidefile"])
|
12
|
+
data = Base64.decode64(json_data["priceguidefile"])
|
13
|
+
gzip = Zlib::GzipReader.new(StringIO.new(data))
|
14
|
+
|
15
|
+
keys = ['id', 'average', 'low', 'trend', 'suggested', 'foil', 'foil_low', 'foil_trend' ]
|
16
|
+
skip_first = gzip.readline # Skip the header
|
17
|
+
|
18
|
+
CSV.parse(gzip.read).map do |a|
|
19
|
+
item = keys.zip(a.map(&:to_f))
|
20
|
+
item[0][1] = item[0][1].to_i
|
21
|
+
|
22
|
+
Hash[ item ]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def productlist
|
28
|
+
json_data = agent.get("productlist")
|
29
|
+
|
30
|
+
if (json_data && json_data["productsfile"])
|
31
|
+
data = Base64.decode64(json_data["productsfile"])
|
32
|
+
gzip = Zlib::GzipReader.new(StringIO.new(data))
|
33
|
+
|
34
|
+
keys = ['id', 'name', 'category_id', 'category', 'expansion_id', 'metacard_id', 'date_added' ]
|
35
|
+
skip_first = gzip.readline # Skip the header
|
36
|
+
|
37
|
+
CSV.parse(gzip.read).map do |a|
|
38
|
+
item = keys.zip(a)
|
39
|
+
item[0][1] = item[0][1].to_i
|
40
|
+
item[2][1] = item[2][1].to_i
|
41
|
+
item[4][1] = item[4][1].to_i
|
42
|
+
item[5][1] = item[5][1].to_i
|
43
|
+
Hash[ item ]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def expansions(game_id = 1)
|
49
|
+
agent.get("games/#{game_id}/expansions")['expansion'].
|
50
|
+
each {|g| g['id'] = g.delete('idExpansion') }
|
51
|
+
end
|
52
|
+
|
53
|
+
def singles(expansion_id = 1)
|
54
|
+
agent.get("expansions/#{expansion_id}/singles")
|
55
|
+
end
|
56
|
+
|
57
|
+
def games
|
58
|
+
agent.get("games")['game'].
|
59
|
+
each {|g| g['id'] = g.delete('idGame') }
|
60
|
+
end
|
61
|
+
|
62
|
+
def card_by_name(name, game_id = 1, language_id = 1)
|
63
|
+
product(name, game_id, language_id, true)
|
64
|
+
end
|
65
|
+
|
66
|
+
def search(name, game_id = 1, language_id = 1)
|
67
|
+
product(name, game_id, language_id, false)
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def product(name, game_id, language_id, search)
|
73
|
+
clean_name = URI.escape(name.gsub(/[^a-zA-Z0-9 ]/, '').downcase)
|
74
|
+
path = ["products", clean_name, game_id, language_id, search].join("/")
|
75
|
+
|
76
|
+
agent.get(path)['product']
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
data/lib/version.rb
ADDED
data/mkmapi.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Arjen Brandenburgh"]
|
6
|
+
gem.email = ["arjen.brandenburgh@gmail.com"]
|
7
|
+
gem.summary = "Simple MagicCardMarket API v2.0 (MkmapiAPI) library for Ruby"
|
8
|
+
gem.description = "Simple MagicCardMarket API v2.0 (MkmapiAPI) library for Ruby"
|
9
|
+
gem.homepage = "http://githib.com/cybey/mkmapi"
|
10
|
+
gem.license = "MIT"
|
11
|
+
|
12
|
+
gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
13
|
+
gem.test_files = `git ls-files -- test/*`.split("\n")
|
14
|
+
gem.name = "mkmapi"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Mkmapi::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'faraday', '~> 0.11'
|
19
|
+
gem.add_dependency 'oj', '~> 2.18'
|
20
|
+
gem.add_dependency 'simple_oauth', '~> 0.3'
|
21
|
+
|
22
|
+
gem.add_development_dependency 'rspec'
|
23
|
+
gem.add_development_dependency 'rdoc'
|
24
|
+
gem.add_development_dependency 'bundler'
|
25
|
+
gem.add_development_dependency 'simplecov'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mkmapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arjen Brandenburgh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.11'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: oj
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.18'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.18'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simple_oauth
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
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: rdoc
|
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: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Simple MagicCardMarket API v2.0 (MkmapiAPI) library for Ruby
|
112
|
+
email:
|
113
|
+
- arjen.brandenburgh@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".DS_Store"
|
119
|
+
- ".gitignore"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE
|
122
|
+
- README
|
123
|
+
- Rakefile
|
124
|
+
- lib/mkmapi.rb
|
125
|
+
- lib/mkmapi/agent.rb
|
126
|
+
- lib/mkmapi/base.rb
|
127
|
+
- lib/mkmapi/marketplace.rb
|
128
|
+
- lib/mkmapi/session.rb
|
129
|
+
- lib/version.rb
|
130
|
+
- mkmapi.gemspec
|
131
|
+
homepage: http://githib.com/cybey/mkmapi
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.5.2
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Simple MagicCardMarket API v2.0 (MkmapiAPI) library for Ruby
|
155
|
+
test_files: []
|