Module: TicketingHub::Request
- Included in:
- Client
- Defined in:
- lib/ticketing_hub/request.rb
Instance Method Summary collapse
- #delete(path, options = {}) ⇒ Object
- #get(path, options = {}) ⇒ Object
- #patch(path, options = {}) ⇒ Object
- #post(path, options = {}) ⇒ Object
- #put(path, options = {}) ⇒ Object
- #request(method, path, options = {}) ⇒ Object
Instance Method Details
#delete(path, options = {}) ⇒ Object
7 8 9 |
# File 'lib/ticketing_hub/request.rb', line 7 def delete(path, ={}) request(:delete, path, ).body end |
#get(path, options = {}) ⇒ Object
11 12 13 |
# File 'lib/ticketing_hub/request.rb', line 11 def get(path, ={}) TicketingHub::Collection.new self, path, end |
#patch(path, options = {}) ⇒ Object
15 16 17 |
# File 'lib/ticketing_hub/request.rb', line 15 def patch(path, ={}) request(:patch, path, ).body end |
#post(path, options = {}) ⇒ Object
19 20 21 |
# File 'lib/ticketing_hub/request.rb', line 19 def post(path, ={}) request(:post, path, ).body end |
#put(path, options = {}) ⇒ Object
23 24 25 |
# File 'lib/ticketing_hub/request.rb', line 23 def put(path, ={}) request(:put, path, ).body end |
#request(method, path, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ticketing_hub/request.rb', line 27 def request(method, path, ={}) force_urlencoded = .delete(:force_urlencoded) || false url = .delete(:endpoint) || api_endpoint = { force_urlencoded: force_urlencoded, url: url } connection().send(method) do |request| case method when :get, :delete, :head request.url(path, ) when :patch, :post, :put request.path = path request.body = force_urlencoded ? : MultiJson.dump() unless .empty? end request.headers['Host'] = TicketingHub.request_host if TicketingHub.request_host end rescue TicketingHub::Unauthorized => e if refresh_token.present? && e.response_body == ' ' body = post '/oauth/token', { grant_type: 'refresh_token', refresh_token: refresh_token, client_id: client_id, client_secret: client_secret } self.refresh_token = body.refresh_token self.access_token = body.access_token self.expires_at = Time.now + body.expires_in.to_i request(method, path, ) else throw e end end |