Class: TF2R::API
- Inherits:
-
Object
- Object
- TF2R::API
- Defined in:
- lib/tf2r/api.rb
Overview
This class handles interaction with TF2R’s “API”, which is really just an open endpoint located at tf2r.com/job.php, in use all over the site for dynamically updating pages.
Constant Summary collapse
- HOST =
'http://tf2r.com'- ENDPOINT =
'/job.php'- MAX_ENTRY_RESPONSE_COUNT =
newentry on a checkraffle job can only return up to 2500 entries. This is a problem for any raffles with a maximum entries greater than 2500.
2500
Class Method Summary collapse
-
.raffle_info(link_snippet) ⇒ Array
Queries the API for information about a raffle.
-
.request(params) ⇒ Object
Submits a request to job.php with the given params.
Class Method Details
.raffle_info(link_snippet) ⇒ Array
Queries the API for information about a raffle.
28 29 30 31 32 |
# File 'lib/tf2r/api.rb', line 28 def self.raffle_info(link_snippet) params = {checkraffle: true, rid: link_snippet[1..-1], lastentrys: 0, lastchat: 0} request(params)['message'] end |
.request(params) ⇒ Object
Submits a request to job.php with the given params. TODO: should this do something with the responses headers?
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tf2r/api.rb', line 38 def self.request(params) uri = URI.parse(HOST) http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(ENDPOINT) request.body = URI.encode_www_form(params) response = http.request(request).body JSON.parse(response) end |