Class: ConveyClient::Request
- Inherits:
-
Object
- Object
- ConveyClient::Request
- Defined in:
- lib/convey_client/request.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(path) ⇒ Request
constructor
A new instance of Request.
- #url ⇒ Object
Constructor Details
#initialize(path) ⇒ Request
Returns a new instance of Request.
7 8 9 |
# File 'lib/convey_client/request.rb', line 7 def initialize(path) self.path = path end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/convey_client/request.rb', line 5 def path @path end |
Class Method Details
.execute(path) ⇒ Object
11 12 13 |
# File 'lib/convey_client/request.rb', line 11 def self.execute(path) new(path).execute end |
Instance Method Details
#execute ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/convey_client/request.rb', line 15 def execute return ConveyClient.cached_response(path) if ConveyClient.cached?(path) response = Net::HTTP.get_response(url) if response.code.to_i == 200 ConveyClient.cache(path, response.body) response.body else if ConveyClient.raise_request_errors raise ConveyClient::RequestError, "#{url} - #{response.code}" else "[]" end end end |
#url ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/convey_client/request.rb', line 31 def url return @url unless @url.nil? full_url = ConveyClient.base_url + path if (auth_token = ConveyClient.auth_token) full_url += full_url.include?("?") ? "&" : "?" full_url += "token=#{auth_token}" end @url = URI.parse(full_url) end |