Class: GW2API::Endpoint
- Inherits:
-
Object
show all
- Defined in:
- lib/endpoint.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Endpoint.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/endpoint.rb', line 5
def initialize
@url = GW2API::BASE_URL
@bulk_expandable = false
@bulk_expandable_all = false
@paginated = false
@localized = false
@authenticated = false
@authenticated_optional = false
end
|
Instance Method Details
#all ⇒ Object
36
37
38
39
|
# File 'lib/endpoint.rb', line 36
def all
return nil unless @bulk_expandable_all
api_call("#{@url}?ids=all")
end
|
#api_call(url) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/endpoint.rb', line 41
def api_call(url)
request = Typhoeus::Request.new(url)
request.on_complete do |resp|
if resp.success?
return JSON.parse(resp.body, object_class: OpenStruct)
else
return nil
end
end
request.run
end
|
#get(id = nil) ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/endpoint.rb', line 27
def get(id = nil)
return nil if id.nil? && @bulk_expandable
if id.kind_of?(Array)
api_call("#{@url}?ids=#{id.join(',')}")
else
api_call("#{@url}/#{id}")
end
end
|
#ids ⇒ Object
22
23
24
25
|
# File 'lib/endpoint.rb', line 22
def ids
return nil unless @bulk_expandable
api_call "#{@url}?ids=all"
end
|