Class: CitizenCodeScripts::Pivotal

Inherits:
Object
  • Object
show all
Defined in:
lib/citizen_code_scripts/begin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Pivotal

Returns a new instance of Pivotal.



8
9
10
# File 'lib/citizen_code_scripts/begin.rb', line 8

def initialize(token)
  @token = token
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/citizen_code_scripts/begin.rb', line 6

def token
  @token
end

Instance Method Details

#request(url, method: "GET", body: nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/citizen_code_scripts/begin.rb', line 12

def request(url, method: "GET", body: nil)
  cmd = %Q{curl --silent -X #{method} -H "X-TrackerToken: #{token}"}
  cmd += %Q{ -H "Content-Type: application/json"}

  if body
    cmd += %Q{ -d '#{body}'}
  end

  cmd += %Q{ "#{url}"}

  result = `#{cmd}`

  JSON.parse(result.strip)
end