Class: Rito::ApiBase

Inherits:
Object
  • Object
show all
Defined in:
lib/rito/api_base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ ApiBase

Returns a new instance of ApiBase


4
5
6
# File 'lib/rito/api_base.rb', line 4

def initialize(attributes = {})
	self.attributes = attributes
end

Class Method Details

.call_api(url, params = {}) ⇒ Object


21
22
23
24
# File 'lib/rito/api_base.rb', line 21

def call_api(url, params = {})
	response = Rito::Request.get(url + parameterize(params))
	check_code(response)
end

.from_list(arr) ⇒ Object


26
27
28
# File 'lib/rito/api_base.rb', line 26

def from_list(arr)
	arr.map{ |x| self.new(x) }
end

.from_map(dict) ⇒ Object


30
31
32
33
34
35
36
# File 'lib/rito/api_base.rb', line 30

def from_map(dict)
	new_dict = dict.dup
	dict.each do |key, value|
		new_dict[key] = self.new(value)
	end
	new_dict
end

.from_map_of_lists(dict) ⇒ Object


38
39
40
41
42
43
44
# File 'lib/rito/api_base.rb', line 38

def from_map_of_lists(dict)
	new_dict = dict.dup
	dict.each do |key, value|
		new_dict[key] = from_list(value)
	end
	new_dict
end

Instance Method Details

#attributes=(attributes) ⇒ Object


8
9
10
11
12
13
# File 'lib/rito/api_base.rb', line 8

def attributes=(attributes)
  attributes ||= {}
  attributes.each_pair do |name, value|
    send("#{name}=", value) if respond_to?("#{name}=")
  end
end