Class: Mtgapi::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mtgapi/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token = ENV['MTG_TOKEN']) ⇒ Client

Returns a new instance of Client.



11
12
13
# File 'lib/mtgapi/client.rb', line 11

def initialize(token = ENV['MTG_TOKEN'])
  @token = token
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



9
10
11
# File 'lib/mtgapi/client.rb', line 9

def token
  @token
end

Instance Method Details

#find_by(attr, value) ⇒ Object



19
20
21
22
# File 'lib/mtgapi/client.rb', line 19

def find_by(attr, value)
  url = self.send("#{attr.to_s}_url", value)
  self.class.get(url).parsed_response
end

#id_url(id) ⇒ Object



24
25
26
# File 'lib/mtgapi/client.rb', line 24

def id_url(id)
  "/card/id/#{id}"
end

#name_url(name) ⇒ Object



28
29
30
# File 'lib/mtgapi/client.rb', line 28

def name_url(name)
  "/card/name/#{name}"
end

#set_url(set) ⇒ Object



32
33
34
# File 'lib/mtgapi/client.rb', line 32

def set_url(set)
  "/card/set/#{set}"
end

#setsObject



15
16
17
# File 'lib/mtgapi/client.rb', line 15

def sets
  self.class.get("/list/sets").parsed_response
end

#token_appendObject



36
37
38
# File 'lib/mtgapi/client.rb', line 36

def token_append
  "?token=#{token}"
end