Class: SWGEM::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/swgem/base.rb

Direct Known Subclasses

Films, People, Planets, Species, Starships, Vehicles

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



3
4
5
6
7
8
# File 'lib/swgem/base.rb', line 3

def initialize
  @conn = Faraday.new(:url => BASE_URL) do |faraday|
    faraday.request :url_encoded
    faraday.adapter Faraday.default_adapter
  end
end

Instance Method Details

#allObject



10
11
12
# File 'lib/swgem/base.rb', line 10

def all
  (JSON.parse((conn.get "#{class_name}/").body))["results"]
end

#by_id(id) ⇒ Object



14
15
16
# File 'lib/swgem/base.rb', line 14

def by_id(id)
  JSON.parse((conn.get "#{class_name}/#{id}/").body)
end

#search(str) ⇒ Object



23
24
25
# File 'lib/swgem/base.rb', line 23

def search(str)
  (JSON.parse((conn.get "#{class_name}/?search=#{str}").body))["results"]
end

#validate_api_statusObject



19
20
21
# File 'lib/swgem/base.rb', line 19

def validate_api_status
  (conn.get "#{class_name}/").status
end