Class: GW2API::Endpoint
- Inherits:
-
Object
show all
- Defined in:
- lib/endpoint.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Endpoint.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/endpoint.rb', line 7
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
38
39
40
41
|
# File 'lib/endpoint.rb', line 38
def all
return nil unless @bulk_expandable_all
api_call("#{@url}?ids=all")
end
|
#api_call(url) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/endpoint.rb', line 43
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
29
30
31
32
33
34
35
36
|
# File 'lib/endpoint.rb', line 29
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
24
25
26
27
|
# File 'lib/endpoint.rb', line 24
def ids
return nil unless @bulk_expandable
api_call "#{@url}?ids=all"
end
|