Class: Yapt::Request
- Inherits:
-
Object
- Object
- Yapt::Request
- Defined in:
- lib/yapt/request.rb
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path, params = {}, method = :get) ⇒ Request
constructor
A new instance of Request.
- #request(method, payload) ⇒ Object
- #result ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(path, params = {}, method = :get) ⇒ Request
Returns a new instance of Request.
7 8 9 |
# File 'lib/yapt/request.rb', line 7 def initialize(path, params = {}, method = :get) @method, @path, @params = method, path, params end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
6 7 8 |
# File 'lib/yapt/request.rb', line 6 def method @method end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'lib/yapt/request.rb', line 6 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/yapt/request.rb', line 6 def path @path end |
Class Method Details
.base_url ⇒ Object
40 41 42 43 |
# File 'lib/yapt/request.rb', line 40 def self.base_url "https://www.pivotaltracker.com/ services/v5/projects/#{Yapt.project_id}".gsub(/\s+/,'') end |
Instance Method Details
#request(method, payload) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/yapt/request.rb', line 15 def request(method, payload) = { "X-TrackerToken" => Yapt.api_token, "Content-Type" => "application/json" } response_handling = ->(response, request, result, &block) { case response.code when 200 JSON.parse(response.to_s) else puts "Non-200 response!" puts response.to_s end } if method == :get RestClient.get(url, .merge(params: payload), &response_handling) else RestClient.send(method, url, payload, , &response_handling) end end |
#result ⇒ Object
11 12 13 |
# File 'lib/yapt/request.rb', line 11 def result request(method, params) end |
#url ⇒ Object
36 37 38 |
# File 'lib/yapt/request.rb', line 36 def url "#{self.class.base_url}/#{path}" end |